{"draft":null,"from":175,"to":318,"files":[{"path":"client/hooks/register.test.ts","added":68,"removed":6,"diff":"--- a/client/hooks/register.test.ts\n+++ b/client/hooks/register.test.ts\n@@ -3,9 +3,10 @@\n \n import type { On } from \"claude-code\";\n import { expect, mock, test } from \"claude-code/testing\";\n+import { HOOK_COMMAND } from \"./stamp.ts\";\n \n /** The world beneath the mod: a chat in /w/p, an abso folder when `inFolder`, and a server with `news` waiting. */\n-function world(on: On, inFolder: boolean, news: string[][]) {\n+function world(on: On, inFolder: boolean, news: string[][], server = \"https://avcs.test\") {\n \tmock.env(on, { AVCS_TOKEN: \"test-token\" });\n \tconst clock = mock.clock(on, { now: 1_000_000 });\n \tconst asked: string[] = [];\n@@ -21,7 +22,7 @@\n \ton(\"fs.read\", (_$, e) => {\n \t\tconst path = norm(e.path);\n \t\tif (inFolder && path === \"/w/p/.abso/config.json\")\n-\t\t\treturn { value: JSON.stringify({ server: \"https://avcs.test\", project: \"p\", agent: \"bob\" }) };\n+\t\t\treturn { value: JSON.stringify({ server, project: \"p\", agent: \"bob\" }) };\n \t\tif (written.has(path)) return { value: written.get(path)! };\n \t\treturn { deny: `ENOENT: ${path}` };\n \t});\n@@ -40,15 +41,17 @@\n \t\tappended.push((e.message.content as { text: string }[])[0]!.text);\n \t\treturn next(e);\n \t});\n+\t// Tools the chat calls run as asked.\n+\ton(\"tool.call\", () => ({ result: { isError: false, text: \"ok\" } }) as never);\n \treturn { clock, asked, auth, clients, appended, written };\n }\n \n-test(\"the news poll asks every 30 seconds in an abso folder, and keeps each item once\", async ($, on) => {\n+test(\"the news poll asks every 5 minutes in an abso folder, and keeps each item once\", async ($, on) => {\n \t// The kit has no conversation to append to, so the append itself is checked in a live session (#25);\n \t// here: the poll's timing, the call, and the news log the view mod reads.\n \tconst w = world(on, true, [[\"Announcement from lead: stop pushing until v12 lands\"], []]);\n \tawait $.session.start({ cwd: \"/w/p\" });\n-\tawait w.clock.advance(29_000);\n+\tawait w.clock.advance(299_000);\n \texpect(w.asked).toEqual([]);\n \tawait w.clock.advance(1_000);\n \texpect(w.asked).toEqual([\"https://avcs.test/p/p/a/bob/news\"]);\n@@ -56,12 +59,37 @@\n \texpect(w.auth[0]).toBe(\"none\");\n \t// Which mod asked: avcs-mod/<version> once installed, avcs-mod/checkout from a checkout (#29).\n \texpect(w.clients[0]).toMatch(/^avcs-mod\\/(checkout|\\d+\\.\\d+\\.\\d+(\\+[\\w.]+)?)$/);\n-\tawait w.clock.advance(30_000);\n+\tawait $.tool.call({ tool: \"Bash\", command: \"ls\" } as never);\n+\tawait w.clock.advance(300_000);\n \texpect(w.asked).toHaveLength(2);\n \tconst log = w.written.get(\"/w/p/.abso/news.log\") ?? \"\";\n \texpect(log.split(\"\\n\").filter((l) => l.includes(\"Announcement from lead\"))).toHaveLength(1);\n });\n \n+test(\"while the seat holds its news stream (abso 690), the poll stands down, and asks again once the mark runs out\", async ($, on) => {\n+\tconst w = world(on, true, [[], []]);\n+\tw.written.set(\"/w/p/.abso/news-stream.json\", JSON.stringify({ until: 1_000_000 + 400_000 }));\n+\tawait $.session.start({ cwd: \"/w/p\" });\n+\tawait w.clock.advance(300_000);\n+\texpect(w.asked).toEqual([]);\n+\tawait $.tool.call({ tool: \"Bash\", command: \"ls\" } as never);\n+\tawait w.clock.advance(300_000);\n+\texpect(w.asked).toEqual([\"https://avcs.test/p/p/a/bob/news\"]);\n+});\n+\n+test(\"a chat with no tool call for 10 minutes stops asking for news; its next tool call starts it again\", async ($, on) => {\n+\tconst w = world(on, true, [[], [], []]);\n+\tawait $.session.start({ cwd: \"/w/p\" });\n+\tawait w.clock.advance(300_000);\n+\texpect(w.asked).toHaveLength(1);\n+\t// Idle since the start: at 10 and 15 minutes it doesn't ask.\n+\tawait w.clock.advance(600_000);\n+\texpect(w.asked).toHaveLength(1);\n+\tawait $.tool.call({ tool: \"Read\", file_path: \"/w/p/a.ts\" } as never);\n+\tawait w.clock.advance(300_000);\n+\texpect(w.asked).toHaveLength(2);\n+});\n+\n test(\"outside an abso folder it never asks\", async ($, on) => {\n \tconst w = world(on, false, [[\"should not arrive\"]]);\n \tawait $.session.start({ cwd: \"/w/p\" });\n@@ -75,7 +103,6 @@\n \tw.written.set(\"/w/p/.abso/known/fuzz.ts\", \"one\\ntwo\\nthree\\n\");\n \tw.written.set(\"/w/p/fuzz.ts\", \"one\\ntwo\\nth\\u0000ree\\n\");\n \ton(\"fs.stat\", () => ({ value: { realPath: \"/w/p/fuzz.ts\" } }) as never);\n-\ton(\"tool.call\", () => ({ result: { isError: false, text: \"ok\" } }) as never);\n \ton(\"session.id\", () => ({ value: \"sess\" }));\n \tawait $.session.start({ cwd: \"/w/p\" });\n \tawait $.tool.call({\n@@ -88,3 +115,38 @@\n \texpect(w.written.get(\"/w/p/.abso/hook.log\") ?? \"\").toContain(\"not sent: a NUL byte at line 3\");\n \texpect(w.asked.filter((u) => !u.endsWith(\"/news\"))).toEqual([]);\n });\n+\n+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) => {\n+\tconst w = world(on, true, [], \"local\");\n+\tw.written.set(\"/w/p/notes.md\", \"hello\\n\");\n+\ton(\"fs.stat\", () => ({ value: { realPath: \"/w/p/notes.md\" } }) as never);\n+\ton(\"session.id\", () => ({ value: \"sess\" }));\n+\tconst ran: { argv: readonly string[]; stdin?: string; env?: Record<string, string> }[] = [];\n+\tconst context = \"abso: Announcement from lead: hold pushes\";\n+\ton(\"process.run\", (_$, e) => {\n+\t\tran.push({ argv: e.argv, stdin: e.init?.stdin, env: e.init?.env });\n+\t\tconst stdout = JSON.stringify({ hookSpecificOutput: { hookEventName: \"PostToolUse\", additionalContext: context } });\n+\t\treturn { value: { exitCode: 0, stdout, stderr: \"\" } } as never;\n+\t});\n+\tawait $.session.start({ cwd: \"/w/p\" });\n+\tawait $.tool.call({ tool: \"Write\", tool_use_id: \"t1\", file_path: \"/w/p/notes.md\", content: \"hello\\n\" } as never);\n+\tawait w.clock.advance(1_000);\n+\t// A local project has no server to call: nothing goes over the network.\n+\texpect(w.asked.filter((u) => !u.endsWith(\"/news\"))).toEqual([]);\n+\tconst log = w.written.get(\"/w/p/.abso/hook.log\") ?? \"\";\n+\tif (HOOK_COMMAND === undefined) {\n+\t\t// Loaded from a checkout, the mod has no client to hand it to.\n+\t\texpect(ran).toEqual([]);\n+\t\texpect(log).toContain(\"skipped: a local project\");\n+\t\treturn;\n+\t}\n+\texpect(ran).toHaveLength(1);\n+\texpect(ran[0]!.argv).toEqual(HOOK_COMMAND);\n+\texpect(ran[0]!.env).toEqual({ ABSO_HOOK_FORCE: \"1\" });\n+\tconst input = JSON.parse(ran[0]!.stdin ?? \"{}\") as Record<string, unknown>;\n+\texpect(input.session_id).toBe(\"sess\");\n+\texpect(input.tool_name).toBe(\"Write\");\n+\texpect((input.tool_input as Record<string, unknown>).file_path).toBe(\"/w/p/notes.md\");\n+\texpect(log).toContain(\"handed to abso hook\");\n+\texpect(w.appended).toEqual([context]);\n+});"}],"unmatched":[]}