diff options
| author | Tommaso Sciortino <[email protected]> | 2025-08-12 15:57:27 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-08-12 22:57:27 +0000 |
| commit | 9d023be1d16a6bf7427569f863e6cfd2c3442d8b (patch) | |
| tree | b983227f56fd9f26008b475061a345b61207c970 /integration-tests/file-system.test.ts | |
| parent | 8d6eb8c322890b5cdf20d4a30dd17afb1541f5aa (diff) | |
Upgrade integration tests to use Vitest (#6021)
Diffstat (limited to 'integration-tests/file-system.test.ts')
| -rw-r--r-- | integration-tests/file-system.test.ts | 132 |
1 files changed, 68 insertions, 64 deletions
diff --git a/integration-tests/file-system.test.ts b/integration-tests/file-system.test.ts index d43f047f..5a7028e0 100644 --- a/integration-tests/file-system.test.ts +++ b/integration-tests/file-system.test.ts @@ -4,86 +4,90 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { strict as assert } from 'assert'; -import { test } from 'node:test'; +import { describe, it, expect } from 'vitest'; import { TestRig, printDebugInfo, validateModelOutput } from './test-helper.js'; -test('should be able to read a file', async () => { - const rig = new TestRig(); - await rig.setup('should be able to read a file'); - rig.createFile('test.txt', 'hello world'); +describe('file-system', () => { + it('should be able to read a file', async () => { + const rig = new TestRig(); + await rig.setup('should be able to read a file'); + rig.createFile('test.txt', 'hello world'); - const result = await rig.run( - `read the file test.txt and show me its contents`, - ); + const result = await rig.run( + `read the file test.txt and show me its contents`, + ); - const foundToolCall = await rig.waitForToolCall('read_file'); + const foundToolCall = await rig.waitForToolCall('read_file'); - // Add debugging information - if (!foundToolCall || !result.includes('hello world')) { - printDebugInfo(rig, result, { - 'Found tool call': foundToolCall, - 'Contains hello world': result.includes('hello world'), - }); - } + // Add debugging information + if (!foundToolCall || !result.includes('hello world')) { + printDebugInfo(rig, result, { + 'Found tool call': foundToolCall, + 'Contains hello world': result.includes('hello world'), + }); + } - assert.ok(foundToolCall, 'Expected to find a read_file tool call'); + expect( + foundToolCall, + 'Expected to find a read_file tool call', + ).toBeTruthy(); - // Validate model output - will throw if no output, warn if missing expected content - validateModelOutput(result, 'hello world', 'File read test'); -}); + // Validate model output - will throw if no output, warn if missing expected content + validateModelOutput(result, 'hello world', 'File read test'); + }); -test('should be able to write a file', async () => { - const rig = new TestRig(); - await rig.setup('should be able to write a file'); - rig.createFile('test.txt', ''); + it('should be able to write a file', async () => { + const rig = new TestRig(); + await rig.setup('should be able to write a file'); + rig.createFile('test.txt', ''); - const result = await rig.run(`edit test.txt to have a hello world message`); + const result = await rig.run(`edit test.txt to have a hello world message`); - // Accept multiple valid tools for editing files - const foundToolCall = await rig.waitForAnyToolCall([ - 'write_file', - 'edit', - 'replace', - ]); + // Accept multiple valid tools for editing files + const foundToolCall = await rig.waitForAnyToolCall([ + 'write_file', + 'edit', + 'replace', + ]); - // Add debugging information - if (!foundToolCall) { - printDebugInfo(rig, result); - } + // Add debugging information + if (!foundToolCall) { + printDebugInfo(rig, result); + } - assert.ok( - foundToolCall, - 'Expected to find a write_file, edit, or replace tool call', - ); + expect( + foundToolCall, + 'Expected to find a write_file, edit, or replace tool call', + ).toBeTruthy(); - // Validate model output - will throw if no output - validateModelOutput(result, null, 'File write test'); + // Validate model output - will throw if no output + validateModelOutput(result, null, 'File write test'); - const fileContent = rig.readFile('test.txt'); + const fileContent = rig.readFile('test.txt'); - // Add debugging for file content - if (!fileContent.toLowerCase().includes('hello')) { - const writeCalls = rig - .readToolLogs() - .filter((t) => t.toolRequest.name === 'write_file') - .map((t) => t.toolRequest.args); + // Add debugging for file content + if (!fileContent.toLowerCase().includes('hello')) { + const writeCalls = rig + .readToolLogs() + .filter((t) => t.toolRequest.name === 'write_file') + .map((t) => t.toolRequest.args); - printDebugInfo(rig, result, { - 'File content mismatch': true, - 'Expected to contain': 'hello', - 'Actual content': fileContent, - 'Write tool calls': JSON.stringify(writeCalls), - }); - } + printDebugInfo(rig, result, { + 'File content mismatch': true, + 'Expected to contain': 'hello', + 'Actual content': fileContent, + 'Write tool calls': JSON.stringify(writeCalls), + }); + } - assert.ok( - fileContent.toLowerCase().includes('hello'), - 'Expected file to contain hello', - ); + expect( + fileContent.toLowerCase().includes('hello'), + 'Expected file to contain hello', + ).toBeTruthy(); - // Log success info if verbose - if (process.env.VERBOSE === 'true') { - console.log('File written successfully with hello message.'); - } + // Log success info if verbose + if (process.env.VERBOSE === 'true') { + console.log('File written successfully with hello message.'); + } + }); }); |
