mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
bug(core): Fix for "no changes" edits. (#6836)
This commit is contained in:
@@ -632,6 +632,33 @@ describe('EditTool', () => {
|
|||||||
expect(result.llmContent).toMatch(/No changes to apply/);
|
expect(result.llmContent).toMatch(/No changes to apply/);
|
||||||
expect(result.returnDisplay).toMatch(/No changes to apply/);
|
expect(result.returnDisplay).toMatch(/No changes to apply/);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should return EDIT_NO_CHANGE error if replacement results in identical content', async () => {
|
||||||
|
// This can happen if ensureCorrectEdit finds a fuzzy match, but the literal
|
||||||
|
// string replacement with `replaceAll` results in no change.
|
||||||
|
const initialContent = 'line 1\nline 2\nline 3'; // Note the double space
|
||||||
|
fs.writeFileSync(filePath, initialContent, 'utf8');
|
||||||
|
const params: EditToolParams = {
|
||||||
|
file_path: filePath,
|
||||||
|
// old_string has a single space, so it won't be found by replaceAll
|
||||||
|
old_string: 'line 1\nline 2\nline 3',
|
||||||
|
new_string: 'line 1\nnew line 2\nline 3',
|
||||||
|
};
|
||||||
|
|
||||||
|
// Mock ensureCorrectEdit to simulate it finding a match (e.g., via fuzzy matching)
|
||||||
|
// but it doesn't correct the old_string to the literal content.
|
||||||
|
mockEnsureCorrectEdit.mockResolvedValueOnce({ params, occurrences: 1 });
|
||||||
|
|
||||||
|
const invocation = tool.build(params);
|
||||||
|
const result = await invocation.execute(new AbortController().signal);
|
||||||
|
|
||||||
|
expect(result.error?.type).toBe(ToolErrorType.EDIT_NO_CHANGE);
|
||||||
|
expect(result.returnDisplay).toMatch(
|
||||||
|
/No changes to apply. The new content is identical to the current content./,
|
||||||
|
);
|
||||||
|
// Ensure the file was not actually changed
|
||||||
|
expect(fs.readFileSync(filePath, 'utf8')).toBe(initialContent);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Error Scenarios', () => {
|
describe('Error Scenarios', () => {
|
||||||
|
|||||||
@@ -204,12 +204,23 @@ class EditToolInvocation implements ToolInvocation<EditToolParams, ToolResult> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const newContent = applyReplacement(
|
const newContent = !error
|
||||||
|
? applyReplacement(
|
||||||
currentContent,
|
currentContent,
|
||||||
finalOldString,
|
finalOldString,
|
||||||
finalNewString,
|
finalNewString,
|
||||||
isNewFile,
|
isNewFile,
|
||||||
);
|
)
|
||||||
|
: (currentContent ?? '');
|
||||||
|
|
||||||
|
if (!error && fileExists && currentContent === newContent) {
|
||||||
|
error = {
|
||||||
|
display:
|
||||||
|
'No changes to apply. The new content is identical to the current content.',
|
||||||
|
raw: `No changes to apply. The new content is identical to the current content in file: ${params.file_path}`,
|
||||||
|
type: ToolErrorType.EDIT_NO_CHANGE,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
currentContent,
|
currentContent,
|
||||||
|
|||||||
Reference in New Issue
Block a user