summaryrefslogtreecommitdiff
path: root/packages/core/src/tools/edit.test.ts
diff options
context:
space:
mode:
authorLeo <[email protected]>2025-06-28 19:02:44 +0100
committerGitHub <[email protected]>2025-06-28 18:02:44 +0000
commit601d9ba36d1c8f6d1e180a0c5cc1d5597906d33a (patch)
tree4f34dfee0c6391a321b5a259957854ae2743cb3f /packages/core/src/tools/edit.test.ts
parent3518ff766345ba98d90495b46c84439e6fc1a61c (diff)
fix edit retrigger (#2306)
Diffstat (limited to 'packages/core/src/tools/edit.test.ts')
-rw-r--r--packages/core/src/tools/edit.test.ts59
1 files changed, 59 insertions, 0 deletions
diff --git a/packages/core/src/tools/edit.test.ts b/packages/core/src/tools/edit.test.ts
index 50f68e2a..9143f3bd 100644
--- a/packages/core/src/tools/edit.test.ts
+++ b/packages/core/src/tools/edit.test.ts
@@ -549,6 +549,65 @@ describe('EditTool', () => {
/Attempted to create a file that already exists/,
);
});
+
+ it('should include modification message when proposed content is modified', async () => {
+ const initialContent = 'This is some old text.';
+ fs.writeFileSync(filePath, initialContent, 'utf8');
+ const params: EditToolParams = {
+ file_path: filePath,
+ old_string: 'old',
+ new_string: 'new',
+ modified_by_user: true,
+ };
+
+ (mockConfig.getApprovalMode as Mock).mockReturnValueOnce(
+ ApprovalMode.AUTO_EDIT,
+ );
+ const result = await tool.execute(params, new AbortController().signal);
+
+ expect(result.llmContent).toMatch(
+ /User modified the `new_string` content/,
+ );
+ });
+
+ it('should not include modification message when proposed content is not modified', async () => {
+ const initialContent = 'This is some old text.';
+ fs.writeFileSync(filePath, initialContent, 'utf8');
+ const params: EditToolParams = {
+ file_path: filePath,
+ old_string: 'old',
+ new_string: 'new',
+ modified_by_user: false,
+ };
+
+ (mockConfig.getApprovalMode as Mock).mockReturnValueOnce(
+ ApprovalMode.AUTO_EDIT,
+ );
+ const result = await tool.execute(params, new AbortController().signal);
+
+ expect(result.llmContent).not.toMatch(
+ /User modified the `new_string` content/,
+ );
+ });
+
+ it('should not include modification message when modified_by_user is not provided', async () => {
+ const initialContent = 'This is some old text.';
+ fs.writeFileSync(filePath, initialContent, 'utf8');
+ const params: EditToolParams = {
+ file_path: filePath,
+ old_string: 'old',
+ new_string: 'new',
+ };
+
+ (mockConfig.getApprovalMode as Mock).mockReturnValueOnce(
+ ApprovalMode.AUTO_EDIT,
+ );
+ const result = await tool.execute(params, new AbortController().signal);
+
+ expect(result.llmContent).not.toMatch(
+ /User modified the `new_string` content/,
+ );
+ });
});
describe('getDescription', () => {