{"draft":null,"from":283,"to":318,"files":[{"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/install.test.ts","added":23,"removed":0,"diff":"--- a/client/test/install.test.ts\n+++ b/client/test/install.test.ts\n@@ -26,6 +26,7 @@\n import { clientVersion, headCommit } from \"../src/client-version.ts\";\n import {\n \tAVCS_MOD,\n+\thookCommand,\n \tinstallerCommand,\n \tinstallMod,\n \tkeptModCommit,\n@@ -114,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\");"},{"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/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":[]}