Files
paseo/packages/app/src/utils/extract-tool-call-file-path.test.ts
T
Mohamed Boudra 521944f19b feat: add open-file button to tool call badges
Show a file-symlink icon on hover that opens the file referenced by read,
edit, write, and simple shell commands (cat, head, tail, etc). Extracts
the file path from tool call details via a new utility with tests.
2026-04-26 08:15:16 +07:00

43 lines
1.6 KiB
TypeScript

import { describe, it, expect } from "vitest";
import { extractToolCallFilePath } from "./extract-tool-call-file-path";
describe("extractToolCallFilePath", () => {
it("returns filePath for read/edit/write", () => {
expect(extractToolCallFilePath({ type: "read", filePath: "/a.ts" })).toBe("/a.ts");
expect(extractToolCallFilePath({ type: "edit", filePath: "/b.ts" })).toBe("/b.ts");
expect(extractToolCallFilePath({ type: "write", filePath: "/c.ts" })).toBe("/c.ts");
});
it("returns null for empty filePath", () => {
expect(extractToolCallFilePath({ type: "read", filePath: "" })).toBeNull();
});
it.each([
["cat ~/file.md", "~/file.md"],
["wc -l ~/.paseo/plans/projects-settings-page.md", "~/.paseo/plans/projects-settings-page.md"],
["head -n 20 src/index.ts", "src/index.ts"],
["tail -f /var/log/x.log", "/var/log/x.log"],
["less ./README.md", "./README.md"],
["stat /tmp/foo", "/tmp/foo"],
])("matches shell command %s", (command, expected) => {
expect(extractToolCallFilePath({ type: "shell", command })).toBe(expected);
});
it.each([
"cat a.ts | grep foo",
"cat a.ts > b.ts",
"cat a.ts b.ts",
"echo hi",
"ls /tmp",
"rm -rf /tmp",
])("returns null for non-matching shell %s", (command) => {
expect(extractToolCallFilePath({ type: "shell", command })).toBeNull();
});
it("returns null for unrelated detail types", () => {
expect(extractToolCallFilePath({ type: "search", query: "foo" })).toBeNull();
expect(extractToolCallFilePath({ type: "unknown", input: null, output: null })).toBeNull();
expect(extractToolCallFilePath(undefined)).toBeNull();
});
});