summaryrefslogtreecommitdiff
path: root/packages/core/src/tools/edit.test.ts
diff options
context:
space:
mode:
authorColt McAnlis <[email protected]>2025-07-07 10:28:56 -0700
committerGitHub <[email protected]>2025-07-07 17:28:56 +0000
commit8f4046c71af6c39711761b69e8ea0bf1aeaab8ff (patch)
treede31e36d80bc072691838db98c360e7d84fcb9b9 /packages/core/src/tools/edit.test.ts
parent229ae03631b40f6997ca7244517a6a6f9b368f74 (diff)
fix: EditTool can clobber human edits to the same file. (#3043)
Co-authored-by: Colt McAnlis <[email protected]> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Diffstat (limited to 'packages/core/src/tools/edit.test.ts')
-rw-r--r--packages/core/src/tools/edit.test.ts32
1 files changed, 17 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);