Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed
MCP
code on this site's /mcp
CLI
none: the JSON below is the answer
JSON
/christopher/abso-core/files/client/hooks/register.test.ts?draft=login-wait&format=json
90 linesFirst import 90% · review 6% · pinch 4%0 versions changed it
1// The abso mod's news poll, against the engine (claude plugin test client):
2// an agent that isn't editing still gets announcements, within 30 seconds.
3
4import type { On } from "claude-code";
5import { expect, mock, test } from "claude-code/testing";
6
7/** The world beneath the mod: a chat in /w/p, an abso folder when `inFolder`, and a server with `news` waiting. */
8function world(on: On, inFolder: boolean, news: string[][]) {
9 mock.env(on, { AVCS_TOKEN: "test-token" });
10 const clock = mock.clock(on, { now: 1_000_000 });
11 const asked: string[] = [];
12 const auth: string[] = [];
13 const clients: string[] = [];
14 const appended: string[] = [];
15 const written = new Map<string, string>();
16 // The engine hands hooks paths resolved for this machine (C:\w\p on Windows).
17 const norm = (p: string) => p.replace(/\\/g, "/").replace(/^[A-Za-z]:/, "");
18 on("session.start", (_$, e) => ({ cwd: (e as { cwd?: string }).cwd ?? "/w/p" }));
19 on("session.cwd", () => ({ value: "/w/p" }));
20 on("fs.exists", (_$, e) => ({ value: inFolder && norm(e.path) === "/w/p/.abso/config.json" }));
21 on("fs.read", (_$, e) => {
22 const path = norm(e.path);
23 if (inFolder && path === "/w/p/.abso/config.json")
24 return { value: JSON.stringify({ server: "https://avcs.test", project: "p", agent: "bob" }) };
25 if (written.has(path)) return { value: written.get(path)! };
26 return { deny: `ENOENT: ${path}` };
27 });
28 on("fs.write", (_$, e) => {
29 written.set(norm(e.path), e.text);
30 return { value: undefined };
31 });
32 on("http.fetch", (_$, e) => {
33 asked.push(e.url);
34 auth.push((e.init?.headers as Record<string, string> | undefined)?.authorization ?? "none");
35 clients.push(String((e.init?.headers as Record<string, string> | undefined)?.["x-abso-client"]));
36 return { value: { status: 200, ok: true, headers: {}, text: JSON.stringify({ news: news.shift() ?? [] }) } };
37 });
38 // The engine stores the row itself: a session.append hook passes it on and answers what next answered.
39 on("session.append", (_$, e, next) => {
40 appended.push((e.message.content as { text: string }[])[0]!.text);
41 return next(e);
42 });
43 return { clock, asked, auth, clients, appended, written };
46test("the news poll asks every 30 seconds in an abso folder, and keeps each item once", async ($, on) => {
47 // The kit has no conversation to append to, so the append itself is checked in a live session (#25);
48 // here: the poll's timing, the call, and the news log the view mod reads.
49 const w = world(on, true, [["Announcement from lead: stop publishing until v12 lands"], []]);
50 await $.session.start({ cwd: "/w/p" });
51 await w.clock.advance(29_000);
52 expect(w.asked).toEqual([]);
53 await w.clock.advance(1_000);
54 expect(w.asked).toEqual(["https://avcs.test/p/p/a/bob/news"]);
55 // avcs.test isn't a server the token goes to (#30): the call goes out without it.
56 expect(w.auth[0]).toBe("none");
57 // Which mod asked: avcs-mod/<version> once installed, avcs-mod/checkout from a checkout (#29).
58 expect(w.clients[0]).toMatch(/^avcs-mod\/(checkout|\d+\.\d+\.\d+(\+[\w.]+)?)$/);
59 await w.clock.advance(30_000);
60 expect(w.asked).toHaveLength(2);
61 const log = w.written.get("/w/p/.abso/news.log") ?? "";
62 expect(log.split("\n").filter((l) => l.includes("Announcement from lead"))).toHaveLength(1);
63});
65test("outside an abso folder it never asks", async ($, on) => {
66 const w = world(on, false, [["should not arrive"]]);
67 await $.session.start({ cwd: "/w/p" });
68 await w.clock.advance(120_000);
69 expect(w.asked).toEqual([]);
70 expect(w.appended).toEqual([]);
71});
73test("an edit that leaves a NUL byte in a text file is not sent, and the log says where", async ($, on) => {
74 const w = world(on, true, []);
75 w.written.set("/w/p/.abso/known/fuzz.ts", "one\ntwo\nthree\n");
76 w.written.set("/w/p/fuzz.ts", "one\ntwo\nth\u0000ree\n");
77 on("fs.stat", () => ({ value: { realPath: "/w/p/fuzz.ts" } }) as never);
78 on("tool.call", () => ({ result: { isError: false, text: "ok" } }) as never);
79 on("session.id", () => ({ value: "sess" }));
80 await $.session.start({ cwd: "/w/p" });
81 await $.tool.call({
82 tool: "Write",
83 tool_use_id: "t1",
84 file_path: "/w/p/fuzz.ts",
85 content: "one\ntwo\nth\u0000ree\n",
86 } as never);
87 await w.clock.advance(1_000);
88 expect(w.written.get("/w/p/.abso/hook.log") ?? "").toContain("not sent: a NUL byte at line 3");
89 expect(w.asked.filter((u) => !u.endsWith("/news"))).toEqual([]);
90});