diff options
Diffstat (limited to 'packages/core/src/tools/edit.test.ts')
| -rw-r--r-- | packages/core/src/tools/edit.test.ts | 59 |
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', () => { |
