{"draft":null,"from":276,"to":318,"files":[{"path":"client/test/body-files.test.ts","added":8,"removed":1,"diff":"--- a/client/test/body-files.test.ts\n+++ b/client/test/body-files.test.ts\n@@ -15,6 +15,9 @@\n // Written with one Windows line ending inside, which arrives as LF.\n writeFileSync(join(dir, \"body.md\"), `${BODY.replace(\"- two\\n\", \"- two\\r\\n\")}\\r\\n`);\n writeFileSync(join(dir, \"empty.md\"), \"\\n  \\n\");\n+// A reply as agents write them: prose, a code block and a Windows path, which no shell quoting mangles here.\n+const REPLY = 'Checked it:\\n\\n```ts\\nconst x = \"a\\\\tb\";\\n```\\n\\nThe log is in C:\\\\Users\\\\me\\\\repo\\\\out.txt.';\n+writeFileSync(join(dir, \"reply.md\"), `${REPLY}\\n`);\n \n const ISSUE = { comment: \"string\", description: \"string\", title: \"string\", drop: \"boolean\" } as const;\n const parse = (command: string, spec: Record<string, \"string\" | \"boolean\">, words: string[], stdin?: string) =>\n@@ -40,10 +43,14 @@\n \t\t);\n \t});\n \n-\tit(\"--file gives ask's question, answer's words and announce's text\", () => {\n+\tit(\"--file gives ask's question, answer's and reply's words, and announce's text\", () => {\n \t\tassert.deepEqual(parse(\"ask\", { issue: \"string\" }, [\"alice\", \"--file\", \"body.md\"]).positionals, [\"alice\", BODY]);\n \t\tassert.deepEqual(parse(\"answer\", { note: \"string\" }, [\"12\", \"--file\", \"body.md\"]).positionals, [\"12\", BODY]);\n \t\tassert.deepEqual(parse(\"announce\", { to: \"string\" }, [\"--file\", \"body.md\"]).positionals, [BODY]);\n+\t\tconst reply = parse(\"reply\", { question: \"boolean\" }, [\"648\", \"--file\", \"reply.md\", \"--question\"]);\n+\t\tassert.deepEqual(reply.positionals, [\"648\", REPLY]);\n+\t\tassert.equal(reply.flags.get(\"question\"), true);\n+\t\tassert.match(bodyFilesHelp(\"reply\", { question: \"boolean\" })!, /--file <path>/);\n \t\tassert.throws(\n \t\t\t() => parse(\"answer\", { note: \"string\" }, [\"12\", \"words\", \"--file\", \"body.md\"]),\n \t\t\t/--file gives answer's text, so leave the words off the command line/,"},{"path":"client/test/caller.test.ts","added":104,"removed":0,"diff":"--- /dev/null\n+++ b/client/test/caller.test.ts\n@@ -0,0 +1,104 @@\n+// Who is calling a seat: one header with the chat's session, the computer and the folder, read back exactly or not at all.\n+import assert from \"node:assert/strict\";\n+import { test } from \"node:test\";\n+import { CALLER_HEADER, CALLER_MAX, callerHeader, callerPlace, parseCaller } from \"../../src/caller.ts\";\n+import { Api } from \"../src/api.ts\";\n+import { callerFor } from \"../src/command-env.ts\";\n+\n+const session = \"0da5c2b7-ab07-4249-b868-e8f09b6ec7b6\";\n+\n+test(\"the client sends a hash of the session and only the folder's last part\", () => {\n+\tconst header = callerFor(session, \"DESKTOP-1\", \"C:\\\\Users\\\\sam\\\\repos\\\\abso\\\\groups\")!;\n+\tconst caller = parseCaller(header)!;\n+\tassert.equal(caller.folder, \"groups\");\n+\tassert.match(caller.session!, /^[0-9a-f]{16}$/);\n+\tassert.notEqual(caller.session, session);\n+\tassert.doesNotMatch(Buffer.from(header, \"base64url\").toString(), /sam|0da5c2b7/);\n+\t// The same chat hashes the same way, so the server still tells one chat from another.\n+\tassert.equal(parseCaller(callerFor(session, \"DESKTOP-1\", \"/x/groups\"))!.session, caller.session);\n+\tassert.equal(parseCaller(callerFor(undefined, \"box\", \"/work/über\"))!.session, undefined);\n+\tassert.equal(callerPlace(caller), \"groups on DESKTOP-1\");\n+});\n+\n+test(\"a caller goes out and comes back as it was\", () => {\n+\tconst header = callerHeader({ session, machine: \"DESKTOP-1\", folder: \"C:\\\\Users\\\\sam\\\\repos\\\\abso\\\\groups\" })!;\n+\tassert.match(header, /^[A-Za-z0-9_-]+$/);\n+\tassert.deepEqual(parseCaller(header), {\n+\t\tsession,\n+\t\tmachine: \"DESKTOP-1\",\n+\t\tfolder: \"C:\\\\Users\\\\sam\\\\repos\\\\abso\\\\groups\",\n+\t});\n+\tassert.equal(callerPlace(parseCaller(header)!), \"groups on DESKTOP-1\");\n+\t// Outside a chat there's no session, and that's still a caller.\n+\tassert.deepEqual(parseCaller(callerHeader({ machine: \"box\", folder: \"/work/über\" })), {\n+\t\tmachine: \"box\",\n+\t\tfolder: \"/work/über\",\n+\t});\n+});\n+\n+test(\"a session that isn't an id is left out, and a long folder keeps its end\", () => {\n+\tassert.deepEqual(parseCaller(callerHeader({ session: \"not a session!\", machine: \"m\", folder: \"/a\" })), {\n+\t\tmachine: \"m\",\n+\t\tfolder: \"/a\",\n+\t});\n+\tconst deep = `/${\"very-long-folder-name/\".repeat(40)}groups`;\n+\tconst header = callerHeader({ session, machine: \"m\", folder: deep })!;\n+\tassert.ok(header.length <= CALLER_MAX);\n+\tassert.ok(parseCaller(header)!.folder.endsWith(\"/groups\"));\n+});\n+\n+test(\"a header that isn't a caller is refused, never guessed at\", () => {\n+\tconst enc = (v: unknown) => Buffer.from(JSON.stringify(v)).toString(\"base64url\");\n+\tfor (const bad of [\n+\t\tundefined,\n+\t\t\"\",\n+\t\t\"not base64!\",\n+\t\tenc(\"text\"),\n+\t\tenc([1]),\n+\t\tenc({ machine: \"m\" }),\n+\t\tenc({ machine: \"has space\", folder: \"/a\" }),\n+\t\tenc({ machine: \"m\", folder: \"/a\", session: \"bad id!\" }),\n+\t\tenc({ machine: \"m\", folder: \"/a\", token: \"x\" }),\n+\t\tenc({ machine: \"m\", folder: \"/a\\nb\" }),\n+\t\t\"A\".repeat(CALLER_MAX + 1),\n+\t])\n+\t\tassert.equal(parseCaller(bad), null, String(bad));\n+});\n+\n+test(\"the Api sends the caller with its calls, except from a visitor folder\", () => {\n+\tconst config = {\n+\t\tserver: \"https://abso.test\",\n+\t\tproject: \"p\",\n+\t\tagent: \"ann\",\n+\t\ttoken: \"abso_sk_x\",\n+\t} as ConstructorParameters<typeof Api>[0];\n+\tconst api = new Api(config);\n+\tassert.equal(api.headers()[CALLER_HEADER], undefined);\n+\tapi.caller = callerHeader({ session, machine: \"m\", folder: \"/a\" });\n+\tassert.equal(api.headers()[CALLER_HEADER], api.caller);\n+\tconst visitor = new Api({ ...config, visitor: true } as ConstructorParameters<typeof Api>[0]);\n+\tvisitor.caller = api.caller;\n+\tassert.equal(visitor.headers()[CALLER_HEADER], undefined);\n+});\n+\n+test(\"a seat notice on any answer is printed once with the news\", async () => {\n+\tconst { takeNews } = await import(\"../src/command-env.ts\");\n+\ttakeNews();\n+\tconst real = globalThis.fetch;\n+\tconst line = \"ann was used from another chat (groups on DESKTOP-2) in the last 30 minutes\";\n+\tglobalThis.fetch = (async () => Response.json({ ok: true, seatNotice: line })) as typeof fetch;\n+\ttry {\n+\t\tconst api = new Api({\n+\t\t\tserver: \"https://abso.test\",\n+\t\t\tproject: \"p\",\n+\t\t\tagent: \"ann\",\n+\t\t\ttoken: \"abso_sk_x\",\n+\t\t} as ConstructorParameters<typeof Api>[0]);\n+\t\tawait api.json(\"GET\", \"/status\");\n+\t\tawait api.json(\"GET\", \"/status\");\n+\t\tassert.deepEqual(takeNews(), [line]);\n+\t\tassert.deepEqual(takeNews(), []);\n+\t} finally {\n+\t\tglobalThis.fetch = real;\n+\t}\n+});"},{"path":"client/test/ci-runs.test.ts","added":60,"removed":0,"diff":"--- /dev/null\n+++ b/client/test/ci-runs.test.ts\n@@ -0,0 +1,60 @@\n+// abso ci for a project whose CI is its pipeline file (abso 719): test-byoc on 2026-10-16 had no abso.json, and abso ci\n+// said \"nothing to run\" while its abso.yml's run 8 was going. The stored run is the project's CI there.\n+\n+import assert from \"node:assert/strict\";\n+import { test } from \"node:test\";\n+import { builtInHasNothing, runLine, storedRuns } from \"../src/ci.ts\";\n+\n+const base = { latest: null, checked: null, running: null, red: null, behind: null } as const;\n+const nothing = {\n+\tversion: 6,\n+\tfrom: 6,\n+\treason: \"nothing to run: no abso.json, and package.json has no test, typecheck or vite\",\n+\tat: \"2026-10-16T16:47:00.000Z\",\n+};\n+\n+test(\"the stored runs are read strictly, newest first as the server lists them\", () => {\n+\tconst runs = storedRuns({\n+\t\tblocked: null,\n+\t\truns: [\n+\t\t\t{ id: 8, version: 6, state: \"running\", file: \"abso.yml\", started: 1 },\n+\t\t\t{ id: \"7\", version: 6, state: \"failed\", file: \"abso.yml\" },\n+\t\t\t{ id: 6, version: 5, state: \"failed\", file: \"abso.yml\" },\n+\t\t],\n+\t});\n+\tassert.deepEqual(\n+\t\truns.map((r) => r.id),\n+\t\t[8, 6],\n+\t);\n+\tassert.deepEqual(storedRuns(null), []);\n+\tassert.deepEqual(storedRuns({ runs: \"no\" }), []);\n+});\n+\n+test(\"a run in a line names its file, its state and where its jobs are\", () => {\n+\tassert.equal(\n+\t\trunLine({ id: 8, version: 6, state: \"running\", file: \"abso.yml\" }),\n+\t\t\"Pipeline run 8 (abso.yml) is running on version 6. abso pipeline runs 8 shows its jobs.\",\n+\t);\n+\tassert.equal(\n+\t\trunLine({ id: 7, version: 6, state: \"failed\", file: \"abso.yml\" }),\n+\t\t\"Pipeline run 7 (abso.yml) failed on version 6. abso pipeline runs 7 shows its jobs.\",\n+\t);\n+\tassert.equal(\n+\t\trunLine({ id: 2, version: 1, state: \"planned\", file: \"abso.yml\" }),\n+\t\t\"Pipeline run 2 (abso.yml) was planned, not run, on version 1. abso pipeline runs 2 shows its jobs.\",\n+\t);\n+});\n+\n+test(\"only the built-in check's own nothing to run is set aside, never a red or another skip\", () => {\n+\tassert.equal(builtInHasNothing({ ...base, skipped: nothing }), true);\n+\tassert.equal(builtInHasNothing({ ...base, skipped: { ...nothing, reason: \"CI is off\" } }), false);\n+\tassert.equal(builtInHasNothing({ ...base }), false);\n+\tassert.equal(\n+\t\tbuiltInHasNothing({\n+\t\t\t...base,\n+\t\t\tred: { version: 6, agent: null, message: null, lastGood: null },\n+\t\t\tskipped: nothing,\n+\t\t}),\n+\t\tfalse,\n+\t);\n+});"},{"path":"client/test/doctor.test.ts","added":10,"removed":6,"diff":"--- a/client/test/doctor.test.ts\n+++ b/client/test/doctor.test.ts\n@@ -211,21 +211,25 @@\n \n test(\"plainError words a refusal by whether a credential went, and a server that can't be reached\", () => {\n \tconst refused = new ApiError(\"GET /status answered 401: missing or wrong token\", 401);\n-\tassert.equal(plainError(refused, false), \"You're not signed in. Run abso login, then abso join <project>.\");\n-\tassert.match(plainError(refused, true)!, /^The server didn't accept this folder's key.*abso doctor checks it/);\n+\tassert.equal(plainError(refused, undefined), \"You're not signed in. Run abso login, then abso join <project>.\");\n+\tassert.match(\n+\t\tplainError(refused, \"this folder's key\")!,\n+\t\t/^The server didn't accept this folder's key.*abso doctor checks it/,\n+\t);\n+\tassert.match(plainError(refused, \"ABSO_TOKEN\")!, /^The server didn't accept ABSO_TOKEN: /);\n \tassert.equal(\n-\t\tplainError(new ApiError(\"could not reach https://api.abso.dev: connect ECONNREFUSED\"), true),\n+\t\tplainError(new ApiError(\"could not reach https://api.abso.dev: connect ECONNREFUSED\"), \"this folder's key\"),\n \t\t\"Can't reach https://api.abso.dev: connect ECONNREFUSED. Check your connection; abso doctor checks the rest.\",\n \t);\n \tassert.equal(\n \t\tplainError(\n \t\t\tnew ApiError(\"could not reach http://x: refused. Nothing was pushed. Run the same command again.\"),\n-\t\t\ttrue,\n+\t\t\t\"this folder's key\",\n \t\t),\n \t\t\"Can't reach http://x: refused. Nothing was pushed. Run the same command again.\",\n \t);\n-\tassert.equal(plainError(new ApiError(\"GET /log answered 500: boom\", 500), true), undefined);\n-\tassert.equal(plainError(new Error(\"anything else\"), true), undefined);\n+\tassert.equal(plainError(new ApiError(\"GET /log answered 500: boom\", 500), \"this folder's key\"), undefined);\n+\tassert.equal(plainError(new Error(\"anything else\"), \"this folder's key\"), undefined);\n });\n \n test(\"whoami with nothing named shows prod, and names the other servers this box is signed in to\", async () => {"},{"path":"client/test/failed-start.test.ts","added":60,"removed":0,"diff":"--- /dev/null\n+++ b/client/test/failed-start.test.ts\n@@ -0,0 +1,60 @@\n+// An init or join that fails against the server leaves the folder as it was, so the same command can run again:\n+// no starting .absoignore or abso.json from init, no .abso/ from join (but a key already here stays).\n+\n+import assert from \"node:assert/strict\";\n+import { existsSync, mkdirSync, mkdtempSync, readdirSync, rmSync, writeFileSync } from \"node:fs\";\n+import { tmpdir } from \"node:os\";\n+import { join } from \"node:path\";\n+import { after, describe, it } from \"node:test\";\n+import { main } from \"../src/main.ts\";\n+\n+// Nothing listens on port 1, so every call fails to connect.\n+const DOWN = \"http://127.0.0.1:1\";\n+const ENV = { ABSO_TOKEN: \"test-token-not-secret\", ABSO_SERVERS_FILE: \"no-servers.json\" };\n+\n+const dirs: string[] = [];\n+after(() => {\n+\tfor (const d of dirs) rmSync(d, { recursive: true, force: true, maxRetries: 5 });\n+});\n+\n+function temp(): string {\n+\tconst d = mkdtempSync(join(tmpdir(), \"abso-failed-start-\"));\n+\tdirs.push(d);\n+\treturn d;\n+}\n+\n+async function run(cwd: string, ...argv: string[]): Promise<number> {\n+\treturn (await main(argv, { cwd, env: ENV, write: () => {} })).exit;\n+}\n+\n+describe(\"a failed start\", () => {\n+\tit(\"init takes back the .absoignore and abso.json it wrote\", async () => {\n+\t\tconst dir = temp();\n+\t\twriteFileSync(join(dir, \"package.json\"), `${JSON.stringify({ scripts: { test: \"node --test\" } })}\\n`);\n+\t\tassert.notEqual(await run(dir, \"init\", \"--server\", DOWN, \"--project\", \"p\", \"--agent\", \"a\"), 0);\n+\t\tassert.deepEqual(readdirSync(dir), [\"package.json\"]);\n+\t});\n+\n+\tit(\"join leaves no .abso folder\", async () => {\n+\t\tconst dir = temp();\n+\t\tassert.notEqual(await run(dir, \"join\", \"p\", \"--server\", DOWN, \"--agent\", \"a\", \"--dir\", dir), 0);\n+\t\tassert.equal(existsSync(join(dir, \".abso\")), false);\n+\t});\n+\n+\tit(\"join keeps a key that was already here\", async () => {\n+\t\tconst dir = temp();\n+\t\tmkdirSync(join(dir, \".abso\"));\n+\t\tconst key = { server: DOWN, key: \"abso_sk_not-a-real-key\", id: \"k_0123abcd\" };\n+\t\twriteFileSync(join(dir, \".abso\", \"key\"), `${JSON.stringify(key)}\\n`);\n+\t\tassert.notEqual(await run(dir, \"join\", \"p\", \"--server\", DOWN, \"--agent\", \"a\", \"--dir\", dir), 0);\n+\t\tassert.deepEqual(readdirSync(join(dir, \".abso\")), [\"key\"]);\n+\t});\n+\n+\tit(\"join with a key it can't read leaves only that key\", async () => {\n+\t\tconst dir = temp();\n+\t\tmkdirSync(join(dir, \".abso\"));\n+\t\twriteFileSync(join(dir, \".abso\", \"key\"), \"{}\\n\");\n+\t\tassert.notEqual(await run(dir, \"join\", \"p\", \"--server\", DOWN, \"--agent\", \"a\", \"--dir\", dir), 0);\n+\t\tassert.deepEqual(readdirSync(join(dir, \".abso\")), [\"key\"]);\n+\t});\n+});"},{"path":"client/test/fake-server.ts","added":8,"removed":0,"diff":"--- a/client/test/fake-server.ts\n+++ b/client/test/fake-server.ts\n@@ -89,6 +89,8 @@\n \tqueueHold: boolean;\n \t/** The next publish: commit it and answer 500 ('after'), or answer 500 without it ('before'), as a storage reset does. */\n \tfailPublish: \"after\" | \"before\" | undefined;\n+\t/** How many of the next pulls to carry out and then cut before answering, as an answer that never arrives (abso-core 26). */\n+\tloseSyncAnswers: number;\n \t/** Run the merge queue's rounds now (after queueHold is let go). */\n \tkickQueue(name: string): Promise<void>;\n \t/** Each run POST's X-Abso-Run-Key, and whether a run started for it. */\n@@ -155,6 +157,7 @@\n \t\tboxExtra: undefined,\n \t\tqueueHold: false,\n \t\tfailPublish: undefined,\n+\t\tloseSyncAnswers: 0,\n \t\tkickQueue: async () => {},\n \t\tclose: async () => {},\n \t};\n@@ -632,6 +635,11 @@\n \t\t\t\t...(typeof body.label === \"string\" ? { label: body.label } : {}),\n \t\t\t\t...(body.full === true ? { full: true } : {}),\n \t\t\t});\n+\t\t\tif (fake.loseSyncAnswers > 0) {\n+\t\t\t\tfake.loseSyncAnswers--;\n+\t\t\t\tres.destroy();\n+\t\t\t\treturn;\n+\t\t\t}\n \t\t\tconst extra = fake.injectSync;\n \t\t\tfake.injectSync = undefined;\n \t\t\tif (extra === undefined) return send(res, 200, synced);"},{"path":"client/test/install.test.ts","added":28,"removed":3,"diff":"--- a/client/test/install.test.ts\n+++ b/client/test/install.test.ts\n@@ -26,6 +26,8 @@\n import { clientVersion, headCommit } from \"../src/client-version.ts\";\n import {\n \tAVCS_MOD,\n+\thookCommand,\n+\tinstallerCommand,\n \tinstallMod,\n \tkeptModCommit,\n \ttype ModSpec,\n@@ -113,6 +115,28 @@\n \t\t);\n \t});\n \n+\tit(\"stamps the command that runs this client's abso hook, where stamp.ts has a HOOK_COMMAND line\", () => {\n+\t\tconst spec = source({\n+\t\t\t\"hooks/stamp.ts\":\n+\t\t\t\t\"export const STAMP: string | undefined = undefined\\nexport const HOOK_COMMAND: readonly string[] | undefined = undefined\\n\",\n+\t\t});\n+\t\tconst target = join(temp(), \"avcs\");\n+\t\tinstallMod(spec, {\n+\t\t\ttarget,\n+\t\t\tcheck: pass,\n+\t\t\tcommit: \"702c616\",\n+\t\t\thookCommand: [\"C:\\\\node.exe\", \"C:\\\\abso\\\\client\\\\abso.ts\", \"hook\"],\n+\t\t});\n+\t\tassert.equal(\n+\t\t\tread(target, \"hooks/stamp.ts\"),\n+\t\t\t\"export const STAMP: string | undefined = '0.1.0+702c616'\\n\" +\n+\t\t\t\t'export const HOOK_COMMAND: readonly string[] | undefined = [\"C:\\\\\\\\node.exe\",\"C:\\\\\\\\abso\\\\\\\\client\\\\\\\\abso.ts\",\"hook\"]\\n',\n+\t\t);\n+\t\t// By default, this checkout's own: the node running it and client/abso.ts.\n+\t\tassert.deepEqual(hookCommand().slice(0, 1), [process.execPath]);\n+\t\tassert.match(hookCommand()[1]!, /client[\\\\/]abso\\.ts$/);\n+\t});\n+\n \tit(\"moves the files in by rename, what the hook imports first and plugin.json last\", () => {\n \t\tconst spec = source();\n \t\tconst target = join(temp(), \"avcs\");\n@@ -427,9 +451,10 @@\n \t\tassert.equal(client, `abso ${clientVersion()} (${dirname(import.meta.dirname)})`);\n \t\tassert.match(\n \t\t\tmod!,\n-\t\t\t/^the abso-hooks mod: 0\\.1\\.0\\+aaaaaaa in .*skills[\\\\/]abso-hooks, installed 2026-10-05 04:30 UTC; this client has 0.2.0(\\+[0-9a-f]{7}(\\.dirty)?)?: node client\\/install-mod\\.ts installs it$/,\n+\t\t\t/^the abso-hooks mod: 0\\.1\\.0\\+aaaaaaa in .*skills[\\\\/]abso-hooks, installed 2026-10-05 04:30 UTC; this client has 0.2.0(\\+[0-9a-f]{7}(\\.dirty)?)?: /,\n \t\t);\n-\t\tassert.equal(view, \"the abso-view mod: not installed (node client/install-view.ts)\");\n+\t\tassert.ok(mod!.endsWith(`: ${installerCommand(\"install-mod.ts\")} installs it`), mod);\n+\t\tassert.equal(view, `the abso-view mod: not installed (${installerCommand(\"install-view.ts\")})`);\n \t\tconst json = JSON.parse(\n \t\t\t(await main([\"--version\", \"--json\"], { cwd: config, env: { CLAUDE_CONFIG_DIR: config }, write: () => {} }))\n \t\t\t\t.stdout,\n@@ -474,7 +499,7 @@\n \t\tconst current = (versionReport(env).json.mods as { current: string }[])[0]!.current;\n \t\tif (/\\+[0-9a-f]{7}$/.test(current))\n \t\t\tassert.deepEqual(modsBehindText(env), [\n-\t\t\t\t`The avcs mod installed on this machine is 0.1.0+aaaaaaa, and this client has ${current}: node client/install-mod.ts installs it (new chats load it).`,\n+\t\t\t\t`The ${AVCS_MOD.name} mod installed on this machine is 0.1.0+aaaaaaa, and this client has ${current}: ${installerCommand(\"install-mod.ts\")} installs it (new chats load it).`,\n \t\t\t]);\n \t\t// A client outside git (an abso folder, a box) can't tell, so it says nothing.\n \t\telse assert.deepEqual(modsBehindText(env), []);"},{"path":"client/test/local.test.ts","added":222,"removed":0,"diff":"--- /dev/null\n+++ b/client/test/local.test.ts\n@@ -0,0 +1,222 @@\n+// Local projects (abso init --local): a project whose history is in a store on this machine, answered by the open\n+// server's own code in the client's process. Every test here runs with fetch replaced by one that throws, so any\n+// call that would leave the machine fails the test.\n+\n+import assert from \"node:assert/strict\";\n+import { spawnSync } from \"node:child_process\";\n+import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from \"node:fs\";\n+import { tmpdir } from \"node:os\";\n+import { join } from \"node:path\";\n+import { after, before, describe, it } from \"node:test\";\n+import { fileURLToPath } from \"node:url\";\n+import { closeLocalStores, LOCAL_BASE, localFetch } from \"../src/local-store.ts\";\n+import { main } from \"../src/main.ts\";\n+import { stateDir } from \"../src/state-dir.ts\";\n+\n+const dirs: string[] = [];\n+const temp = (label: string) => {\n+\tconst d = mkdtempSync(join(tmpdir(), `abso-local-${label}-`));\n+\tdirs.push(d);\n+\treturn d;\n+};\n+\n+const outside: string[] = [];\n+const realFetch = globalThis.fetch;\n+before(() => {\n+\tglobalThis.fetch = (async (input: unknown) => {\n+\t\toutside.push(String(input instanceof Request ? input.url : input));\n+\t\tthrow new TypeError(\"network is off in this test\");\n+\t}) as typeof fetch;\n+});\n+after(() => {\n+\tglobalThis.fetch = realFetch;\n+\tfor (const d of dirs) rmSync(d, { recursive: true, force: true, maxRetries: 5 });\n+\tassert.deepEqual(outside, [], \"nothing reached for the network\");\n+});\n+\n+let store: string;\n+const env = () => ({ ABSO_STORE: store, ABSO_SERVERS_FILE: \"no-servers.json\", ABSO_HOOK_FORCE: \"1\" });\n+async function run(cwd: string, ...argv: string[]): Promise<{ exit: number; out: string; err: string }> {\n+\tconst r = await main(argv, { cwd, env: env(), write: () => {} });\n+\treturn { exit: r.exit, out: r.stdout, err: r.stderr };\n+}\n+const text = (dir: string, rel: string) => readFileSync(join(dir, rel), \"utf8\");\n+\n+/** A copy of the client without the open server beside it (a platform that pins only client/) has no local projects to test. */\n+const noServer = existsSync(fileURLToPath(new URL(\"../../server/src/router.ts\", import.meta.url)))\n+\t? false\n+\t: \"no server/src beside this client, so no local projects\";\n+\n+describe(\"a local project, with the network off\", { skip: noServer }, () => {\n+\tlet alice: string;\n+\tlet bob: string;\n+\tbefore(() => {\n+\t\tstore = temp(\"store\");\n+\t});\n+\n+\tit(\"init --local makes the project in the store, with no sign-in\", async () => {\n+\t\talice = temp(\"alice\");\n+\t\twriteFileSync(join(alice, \"a.txt\"), \"one\\ntwo\\nthree\\n\");\n+\t\tconst r = await run(alice, \"init\", \"--local\", \"--project\", \"demo\", \"--agent\", \"alice\");\n+\t\tassert.equal(r.exit, 0, r.out + r.err);\n+\t\tassert.match(r.out, /Created project demo at version 0 from 2 text files/, \"a.txt and the starting .absoignore\");\n+\t\tassert.doesNotMatch(r.out, /CI has nothing to run/);\n+\t\tassert.match(r.out, /It's a local project: its history is in .*demo, on this machine/);\n+\t\tassert.doesNotMatch(r.out + r.err, /Signing in/);\n+\t\tassert.ok(existsSync(join(store, \"demo\", \"project.sqlite\")));\n+\t\tconst config = JSON.parse(readFileSync(join(stateDir(alice), \"config.json\"), \"utf8\"));\n+\t\tassert.equal(config.server, \"local\");\n+\t\tassert.equal(config.store, undefined, \"the store came from ABSO_STORE, so the folder doesn't name it\");\n+\t});\n+\n+\tit(\"record and push make version 1, and log says so\", async () => {\n+\t\twriteFileSync(join(alice, \"a.txt\"), \"one\\nTWO\\nthree\\n\");\n+\t\twriteFileSync(join(alice, \"b.txt\"), \"new\\n\");\n+\t\tassert.equal((await run(alice, \"record\")).exit, 0);\n+\t\tconst pushed = await run(alice, \"push\", \"-m\", \"Change two, add b\");\n+\t\tassert.equal(pushed.exit, 0, pushed.out + pushed.err);\n+\t\tassert.match(pushed.out, /Pushed version 1/);\n+\t\tconst log = await run(alice, \"log\");\n+\t\tassert.equal(log.exit, 0, log.err);\n+\t\tassert.match(log.out, /Change two, add b/);\n+\t});\n+\n+\tit(\"a second folder joins, and pulls what the first pushes\", async () => {\n+\t\tbob = temp(\"bob\");\n+\t\tconst joined = await run(bob, \"join\", \"demo\", \"--local\", \"--agent\", \"bob\", \"--dir\", bob);\n+\t\tassert.equal(joined.exit, 0, joined.out + joined.err);\n+\t\tassert.equal(text(bob, \"a.txt\"), \"one\\nTWO\\nthree\\n\");\n+\t\tassert.equal(text(bob, \"b.txt\"), \"new\\n\");\n+\t\twriteFileSync(join(alice, \"b.txt\"), \"new\\nmore\\n\");\n+\t\tassert.equal((await run(alice, \"push\", \"-m\", \"More in b\")).exit, 0);\n+\t\tconst pulled = await run(bob, \"pull\");\n+\t\tassert.equal(pulled.exit, 0, pulled.out + pulled.err);\n+\t\tassert.equal(text(bob, \"b.txt\"), \"new\\nmore\\n\");\n+\t});\n+\n+\tit(\"blame names who wrote each line\", async () => {\n+\t\tconst r = await run(bob, \"blame\", \"a.txt\");\n+\t\tassert.equal(r.exit, 0, r.err);\n+\t\tassert.match(r.out, /alice/);\n+\t\tassert.match(r.out, /TWO/);\n+\t});\n+\n+\tit(\"a push that collides with work pushed since is held\", async () => {\n+\t\tassert.equal((await run(bob, \"pull\")).exit, 0);\n+\t\twriteFileSync(join(alice, \"a.txt\"), \"one\\nalice's\\nthree\\n\");\n+\t\tassert.equal((await run(alice, \"push\", \"-m\", \"Alice's two\")).exit, 0);\n+\t\twriteFileSync(join(bob, \"a.txt\"), \"one\\nbob's\\nthree\\n\");\n+\t\tconst held = await run(bob, \"push\", \"-m\", \"Bob's two\");\n+\t\tassert.notEqual(held.exit, 0);\n+\t\tassert.match(held.out + held.err, /collision/);\n+\t});\n+\n+\tit(\"issues, asks and news work too, kept in issues.sqlite beside the project\", async () => {\n+\t\tconst opened = await run(alice, \"issue\", \"new\", \"Fix the parser\", \"--agent\", \"bob\");\n+\t\tassert.equal(opened.exit, 0, opened.out + opened.err);\n+\t\tassert.ok(existsSync(join(store, \"demo\", \"issues.sqlite\")));\n+\t\tconst listed = await run(bob, \"issues\");\n+\t\tassert.equal(listed.exit, 0, listed.err);\n+\t\tassert.match(listed.out, /Fix the parser/);\n+\t\tconst started = await run(bob, \"start\", \"Parser fix\", \"--issue\", \"1\");\n+\t\tassert.equal(started.exit, 0, started.out + started.err);\n+\t\tconst asked = await run(alice, \"ask\", \"bob\", \"Which grammar?\", \"--issue\", \"1\");\n+\t\tassert.equal(asked.exit, 0, asked.out + asked.err);\n+\t\tconst waiting = await run(bob, \"waiting\", \"--mine\");\n+\t\tassert.equal(waiting.exit, 0, waiting.err);\n+\t\tassert.match(waiting.out, /Which grammar\\?/);\n+\t\tconst answered = await run(bob, \"answer\", \"1\", \"The new one\");\n+\t\tassert.equal(answered.exit, 0, answered.out + answered.err);\n+\t\tconst news = await run(alice, \"news\");\n+\t\tassert.equal(news.exit, 0, news.err);\n+\t\tassert.match(news.out, /The new one/);\n+\t\tconst issue = await run(alice, \"issue\", \"1\");\n+\t\tassert.match(issue.out, /In progress|bob/);\n+\t});\n+\n+\tit(\"two calls at once on one project are both answered, one after the other\", async () => {\n+\t\t// As abso ci and waiting --mine make them, with Promise.all.\n+\t\tconst local = localFetch(store);\n+\t\tconst answers = await Promise.all([local(`${LOCAL_BASE}/p/demo/queue`), local(`${LOCAL_BASE}/p/demo/queue`)]);\n+\t\tcloseLocalStores();\n+\t\tfor (const a of answers) assert.equal(a.status, 200, await a.text());\n+\t});\n+\n+\tit(\"a project's name can't start with a dot, so its folder stays inside the store\", async () => {\n+\t\tconst dir = temp(\"dots\");\n+\t\twriteFileSync(join(dir, \"a.txt\"), \"x\\n\");\n+\t\tfor (const name of [\"..\", \".hidden\"]) {\n+\t\t\tconst r = await run(dir, \"init\", \"--local\", \"--project\", name, \"--agent\", \"a\");\n+\t\t\tassert.equal(r.exit, 1, r.out + r.err);\n+\t\t\t// The name rule says why, before any call is made (a \"..\" would collapse the call's path).\n+\t\t\tassert.match(r.err, /project names are letters, digits, dot, dash and underscore/);\n+\t\t}\n+\t\tassert.ok(!existsSync(join(store, \"..\", \"project.sqlite\")));\n+\t\tassert.deepEqual(readdirSync(dir), [\"a.txt\"], \"init left nothing behind\");\n+\t});\n+});\n+\n+describe(\"where a local project's store is\", { skip: noServer }, () => {\n+\tit(\"--store inside the folder is kept in its settings and left out of its files\", async () => {\n+\t\tstore = temp(\"unused\");\n+\t\tconst dir = temp(\"venv\");\n+\t\twriteFileSync(join(dir, \"a.txt\"), \"x\\n\");\n+\t\tconst r = await run(dir, \"init\", \"--local\", \"--project\", \"beside\", \"--agent\", \"a\", \"--store\", \".abso-store\");\n+\t\tassert.equal(r.exit, 0, r.out + r.err);\n+\t\tassert.ok(existsSync(join(dir, \".abso-store\", \"beside\", \"project.sqlite\")));\n+\t\tassert.equal(JSON.parse(readFileSync(join(stateDir(dir), \"config.json\"), \"utf8\")).store, join(dir, \".abso-store\"));\n+\t\tassert.match(text(dir, \".absoignore\"), /^\\/\\.abso-store\\/$/m);\n+\t\tassert.match(r.out, /from 2 text files/, \"a.txt and .absoignore, not the store\");\n+\t\t// Every later command finds the store from the folder's settings, whatever ABSO_STORE says.\n+\t\twriteFileSync(join(dir, \"a.txt\"), \"y\\n\");\n+\t\tassert.equal((await run(dir, \"push\", \"-m\", \"y\")).exit, 0);\n+\t});\n+\n+\tit(\"--local refuses --server, and --store needs --local\", async () => {\n+\t\tconst dir = temp(\"refuse\");\n+\t\tmkdirSync(join(dir, \"x\"));\n+\t\tconst both = await run(dir, \"init\", \"--local\", \"--server\", \"https://abso.test\", \"--project\", \"p\");\n+\t\tassert.match(both.out + both.err, /--local or --server, not both/);\n+\t\tconst alone = await run(dir, \"init\", \"--store\", \"s\", \"--project\", \"p\");\n+\t\tassert.match(alone.out + alone.err, /--store goes with --local/);\n+\t});\n+\n+\tit(\"joining a project the store doesn't have leaves nothing behind\", async () => {\n+\t\tstore = temp(\"empty\");\n+\t\tconst dir = temp(\"nojoin\");\n+\t\tconst r = await run(dir, \"join\", \"nothing\", \"--local\", \"--agent\", \"a\", \"--dir\", dir);\n+\t\tassert.notEqual(r.exit, 0);\n+\t\tassert.match(r.out + r.err, /no local project nothing/);\n+\t\tassert.equal(existsSync(join(dir, \".abso\")) || existsSync(join(dir, \".avcs\")), false);\n+\t});\n+});\n+\n+describe(\"local commands as their own processes\", { skip: noServer }, () => {\n+\t// The way people and agents run them: client/abso.ts, a process per command, Node's compile cache as it is.\n+\tconst entry = fileURLToPath(new URL(\"../abso.ts\", import.meta.url));\n+\tconst cli = (cwd: string, processStore: string, ...argv: string[]) =>\n+\t\tspawnSync(process.execPath, [entry, ...argv], {\n+\t\t\tcwd,\n+\t\t\tenv: { ...process.env, ABSO_STORE: processStore, ABSO_SERVERS_FILE: \"no-servers.json\" },\n+\t\t\tencoding: \"utf8\",\n+\t\t});\n+\n+\tit(\"init, push, status and log each exit cleanly\", () => {\n+\t\tconst processStore = temp(\"process-store\");\n+\t\tconst dir = temp(\"process\");\n+\t\twriteFileSync(join(dir, \"a.txt\"), \"one\\n\");\n+\t\tconst steps: [string, string[]][] = [\n+\t\t\t[\"init\", [\"init\", \"--local\", \"--project\", \"proc\", \"--agent\", \"p\"]],\n+\t\t\t[\"push\", [\"push\", \"-m\", \"Two\"]],\n+\t\t\t[\"status\", [\"status\"]],\n+\t\t\t[\"log\", [\"log\"]],\n+\t\t];\n+\t\tfor (const [name, argv] of steps) {\n+\t\t\tif (name === \"push\") writeFileSync(join(dir, \"a.txt\"), \"one\\ntwo\\n\");\n+\t\t\tconst r = cli(dir, processStore, ...argv);\n+\t\t\tassert.equal(r.status, 0, `${name}: exit ${r.status} ${r.signal ?? \"\"}\\n${r.stdout}${r.stderr}`);\n+\t\t\tif (name === \"status\") assert.match(r.stdout, /It's a local project, in /);\n+\t\t\tif (name === \"log\") assert.match(r.stdout, /Two/);\n+\t\t}\n+\t});\n+});"},{"path":"client/test/lost-pull.test.ts","added":88,"removed":0,"diff":"--- /dev/null\n+++ b/client/test/lost-pull.test.ts\n@@ -0,0 +1,88 @@\n+// A pull whose answer never arrives (abso-core 26): the server has moved the agent's base, so later pulls\n+// send only what changed since then. The folder notes the pull it started and, until one is written, the\n+// next pull asks for every file and writes the ones that differ. Status says so in the meantime.\n+\n+import assert from \"node:assert/strict\";\n+import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from \"node:fs\";\n+import { tmpdir } from \"node:os\";\n+import { join } from \"node:path\";\n+import { after, before, describe, it } from \"node:test\";\n+import { main } from \"../src/main.ts\";\n+import { type Fake, startFake } from \"./fake-server.ts\";\n+\n+const TOKEN = \"test-token-not-secret\";\n+const ENV = { AVCS_TOKEN: TOKEN, AVCS_HOOK_FORCE: \"1\", AVCS_SERVERS_FILE: \"no-servers.json\" };\n+\n+let fake: Fake;\n+const dirs: string[] = [];\n+before(async () => {\n+\tfake = await startFake(0, TOKEN);\n+});\n+after(async () => {\n+\tawait fake.close();\n+\tfor (const d of dirs) rmSync(d, { recursive: true, force: true, maxRetries: 5 });\n+});\n+\n+function temp(): string {\n+\tconst d = mkdtempSync(join(tmpdir(), \"abso-lost-pull-\"));\n+\tdirs.push(d);\n+\treturn d;\n+}\n+\n+async function run(cwd: string, ...argv: string[]): Promise<{ exit: number; out: string }> {\n+\tconst r = await main(argv, { cwd, env: ENV, write: () => {} });\n+\treturn { exit: r.exit, out: r.stdout + r.stderr };\n+}\n+\n+let projects = 0;\n+/** alice and bob on one project; alice pushes a change and a new file, and bob's pull of them is lost. */\n+async function lost(): Promise<{ alice: string; bob: string }> {\n+\tconst name = `lost${++projects}`;\n+\tconst alice = temp();\n+\twriteFileSync(join(alice, \"a.txt\"), \"one\\n\");\n+\tassert.equal(\n+\t\t(await run(alice, \"init\", \"--server\", fake.url, \"--project\", name, \"--agent\", \"alice\", \"--as-is\")).exit,\n+\t\t0,\n+\t);\n+\tconst bob = temp();\n+\tassert.equal((await run(bob, \"join\", name, \"--agent\", \"bob\", \"--server\", fake.url)).exit, 0);\n+\twriteFileSync(join(alice, \"a.txt\"), \"two\\n\");\n+\twriteFileSync(join(alice, \"b.txt\"), \"new\\n\");\n+\tconst pushed = await run(alice, \"push\", \"-m\", \"Change a.txt and add b.txt\");\n+\tassert.equal(pushed.exit, 0, pushed.out);\n+\tfake.loseSyncAnswers = 1;\n+\tassert.notEqual((await run(bob, \"pull\")).exit, 0, \"the pull whose answer was lost fails\");\n+\treturn { alice, bob };\n+}\n+\n+const text = (dir: string, rel: string) => readFileSync(join(dir, rel), \"utf8\");\n+\n+describe(\"a pull whose answer never arrives\", () => {\n+\tit(\"leaves the folder as it was, and status says a pull didn't finish\", async () => {\n+\t\tconst { bob } = await lost();\n+\t\tassert.equal(text(bob, \"a.txt\"), \"one\\n\");\n+\t\tassert.equal(existsSync(join(bob, \"b.txt\")), false);\n+\t\tconst status = await run(bob, \"status\");\n+\t\tassert.match(status.out, /A pull here didn't finish/);\n+\t});\n+\n+\tit(\"the next pull asks for every file and writes what the lost one would have\", async () => {\n+\t\tconst { bob } = await lost();\n+\t\tconst pulled = await run(bob, \"pull\");\n+\t\tassert.equal(pulled.exit, 0, pulled.out);\n+\t\tassert.match(pulled.out, /The last pull here didn't finish, so this one asked for every file/);\n+\t\tassert.equal(text(bob, \"a.txt\"), \"two\\n\");\n+\t\tassert.equal(text(bob, \"b.txt\"), \"new\\n\");\n+\t\tassert.doesNotMatch((await run(bob, \"status\")).out, /A pull here didn't finish/);\n+\t\tconst again = await run(bob, \"pull\");\n+\t\tassert.doesNotMatch(again.out, /didn't finish/, \"once caught up, pulls are plain again\");\n+\t});\n+\n+\tit(\"keeps work done in the folder meanwhile\", async () => {\n+\t\tconst { bob } = await lost();\n+\t\twriteFileSync(join(bob, \"a.txt\"), \"bob's own\\n\");\n+\t\tconst pulled = await run(bob, \"pull\");\n+\t\tassert.equal(text(bob, \"a.txt\"), \"bob's own\\n\", pulled.out);\n+\t\tassert.equal(text(bob, \"b.txt\"), \"new\\n\");\n+\t});\n+});"},{"path":"client/test/news-stream.test.ts","added":49,"removed":0,"diff":"--- a/client/test/news-stream.test.ts\n+++ b/client/test/news-stream.test.ts\n@@ -3,6 +3,7 @@\n import assert from \"node:assert/strict\";\n import { test } from \"node:test\";\n import {\n+\texpiresAtMs,\n \ttype FollowDeps,\n \tfollow,\n \tisRefusal,\n@@ -41,6 +42,11 @@\n \tassert.match(text[0]!, /within 45 seconds/);\n \tassert.match(text[0]!, /run abso news --stream again/);\n \tassert.deepEqual(JSON.parse(text[1]!), args);\n+\t// The server sends the expiry as an ISO time (staging 1418); the countdown and the stream mark read it the same.\n+\tconst iso = { ...ticket(1), expiresAt: new Date(NOW + 60_000).toISOString() };\n+\tassert.match(streamText(iso, \"abso\", \"fe\", NOW + 15_000), /within 45 seconds/);\n+\tassert.equal(streamMarkUntil(iso, NOW), NOW + 60_000 + MONITOR_TIMEOUT_MS);\n+\tassert.equal(expiresAtMs({ ...ticket(1), expiresAt: \"soon\" }, NOW), NOW);\n });\n \n test(\"a refusal close stops --follow; any other close opens again, waiting 1 s doubling to a minute\", () => {\n@@ -128,6 +134,49 @@\n \tassert.equal(w.notes.length, 0);\n });\n \n+test(\"a frame is a wake: --follow reads the news and prints that once; an empty read prints the frames\", async () => {\n+\t// The server's frames don't count as heard (abso 690): the read takes them, so each item prints once.\n+\tconst w = world([{ frames: [\"fe told you: hello\", \"cloud asks: ship it?\"], close: { code: 1006 } }]);\n+\tconst reads: string[][] = [[\"fe told you: hello\", \"cloud asks: ship it?\"], []];\n+\tlet calls = 0;\n+\tw.deps.take = async () => {\n+\t\tcalls++;\n+\t\treturn reads.shift() ?? [];\n+\t};\n+\tawait follow(w.deps);\n+\t// Two frames, one read in flight: the second folds into one more read, which finds nothing new; its frame was\n+\t// already printed by the first read, so nothing prints twice.\n+\tassert.equal(calls, 2);\n+\tassert.deepEqual(w.lines, [\"fe told you: hello\", \"cloud asks: ship it?\"]);\n+\n+\t// A server that counts a frame as heard already (staging 1418): the read is empty, so the frame is what shows.\n+\tconst old = world([{ frames: [\"fe told you: hello\"], close: { code: 1006 } }]);\n+\told.deps.take = async () => [];\n+\tawait follow(old.deps);\n+\tassert.deepEqual(old.lines, [\"fe told you: hello\"]);\n+\n+\t// On that server a read can find other news waiting: the frame's own item still shows (Code Review, 291).\n+\tconst mixed = world([{ frames: [\"fe told you: hello\"], close: { code: 1006 } }]);\n+\tmixed.deps.take = async () => [\"cloud: an older item\"];\n+\tawait follow(mixed.deps);\n+\tassert.deepEqual(mixed.lines, [\"cloud: an older item\", \"fe told you: hello\"]);\n+\n+\t// A catch-up frame names the first few waiting items and how many more: the read shows them all, the frame adds nothing.\n+\tconst catchUp = world([{ frames: [\"fe told you: hello\\ncloud: ship it?\\nand 1 more\"], close: { code: 1006 } }]);\n+\tcatchUp.deps.take = async () => [\"fe told you: hello\", \"cloud: ship it?\", \"desk: a third\"];\n+\tawait follow(catchUp.deps);\n+\tassert.deepEqual(catchUp.lines, [\"fe told you: hello\", \"cloud: ship it?\", \"desk: a third\"]);\n+\n+\t// A read that fails shows the frames and says why.\n+\tconst down = world([{ frames: [\"fe told you: hello\"], close: { code: 1006 } }]);\n+\tdown.deps.take = async () => {\n+\t\tthrow new Error(\"could not reach the server\");\n+\t};\n+\tawait follow(down.deps);\n+\tassert.deepEqual(down.lines, [\"fe told you: hello\"]);\n+\tassert.match(down.notes[0]!, /couldn't read the news: could not reach the server/);\n+});\n+\n test(\"--follow keeps an idle socket open with a ping the object answers without waking\", async () => {\n \tconst w = world([{ frames: [], close: { code: 1006 } }]);\n \tconst held: number[] = [];"},{"path":"client/test/web-session.test.ts","added":106,"removed":0,"diff":"--- /dev/null\n+++ b/client/test/web-session.test.ts\n@@ -0,0 +1,106 @@\n+// abso login --web: a staging website session handed to a browser as a one-use link, with no secret printed.\n+\n+import assert from \"node:assert/strict\";\n+import { mkdtempSync, writeFileSync } from \"node:fs\";\n+import { tmpdir } from \"node:os\";\n+import { join } from \"node:path\";\n+import { test } from \"node:test\";\n+import { handoffText, patFromFile, siteFor, webHandoff, webLogin } from \"../src/web-session.ts\";\n+\n+const SITE = \"https://abso-website-staging.chrisazy.workers.dev\";\n+const STAGING = \"https://abso-staging.chrisazy.workers.dev\";\n+const BOX = `abso_bx_${\"C\".repeat(43)}`;\n+const PAT = `abso_pat_${\"A\".repeat(40)}`;\n+const NOW = Date.UTC(2026, 9, 16, 9, 0, 0);\n+\n+test(\"the credential goes only to the staging website beside the folder's staging server (Security condition 6)\", () => {\n+\tassert.equal(siteFor(STAGING, undefined, \"box\"), SITE);\n+\tassert.equal(siteFor(\"https://avcs-staging.chrisazy.workers.dev/\", undefined, \"pat\"), SITE);\n+\t// A server that isn't staging is refused, prod included, whatever is asked.\n+\tassert.throws(\n+\t\t() => siteFor(\"https://api.abso.dev\", undefined, \"box\"),\n+\t\t/for staging.*never sign in to the website on prod/,\n+\t);\n+\tassert.throws(() => siteFor(\"https://api.abso.dev\", \"http://localhost:8871\", \"pat\"), /for staging/);\n+\t// A box's sign-in takes no --site, not even the staging website's own address.\n+\tassert.throws(() => siteFor(STAGING, SITE, \"box\"), /isn't taken with a box's sign-in/);\n+\tassert.throws(() => siteFor(STAGING, \"http://localhost:8871\", \"box\"), /isn't taken with a box's sign-in/);\n+\t// A PAT may name this machine over http, and nothing else.\n+\tassert.equal(siteFor(STAGING, \"http://localhost:8871/x\", \"pat\"), \"http://localhost:8871\");\n+\tassert.equal(siteFor(STAGING, \"http://127.0.0.1:8871\", \"pat\"), \"http://127.0.0.1:8871\");\n+\tfor (const elsewhere of [\"https://anywhere.example\", SITE, \"https://localhost:8871\", \"not a url\"])\n+\t\tassert.throws(() => siteFor(STAGING, elsewhere, \"pat\"), /names this machine only/, elsewhere);\n+});\n+\n+test(\"a refused handoff reads no credential and sends no request\", async () => {\n+\tconst sent: string[] = [];\n+\tconst fetcher = (async (url: string) => (sent.push(url), Response.json({}))) as unknown as typeof fetch;\n+\tlet read = 0;\n+\tconst credential = () => (read++, BOX);\n+\tfor (const asked of [\n+\t\t{ server: \"https://api.abso.dev\", site: undefined, kind: \"box\" as const },\n+\t\t{ server: STAGING, site: \"https://anywhere.example\", kind: \"box\" as const },\n+\t\t{ server: STAGING, site: SITE, kind: \"box\" as const },\n+\t\t{ server: \"https://api.abso.dev\", site: \"http://localhost:8871\", kind: \"pat\" as const },\n+\t\t{ server: STAGING, site: \"https://anywhere.example\", kind: \"pat\" as const },\n+\t])\n+\t\tawait assert.rejects(webLogin({ ...asked, credential, fetcher }), /Nothing was sent/, JSON.stringify(asked));\n+\tassert.deepEqual(sent, []);\n+\tassert.equal(read, 0);\n+\t// Allowed, it goes to the staging website only.\n+\tawait webLogin({ server: STAGING, site: undefined, kind: \"pat\", credential: () => PAT, fetcher }).catch(() => {});\n+\tassert.deepEqual(sent, [`${SITE}/login/handoff`]);\n+});\n+\n+test(\"the credential goes in Authorization only, and the answer is the one link and who it signs in as\", async () => {\n+\tconst seen: { url: string; authorization: string | null; body: unknown }[] = [];\n+\tconst fetcher = (async (url: string, init: RequestInit) => {\n+\t\tseen.push({ url, authorization: new Headers(init.headers).get(\"authorization\"), body: init.body ?? null });\n+\t\treturn Response.json({\n+\t\t\turl: `${SITE}/login/handoff#${\"t\".repeat(50)}`,\n+\t\t\texpiresAt: new Date(NOW + 60_000).toISOString(),\n+\t\t\taccount: \"acct_person1\",\n+\t\t\tname: \"christopher\",\n+\t\t\tsessionEnds: \"2026-10-16T21:00:00.000Z\",\n+\t\t});\n+\t}) as typeof fetch;\n+\tconst h = await webHandoff(SITE, BOX, fetcher);\n+\tassert.deepEqual(seen, [{ url: `${SITE}/login/handoff`, authorization: `Bearer ${BOX}`, body: null }]);\n+\tconst text = handoffText(h, SITE, true, NOW);\n+\tassert.match(text, /within 60 seconds/);\n+\tassert.match(text, /as christopher, until 2026-10-16T21:00:00.000Z, and works once/);\n+\tassert.match(text, /only to the projects this box was granted, at most as a writer/);\n+\tassert.match(handoffText(h, SITE, false, NOW), /It reaches at most as a writer:/);\n+\tassert.match(text, /\\/login\\/handoff#t{50}$/);\n+\tassert.doesNotMatch(text + JSON.stringify(h), /abso_bx_/);\n+});\n+\n+test(\"a refusal says why without the credential; an answer that isn't the site's own link is refused\", async () => {\n+\tconst echo = (async () =>\n+\t\tResponse.json({ error: `that key was refused: ${BOX}` }, { status: 401 })) as unknown as typeof fetch;\n+\tawait assert.rejects(webHandoff(SITE, BOX, echo), (err: Error) => {\n+\t\tassert.match(err.message, /refused: that key was refused: \\[the credential\\]/);\n+\t\tassert.doesNotMatch(err.message, /abso_bx_/);\n+\t\treturn true;\n+\t});\n+\tconst off = (async () => Response.json({ error: \"not found\" }, { status: 404 })) as unknown as typeof fetch;\n+\tawait assert.rejects(webHandoff(SITE, BOX, off), /doesn't hand out sign-in links/);\n+\tconst elsewhere = (async () =>\n+\t\tResponse.json({\n+\t\t\turl: \"https://elsewhere.example/login/handoff#x\",\n+\t\t\texpiresAt: new Date(NOW).toISOString(),\n+\t\t\taccount: \"acct_x\",\n+\t\t})) as unknown as typeof fetch;\n+\tawait assert.rejects(webHandoff(SITE, BOX, elsewhere), /isn't a sign-in link/);\n+});\n+\n+test(\"--pat-file reads a PAT from its file, and refuses a file that doesn't hold one\", () => {\n+\tconst dir = mkdtempSync(join(tmpdir(), \"abso-web-\"));\n+\tconst good = join(dir, \"pat\");\n+\twriteFileSync(good, `abso_pat_${\"A\".repeat(40)}\\n`);\n+\tassert.equal(patFromFile(good), `abso_pat_${\"A\".repeat(40)}`);\n+\tconst bad = join(dir, \"not\");\n+\twriteFileSync(bad, \"hello\");\n+\tassert.throws(() => patFromFile(bad), /doesn't hold a PAT/);\n+\tassert.throws(() => patFromFile(join(dir, \"missing\")), /can't read/);\n+});"}],"unmatched":[]}