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/test/doctor.test.ts?version=156&format=json
245 linesspeed 99% · rename 1%Last change speed in version 156, 4 versions changed it

You're reading version 156. The newest is 318, and 2 versions since then changed this file. Go to the newestCompare with 318

1// abso whoami and abso doctor: each check's line, the next step when one fails, the server asked as the box and as
2// the folder's key, and no credential in anything printed. plainError's wording of the commonest failures.
3
4import assert from "node:assert/strict";
5import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
6import { tmpdir } from "node:os";
7import { join } from "node:path";
8import { test } from "node:test";
9import { ApiError } from "../src/api-error.ts";
10import { writeBox } from "../src/box.ts";
11import { doctor, doctorText, nodeNeeded, type Probe, plainError, whoami } from "../src/doctor.ts";
13const SERVER = "https://staging.abso.example";
14const CREDENTIAL = "abso_bx_the-secret-credential";
15const KEY = "abso_sk_the-secret-key";
16const NOW = Date.parse("2026-10-10T06:00:00.000Z");
17const grant = { projects: [{ project: "game", role: "writer" }], max_agents: 3 };
18const box = (expiresAt = Date.parse("2026-10-20T00:00:00.000Z")) => ({
19 server: SERVER,
20 id: "b_0123abcd",
21 credential: CREDENTIAL,
22 grant,
23 expiresAt,
24});
26const temp = (name: string) => mkdtempSync(join(tmpdir(), `abso-doctor-${name}-`));
28function folder(): string {
29 const root = temp("folder");
30 mkdirSync(join(root, ".abso"));
31 writeFileSync(
32 join(root, ".abso", "config.json"),
33 JSON.stringify({ server: SERVER, project: "game", agent: "builder" }),
34 );
35 writeFileSync(join(root, ".abso", "key"), JSON.stringify({ server: SERVER, key: KEY, id: "k_00c0ffee" }));
36 return root;
39type Seen = { url: string; auth: string | null }[];
40/** A server answering by path: /version, /box, /p/game/head. A missing path throws, like a refused connection. */
41function server(answers: Record<string, [number, unknown]>, seen: Seen = []): typeof fetch {
42 return (async (url, init) => {
43 const u = new URL(String(url));
44 seen.push({ url: u.pathname, auth: new Headers(init?.headers).get("authorization") });
45 const answer = answers[u.pathname];
46 if (!answer)
47 throw Object.assign(new TypeError("fetch failed"), {
48 cause: { code: "ECONNREFUSED", message: "connect ECONNREFUSED" },
49 });
50 return new Response(JSON.stringify(answer[1]), { status: answer[0] });
51 }) as typeof fetch;
54const probe = (fetcher: typeof fetch, home: string, node = "24.7.0", built = false): Probe => ({
55 fetcher,
56 now: NOW,
57 node,
58 built,
59 home,
60});
61const accepted = { box_id: "b_0123abcd", revoked_at: null, approved_by: "christopher", grant };
63test("the npm package needs Node 20; a checkout, which runs its .ts as is, needs 24", () => {
64 assert.equal(nodeNeeded(true), 20);
65 assert.equal(nodeNeeded(false), 24);
66});
68test("doctor outside a folder with no sign-in: the box check fails with abso login, the folder check doesn't apply", async () => {
69 const checks = await doctor(
70 SERVER,
71 temp("outside"),
72 {},
73 probe(server({ "/version": [200, { commit: "ff7cd0e1" }] }), temp("home")),
74 );
75 assert.deepEqual(
76 checks.map((c) => [c.check, c.result]),
77 [
78 ["node", "ok"],
79 ["server", "ok"],
80 ["box", "fail"],
81 ["folder", "skip"],
82 ],
83 );
84 assert.match(checks[1]!.text, /answers \(version ff7cd0e\)/);
85 assert.match(checks[2]!.text, /isn't signed in to https:\/\/staging\.abso\.example\. Run abso login\./);
86 assert.match(checks[3]!.text, /abso join <project> makes one/);
87});
89test("doctor in a folder, signed in: every check passes, the box and the key each go to their own check", async () => {
90 const home = temp("home");
91 writeBox(box(), home);
92 const seen: Seen = [];
93 const checks = await doctor(
94 SERVER,
95 folder(),
96 {},
97 probe(
98 server({ "/version": [200, { commit: "ff7cd0e" }], "/box": [200, accepted], "/p/game/head": [200, {}] }, seen),
99 home,
100 ),
101 );
102 assert.deepEqual(
103 checks.map((c) => c.result),
104 ["ok", "ok", "ok", "ok"],
105 );
106 assert.match(checks[3]!.text, /agent builder in game, with the agent key k_00c0ffee, which the server accepts/);
107 assert.deepEqual(seen, [
108 { url: "/version", auth: null },
109 { url: "/box", auth: `Box ${CREDENTIAL}` },
110 { url: "/p/game/head", auth: `Bearer ${KEY}` },
111 ]);
112 const text = doctorText(checks);
113 assert.ok(!text.includes(CREDENTIAL) && !text.includes(KEY));
114 assert.match(text, /^ok {4}Node 24\.7\.0/);
115});
117test("doctor when the server can't be reached: says so with the next step, and the checks that need it don't apply", async () => {
118 const home = temp("home");
119 writeBox(box(), home);
120 const checks = await doctor(SERVER, folder(), {}, probe(server({}), home));
121 assert.deepEqual(
122 checks.map((c) => c.result),
123 ["ok", "fail", "skip", "skip"],
124 );
125 assert.match(
126 checks[1]!.text,
127 /Can't reach https:\/\/staging\.abso\.example: the connection was refused\. Check your connection, and the server in \.abso\/config\.json\./,
128 );
129});
131test("doctor when the server refuses the box and the key: each fails with what to do", async () => {
132 const home = temp("home");
133 writeBox(box(), home);
134 const checks = await doctor(
135 SERVER,
136 folder(),
137 {},
138 probe(
139 server({
140 "/version": [200, {}],
141 "/box": [200, { ...accepted, revoked_at: NOW - 1000 }],
142 "/p/game/head": [401, { error: "missing or wrong token" }],
143 }),
144 home,
145 ),
146 );
147 assert.deepEqual(
148 checks.map((c) => c.result),
149 ["ok", "ok", "fail", "fail"],
150 );
151 assert.match(checks[2]!.text, /no longer accepts this box's sign-in \(signed out or revoked\)\. Run abso login\./);
152 assert.match(checks[3]!.text, /didn't accept the agent key k_00c0ffee for game.*abso join game again/);
153});
155test("doctor: an expired sign-in and an old Node fail without asking the server about them", async () => {
156 const home = temp("home");
157 writeBox(box(NOW - 60_000), home);
158 const seen: Seen = [];
159 const checks = await doctor(
160 SERVER,
161 temp("outside"),
162 {},
163 probe(server({ "/version": [200, {}] }, seen), home, "20.11.0", false),
164 );
165 assert.equal(checks[0]!.result, "fail");
166 assert.match(checks[0]!.text, /Node 20\.11\.0 is too old: abso needs 24 or later\./);
167 assert.equal(checks[2]!.result, "fail");
168 assert.match(checks[2]!.text, /expired 2026-10-10 05:59 UTC\. Run abso login\./);
169 assert.deepEqual(
170 seen.map((s) => s.url),
171 ["/version"],
172 );
173});
175test("whoami: the box as the server sees it, who approved it, and this folder's agent and key, never a credential", async () => {
176 const home = temp("home");
177 writeBox(box(), home);
178 const out = await whoami(SERVER, folder(), {}, probe(server({ "/box": [200, accepted] }), home));
179 assert.match(
180 out.text,
181 /^Signed in to https:\/\/staging\.abso\.example as box b_0123abcd, approved by christopher\.\n/,
182 );
183 assert.match(out.text, /Projects: game \(writer\)\. Up to 3 agents\./);
184 assert.match(
185 out.text,
186 /This folder is agent builder in project game on https:\/\/staging\.abso\.example, with the agent key k_00c0ffee\./,
187 );
188 assert.ok(!JSON.stringify(out).includes(CREDENTIAL) && !JSON.stringify(out).includes(KEY));
189 assert.equal((out.json.box as { confirmed: boolean }).confirmed, true);
190});
192test("whoami signed out, outside a folder: the next step for each", async () => {
193 const out = await whoami(SERVER, temp("outside"), {}, probe(server({}), temp("home")));
194 assert.equal(
195 out.text,
196 "This box isn't signed in to https://staging.abso.example. Run abso login.\nYou're not in an abso folder. abso join <project> makes one.",
197 );
198});
200test("whoami when the server says the box is revoked", async () => {
201 const home = temp("home");
202 writeBox(box(), home);
203 const out = await whoami(
204 SERVER,
205 temp("outside"),
206 {},
207 probe(server({ "/box": [401, { error: "missing or wrong token" }] }), home),
208 );
209 assert.match(out.text, /no longer accepts this box's sign-in \(signed out or revoked\)\. Run abso login\./);
210});
212test("plainError words a refusal by whether a credential went, and a server that can't be reached", () => {
213 const refused = new ApiError("GET /status answered 401: missing or wrong token", 401);
214 assert.equal(plainError(refused, false), "You're not signed in. Run abso login, then abso join <project>.");
215 assert.match(plainError(refused, true)!, /^The server didn't accept this folder's key.*abso doctor checks it/);
216 assert.equal(
217 plainError(new ApiError("could not reach https://api.abso.dev: connect ECONNREFUSED"), true),
218 "Can't reach https://api.abso.dev: connect ECONNREFUSED. Check your connection; abso doctor checks the rest.",
219 );
220 assert.equal(
221 plainError(
222 new ApiError("could not reach http://x: refused. Nothing was pushed. Run the same command again."),
223 true,
224 ),
225 "Can't reach http://x: refused. Nothing was pushed. Run the same command again.",
226 );
227 assert.equal(plainError(new ApiError("GET /log answered 500: boom", 500), true), undefined);
228 assert.equal(plainError(new Error("anything else"), true), undefined);
229});
231test("whoami with nothing named shows prod, and names the other servers this box is signed in to", async () => {
232 const outside = temp("outside");
233 const home = temp("home");
234 writeBox(box(), home);
235 const fetcher = server({ "/box": [200, { revoked_at: null }] });
236 const prod = await whoami("https://api.abso.dev", outside, {}, probe(fetcher, home));
237 assert.match(
238 prod.text,
239 /This box isn't signed in to https:\/\/api\.abso\.dev\. Run abso login\. This box is signed in to https:\/\/staging\.abso\.example: abso whoami --server <url> uses it\./,
240 );
241 writeBox({ ...box(), server: "https://api.abso.dev" }, home);
242 const both = await whoami("https://api.abso.dev", outside, {}, probe(fetcher, home));
243 assert.match(both.text, /Signed in to https:\/\/api\.abso\.dev as box b_0123abcd/);
244 assert.equal(both.json.server, "https://api.abso.dev");
245});