Skip to content
Source
Sign inSign up

toolActivity.test.ts

48 lines2.2 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { classifyToolActivity, dynamicToolSurface, mergeToolActivityData } from "./toolActivity.ts";
4​
5describe("toolActivity", () => {
6 it("classifies from kind and toolName without sniffing titles", () => {
7 expect(classifyToolActivity({ data: { kind: "read" } })).toBe("read");
8 expect(classifyToolActivity({ data: { toolName: "Grep" } })).toBe("search");
9 expect(classifyToolActivity({ data: { toolName: "Read" } })).toBe("read");
10 for (const toolName of ["github.read_file", "mongodb.find", "mcp__github__read_file"]) {
11 expect(classifyToolActivity({ data: { toolName } })).toBe("other");
12 }
13 expect(classifyToolActivity({ title: "Find", data: {} })).toBe("other");
14 });
15​
16 it("classifies Claude search tools ahead of their broad file-read request kind", () => {
17 for (const toolName of ["Glob", "Grep", "LS"]) {
18 expect(classifyToolActivity({ requestKind: "file-read", data: { toolName } })).toBe("search");
19 }
20 expect(classifyToolActivity({ requestKind: "file-read", data: { toolName: "Read" } })).toBe(
21 "read",
22 );
23 });
24​
25 it("keeps the first non-empty rawInput when a later update is empty", () => {
26 expect(
27 mergeToolActivityData({ rawInput: { path: "src/a.ts" } }, { rawInput: {}, kind: "read" }),
28 ).toEqual({
29 rawInput: { path: "src/a.ts" },
30 kind: "read",
31 });
32 expect(
33 mergeToolActivityData({ rawInput: { path: "src/a.ts" } }, { rawInput: { startLine: 4 } }),
34 ).toEqual({ rawInput: { path: "src/a.ts", startLine: 4 } });
35 });
36​
37 it("recognizes computer-use REPL calls before result metadata exists", () => {
38 expect(dynamicToolSurface("cua_repl.js", {})).toBe("computer");
39 for (const name of ["node_repl.js", "js"]) {
40 expect(dynamicToolSurface(name, { code: "await sky.get_app_state(app);" })).toBe("computer");
41 expect(dynamicToolSurface(name, { code: "const sky = await import('@oai/sky');" })).toBe(
42 "computer",
43 );
44 expect(dynamicToolSurface(name, { code: "await fs.readFile(path);" })).toBeUndefined();
45 }
46 expect(dynamicToolSurface("github.js", { code: "await sky.click(app);" })).toBeUndefined();
47 });
48});