|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import { describe, it, expect } from 'vitest'; |
|
|
import { TestRig, printDebugInfo, validateModelOutput } from './test-helper.js'; |
|
|
import { existsSync } from 'node:fs'; |
|
|
import { join } from 'node:path'; |
|
|
|
|
|
describe('list_directory', () => { |
|
|
it('should be able to list a directory', async () => { |
|
|
const rig = new TestRig(); |
|
|
await rig.setup('should be able to list a directory'); |
|
|
rig.createFile('file1.txt', 'file 1 content'); |
|
|
rig.mkdir('subdir'); |
|
|
rig.sync(); |
|
|
|
|
|
|
|
|
await rig.poll( |
|
|
() => { |
|
|
|
|
|
const file1Path = join(rig.testDir!, 'file1.txt'); |
|
|
const subdirPath = join(rig.testDir!, 'subdir'); |
|
|
return existsSync(file1Path) && existsSync(subdirPath); |
|
|
}, |
|
|
1000, |
|
|
50, |
|
|
); |
|
|
|
|
|
const prompt = `Can you list the files in the current directory. Display them in the style of 'ls'`; |
|
|
|
|
|
const result = await rig.run(prompt); |
|
|
|
|
|
const foundToolCall = await rig.waitForToolCall('list_directory'); |
|
|
|
|
|
|
|
|
if ( |
|
|
!foundToolCall || |
|
|
!result.includes('file1.txt') || |
|
|
!result.includes('subdir') |
|
|
) { |
|
|
const allTools = printDebugInfo(rig, result, { |
|
|
'Found tool call': foundToolCall, |
|
|
'Contains file1.txt': result.includes('file1.txt'), |
|
|
'Contains subdir': result.includes('subdir'), |
|
|
}); |
|
|
|
|
|
console.error( |
|
|
'List directory calls:', |
|
|
allTools |
|
|
.filter((t) => t.toolRequest.name === 'list_directory') |
|
|
.map((t) => t.toolRequest.args), |
|
|
); |
|
|
} |
|
|
|
|
|
expect( |
|
|
foundToolCall, |
|
|
'Expected to find a list_directory tool call', |
|
|
).toBeTruthy(); |
|
|
|
|
|
|
|
|
validateModelOutput(result, ['file1.txt', 'subdir'], 'List directory test'); |
|
|
}); |
|
|
}); |
|
|
|