| |
| |
| |
| |
| |
|
|
| import { describe, it, expect, vi } from 'vitest'; |
| import { TestRig, printDebugInfo, validateModelOutput } from './test-helper.js'; |
|
|
| describe('replace', () => { |
| it('should be able to replace content in a file', async () => { |
| const rig = new TestRig(); |
| await rig.setup('should be able to replace content in a file'); |
|
|
| const fileName = 'file_to_replace.txt'; |
| const originalContent = 'original content'; |
| const expectedContent = 'replaced content'; |
|
|
| rig.createFile(fileName, originalContent); |
| const prompt = `Can you replace 'original' with 'replaced' in the file 'file_to_replace.txt'`; |
|
|
| const result = await rig.run(prompt); |
|
|
| const foundToolCall = await rig.waitForToolCall('replace'); |
|
|
| |
| if (!foundToolCall) { |
| printDebugInfo(rig, result); |
| } |
|
|
| expect(foundToolCall, 'Expected to find a replace tool call').toBeTruthy(); |
|
|
| |
| validateModelOutput( |
| result, |
| ['replaced', 'file_to_replace.txt'], |
| 'Replace content test', |
| ); |
|
|
| const newFileContent = rig.readFile(fileName); |
|
|
| |
| if (newFileContent !== expectedContent) { |
| console.error('File content mismatch - Debug info:'); |
| console.error('Expected:', expectedContent); |
| console.error('Actual:', newFileContent); |
| console.error( |
| 'Tool calls:', |
| rig.readToolLogs().map((t) => ({ |
| name: t.toolRequest.name, |
| args: t.toolRequest.args, |
| })), |
| ); |
| } |
|
|
| expect(newFileContent).toBe(expectedContent); |
|
|
| |
| vi.stubEnv('VERBOSE', 'true'); |
| if (process.env['VERBOSE'] === 'true') { |
| console.log('File replaced successfully. New content:', newFileContent); |
| } |
| }); |
| }); |
|
|