Files
gemini-cli/integration-tests/write_file.test.ts

84 lines
2.0 KiB
TypeScript
Raw Permalink Normal View History

2025-06-16 08:27:29 -07:00
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import {
TestRig,
createToolCallErrorMessage,
printDebugInfo,
assertModelHasOutput,
checkModelOutputContent,
} from './test-helper.js';
2025-06-16 08:27:29 -07:00
describe('write_file', () => {
let rig: TestRig;
beforeEach(() => {
rig = new TestRig();
});
afterEach(async () => await rig.cleanup());
it('should be able to write a joke to a file', async () => {
await rig.setup('should be able to write a joke to a file', {
settings: { tools: { core: ['write_file', 'read_file'] } },
});
const prompt = `show me an example of using the write tool. put a dad joke in dad.txt`;
2025-06-16 08:27:29 -07:00
2025-12-15 13:18:04 -08:00
const result = await rig.run({ args: prompt });
const foundToolCall = await rig.waitForToolCall('write_file');
// Add debugging information
if (!foundToolCall) {
printDebugInfo(rig, result);
}
const allTools = rig.readToolLogs();
expect(
foundToolCall,
createToolCallErrorMessage(
'write_file',
allTools.map((t) => t.toolRequest.name),
result,
),
).toBeTruthy();
assertModelHasOutput(result);
checkModelOutputContent(result, {
expectedContent: 'dad.txt',
testName: 'Write file test',
});
const newFilePath = 'dad.txt';
2025-06-16 08:27:29 -07:00
const newFileContent = rig.readFile(newFilePath);
// Add debugging for file content
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('');
// Log success info if verbose
vi.stubEnv('VERBOSE', 'true');
if (process.env['VERBOSE'] === 'true') {
console.log(
'File created successfully with content:',
newFileContent.substring(0, 100) + '...',
);
}
});
2025-06-16 08:27:29 -07:00
});