{"draft":null,"from":154,"to":318,"files":[{"path":"client/test/box.test.ts","added":148,"removed":33,"diff":"--- a/client/test/box.test.ts\n+++ b/client/test/box.test.ts\n@@ -9,6 +9,7 @@\n import { test } from \"node:test\";\n import { parseArgs } from \"../src/args.ts\";\n import {\n+\tboxCreateProject,\n \tboxPublic,\n \tboxText,\n \tforgetBox,\n@@ -31,7 +32,6 @@\n \t\t{ project: \"abso\", role: \"writer\" },\n \t\t{ project: \"game\", role: \"reader\" },\n \t],\n-\tmax_agents: 5,\n };\n const EXPIRES = \"2026-10-15T00:00:00.000Z\";\n const record = { server: SERVER, id: \"b_0123abcd\", credential: CREDENTIAL, grant, expiresAt: Date.parse(EXPIRES) };\n@@ -70,23 +70,21 @@\n \t};\n }\n \n-test(\"login grant options validate project lists, roles, limits and duration\", () => {\n+test(\"login grant options validate project lists, roles and duration\", () => {\n \tconst request = (...words: string[]) =>\n \t\tloginRequest(\n \t\t\tparseArgs(\"login\", words, {\n \t\t\t\tprojects: \"string\",\n \t\t\t\trole: \"string\",\n-\t\t\t\t\"max-agents\": \"string\",\n \t\t\t\tdays: \"string\",\n \t\t\t}),\n \t\t);\n \tassert.equal(request(), undefined);\n-\tassert.deepEqual(request(\"--projects\", \"alpha, beta,alpha\", \"--max-agents\", \"1\", \"--days\", \"30\"), {\n+\tassert.deepEqual(request(\"--projects\", \"alpha, beta,alpha\", \"--days\", \"30\"), {\n \t\tprojects: [\n \t\t\t{ project: \"alpha\", role: \"writer\" },\n \t\t\t{ project: \"beta\", role: \"writer\" },\n \t\t],\n-\t\tmax_agents: 1,\n \t\tdays: 30,\n \t});\n \tassert.deepEqual(request(\"--projects\", \"alpha\", \"--role\", \"reader\"), {\n@@ -95,7 +93,7 @@\n \tassert.deepEqual(request(\"--projects\", \"alpha\", \"--role\", \"owner\"), {\n \t\tprojects: [{ project: \"alpha\", role: \"owner\" }],\n \t});\n-\tassert.deepEqual(request(\"--max-agents\", \"50\", \"--days\", \"90\"), { max_agents: 50, days: 90 });\n+\tassert.deepEqual(request(\"--days\", \"90\"), { days: 90 });\n \tfor (const words of [\n \t\t[\"--role\", \"writer\"],\n \t\t[\"--projects\", \"\"],\n@@ -105,18 +103,16 @@\n \t\t[\"--projects\", Array.from({ length: 101 }, (_, i) => `p${i}`).join(\",\")],\n \t])\n \t\tassert.throws(() => request(...words));\n-\tfor (const flag of [\"--max-agents\", \"--days\"]) {\n-\t\tfor (const value of [\"0\", \"-1\", \"1.5\", \"1e1\", \"Infinity\", \"100\", \"abc\", \"\"])\n-\t\t\tassert.throws(() => request(flag, value));\n-\t}\n+\tfor (const value of [\"0\", \"-1\", \"1.5\", \"1e1\", \"Infinity\", \"100\", \"abc\", \"\"])\n+\t\tassert.throws(() => request(\"--days\", value));\n });\n \n test(\"login sends requested grants only at device start and retains the user's actual approval\", async () => {\n \tconst h = home();\n \tconst seen: Seen = [];\n \tconst c = clock();\n-\tconst requested = { projects: [{ project: \"abso\", role: \"owner\" as const }], max_agents: 10, days: 90 };\n-\tconst approved = { projects: [{ project: \"abso\", role: \"reader\" }], max_agents: 1 };\n+\tconst requested = { projects: [{ project: \"abso\", role: \"owner\" as const }], days: 90 };\n+\tconst approved = { projects: [{ project: \"abso\", role: \"reader\" }] };\n \tconst got = await login(\n \t\tSERVER,\n \t\t{\n@@ -209,7 +205,8 @@\n \tassert.equal(files.length, 1);\n \tassert.ok(readFileSync(join(h, \".abso\", \"boxes\", files[0]!), \"utf8\").includes(CREDENTIAL));\n \tassert.equal(boxText(got, SERVER, 0).includes(CREDENTIAL), false);\n-\tassert.match(boxText(got, SERVER, 0), /abso \\(writer\\), game \\(reader\\)\\. Up to 5 agents\\./);\n+\tassert.match(boxText(got, SERVER, 0), /abso \\(writer\\), game \\(reader\\)\\.\\n/);\n+\tassert.doesNotMatch(boxText(got, SERVER, 0), /agents/);\n \tassert.equal(JSON.stringify(boxPublic(got)).includes(CREDENTIAL), false);\n });\n \n@@ -383,27 +380,22 @@\n \tassert.equal(forgetBox(SERVER, h), false);\n });\n \n-test(\"join and init pick the server: --server, ABSO_SERVER, the box's sign-in, then api.abso.dev\", () => {\n+test(\"join and init pick the server in the one order: --server, the folder's, ABSO_SERVER, then prod\", () => {\n \tconst h = home();\n+\tconst outside = home();\n \tconst args = (server?: string) => ({ positionals: [], flags: new Map(server ? [[\"server\", server]] : []) });\n-\tconst none = { env: {} };\n-\tassert.equal(serverFrom(args(), none, h), \"https://api.abso.dev\", \"nothing signed in: the abso API\");\n+\tconst none = { env: {}, cwd: outside };\n+\tassert.equal(serverFrom(args(), none), \"https://api.abso.dev\", \"nothing named: prod\");\n \twriteBox({ ...record, expiresAt: Date.now() + 1e6 }, h);\n \tassert.deepEqual(signedInServers(h), [SERVER]);\n-\tassert.equal(serverFrom(args(), none, h), SERVER, \"the server abso login signed this box in to\");\n+\tassert.equal(serverFrom(args(), none), \"https://api.abso.dev\", \"a sign-in elsewhere doesn't pick the server\");\n \tassert.deepEqual(signedInServers(h, Date.now() + 2e6), [], \"an expired sign-in doesn't count\");\n-\tassert.equal(serverFrom(args(), { env: { ABSO_SERVER: \"https://env.example\" } }, h), \"https://env.example\");\n+\tassert.equal(serverFrom(args(), { ...none, env: { ABSO_SERVER: \"https://env.example\" } }), \"https://env.example\");\n \tassert.equal(\n-\t\tserverFrom(args(\"https://flag.example\"), { env: { ABSO_SERVER: \"https://env.example\" } }, h),\n+\t\tserverFrom(args(\"https://flag.example\"), { ...none, env: { ABSO_SERVER: \"https://env.example\" } }),\n \t\t\"https://flag.example\",\n \t);\n-\twriteBox({ ...record, server: \"https://other.abso.example\", expiresAt: Date.now() + 1e6 }, h);\n-\twriteBox({ ...record, expiresAt: Date.now() + 1e6 }, h);\n-\tassert.throws(\n-\t\t() => serverFrom(args(), none, h),\n-\t\t/signed in to https:\\/\\/other\\.abso\\.example and https:\\/\\/staging\\.abso\\.example: say which with --server/,\n-\t);\n-\tassert.equal(serverFrom(args(SERVER), none, h), SERVER, \"--server settles it\");\n+\tassert.equal(serverFrom(args(SERVER), none), SERVER, \"--server is used as given\");\n });\n \n test(\"join with no --agent takes the box's name, skips names this box holds, and moves past a taken one\", async () => {\n@@ -427,13 +419,136 @@\n \t\t],\n \t\t\"snow is this box's already: never minted again, which would replace its key\",\n \t);\n+});\n \n-\tconst limit = server(\n-\t\t[\n-\t\t\t[200, { box_id: record.id, agents: [] }],\n-\t\t\t[409, { error: \"this box is at its agent limit\" }],\n-\t\t],\n-\t\t[],\n+test(\"abso init from a box (abso 663): one key for every try, waiting out a pending create; abso box says all projects\", async () => {\n+\tconst record = { server: SERVER, id: \"b_1\", credential: CREDENTIAL, grant, expiresAt: Date.now() + 86_400_000 };\n+\tconst seen: { path: string; key: string | null; auth: string | null; body: string }[] = [];\n+\tlet calls = 0;\n+\tconst fetcher = (async (url: string | URL | Request, init?: RequestInit) => {\n+\t\tconst headers = new Headers(init?.headers);\n+\t\tseen.push({\n+\t\t\tpath: new URL(String(url)).pathname,\n+\t\t\tkey: headers.get(\"idempotency-key\"),\n+\t\t\tauth: headers.get(\"authorization\"),\n+\t\t\tbody: String(init?.body),\n+\t\t});\n+\t\tcalls++;\n+\t\tconst body =\n+\t\t\tcalls < 3\n+\t\t\t\t? { operation: { id: \"op\", state: \"pending\" } }\n+\t\t\t\t: { project: \"made\", id: \"proj_1\", visibility: \"private\" };\n+\t\treturn new Response(JSON.stringify(body), { status: calls < 3 ? 202 : 200 });\n+\t}) as typeof fetch;\n+\tconst made = await boxCreateProject(\n+\t\trecord,\n+\t\t{ name: \"made\", files: [{ path: \"a.txt\", text: \"hi\\n\" }] },\n+\t\t\"33333333-3333-4333-8333-333333333333\",\n+\t\tfetcher,\n+\t\tasync () => {},\n \t);\n-\tawait assert.rejects(mintFreeName(record, \"abso\", \"snow\", limit), /this box is at its agent limit \\(5\\)/);\n+\tassert.equal(made.id, \"proj_1\");\n+\tassert.equal(seen.length, 3);\n+\tassert.ok(seen.every((s) => s.path === \"/box/projects\" && s.key === \"33333333-3333-4333-8333-333333333333\"));\n+\tassert.ok(seen.every((s) => s.auth === `Box ${CREDENTIAL}`));\n+\tassert.deepEqual(JSON.parse(seen[0]!.body), { name: \"made\", files: [{ path: \"a.txt\", text: \"hi\\n\" }] });\n+\tconst all = { ...record, grant: { projects: [], scopes: [{ kind: \"member-all\", role: \"writer\" }] } };\n+\tassert.match(\n+\t\tboxText(all, SERVER),\n+\t\t/Projects: all of yours, now and later \\(writer at most\\)\\. abso init makes a new one/,\n+\t);\n });\n+\n+// abso 684: in an agent's folder, login asks a person in the project instead of relaying the code.\n+function askedOf(withdrawn: number[]): NonNullable<Parameters<typeof login>[1][\"ask\"]> {\n+\treturn async ({ device, user }) => {\n+\t\tassert.equal(device, started.device_code, \"the ask is made with this client's own device code\");\n+\t\tassert.equal(user, started.user_code);\n+\t\treturn {\n+\t\t\tproject: \"abso\",\n+\t\t\twho: \"the person who approved this agent's box\",\n+\t\t\tasks: [41],\n+\t\t\texpiresAt: Date.parse(\"2026-10-15T19:30:00Z\"),\n+\t\t\trole: \"writer\",\n+\t\t\twithdraw: async () => void withdrawn.push(41),\n+\t\t};\n+\t};\n+}\n+\n+test(\"an asked login says who was asked and until when, and doesn't lead with the code (abso 684)\", async () => {\n+\tconst said: string[] = [];\n+\tconst c = clock();\n+\tawait login(\n+\t\tSERVER,\n+\t\t{\n+\t\t\task: askedOf([]),\n+\t\t\tfetch: server(\n+\t\t\t\t[\n+\t\t\t\t\t[200, started],\n+\t\t\t\t\t[200, { box_id: \"b_test\", box_token: CREDENTIAL, expires_at: EXPIRES, grant: { projects: [] } }],\n+\t\t\t\t],\n+\t\t\t\t[],\n+\t\t\t),\n+\t\t\tsleep: c.sleep,\n+\t\t\tnow: c.now,\n+\t\t\tsay: (line) => said.push(line),\n+\t\t},\n+\t\thome(),\n+\t);\n+\tassert.match(\n+\t\tsaid[0]!,\n+\t\t/^Asked the person who approved this agent's box \\(ask 41 in abso\\) to sign this box in, as at most writer\\.$/,\n+\t);\n+\tassert.match(said[1]!, /^Waiting for their answer, until .* CT\\. To approve it yourself instead: /);\n+\tassert.doesNotMatch(said.join(\"\\n\"), /approve the code/);\n+});\n+\n+test(\"an asked login that's turned down says who turned it down (abso 684)\", async () => {\n+\tconst c = clock();\n+\tawait assert.rejects(\n+\t\tlogin(\n+\t\t\tSERVER,\n+\t\t\t{\n+\t\t\t\task: askedOf([]),\n+\t\t\t\tfetch: server(\n+\t\t\t\t\t[\n+\t\t\t\t\t\t[200, started],\n+\t\t\t\t\t\t[400, { error: \"access_denied\" }],\n+\t\t\t\t\t],\n+\t\t\t\t\t[],\n+\t\t\t\t),\n+\t\t\t\tsleep: c.sleep,\n+\t\t\t\tnow: c.now,\n+\t\t\t\tsay: () => {},\n+\t\t\t},\n+\t\t\thome(),\n+\t\t),\n+\t\t/the person who approved this agent's box turned this sign-in down/,\n+\t);\n+});\n+\n+test(\"an asked login that nobody answers withdraws its ask and grants nothing (abso 684)\", async () => {\n+\tconst withdrawn: number[] = [];\n+\tconst c = clock();\n+\tawait assert.rejects(\n+\t\tlogin(\n+\t\t\tSERVER,\n+\t\t\t{\n+\t\t\t\task: askedOf(withdrawn),\n+\t\t\t\tfetch: server(\n+\t\t\t\t\t[\n+\t\t\t\t\t\t[200, started],\n+\t\t\t\t\t\t[400, { error: \"expired_token\" }],\n+\t\t\t\t\t],\n+\t\t\t\t\t[],\n+\t\t\t\t),\n+\t\t\t\tsleep: c.sleep,\n+\t\t\t\tnow: c.now,\n+\t\t\t\tsay: () => {},\n+\t\t\t},\n+\t\t\thome(),\n+\t\t),\n+\t\t/nobody answered in time, so nothing was granted/,\n+\t);\n+\tassert.deepEqual(withdrawn, [41]);\n+});"}],"unmatched":[]}