| | |
| | |
| | |
| | |
| | |
| |
|
| | import { describe, it, expect, vi } from 'vitest'; |
| | import { |
| | TestRig, |
| | createToolCallErrorMessage, |
| | printDebugInfo, |
| | validateModelOutput, |
| | } from './test-helper.js'; |
| |
|
| | describe('write_file', () => { |
| | it('should be able to write a file', async () => { |
| | const rig = new TestRig(); |
| | await rig.setup('should be able to write a file'); |
| | const prompt = `show me an example of using the write tool. put a dad joke in dad.txt`; |
| |
|
| | const result = await rig.run(prompt); |
| |
|
| | const foundToolCall = await rig.waitForToolCall('write_file'); |
| |
|
| | |
| | if (!foundToolCall) { |
| | printDebugInfo(rig, result); |
| | } |
| |
|
| | const allTools = rig.readToolLogs(); |
| | expect(foundToolCall, 'Expected to find a write_file tool call').toBeTruthy( |
| | createToolCallErrorMessage( |
| | 'write_file', |
| | allTools.map((t) => t.toolRequest.name), |
| | result, |
| | ), |
| | ); |
| |
|
| | |
| | validateModelOutput(result, 'dad.txt', 'Write file test'); |
| |
|
| | const newFilePath = 'dad.txt'; |
| |
|
| | const newFileContent = rig.readFile(newFilePath); |
| |
|
| | |
| | if (newFileContent === '') { |
| | console.error('File was created but is empty'); |
| | console.error( |
| | 'Tool calls:', |
| | rig.readToolLogs().map((t) => ({ |
| | name: t.toolRequest.name, |
| | args: t.toolRequest.args, |
| | })), |
| | ); |
| | } |
| |
|
| | expect(newFileContent).not.toBe(''); |
| |
|
| | |
| | vi.stubEnv('VERBOSE', 'true'); |
| | if (process.env['VERBOSE'] === 'true') { |
| | console.log( |
| | 'File created successfully with content:', |
| | newFileContent.substring(0, 100) + '...', |
| | ); |
| | } |
| | }); |
| | }); |
| |
|