2025-06-16 08:27:29 -07:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
2025-12-15 11:11:08 -08:00
|
|
|
import { describe, it, beforeEach, afterEach } from 'vitest';
|
2025-10-11 08:33:01 -07:00
|
|
|
import {
|
|
|
|
|
TestRig,
|
|
|
|
|
poll,
|
|
|
|
|
printDebugInfo,
|
2026-02-05 10:07:47 -08:00
|
|
|
assertModelHasOutput,
|
|
|
|
|
checkModelOutputContent,
|
2025-10-11 08:33:01 -07:00
|
|
|
} from './test-helper.js';
|
2025-08-25 22:11:27 +02:00
|
|
|
import { existsSync } from 'node:fs';
|
|
|
|
|
import { join } from 'node:path';
|
2025-06-16 08:27:29 -07:00
|
|
|
|
2025-08-12 15:57:27 -07:00
|
|
|
describe('list_directory', () => {
|
2025-12-15 11:11:08 -08:00
|
|
|
let rig: TestRig;
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
rig = new TestRig();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
afterEach(async () => await rig.cleanup());
|
|
|
|
|
|
2025-08-12 15:57:27 -07:00
|
|
|
it('should be able to list a directory', async () => {
|
2025-12-02 17:43:06 -08:00
|
|
|
await rig.setup('should be able to list a directory', {
|
|
|
|
|
settings: { tools: { core: ['list_directory'] } },
|
|
|
|
|
});
|
2025-08-12 15:57:27 -07:00
|
|
|
rig.createFile('file1.txt', 'file 1 content');
|
|
|
|
|
rig.mkdir('subdir');
|
|
|
|
|
rig.sync();
|
|
|
|
|
|
|
|
|
|
// Poll for filesystem changes to propagate in containers
|
2025-10-11 08:33:01 -07:00
|
|
|
await poll(
|
2025-08-12 15:57:27 -07:00
|
|
|
() => {
|
|
|
|
|
// Check if the files exist in the test directory
|
|
|
|
|
const file1Path = join(rig.testDir!, 'file1.txt');
|
|
|
|
|
const subdirPath = join(rig.testDir!, 'subdir');
|
|
|
|
|
return existsSync(file1Path) && existsSync(subdirPath);
|
|
|
|
|
},
|
|
|
|
|
1000, // 1 second max wait
|
|
|
|
|
50, // check every 50ms
|
2025-08-01 14:33:33 -07:00
|
|
|
);
|
|
|
|
|
|
2025-09-14 23:59:27 -04:00
|
|
|
const prompt = `Can you list the files in the current directory.`;
|
2025-08-12 15:57:27 -07:00
|
|
|
|
2025-12-15 13:18:04 -08:00
|
|
|
const result = await rig.run({ args: prompt });
|
2025-08-12 15:57:27 -07:00
|
|
|
|
2025-11-05 11:00:06 -05:00
|
|
|
try {
|
|
|
|
|
await rig.expectToolCallSuccess(['list_directory']);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
// Add debugging information
|
|
|
|
|
if (!result.includes('file1.txt') || !result.includes('subdir')) {
|
|
|
|
|
const allTools = printDebugInfo(rig, result, {
|
|
|
|
|
'Found tool call': false,
|
|
|
|
|
'Contains file1.txt': result.includes('file1.txt'),
|
|
|
|
|
'Contains subdir': result.includes('subdir'),
|
|
|
|
|
});
|
2025-08-12 15:57:27 -07:00
|
|
|
|
2025-11-05 11:00:06 -05:00
|
|
|
console.error(
|
|
|
|
|
'List directory calls:',
|
|
|
|
|
allTools
|
|
|
|
|
.filter((t) => t.toolRequest.name === 'list_directory')
|
|
|
|
|
.map((t) => t.toolRequest.args),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
throw e;
|
2025-08-12 15:57:27 -07:00
|
|
|
}
|
|
|
|
|
|
2026-02-05 10:07:47 -08:00
|
|
|
assertModelHasOutput(result);
|
|
|
|
|
checkModelOutputContent(result, {
|
|
|
|
|
expectedContent: ['file1.txt', 'subdir'],
|
|
|
|
|
testName: 'List directory test',
|
|
|
|
|
});
|
2025-08-12 15:57:27 -07:00
|
|
|
});
|
2025-06-16 08:27:29 -07:00
|
|
|
});
|