Lines 9–15 at 318 (were 9–14 at 166)
99import { test } from "node:test"; 1010import { parseArgs } from "../src/args.ts"; Lines 32–37 at 318 (were 31–37 at 166)
3132 { project: "abso", role: "writer" }, 3233 { project: "game", role: "reader" }, 34− max_agents: 5,
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 166)
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[]) => 7676 parseArgs("login", words, { 79− "max-agents": "string",
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"), { 8685 { project: "alpha", role: "writer" }, 8786 { project: "beta", role: "writer" }, 89− max_agents: 1,
9290 assert.deepEqual(request("--projects", "alpha", "--role", "reader"), { Lines 93–99 at 318 (were 95–101 at 166)
9593 assert.deepEqual(request("--projects", "alpha", "--role", "owner"), { 9694 projects: [{ project: "alpha", role: "owner" }], 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 166)
105103 ["--projects", Array.from({ length: 101 }, (_, i) => `p${i}`).join(",")], 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)); 114110test("login sends requested grants only at device start and retains the user's actual approval", async () => { 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( Lines 205–212 at 318 (were 209–215 at 166)
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); Lines 419–554 at 318 (were 422–434 at 166)
423420 "snow is this box's already: never minted again, which would replace its key", 426− const limit = server(
427− [
428− [200, { box_id: record.id, agents: [] }],
429− [409, { error: "this box is at its agent limit" }],
430− ],
431− [],
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 }[] = []; 428+ const fetcher = (async (url: string | URL | Request, init?: RequestInit) => { 429+ const headers = new Headers(init?.headers); 431+ path: new URL(String(url)).pathname, 432+ key: headers.get("idempotency-key"), 433+ auth: headers.get("authorization"), 434+ body: String(init?.body), 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 }); 443+ const made = await boxCreateProject( 445+ { name: "made", files: [{ path: "a.txt", text: "hi\n" }] }, 446+ "33333333-3333-4333-8333-333333333333", 433− 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" }] } }; 457+ boxText(all, SERVER), 458+ /Projects: all of yours, now and later \(writer at most\)\. abso init makes a new one/, 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); 469+ who: "the person who approved this agent's box", 471+ expiresAt: Date.parse("2026-10-15T19:30:00Z"), 473+ withdraw: async () => void withdrawn.push(41), 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[] = []; 488+ [200, { box_id: "b_test", box_token: CREDENTIAL, expires_at: EXPIRES, grant: { projects: [] } }], 494+ say: (line) => said.push(line), 500+ /^Asked the person who approved this agent's box \(ask 41 in abso\) to sign this box in, as at most writer\.$/, 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/); 506+test("an asked login that's turned down says who turned it down (abso 684)", async () => { 508+ await assert.rejects( 516+ [400, { error: "access_denied" }], 526+ /the person who approved this agent's box turned this sign-in down/, 530+test("an asked login that nobody answers withdraws its ask and grants nothing (abso 684)", async () => { 531+ const withdrawn: number[] = []; 533+ await assert.rejects( 537+ ask: askedOf(withdrawn), 541+ [400, { error: "expired_token" }], 551+ /nobody answered in time, so nothing was granted/, 553+ assert.deepEqual(withdrawn, [41]);