Lines 3–12 at 318 (were 3–11 at 116)
44import type { On } from "claude-code"; 55import { expect, mock, test } from "claude-code/testing"; 6+import { HOOK_COMMAND } from "./stamp.ts"; 78/** The world beneath the mod: a chat in /w/p, an abso folder when `inFolder`, and a server with `news` waiting. */ 8−function world(on: On, inFolder: boolean, news: string[][]) {
9+function world(on: On, inFolder: boolean, news: string[][], server = "https://avcs.test") { 910 mock.env(on, { AVCS_TOKEN: "test-token" }); 1011 const clock = mock.clock(on, { now: 1_000_000 }); 1112 const asked: string[] = []; Lines 22–28 at 318 (were 21–27 at 116)
2122 on("fs.read", (_$, e) => { 2223 const path = norm(e.path); 2324 if (inFolder && path === "/w/p/.abso/config.json") 24− return { value: JSON.stringify({ server: "https://avcs.test", project: "p", agent: "bob" }) };
25+ return { value: JSON.stringify({ server, project: "p", agent: "bob" }) }; 2526 if (written.has(path)) return { value: written.get(path)! }; 2627 return { deny: `ENOENT: ${path}` }; Lines 41–57 at 318 (were 40–54 at 116)
4041 appended.push((e.message.content as { text: string }[])[0]!.text); 44+ // Tools the chat calls run as asked. 45+ on("tool.call", () => ({ result: { isError: false, text: "ok" } }) as never); 4346 return { clock, asked, auth, clients, appended, written }; 46−test("the news poll asks every 30 seconds in an abso folder, and keeps each item once", async ($, on) => {
49+test("the news poll asks every 5 minutes in an abso folder, and keeps each item once", async ($, on) => { 4750 // The kit has no conversation to append to, so the append itself is checked in a live session (#25); 4851 // here: the poll's timing, the call, and the news log the view mod reads. 4952 const w = world(on, true, [["Announcement from lead: stop pushing until v12 lands"], []]); 5053 await $.session.start({ cwd: "/w/p" }); 51− await w.clock.advance(29_000);
54+ await w.clock.advance(299_000); 5255 expect(w.asked).toEqual([]); 5356 await w.clock.advance(1_000); 5457 expect(w.asked).toEqual(["https://avcs.test/p/p/a/bob/news"]); Lines 59–95 at 318 (were 56–67 at 116)
5659 expect(w.auth[0]).toBe("none"); 5760 // Which mod asked: avcs-mod/<version> once installed, avcs-mod/checkout from a checkout (#29). 5861 expect(w.clients[0]).toMatch(/^avcs-mod\/(checkout|\d+\.\d+\.\d+(\+[\w.]+)?)$/); 59− await w.clock.advance(30_000);
62+ await $.tool.call({ tool: "Bash", command: "ls" } as never); 63+ await w.clock.advance(300_000); 6064 expect(w.asked).toHaveLength(2); 6165 const log = w.written.get("/w/p/.abso/news.log") ?? ""; 6266 expect(log.split("\n").filter((l) => l.includes("Announcement from lead"))).toHaveLength(1); 69+test("while the seat holds its news stream (abso 690), the poll stands down, and asks again once the mark runs out", async ($, on) => { 70+ const w = world(on, true, [[], []]); 71+ w.written.set("/w/p/.abso/news-stream.json", JSON.stringify({ until: 1_000_000 + 400_000 })); 72+ await $.session.start({ cwd: "/w/p" }); 73+ await w.clock.advance(300_000); 74+ expect(w.asked).toEqual([]); 75+ await $.tool.call({ tool: "Bash", command: "ls" } as never); 76+ await w.clock.advance(300_000); 77+ expect(w.asked).toEqual(["https://avcs.test/p/p/a/bob/news"]); 80+test("a chat with no tool call for 10 minutes stops asking for news; its next tool call starts it again", async ($, on) => { 81+ const w = world(on, true, [[], [], []]); 82+ await $.session.start({ cwd: "/w/p" }); 83+ await w.clock.advance(300_000); 84+ expect(w.asked).toHaveLength(1); 85+ // Idle since the start: at 10 and 15 minutes it doesn't ask. 86+ await w.clock.advance(600_000); 87+ expect(w.asked).toHaveLength(1); 88+ await $.tool.call({ tool: "Read", file_path: "/w/p/a.ts" } as never); 89+ await w.clock.advance(300_000); 90+ expect(w.asked).toHaveLength(2); 6593test("outside an abso folder it never asks", async ($, on) => { 6694 const w = world(on, false, [["should not arrive"]]); 6795 await $.session.start({ cwd: "/w/p" }); Lines 103–108 at 318 (were 75–81 at 116)
75103 w.written.set("/w/p/.abso/known/fuzz.ts", "one\ntwo\nthree\n"); 76104 w.written.set("/w/p/fuzz.ts", "one\ntwo\nth\u0000ree\n"); 77105 on("fs.stat", () => ({ value: { realPath: "/w/p/fuzz.ts" } }) as never); 78− on("tool.call", () => ({ result: { isError: false, text: "ok" } }) as never);
79106 on("session.id", () => ({ value: "sess" })); 80107 await $.session.start({ cwd: "/w/p" }); 81108 await $.tool.call({ Lines 115–152 at 318 (were 88–90 at 116)
88115 expect(w.written.get("/w/p/.abso/hook.log") ?? "").toContain("not sent: a NUL byte at line 3"); 89116 expect(w.asked.filter((u) => !u.endsWith("/news"))).toEqual([]); 119+test("a local project's edit goes to abso hook as Claude Code's command hook would get it, and its news to the chat", async ($, on) => { 120+ const w = world(on, true, [], "local"); 121+ w.written.set("/w/p/notes.md", "hello\n"); 122+ on("fs.stat", () => ({ value: { realPath: "/w/p/notes.md" } }) as never); 123+ on("session.id", () => ({ value: "sess" })); 124+ const ran: { argv: readonly string[]; stdin?: string; env?: Record<string, string> }[] = []; 125+ const context = "abso: Announcement from lead: hold pushes"; 126+ on("process.run", (_$, e) => { 127+ ran.push({ argv: e.argv, stdin: e.init?.stdin, env: e.init?.env }); 128+ const stdout = JSON.stringify({ hookSpecificOutput: { hookEventName: "PostToolUse", additionalContext: context } }); 129+ return { value: { exitCode: 0, stdout, stderr: "" } } as never; 131+ await $.session.start({ cwd: "/w/p" }); 132+ await $.tool.call({ tool: "Write", tool_use_id: "t1", file_path: "/w/p/notes.md", content: "hello\n" } as never); 133+ await w.clock.advance(1_000); 134+ // A local project has no server to call: nothing goes over the network. 135+ expect(w.asked.filter((u) => !u.endsWith("/news"))).toEqual([]); 136+ const log = w.written.get("/w/p/.abso/hook.log") ?? ""; 137+ if (HOOK_COMMAND === undefined) { 138+ // Loaded from a checkout, the mod has no client to hand it to. 139+ expect(ran).toEqual([]); 140+ expect(log).toContain("skipped: a local project"); 143+ expect(ran).toHaveLength(1); 144+ expect(ran[0]!.argv).toEqual(HOOK_COMMAND); 145+ expect(ran[0]!.env).toEqual({ ABSO_HOOK_FORCE: "1" }); 146+ const input = JSON.parse(ran[0]!.stdin ?? "{}") as Record<string, unknown>; 147+ expect(input.session_id).toBe("sess"); 148+ expect(input.tool_name).toBe("Write"); 149+ expect((input.tool_input as Record<string, unknown>).file_path).toBe("/w/p/notes.md"); 150+ expect(log).toContain("handed to abso hook"); 151+ expect(w.appended).toEqual([context]);