summaryrefslogtreecommitdiffhomepage
path: root/js/test/tool/tool.test.ts
blob: 4b6d2efd32a99c87bb522dd9cf0c913ea5c335db (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
import { describe, expect, test } from "bun:test";
import { App } from "../../src/app/app";
import { glob } from "../../src/tool/glob";
import { ls } from "../../src/tool/ls";

describe("tool.glob", () => {
  test("truncate", async () => {
    await App.provide({ directory: process.cwd() }, async () => {
      let result = await glob.execute(
        {
          pattern: "./node_modules/**/*",
        },
        {
          toolCallId: "test",
          messages: [],
        },
      );
      expect(result.metadata.truncated).toBe(true);
    });
  });
  test("basic", async () => {
    await App.provide({ directory: process.cwd() }, async () => {
      let result = await glob.execute(
        {
          pattern: "*.json",
        },
        {
          toolCallId: "test",
          messages: [],
        },
      );
      expect(result.metadata).toMatchObject({
        truncated: false,
        count: 2,
      });
    });
  });
});

describe("tool.ls", () => {
  test("basic", async () => {
    const result = await App.provide({ directory: process.cwd() }, async () => {
      return await ls.execute(
        {
          path: "./example",
        },
        {
          toolCallId: "test",
          messages: [],
        },
      );
    });
    expect(result.output).toMatchSnapshot();
  });
});