fix(core-tools): bypass LLM correction for JSON and IPYNB files in write_file and replace (#28223)

Co-authored-by: David Pierce <davidapierce@google.com>
This commit is contained in:
amelidev
2026-07-09 13:31:50 -06:00
committed by GitHub
parent 172ff92c34
commit a8b115caa1
4 changed files with 98 additions and 15 deletions
@@ -428,6 +428,39 @@ describe('WriteFileTool', () => {
expect(result.error).toBeUndefined();
});
it('should not call ensureCorrectFileContent for .json files', async () => {
const filePath = path.join(rootDir, 'config.json');
const proposedContent = '{"key": "value\\nwith\\nescapes"}';
const abortSignal = new AbortController().signal;
const result = await getCorrectedFileContent(
mockConfig,
filePath,
proposedContent,
abortSignal,
);
expect(mockEnsureCorrectFileContent).not.toHaveBeenCalled();
expect(result.correctedContent).toBe(proposedContent);
});
it('should not call ensureCorrectFileContent for .ipynb files', async () => {
const filePath = path.join(rootDir, 'notebook.ipynb');
const proposedContent =
'{"cells": [{"source": ["print(\\"hello\\\\n\\")"]}]}';
const abortSignal = new AbortController().signal;
const result = await getCorrectedFileContent(
mockConfig,
filePath,
proposedContent,
abortSignal,
);
expect(mockEnsureCorrectFileContent).not.toHaveBeenCalled();
expect(result.correctedContent).toBe(proposedContent);
});
it('should return error if reading an existing file fails (e.g. permissions)', async () => {
const filePath = path.join(rootDir, 'unreadable_file.txt');
const proposedContent = 'some content';