feat(core): instrument file system tools for JIT context discovery (#22082)

This commit is contained in:
Sandy Tao
2026-03-12 20:44:42 -07:00
committed by GitHub
parent d44615ac2f
commit 7b4a822b0e
14 changed files with 523 additions and 2 deletions
@@ -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',
);
});
});
});