2025-10-01 16:56:50 +00:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import { expect, describe, it, beforeEach, afterEach } from 'vitest';
|
2025-10-13 13:43:53 -04:00
|
|
|
import { TestRig } from './test-helper.js';
|
2025-10-01 16:56:50 +00:00
|
|
|
|
2025-10-17 17:25:31 -04:00
|
|
|
describe('Interactive file system', () => {
|
2025-10-01 16:56:50 +00:00
|
|
|
let rig: TestRig;
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
rig = new TestRig();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
afterEach(async () => {
|
|
|
|
|
await rig.cleanup();
|
|
|
|
|
});
|
|
|
|
|
|
2025-10-13 13:43:53 -04:00
|
|
|
it('should perform a read-then-write sequence', async () => {
|
2025-10-10 11:02:36 -07:00
|
|
|
const fileName = 'version.txt';
|
2025-10-22 11:57:10 -07:00
|
|
|
await rig.setup('interactive-read-then-write', {
|
|
|
|
|
settings: {
|
|
|
|
|
security: {
|
|
|
|
|
auth: {
|
|
|
|
|
selectedType: 'gemini-api-key',
|
|
|
|
|
},
|
|
|
|
|
disableYoloMode: false,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
2025-10-10 11:02:36 -07:00
|
|
|
rig.createFile(fileName, '1.0.0');
|
|
|
|
|
|
2025-10-11 08:33:01 -07:00
|
|
|
const run = await rig.runInteractive();
|
2025-10-10 11:02:36 -07:00
|
|
|
|
|
|
|
|
// Step 1: Read the file
|
|
|
|
|
const readPrompt = `Read the version from ${fileName}`;
|
2025-10-11 08:33:01 -07:00
|
|
|
await run.type(readPrompt);
|
2026-01-05 14:46:23 -08:00
|
|
|
await run.type('\r');
|
2025-10-10 11:02:36 -07:00
|
|
|
|
|
|
|
|
const readCall = await rig.waitForToolCall('read_file', 30000);
|
|
|
|
|
expect(readCall, 'Expected to find a read_file tool call').toBe(true);
|
|
|
|
|
|
|
|
|
|
// Step 2: Write the file
|
|
|
|
|
const writePrompt = `now change the version to 1.0.1 in the file`;
|
2025-10-11 08:33:01 -07:00
|
|
|
await run.type(writePrompt);
|
2026-01-05 14:46:23 -08:00
|
|
|
await run.type('\r');
|
2025-10-10 11:02:36 -07:00
|
|
|
|
2025-10-17 17:25:31 -04:00
|
|
|
// Check tool calls made with right args
|
|
|
|
|
await rig.expectToolCallSuccess(
|
|
|
|
|
['write_file', 'replace'],
|
|
|
|
|
30000,
|
|
|
|
|
(args) => args.includes('1.0.1') && args.includes(fileName),
|
|
|
|
|
);
|
2025-10-20 19:29:53 +02:00
|
|
|
|
|
|
|
|
// Wait for telemetry to flush and file system to sync, especially in sandboxed environments
|
|
|
|
|
await rig.waitForTelemetryReady();
|
2025-10-10 11:02:36 -07:00
|
|
|
});
|
2025-10-01 16:56:50 +00:00
|
|
|
});
|