Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import {
4 claudeSkillInvocation,
5 classifyToolActivity,
6 collectToolFilePaths,
7 deriveToolActivityPresentation,
8 dynamicToolTitle,
9 formatReadToolLabel,
10 formatSearchToolLabel,
11 mergeToolActivityData,
12} from "./toolActivity.ts";
13
14describe("toolActivity", () => {
15 it("normalizes command tools to a stable ran-command label", () => {
16 expect(
17 deriveToolActivityPresentation({
18 itemType: "command_execution",
19 title: "Terminal",
20 detail: "Terminal",
21 data: {
22 command: "bun run lint",
23 },
24 fallbackSummary: "Terminal",
25 }),
26 ).toEqual({
27 summary: "Ran command",
28 detail: "bun run lint",
29 });
30 });
31
32 it("uses structured file paths for read-file tools when available", () => {
33 expect(
34 deriveToolActivityPresentation({
35 itemType: "dynamic_tool_call",
36 title: "Read File",
37 detail: "Read File",
38 data: {
39 kind: "read",
40 locations: [{ path: "/tmp/app.ts" }],
41 },
42 fallbackSummary: "Read File",
43 }),
44 ).toEqual({
45 summary: "Read /tmp/app.ts",
46 });
47 });
48
49 it("drops duplicated generic read-file detail when no path is available", () => {
50 expect(
51 deriveToolActivityPresentation({
52 itemType: "dynamic_tool_call",
53 title: "Read File",
54 detail: "Read File",
55 data: {
56 kind: "read",
57 rawInput: {},
58 },
59 fallbackSummary: "Read File",
60 }),
61 ).toEqual({
62 summary: "Read file",
63 });
64 });
65
66 it("classifies from kind and toolName without sniffing titles", () => {
67 expect(classifyToolActivity({ data: { kind: "read" } })).toBe("read");
68 expect(classifyToolActivity({ data: { toolName: "Grep" } })).toBe("search");
69 expect(classifyToolActivity({ data: { toolName: "Read" } })).toBe("read");
70 for (const toolName of ["github.read_file", "mongodb.find", "mcp__github__read_file"]) {
71 expect(classifyToolActivity({ data: { toolName } })).toBe("other");
72 }
73 expect(classifyToolActivity({ title: "Find", data: {} })).toBe("other");
74 });
75
76 it("classifies Claude search tools ahead of their broad file-read request kind", () => {
77 for (const toolName of ["Glob", "Grep", "LS"]) {
78 expect(classifyToolActivity({ requestKind: "file-read", data: { toolName } })).toBe("search");
79 }
80 expect(classifyToolActivity({ requestKind: "file-read", data: { toolName: "Read" } })).toBe(
81 "read",
82 );
83 });
84
85 it("formats read and search labels from structured input", () => {
86 expect(formatReadToolLabel("src/env.ts")).toBe("Read src/env.ts");
87 expect(formatReadToolLabel("src/env.ts", 2)).toBe("Read src/env.ts +2 more");
88 expect(formatReadToolLabel("")).toBe("Read file");
89 expect(
90 formatSearchToolLabel({
91 input: { pattern: "TODO", path: "apps/web" },
92 }),
93 ).toBe("Searched TODO in web");
94 expect(
95 formatSearchToolLabel({
96 input: { glob: "*.ts", path: "/tmp/t3chat-new" },
97 }),
98 ).toBe("Searched files *.ts in t3chat-new");
99 expect(
100 formatSearchToolLabel({ rawInput: {}, input: { pattern: "TODO", path: "apps/web" } }),
101 ).toBe("Searched TODO in web");
102 expect(formatSearchToolLabel({ input: { globPattern: "*.tsx", path: "apps/web" } })).toBe(
103 "Searched files *.tsx in web",
104 );
105 expect(
106 formatSearchToolLabel({ input: { pattern: "TODO", glob: "*.ts", path: "apps/web" } }),
107 ).toBe("Searched TODO in web");
108 });
109
110 it("keeps bare filenames from explicit path fields", () => {
111 expect(collectToolFilePaths({ input: { file_path: "README" } })).toEqual(["README"]);
112 });
113
114 it("keeps the first non-empty rawInput when a later update is empty", () => {
115 expect(
116 mergeToolActivityData({ rawInput: { path: "src/a.ts" } }, { rawInput: {}, kind: "read" }),
117 ).toEqual({
118 rawInput: { path: "src/a.ts" },
119 kind: "read",
120 });
121 expect(
122 mergeToolActivityData({ rawInput: { path: "src/a.ts" } }, { rawInput: { startLine: 4 } }),
123 ).toEqual({ rawInput: { path: "src/a.ts", startLine: 4 } });
124 });
125
126 it("titles Claude skill calls with the skill they load", () => {
127 expect(dynamicToolTitle("Skill", { skill: "full-send" })).toBe("Skill: full-send");
128 expect(claudeSkillInvocation("Skill", { skill: "claude-api", args: " pricing " })).toEqual({
129 name: "claude-api",
130 args: "pricing",
131 });
132 expect(dynamicToolTitle("Skill", { skill: " " })).toBeUndefined();
133 expect(dynamicToolTitle("Read", { skill: "full-send" })).toBeUndefined();
134 });
135});