mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-21 09:17:53 +00:00
Sync upstream Gemini-CLI v0.8.2 (#838)
This commit is contained in:
@@ -4,18 +4,25 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
||||
import {
|
||||
describe,
|
||||
it,
|
||||
expect,
|
||||
vi,
|
||||
beforeEach,
|
||||
afterEach,
|
||||
type Mock,
|
||||
} from 'vitest';
|
||||
import { GitService } from './gitService.js';
|
||||
import { Storage } from '../config/storage.js';
|
||||
import * as path from 'node:path';
|
||||
import * as fs from 'node:fs/promises';
|
||||
import * as os from 'node:os';
|
||||
import type { ChildProcess } from 'node:child_process';
|
||||
import { getProjectHash, QWEN_DIR } from '../utils/paths.js';
|
||||
import { spawnAsync } from '../utils/shell-utils.js';
|
||||
|
||||
const hoistedMockExec = vi.hoisted(() => vi.fn());
|
||||
vi.mock('node:child_process', () => ({
|
||||
exec: hoistedMockExec,
|
||||
vi.mock('../utils/shell-utils.js', () => ({
|
||||
spawnAsync: vi.fn(),
|
||||
}));
|
||||
|
||||
const hoistedMockEnv = vi.hoisted(() => vi.fn());
|
||||
@@ -69,13 +76,9 @@ describe('GitService', () => {
|
||||
|
||||
vi.clearAllMocks();
|
||||
hoistedIsGitRepositoryMock.mockReturnValue(true);
|
||||
hoistedMockExec.mockImplementation((command, callback) => {
|
||||
if (command === 'git --version') {
|
||||
callback(null, 'git version 2.0.0');
|
||||
} else {
|
||||
callback(new Error('Command not mocked'));
|
||||
}
|
||||
return {};
|
||||
(spawnAsync as Mock).mockResolvedValue({
|
||||
stdout: 'git version 2.0.0',
|
||||
stderr: '',
|
||||
});
|
||||
|
||||
hoistedMockHomedir.mockReturnValue(homedir);
|
||||
@@ -120,13 +123,11 @@ describe('GitService', () => {
|
||||
it('should resolve true if git --version command succeeds', async () => {
|
||||
const service = new GitService(projectRoot, storage);
|
||||
await expect(service.verifyGitAvailability()).resolves.toBe(true);
|
||||
expect(spawnAsync).toHaveBeenCalledWith('git', ['--version']);
|
||||
});
|
||||
|
||||
it('should resolve false if git --version command fails', async () => {
|
||||
hoistedMockExec.mockImplementation((command, callback) => {
|
||||
callback(new Error('git not found'));
|
||||
return {} as ChildProcess;
|
||||
});
|
||||
(spawnAsync as Mock).mockRejectedValue(new Error('git not found'));
|
||||
const service = new GitService(projectRoot, storage);
|
||||
await expect(service.verifyGitAvailability()).resolves.toBe(false);
|
||||
});
|
||||
@@ -134,10 +135,7 @@ describe('GitService', () => {
|
||||
|
||||
describe('initialize', () => {
|
||||
it('should throw an error if Git is not available', async () => {
|
||||
hoistedMockExec.mockImplementation((command, callback) => {
|
||||
callback(new Error('git not found'));
|
||||
return {} as ChildProcess;
|
||||
});
|
||||
(spawnAsync as Mock).mockRejectedValue(new Error('git not found'));
|
||||
const service = new GitService(projectRoot, storage);
|
||||
await expect(service.initialize()).rejects.toThrow(
|
||||
'Checkpointing is enabled, but Git is not installed. Please install Git or disable checkpointing to continue.',
|
||||
|
||||
Reference in New Issue
Block a user