The best way to control Claude Code, Codex and more from any computer or phone

main
ts 95 lines 2.91 KB
Raw
1 import { describe, expect, it } from "@effect/vitest";
2
3 import type { MuseItem } from "./protocol.ts";
4 import { museItemStatus, museToolPresentation } from "./itemPresentation.ts";
5
6 const item = (fields: Partial<MuseItem>): MuseItem => ({
7 itemId: "native-item",
8 kind: "toolCall",
9 status: "completed",
10 revision: 1,
11 ...fields,
12 });
13
14 describe("Muse item presentation", () => {
15 it("preserves an edit's file and exact old/new text for the shared diff UI", () => {
16 expect(
17 museToolPresentation(
18 item({
19 tool: "edit_file",
20 args: JSON.stringify({ file_path: "src/index.ts", old_string: "old\n", new_string: "" }),
21 }),
22 ),
23 ).toMatchObject({
24 type: "file_change",
25 status: "completed",
26 fileName: "src/index.ts",
27 oldStr: "old\n",
28 newStr: "",
29 });
30 });
31
32 it("preserves write content and provider-supplied patches", () => {
33 expect(
34 museToolPresentation(
35 item({
36 tool: "write_file",
37 args: JSON.stringify({ path: "README.md", content: "Hello\n" }),
38 }),
39 ),
40 ).toMatchObject({ type: "file_change", newStr: "Hello\n" });
41 expect(
42 museToolPresentation(
43 item({
44 tool: "apply_patch",
45 args: JSON.stringify({ path: "README.md", patch: "@@ -1 +1 @@\n-old\n+new" }),
46 }),
47 ),
48 ).toMatchObject({ type: "file_change", diffStr: "@@ -1 +1 @@\n-old\n+new" });
49 });
50
51 it.each(["rejected", "timedOut", "handedOff"])(
52 "does not report native %s activity as successful",
53 (status) => {
54 const native = item({ tool: "search_files", status, fallbackText: "Native explanation" });
55 expect(museItemStatus(native)).toBe("failed");
56 expect(museToolPresentation(native)).toMatchObject({
57 status: "failed",
58 output: `Muse reported ${status}.\nNative explanation`,
59 });
60 },
61 );
62
63 it("lists each web search hit and links a fetched page", () => {
64 const search = item({
65 tool: "web_search",
66 args: JSON.stringify({ query: "node lts" }),
67 visibleOutput: JSON.stringify({
68 query: "node lts",
69 results: [
70 { url: "https://nodejs.org/", title: "Node.js", snippet: "Node 24 is LTS", extra: 1 },
71 { url: "", title: "", snippet: "No link" },
72 ],
73 }),
74 });
75 expect(museToolPresentation(search)).toEqual({
76 status: "completed",
77 title: "web_search",
78 type: "web_search",
79 patterns: ["node lts"],
80 results: [
81 { url: "https://nodejs.org/", title: "Node.js", snippet: "Node 24 is LTS" },
82 { snippet: "No link" },
83 ],
84 });
85 const fetch = item({
86 tool: "web_fetch",
87 args: JSON.stringify({ url: "https://nodejs.org/en/about" }),
88 visibleOutput: "About Node.js",
89 });
90 expect(museToolPresentation(fetch)).toMatchObject({
91 type: "web_search",
92 results: [{ url: "https://nodejs.org/en/about", snippet: "About Node.js" }],
93 });
94 });
95 });