mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-20 16:57:46 +00:00
fix(checkpoint): Prevent silent failure and enable for non-Git projects (#4144)
This commit is contained in:
@@ -17,6 +17,7 @@ import {
|
||||
createContentGeneratorConfig,
|
||||
} from '../core/contentGenerator.js';
|
||||
import { GeminiClient } from '../core/client.js';
|
||||
import { GitService } from '../services/gitService.js';
|
||||
import { loadServerHierarchicalMemory } from '../utils/memoryDiscovery.js';
|
||||
|
||||
// Mock dependencies that might be called during Config construction or createServerConfig
|
||||
@@ -75,6 +76,12 @@ vi.mock('../telemetry/index.js', async (importOriginal) => {
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock('../services/gitService.js', () => {
|
||||
const GitServiceMock = vi.fn();
|
||||
GitServiceMock.prototype.initialize = vi.fn();
|
||||
return { GitService: GitServiceMock };
|
||||
});
|
||||
|
||||
describe('Server Config (config.ts)', () => {
|
||||
const MODEL = 'gemini-pro';
|
||||
const SANDBOX: SandboxConfig = {
|
||||
@@ -108,6 +115,32 @@ describe('Server Config (config.ts)', () => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
describe('initialize', () => {
|
||||
it('should throw an error if checkpointing is enabled and GitService fails', async () => {
|
||||
const gitError = new Error('Git is not installed');
|
||||
(GitService.prototype.initialize as Mock).mockRejectedValue(gitError);
|
||||
|
||||
const config = new Config({
|
||||
...baseParams,
|
||||
checkpointing: true,
|
||||
});
|
||||
|
||||
await expect(config.initialize()).rejects.toThrow(gitError);
|
||||
});
|
||||
|
||||
it('should not throw an error if checkpointing is disabled and GitService fails', async () => {
|
||||
const gitError = new Error('Git is not installed');
|
||||
(GitService.prototype.initialize as Mock).mockRejectedValue(gitError);
|
||||
|
||||
const config = new Config({
|
||||
...baseParams,
|
||||
checkpointing: false,
|
||||
});
|
||||
|
||||
await expect(config.initialize()).resolves.toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('refreshAuth', () => {
|
||||
it('should refresh auth and update config', async () => {
|
||||
const config = new Config(baseParams);
|
||||
|
||||
@@ -259,11 +259,7 @@ export class Config {
|
||||
// Initialize centralized FileDiscoveryService
|
||||
this.getFileService();
|
||||
if (this.getCheckpointingEnabled()) {
|
||||
try {
|
||||
await this.getGitService();
|
||||
} catch {
|
||||
// For now swallow the error, later log it.
|
||||
}
|
||||
await this.getGitService();
|
||||
}
|
||||
this.toolRegistry = await this.createToolRegistry();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user