summaryrefslogtreecommitdiff
path: root/integration-tests/list_directory.test.js
blob: 16f49f4b2178024a59bfea00a5667dff8f11d8e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
 * @license
 * Copyright 2025 Google LLC
 * SPDX-License-Identifier: Apache-2.0
 */

import { test } from 'node:test';
import { strict as assert } from 'assert';
import { TestRig, printDebugInfo, validateModelOutput } from './test-helper.js';
import { existsSync } from 'fs';
import { join } from 'path';

test('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();

  // Poll for filesystem changes to propagate in containers
  await rig.poll(
    () => {
      // 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
  );

  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');

  // Add debugging information
  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),
    );
  }

  assert.ok(foundToolCall, 'Expected to find a list_directory tool call');

  // Validate model output - will throw if no output, warn if missing expected content
  validateModelOutput(result, ['file1.txt', 'subdir'], 'List directory test');
});