diff options
Diffstat (limited to 'packages/core/src/tools')
| -rw-r--r-- | packages/core/src/tools/edit.test.ts | 32 | ||||
| -rw-r--r-- | packages/core/src/tools/edit.ts | 1 | ||||
| -rw-r--r-- | packages/core/src/tools/write-file.test.ts | 4 | ||||
| -rw-r--r-- | packages/core/src/tools/write-file.ts | 1 |
4 files changed, 23 insertions, 15 deletions
diff --git a/packages/core/src/tools/edit.test.ts b/packages/core/src/tools/edit.test.ts index 1341fdd0..ab42450a 100644 --- a/packages/core/src/tools/edit.test.ts +++ b/packages/core/src/tools/edit.test.ts @@ -84,20 +84,22 @@ describe('EditTool', () => { // Reset mocks and set default implementation for ensureCorrectEdit mockEnsureCorrectEdit.mockReset(); - mockEnsureCorrectEdit.mockImplementation(async (currentContent, params) => { - let occurrences = 0; - if (params.old_string && currentContent) { - // Simple string counting for the mock - let index = currentContent.indexOf(params.old_string); - while (index !== -1) { - occurrences++; - index = currentContent.indexOf(params.old_string, index + 1); + mockEnsureCorrectEdit.mockImplementation( + async (_, currentContent, params) => { + let occurrences = 0; + if (params.old_string && currentContent) { + // Simple string counting for the mock + let index = currentContent.indexOf(params.old_string); + while (index !== -1) { + occurrences++; + index = currentContent.indexOf(params.old_string, index + 1); + } + } else if (params.old_string === '') { + occurrences = 0; // Creating a new file } - } else if (params.old_string === '') { - occurrences = 0; // Creating a new file - } - return Promise.resolve({ params, occurrences }); - }); + return Promise.resolve({ params, occurrences }); + }, + ); // Default mock for generateJson to return the snippet unchanged mockGenerateJson.mockReset(); @@ -333,7 +335,7 @@ describe('EditTool', () => { // Set a specific mock for this test case let mockCalled = false; mockEnsureCorrectEdit.mockImplementationOnce( - async (content, p, client) => { + async (_, content, p, client) => { mockCalled = true; expect(content).toBe(originalContent); expect(p).toBe(params); @@ -383,7 +385,7 @@ describe('EditTool', () => { beforeEach(() => { filePath = path.join(rootDir, testFile); // Default for execute tests, can be overridden - mockEnsureCorrectEdit.mockImplementation(async (content, params) => { + mockEnsureCorrectEdit.mockImplementation(async (_, content, params) => { let occurrences = 0; if (params.old_string && content) { let index = content.indexOf(params.old_string); diff --git a/packages/core/src/tools/edit.ts b/packages/core/src/tools/edit.ts index 1e04ab35..2df01a22 100644 --- a/packages/core/src/tools/edit.ts +++ b/packages/core/src/tools/edit.ts @@ -236,6 +236,7 @@ Expectation for required parameters: } else if (currentContent !== null) { // Editing an existing file const correctedEdit = await ensureCorrectEdit( + params.file_path, currentContent, params, this.client, diff --git a/packages/core/src/tools/write-file.test.ts b/packages/core/src/tools/write-file.test.ts index 3f9825c6..c33b5fa2 100644 --- a/packages/core/src/tools/write-file.test.ts +++ b/packages/core/src/tools/write-file.test.ts @@ -114,6 +114,7 @@ describe('WriteFileTool', () => { // Default mock implementations that return valid structures mockEnsureCorrectEdit.mockImplementation( async ( + filePath: string, _currentContent: string, params: EditToolParams, _client: GeminiClient, @@ -248,6 +249,7 @@ describe('WriteFileTool', () => { ); expect(mockEnsureCorrectEdit).toHaveBeenCalledWith( + filePath, originalContent, { old_string: originalContent, @@ -388,6 +390,7 @@ describe('WriteFileTool', () => { )) as ToolEditConfirmationDetails; expect(mockEnsureCorrectEdit).toHaveBeenCalledWith( + filePath, originalContent, { old_string: originalContent, @@ -523,6 +526,7 @@ describe('WriteFileTool', () => { const result = await tool.execute(params, abortSignal); expect(mockEnsureCorrectEdit).toHaveBeenCalledWith( + filePath, initialContent, { old_string: initialContent, diff --git a/packages/core/src/tools/write-file.ts b/packages/core/src/tools/write-file.ts index c343cab8..37a1ba78 100644 --- a/packages/core/src/tools/write-file.ts +++ b/packages/core/src/tools/write-file.ts @@ -367,6 +367,7 @@ export class WriteFileTool if (fileExists) { // This implies originalContent is available const { params: correctedParams } = await ensureCorrectEdit( + filePath, originalContent, { old_string: originalContent, // Treat entire current content as old_string |
