Add edit correction.

This commit is contained in:
Christian Gunderman
2026-02-14 13:29:03 -08:00
parent 1e4cdfd691
commit 1a6c3ec9ef
2 changed files with 178 additions and 0 deletions
+47
View File
@@ -373,6 +373,53 @@ describe('EditTool', () => {
expect(result.occurrences).toBe(1);
});
it('should perform a fuzzy replacement when exact match fails but similarity is high', async () => {
const content =
'const myConfig = {\n enableFeature: true,\n retries: 3\n};';
// Typo: missing comma after true
const oldString =
'const myConfig = {\n enableFeature: true\n retries: 3\n};';
const newString =
'const myConfig = {\n enableFeature: false,\n retries: 5\n};';
const result = await calculateReplacement(mockConfig, {
params: {
file_path: 'config.ts',
instruction: 'update config',
old_string: oldString,
new_string: newString,
},
currentContent: content,
abortSignal,
});
expect(result.occurrences).toBe(1);
expect(result.newContent).toBe(newString);
});
it('should NOT perform a fuzzy replacement when similarity is below threshold', async () => {
const content =
'const myConfig = {\n enableFeature: true,\n retries: 3\n};';
// Completely different string
const oldString = 'function somethingElse() {\n return false;\n}';
const newString =
'const myConfig = {\n enableFeature: false,\n retries: 5\n};';
const result = await calculateReplacement(mockConfig, {
params: {
file_path: 'config.ts',
instruction: 'update config',
old_string: oldString,
new_string: newString,
},
currentContent: content,
abortSignal,
});
expect(result.occurrences).toBe(0);
expect(result.newContent).toBe(content);
});
it('should NOT insert extra newlines when replacing a block preceded by a blank line (regression)', async () => {
const content = '\n function oldFunc() {\n // some code\n }';
const result = await calculateReplacement(mockConfig, {