mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-21 02:24:09 -07:00
feat(core): instrument file system tools for JIT context discovery (#22082)
This commit is contained in:
@@ -115,6 +115,14 @@ vi.mock('../telemetry/loggers.js', () => ({
|
||||
logFileOperation: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('./jit-context.js', () => ({
|
||||
discoverJitContext: vi.fn().mockResolvedValue(''),
|
||||
appendJitContext: vi.fn().mockImplementation((content, context) => {
|
||||
if (!context) return content;
|
||||
return `${content}\n\n--- Newly Discovered Project Context ---\n${context}\n--- End Project Context ---`;
|
||||
}),
|
||||
}));
|
||||
|
||||
// --- END MOCKS ---
|
||||
|
||||
describe('WriteFileTool', () => {
|
||||
@@ -1065,4 +1073,42 @@ describe('WriteFileTool', () => {
|
||||
expect(result.fileExists).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('JIT context discovery', () => {
|
||||
const abortSignal = new AbortController().signal;
|
||||
|
||||
it('should append JIT context to output when enabled and context is found', async () => {
|
||||
const { discoverJitContext } = await import('./jit-context.js');
|
||||
vi.mocked(discoverJitContext).mockResolvedValue('Use the useAuth hook.');
|
||||
|
||||
const filePath = path.join(rootDir, 'jit-write-test.txt');
|
||||
const content = 'JIT test content.';
|
||||
mockEnsureCorrectFileContent.mockResolvedValue(content);
|
||||
|
||||
const params = { file_path: filePath, content };
|
||||
const invocation = tool.build(params);
|
||||
const result = await invocation.execute(abortSignal);
|
||||
|
||||
expect(discoverJitContext).toHaveBeenCalled();
|
||||
expect(result.llmContent).toContain('Newly Discovered Project Context');
|
||||
expect(result.llmContent).toContain('Use the useAuth hook.');
|
||||
});
|
||||
|
||||
it('should not append JIT context when disabled', async () => {
|
||||
const { discoverJitContext } = await import('./jit-context.js');
|
||||
vi.mocked(discoverJitContext).mockResolvedValue('');
|
||||
|
||||
const filePath = path.join(rootDir, 'jit-disabled-write-test.txt');
|
||||
const content = 'No JIT content.';
|
||||
mockEnsureCorrectFileContent.mockResolvedValue(content);
|
||||
|
||||
const params = { file_path: filePath, content };
|
||||
const invocation = tool.build(params);
|
||||
const result = await invocation.execute(abortSignal);
|
||||
|
||||
expect(result.llmContent).not.toContain(
|
||||
'Newly Discovered Project Context',
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user