Files
t3code/packages/shared/src/toolActivity.test.ts
T
+36 de34391427 feat(orchestrator): introduce new orchestrator (#2829)
Co-authored-by: maria-rcks <[email protected]>
Co-authored-by: Bilal Bakr <[email protected]>
Co-authored-by: shivam <[email protected]>
Co-authored-by: Vitalii Yehorov <[email protected]>
Co-authored-by: Jake Leventhal <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Co-authored-by: Alex Southwell <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Nicholas Wasmiller <[email protected]>
Co-authored-by: PB <[email protected]>
Co-authored-by: Exotic <[email protected]>
Co-authored-by: Yash Singh <[email protected]>
Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Theo Browne <[email protected]>
Co-authored-by: Gabriel De Andrade <[email protected]>
Co-authored-by: Dara Adedeji <[email protected]>
Co-authored-by: scratchyone <[email protected]>
Co-authored-by: Dominic Roy <[email protected]>
Co-authored-by: chukfinley <[email protected]>
Co-authored-by: Primož Ajdišek <[email protected]>
Co-authored-by: benthecarman <[email protected]>
Co-authored-by: NaveDanan <[email protected]>
Co-authored-by: aaditagrawal <[email protected]>
Co-authored-by: Aditya Garud <[email protected]>
Co-authored-by: Nick Anisimov <[email protected]>
Co-authored-by: MacKinley Smith <[email protected]>
Co-authored-by: Yordis Prieto <[email protected]>
Co-authored-by: t3-code[bot] <269035359+t3-code[bot]@users.noreply.github.com>
Co-authored-by: AKolenda <[email protected]>
Co-authored-by: Guillermo Casanova <[email protected]>
Co-authored-by: Otavio Salvador <[email protected]>
Co-authored-by: Shirish Pothi <[email protected]>
Co-authored-by: Ishaan Kothari <[email protected]>
Co-authored-by: Bob Fowler <[email protected]>
Co-authored-by: Anton Bezdenezhnykh <[email protected]>
Co-authored-by: ValeraZSD <[email protected]>
Co-authored-by: Ephraim <[email protected]>
Co-authored-by: Ryan Ilano <[email protected]>
Co-authored-by: Alex <[email protected]>
Co-authored-by: maco <[email protected]>
Co-authored-by: Cursor <[email protected]>
Co-authored-by: Tristan Knight <[email protected]>
Co-authored-by: PR Batch Tester <[email protected]>
Co-authored-by: oliver <[email protected]>
Co-authored-by: kamkm <[email protected]>
Signed-off-by: Yordis Prieto <[email protected]>
2026-10-02 12:22:22 -07:00

124 lines
4.0 KiB
TypeScript

import { describe, expect, it } from "vite-plus/test";
import {
classifyToolActivity,
collectToolFilePaths,
deriveToolActivityPresentation,
formatReadToolLabel,
formatSearchToolLabel,
mergeToolActivityData,
} from "./toolActivity.ts";
describe("toolActivity", () => {
it("normalizes command tools to a stable ran-command label", () => {
expect(
deriveToolActivityPresentation({
itemType: "command_execution",
title: "Terminal",
detail: "Terminal",
data: {
command: "bun run lint",
},
fallbackSummary: "Terminal",
}),
).toEqual({
summary: "Ran command",
detail: "bun run lint",
});
});
it("uses structured file paths for read-file tools when available", () => {
expect(
deriveToolActivityPresentation({
itemType: "dynamic_tool_call",
title: "Read File",
detail: "Read File",
data: {
kind: "read",
locations: [{ path: "/tmp/app.ts" }],
},
fallbackSummary: "Read File",
}),
).toEqual({
summary: "Read /tmp/app.ts",
});
});
it("drops duplicated generic read-file detail when no path is available", () => {
expect(
deriveToolActivityPresentation({
itemType: "dynamic_tool_call",
title: "Read File",
detail: "Read File",
data: {
kind: "read",
rawInput: {},
},
fallbackSummary: "Read File",
}),
).toEqual({
summary: "Read file",
});
});
it("classifies from kind and toolName without sniffing titles", () => {
expect(classifyToolActivity({ data: { kind: "read" } })).toBe("read");
expect(classifyToolActivity({ data: { toolName: "Grep" } })).toBe("search");
expect(classifyToolActivity({ data: { toolName: "Read" } })).toBe("read");
for (const toolName of ["github.read_file", "mongodb.find", "mcp__github__read_file"]) {
expect(classifyToolActivity({ data: { toolName } })).toBe("other");
}
expect(classifyToolActivity({ title: "Find", data: {} })).toBe("other");
});
it("classifies Claude search tools ahead of their broad file-read request kind", () => {
for (const toolName of ["Glob", "Grep", "LS"]) {
expect(classifyToolActivity({ requestKind: "file-read", data: { toolName } })).toBe("search");
}
expect(classifyToolActivity({ requestKind: "file-read", data: { toolName: "Read" } })).toBe(
"read",
);
});
it("formats read and search labels from structured input", () => {
expect(formatReadToolLabel("src/env.ts")).toBe("Read src/env.ts");
expect(formatReadToolLabel("src/env.ts", 2)).toBe("Read src/env.ts +2 more");
expect(formatReadToolLabel("")).toBe("Read file");
expect(
formatSearchToolLabel({
input: { pattern: "TODO", path: "apps/web" },
}),
).toBe("Searched TODO in web");
expect(
formatSearchToolLabel({
input: { glob: "*.ts", path: "/tmp/t3chat-new" },
}),
).toBe("Searched files *.ts in t3chat-new");
expect(
formatSearchToolLabel({ rawInput: {}, input: { pattern: "TODO", path: "apps/web" } }),
).toBe("Searched TODO in web");
expect(formatSearchToolLabel({ input: { globPattern: "*.tsx", path: "apps/web" } })).toBe(
"Searched files *.tsx in web",
);
expect(
formatSearchToolLabel({ input: { pattern: "TODO", glob: "*.ts", path: "apps/web" } }),
).toBe("Searched TODO in web");
});
it("keeps bare filenames from explicit path fields", () => {
expect(collectToolFilePaths({ input: { file_path: "README" } })).toEqual(["README"]);
});
it("keeps the first non-empty rawInput when a later update is empty", () => {
expect(
mergeToolActivityData({ rawInput: { path: "src/a.ts" } }, { rawInput: {}, kind: "read" }),
).toEqual({
rawInput: { path: "src/a.ts" },
kind: "read",
});
expect(
mergeToolActivityData({ rawInput: { path: "src/a.ts" } }, { rawInput: { startLine: 4 } }),
).toEqual({ rawInput: { path: "src/a.ts", startLine: 4 } });
});
});