diff --git a/packages/core/src/tools/edit.test.ts b/packages/core/src/tools/edit.test.ts index 9143f3bd..1341fdd0 100644 --- a/packages/core/src/tools/edit.test.ts +++ b/packages/core/src/tools/edit.test.ts @@ -486,10 +486,10 @@ describe('EditTool', () => { // The default mockEnsureCorrectEdit will return 2 occurrences for 'old' const result = await tool.execute(params, new AbortController().signal); expect(result.llmContent).toMatch( - /Expected 1 occurrences but found 2 for old_string in file/, + /Expected 1 occurrence but found 2 for old_string in file/, ); expect(result.returnDisplay).toMatch( - /Failed to edit, expected 1 occurrence\(s\) but found 2/, + /Failed to edit, expected 1 occurrence but found 2/, ); }); @@ -532,7 +532,7 @@ describe('EditTool', () => { /Expected 3 occurrences but found 2 for old_string in file/, ); expect(result.returnDisplay).toMatch( - /Failed to edit, expected 3 occurrence\(s\) but found 2/, + /Failed to edit, expected 3 occurrences but found 2/, ); }); diff --git a/packages/core/src/tools/edit.ts b/packages/core/src/tools/edit.ts index 2515261d..1e04ab35 100644 --- a/packages/core/src/tools/edit.ts +++ b/packages/core/src/tools/edit.ts @@ -257,9 +257,12 @@ Expectation for required parameters: raw: `Failed to edit, 0 occurrences found for old_string in ${params.file_path}. No edits made. The exact text in old_string was not found. Ensure you're not escaping content incorrectly and check whitespace, indentation, and context. Use ${ReadFileTool.Name} tool to verify.`, }; } else if (occurrences !== expectedReplacements) { + const occurenceTerm = + expectedReplacements === 1 ? 'occurrence' : 'occurrences'; + error = { - display: `Failed to edit, expected ${expectedReplacements} occurrence(s) but found ${occurrences}.`, - raw: `Failed to edit, Expected ${expectedReplacements} occurrences but found ${occurrences} for old_string in file: ${params.file_path}`, + display: `Failed to edit, expected ${expectedReplacements} ${occurenceTerm} but found ${occurrences}.`, + raw: `Failed to edit, Expected ${expectedReplacements} ${occurenceTerm} but found ${occurrences} for old_string in file: ${params.file_path}`, }; } } else {