diff options
| author | Leo <[email protected]> | 2025-06-14 19:20:04 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-06-14 11:20:04 -0700 |
| commit | 2c6aae863af084fdd515c56a41ef01cd9d7b2c0b (patch) | |
| tree | d60ee092c436a37d822883149099c6454736901a /packages/core/src/tools/edit.test.ts | |
| parent | 93909a2dd3bf901e8f98a9fd41e1300faa585a84 (diff) | |
Enable "modify" in write tool (#1044)
Diffstat (limited to 'packages/core/src/tools/edit.test.ts')
| -rw-r--r-- | packages/core/src/tools/edit.test.ts | 137 |
1 files changed, 0 insertions, 137 deletions
diff --git a/packages/core/src/tools/edit.test.ts b/packages/core/src/tools/edit.test.ts index dd3b481d..7dff5bf9 100644 --- a/packages/core/src/tools/edit.test.ts +++ b/packages/core/src/tools/edit.test.ts @@ -605,141 +605,4 @@ describe('EditTool', () => { ); }); }); - - describe('onModify', () => { - const testFile = 'some_file.txt'; - let filePath: string; - const diffDir = path.join(os.tmpdir(), 'gemini-cli-edit-tool-diffs'); - - beforeEach(() => { - filePath = path.join(rootDir, testFile); - mockOpenDiff.mockClear(); - }); - - afterEach(() => { - fs.rmSync(diffDir, { recursive: true, force: true }); - }); - - it('should create temporary files, call openDiff, and return updated params with diff', async () => { - const originalContent = 'original content'; - const params: EditToolParams = { - file_path: filePath, - old_string: originalContent, - new_string: 'modified content', - }; - - fs.writeFileSync(filePath, originalContent, 'utf8'); - - const result = await tool.onModify( - params, - new AbortController().signal, - 'vscode', - ); - - expect(mockOpenDiff).toHaveBeenCalledTimes(1); - const [oldPath, newPath] = mockOpenDiff.mock.calls[0]; - expect(oldPath).toMatch( - /gemini-cli-edit-tool-diffs[/\\]gemini-cli-edit-some_file\.txt-old-\d+/, - ); - expect(newPath).toMatch( - /gemini-cli-edit-tool-diffs[/\\]gemini-cli-edit-some_file\.txt-new-\d+/, - ); - - expect(result).toBeDefined(); - expect(result!.updatedParams).toEqual({ - file_path: filePath, - old_string: originalContent, - new_string: 'modified content', - }); - expect(result!.updatedDiff).toEqual(`Index: some_file.txt -=================================================================== ---- some_file.txt\tCurrent -+++ some_file.txt\tProposed -@@ -1,1 +1,1 @@ --original content -\\ No newline at end of file -+modified content -\\ No newline at end of file -`); - - // Verify temp files are cleaned up - expect(fs.existsSync(oldPath)).toBe(false); - expect(fs.existsSync(newPath)).toBe(false); - }); - - it('should handle non-existent files and return updated params', async () => { - const params: EditToolParams = { - file_path: filePath, - old_string: '', - new_string: 'new file content', - }; - - const result = await tool.onModify( - params, - new AbortController().signal, - 'vscode', - ); - - expect(mockOpenDiff).toHaveBeenCalledTimes(1); - - const [oldPath, newPath] = mockOpenDiff.mock.calls[0]; - - expect(result).toBeDefined(); - expect(result!.updatedParams).toEqual({ - file_path: filePath, - old_string: '', - new_string: 'new file content', - }); - expect(result!.updatedDiff).toContain('new file content'); - - // Verify temp files are cleaned up - expect(fs.existsSync(oldPath)).toBe(false); - expect(fs.existsSync(newPath)).toBe(false); - }); - - it('should clean up previous temp files before creating new ones', async () => { - const params: EditToolParams = { - file_path: filePath, - old_string: 'old', - new_string: 'new', - }; - - fs.writeFileSync(filePath, 'some old content', 'utf8'); - - // Call onModify first time - const result1 = await tool.onModify( - params, - new AbortController().signal, - 'vscode', - ); - const firstCall = mockOpenDiff.mock.calls[0]; - const firstOldPath = firstCall[0]; - const firstNewPath = firstCall[1]; - - expect(result1).toBeDefined(); - expect(fs.existsSync(firstOldPath)).toBe(false); - expect(fs.existsSync(firstNewPath)).toBe(false); - - // Ensure different timestamps so that the file names are different for testing. - await new Promise((resolve) => setTimeout(resolve, 2)); - - const result2 = await tool.onModify( - params, - new AbortController().signal, - 'vscode', - ); - const secondCall = mockOpenDiff.mock.calls[1]; - const secondOldPath = secondCall[0]; - const secondNewPath = secondCall[1]; - - // Call onModify second time - expect(result2).toBeDefined(); - expect(fs.existsSync(secondOldPath)).toBe(false); - expect(fs.existsSync(secondNewPath)).toBe(false); - - // Verify different file names were used - expect(firstOldPath).not.toBe(secondOldPath); - expect(firstNewPath).not.toBe(secondNewPath); - }); - }); }); |
