- MCP
- code on this site's /mcp
- CLI
- none: the JSON below is the answer
- JSON
- /christopher/abso-core/files/client/view/hooks/register.test.ts?format=json
138 linesFirst import 91% · review 7% · pinch 2% · rename 1%Last change rename in version 100, 6 versions changed it
1// abso-view against the engine: the server and the folder are answered here.
3import type { On } from "claude-code";
4import { expect, mock, test } from "claude-code/testing";
6const STATUS = {
7 version: 7,
8 agents: [
9 {
10 agent: "me",
11 draft: null,
12 base: 5,
13 draftChanges: 3,
14 files: ["src/a.ts", "src/b.ts"],
15 parked: [{ draft: "exp", draftChanges: 2 }],
16 },
17 { agent: "bob", draft: null, base: 7, draftChanges: 1, files: ["src/a.ts"] },
18 ],
19 drafts: [],
20};
21const WHERE = {
22 version: 7,
23 files: {
24 "src/a.ts": [
25 { agent: "me", lines: [[1, 2]], shared: [[1, 2]], changes: 2, lastEdit: 0 },
26 { agent: "bob", lines: [[9, 9]], shared: [[9, 9]], changes: 1, lastEdit: 0 },
27 ],
28 "src/b.ts": [{ agent: "me", lines: [[1, 1]], shared: [[1, 1]], changes: 1, lastEdit: 0 }],
29 },
30};
31const NEWS = "2026-10-05T01:00:00.000Z\tbob changed parse, which src/a.ts uses.\n";
33/** The world beneath the plugin: a session in /w/proj/src, an abso folder at /w/proj when `inFolder`. */
34function world(on: On, inFolder: boolean) {
35 mock.env(on, { AVCS_TOKEN: "test-token" });
36 const clock = mock.clock(on, { now: 1_000_000 });
37 const fetched: string[] = [];
38 const statuses: (string | undefined)[] = [];
39 const opened: string[] = [];
40 const reads: string[] = [];
41 on("session.start", (_$, e) => ({ cwd: (e as { cwd?: string }).cwd ?? "/w/proj/src" }));
42 on("session.cwd", () => ({ value: "/w/proj/src" }));
43 on("command.register", (_$, e) => ({ value: { command: e.name } }));
44 on("fs.exists", (_$, e) => ({
45 value: inFolder && e.path.replace(/\\/g, "/").replace(/^[A-Za-z]:/, "") === "/w/proj/.abso/config.json",
46 }));
47 on("fs.read", (_$, e) => {
48 // The engine hands hooks the path resolved for this machine (C:\w\proj on Windows).
49 const path = e.path.replace(/\\/g, "/").replace(/^[A-Za-z]:/, "");
50 reads.push(path);
51 if (inFolder && path === "/w/proj/.abso/config.json")
52 return { value: JSON.stringify({ server: "https://avcs.test", project: "p", agent: "me" }) };
53 if (inFolder && path === "/w/proj/.abso/news.log") return { value: NEWS };
54 return { deny: `ENOENT: ${e.path}` };
55 });
56 on("http.fetch", (_$, e) => {
57 fetched.push(e.url);
58 const body = e.url.endsWith("/status") ? STATUS : WHERE;
59 return { value: { status: 200, ok: true, headers: {}, text: JSON.stringify(body) } };
60 });
61 on("ui.status", (_$, e) => {
62 statuses.push(e.text);
63 return { value: undefined };
64 });
65 on("ui.open", (_$, e) => {
66 opened.push(e.id);
67 return { value: { isPlaced: true } };
68 });
69 return { clock, fetched, statuses, opened, reads };
70}
72test("outside an abso folder it asks nothing and shows nothing", async ($, on) => {
73 const w = world(on, false);
74 await $.session.start({ cwd: "/w/proj/src" });
75 await w.clock.advance(120_000);
76 expect(w.fetched).toEqual([]);
77 expect(w.statuses).toEqual([]);
78});
80test("in an abso folder it keeps a status line, and refreshes on a timer", async ($, on) => {
81 const w = world(on, true);
82 await $.session.start({ cwd: "/w/proj/src" });
83 await w.clock.advance(1);
84 expect(w.fetched).toEqual(["https://avcs.test/p/p/status", "https://avcs.test/p/p/where"]);
85 expect(w.statuses.at(-1)).toBe(
86 "abso: shared · 2 files unpushed · shared is 2 ahead (abso pull) · bob also on your files · 1 news item (/abso-view)",
87 );
88 await w.clock.advance(31_000);
89 expect(w.fetched.length).toBe(4);
90});
92test("the pane shows the space, the draft, who else is on the files, and news", async ($, on) => {
93 const w = world(on, true);
94 await $.session.start({ cwd: "/w/proj/src" });
95 await w.clock.advance(1);
96 for (const surface of ["terminal", "desktop"] as const) {
97 const ui = await $.ui.mount({
98 plugin: "abso-view",
99 surface,
100 component: "Pane",
101 requestId: "abso-view",
102 props: { title: "avcs", isFocused: false, bodyColumns: 80, placement: "dock" } as never,
103 });
104 expect(await ui.find({ text: /Working in shared, at version 7/ })).toBeDefined();
105 expect(await ui.find({ text: /3 changes in 2 files/ })).toBeDefined();
106 expect(await ui.find({ text: /bob: src\/a\.ts/ })).toBeDefined();
107 expect(await ui.find({ text: /Parked: exp \(2 changes\)/ })).toBeDefined();
108 expect(await ui.find({ text: /bob changed parse/ })).toBeDefined();
109 }
110});
112test("/abso-view opens the pane, and the status line stops counting the news it showed", async ($, on) => {
113 const w = world(on, true);
114 await $.session.start({ cwd: "/w/proj/src" });
115 await w.clock.advance(1);
116 expect(w.statuses.at(-1)).toContain("1 news item");
117 const answer = await $.command.run({ command: "abso-view", args: "" } as never);
118 expect(answer).toMatchObject({ text: "Opened the abso view." });
119 expect(w.opened).toEqual(["abso-view"]);
120 expect(w.statuses.at(-1)).not.toContain("news");
121});
123test("an edit brings a refresh a few seconds later, not 30", async ($, on) => {
124 const w = world(on, true);
125 on("tool.call", () => ({ result: { isError: false, text: "ok" } }) as never);
126 await $.session.start({ cwd: "/w/proj/src" });
127 await w.clock.advance(1);
128 expect(w.fetched.length).toBe(2);
129 await $.tool.call({
130 tool: "Edit",
131 tool_use_id: "t1",
132 file_path: "/w/proj/src/a.ts",
133 old_string: "a",
134 new_string: "b",
135 } as never);
136 await w.clock.advance(6_000);
137 expect(w.fetched.length).toBe(4);
138});