{"draft":null,"from":305,"to":306,"files":[{"path":"client/test/web-session.test.ts","added":40,"removed":7,"diff":"--- a/client/test/web-session.test.ts\n+++ b/client/test/web-session.test.ts\n@@ -5,20 +5,53 @@\n import { tmpdir } from \"node:os\";\n import { join } from \"node:path\";\n import { test } from \"node:test\";\n-import { handoffText, patFromFile, siteFor, webHandoff } from \"../src/web-session.ts\";\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 website is the staging one beside the server, or --site; prod has none, since agents never sign in there\", () => {\n-\tassert.equal(siteFor(\"https://abso-staging.chrisazy.workers.dev\"), SITE);\n-\tassert.equal(siteFor(\"https://avcs-staging.chrisazy.workers.dev/\"), SITE);\n-\tassert.throws(() => siteFor(\"https://api.abso.dev\"), /for staging.*never sign in to the website on prod/);\n-\tassert.equal(siteFor(\"https://api.abso.dev\", \"http://localhost:8871/x\"), \"http://localhost:8871\");\n-\tassert.throws(() => siteFor(\"https://api.abso.dev\", \"http://elsewhere.example\"), /https/);\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) => {"}],"unmatched":[]}