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

Versions 116 to 318

Compare

+148 −33 in 8 places
Lines 9–15 at 318 (were 9–14 at 116)
99import { test } from "node:test";
1010import { parseArgs } from "../src/args.ts";
1111import {
12+ boxCreateProject,
1213 boxPublic,
1314 boxText,
1415 forgetBox,
Lines 32–37 at 318 (were 31–37 at 116)
3132 { project: "abso", role: "writer" },
3233 { project: "game", role: "reader" },
3334 ],
34− max_agents: 5,
3535};
3636const EXPIRES = "2026-10-15T00:00:00.000Z";
3737const record = { server: SERVER, id: "b_0123abcd", credential: CREDENTIAL, grant, expiresAt: Date.parse(EXPIRES) };
Lines 70–90 at 318 (were 70–92 at 116)
7070 };
7171}
7272
73−test("login grant options validate project lists, roles, limits and duration", () => {
73+test("login grant options validate project lists, roles and duration", () => {
7474 const request = (...words: string[]) =>
7575 loginRequest(
7676 parseArgs("login", words, {
7777 projects: "string",
7878 role: "string",
79− "max-agents": "string",
8079 days: "string",
8180 }),
8281 );
8382 assert.equal(request(), undefined);
84− assert.deepEqual(request("--projects", "alpha, beta,alpha", "--max-agents", "1", "--days", "30"), {
83+ assert.deepEqual(request("--projects", "alpha, beta,alpha", "--days", "30"), {
8584 projects: [
8685 { project: "alpha", role: "writer" },
8786 { project: "beta", role: "writer" },
8887 ],
89− max_agents: 1,
9088 days: 30,
9189 });
9290 assert.deepEqual(request("--projects", "alpha", "--role", "reader"), {
Lines 93–99 at 318 (were 95–101 at 116)
9593 assert.deepEqual(request("--projects", "alpha", "--role", "owner"), {
9694 projects: [{ project: "alpha", role: "owner" }],
9795 });
98− assert.deepEqual(request("--max-agents", "50", "--days", "90"), { max_agents: 50, days: 90 });
96+ assert.deepEqual(request("--days", "90"), { days: 90 });
9997 for (const words of [
10098 ["--role", "writer"],
10199 ["--projects", ""],
Lines 103–118 at 318 (were 105–122 at 116)
105103 ["--projects", Array.from({ length: 101 }, (_, i) => `p${i}`).join(",")],
106104 ])
107105 assert.throws(() => request(...words));
108− for (const flag of ["--max-agents", "--days"]) {
109− for (const value of ["0", "-1", "1.5", "1e1", "Infinity", "100", "abc", ""])
110− assert.throws(() => request(flag, value));
111− }
106+ for (const value of ["0", "-1", "1.5", "1e1", "Infinity", "100", "abc", ""])
107+ assert.throws(() => request("--days", value));
112108});
113109
114110test("login sends requested grants only at device start and retains the user's actual approval", async () => {
115111 const h = home();
116112 const seen: Seen = [];
117113 const c = clock();
118− const requested = { projects: [{ project: "abso", role: "owner" as const }], max_agents: 10, days: 90 };
119− const approved = { projects: [{ project: "abso", role: "reader" }], max_agents: 1 };
114+ const requested = { projects: [{ project: "abso", role: "owner" as const }], days: 90 };
115+ const approved = { projects: [{ project: "abso", role: "reader" }] };
120116 const got = await login(
121117 SERVER,
122118 {
Lines 205–212 at 318 (were 209–215 at 116)
209205 assert.equal(files.length, 1);
210206 assert.ok(readFileSync(join(h, ".abso", "boxes", files[0]!), "utf8").includes(CREDENTIAL));
211207 assert.equal(boxText(got, SERVER, 0).includes(CREDENTIAL), false);
212− assert.match(boxText(got, SERVER, 0), /abso \(writer\), game \(reader\)\. Up to 5 agents\./);
208+ assert.match(boxText(got, SERVER, 0), /abso \(writer\), game \(reader\)\.\n/);
209+ assert.doesNotMatch(boxText(got, SERVER, 0), /agents/);
213210 assert.equal(JSON.stringify(boxPublic(got)).includes(CREDENTIAL), false);
214211});
215212
Lines 380–401 at 318 (were 383–409 at 116)
383380 assert.equal(forgetBox(SERVER, h), false);
384381});
385382
386−test("join and init pick the server: --server, ABSO_SERVER, the box's sign-in, then api.abso.dev", () => {
383+test("join and init pick the server in the one order: --server, the folder's, ABSO_SERVER, then prod", () => {
387384 const h = home();
385+ const outside = home();
388386 const args = (server?: string) => ({ positionals: [], flags: new Map(server ? [["server", server]] : []) });
389− const none = { env: {} };
390− assert.equal(serverFrom(args(), none, h), "https://api.abso.dev", "nothing signed in: the abso API");
387+ const none = { env: {}, cwd: outside };
388+ assert.equal(serverFrom(args(), none), "https://api.abso.dev", "nothing named: prod");
391389 writeBox({ ...record, expiresAt: Date.now() + 1e6 }, h);
392390 assert.deepEqual(signedInServers(h), [SERVER]);
393− assert.equal(serverFrom(args(), none, h), SERVER, "the server abso login signed this box in to");
391+ assert.equal(serverFrom(args(), none), "https://api.abso.dev", "a sign-in elsewhere doesn't pick the server");
394392 assert.deepEqual(signedInServers(h, Date.now() + 2e6), [], "an expired sign-in doesn't count");
395− assert.equal(serverFrom(args(), { env: { ABSO_SERVER: "https://env.example" } }, h), "https://env.example");
393+ assert.equal(serverFrom(args(), { ...none, env: { ABSO_SERVER: "https://env.example" } }), "https://env.example");
396394 assert.equal(
397− serverFrom(args("https://flag.example"), { env: { ABSO_SERVER: "https://env.example" } }, h),
395+ serverFrom(args("https://flag.example"), { ...none, env: { ABSO_SERVER: "https://env.example" } }),
398396 "https://flag.example",
399397 );
400− writeBox({ ...record, server: "https://other.abso.example", expiresAt: Date.now() + 1e6 }, h);
401− writeBox({ ...record, expiresAt: Date.now() + 1e6 }, h);
402− assert.throws(
403− () => serverFrom(args(), none, h),
404− /signed in to https:\/\/other\.abso\.example and https:\/\/staging\.abso\.example: say which with --server/,
405− );
406− assert.equal(serverFrom(args(SERVER), none, h), SERVER, "--server settles it");
398+ assert.equal(serverFrom(args(SERVER), none), SERVER, "--server is used as given");
407399});
408400
409401test("join with no --agent takes the box's name, skips names this box holds, and moves past a taken one", async () => {
Lines 419–554 at 318 (were 427–439 at 116)
427419 ],
428420 "snow is this box's already: never minted again, which would replace its key",
429421 );
422+});
430423
431− const limit = server(
432− [
433− [200, { box_id: record.id, agents: [] }],
434− [409, { error: "this box is at its agent limit" }],
435− ],
436− [],
424+test("abso init from a box (abso 663): one key for every try, waiting out a pending create; abso box says all projects", async () => {
425+ const record = { server: SERVER, id: "b_1", credential: CREDENTIAL, grant, expiresAt: Date.now() + 86_400_000 };
426+ const seen: { path: string; key: string | null; auth: string | null; body: string }[] = [];
427+ let calls = 0;
428+ const fetcher = (async (url: string | URL | Request, init?: RequestInit) => {
429+ const headers = new Headers(init?.headers);
430+ seen.push({
431+ path: new URL(String(url)).pathname,
432+ key: headers.get("idempotency-key"),
433+ auth: headers.get("authorization"),
434+ body: String(init?.body),
435+ });
436+ calls++;
437+ const body =
438+ calls < 3
439+ ? { operation: { id: "op", state: "pending" } }
440+ : { project: "made", id: "proj_1", visibility: "private" };
441+ return new Response(JSON.stringify(body), { status: calls < 3 ? 202 : 200 });
442+ }) as typeof fetch;
443+ const made = await boxCreateProject(
444+ record,
445+ { name: "made", files: [{ path: "a.txt", text: "hi\n" }] },
446+ "33333333-3333-4333-8333-333333333333",
447+ fetcher,
448+ async () => {},
437449 );
438− await assert.rejects(mintFreeName(record, "abso", "snow", limit), /this box is at its agent limit \(5\)/);
450+ assert.equal(made.id, "proj_1");
451+ assert.equal(seen.length, 3);
452+ assert.ok(seen.every((s) => s.path === "/box/projects" && s.key === "33333333-3333-4333-8333-333333333333"));
453+ assert.ok(seen.every((s) => s.auth === `Box ${CREDENTIAL}`));
454+ assert.deepEqual(JSON.parse(seen[0]!.body), { name: "made", files: [{ path: "a.txt", text: "hi\n" }] });
455+ const all = { ...record, grant: { projects: [], scopes: [{ kind: "member-all", role: "writer" }] } };
456+ assert.match(
457+ boxText(all, SERVER),
458+ /Projects: all of yours, now and later \(writer at most\)\. abso init makes a new one/,
459+ );
439460});
462+// abso 684: in an agent's folder, login asks a person in the project instead of relaying the code.
463+function askedOf(withdrawn: number[]): NonNullable<Parameters<typeof login>[1]["ask"]> {
464+ return async ({ device, user }) => {
465+ assert.equal(device, started.device_code, "the ask is made with this client's own device code");
466+ assert.equal(user, started.user_code);
467+ return {
468+ project: "abso",
469+ who: "the person who approved this agent's box",
470+ asks: [41],
471+ expiresAt: Date.parse("2026-10-15T19:30:00Z"),
472+ role: "writer",
473+ withdraw: async () => void withdrawn.push(41),
474+ };
475+ };
476+}
478+test("an asked login says who was asked and until when, and doesn't lead with the code (abso 684)", async () => {
479+ const said: string[] = [];
480+ const c = clock();
481+ await login(
482+ SERVER,
483+ {
484+ ask: askedOf([]),
485+ fetch: server(
486+ [
487+ [200, started],
488+ [200, { box_id: "b_test", box_token: CREDENTIAL, expires_at: EXPIRES, grant: { projects: [] } }],
489+ ],
490+ [],
491+ ),
492+ sleep: c.sleep,
493+ now: c.now,
494+ say: (line) => said.push(line),
495+ },
496+ home(),
497+ );
498+ assert.match(
499+ said[0]!,
500+ /^Asked the person who approved this agent's box \(ask 41 in abso\) to sign this box in, as at most writer\.$/,
501+ );
502+ assert.match(said[1]!, /^Waiting for their answer, until .* CT\. To approve it yourself instead: /);
503+ assert.doesNotMatch(said.join("\n"), /approve the code/);
504+});
506+test("an asked login that's turned down says who turned it down (abso 684)", async () => {
507+ const c = clock();
508+ await assert.rejects(
509+ login(
510+ SERVER,
511+ {
512+ ask: askedOf([]),
513+ fetch: server(
514+ [
515+ [200, started],
516+ [400, { error: "access_denied" }],
517+ ],
518+ [],
519+ ),
520+ sleep: c.sleep,
521+ now: c.now,
522+ say: () => {},
523+ },
524+ home(),
525+ ),
526+ /the person who approved this agent's box turned this sign-in down/,
527+ );
528+});
530+test("an asked login that nobody answers withdraws its ask and grants nothing (abso 684)", async () => {
531+ const withdrawn: number[] = [];
532+ const c = clock();
533+ await assert.rejects(
534+ login(
535+ SERVER,
536+ {
537+ ask: askedOf(withdrawn),
538+ fetch: server(
539+ [
540+ [200, started],
541+ [400, { error: "expired_token" }],
542+ ],
543+ [],
544+ ),
545+ sleep: c.sleep,
546+ now: c.now,
547+ say: () => {},
548+ },
549+ home(),
550+ ),
551+ /nobody answered in time, so nothing was granted/,
552+ );
553+ assert.deepEqual(withdrawn, [41]);
554+});
MCP
compare on this site's /mcp
CLI
abso diff 116 318 client/test/box.test.ts --json
JSON
/christopher/abso-core/compare/116..318?file=client%2Ftest%2Fbox.test.ts&format=json