- MCP
- blame on this site's /mcp
- CLI
- abso blame client/test/web-session.test.ts --json
- JSON
- /christopher/abso-core/blame/client/test/web-session.test.ts?format=json
106 linesbox-grants 100%Last change box-grants in version 306,
106 lines from 4 changes in 3 versions.
box-grants302abso login --web: a staging website session in an agent's own browser with no secret in its hands. It sends this box's sign-in (or, with --pat-file, a test account's PAT read from that file) to the staging website's /login/handoff and prints only the one-use link it answers, which signs whichever browser opens it in as that person, within a minute. Prod has no website for it: agents never sign in there. Tests: client/test/web-session.test.ts.Compare1// abso login --web: a staging website session handed to a browser as a one-use link, with no secret printed.
3import assert from "node:assert/strict";
4import { mkdtempSync, writeFileSync } from "node:fs";
5import { tmpdir } from "node:os";
6import { join } from "node:path";
7import { test } from "node:test";
box-grants306abso login --web sends a credential only to the staging website beside the folder's own staging server (Security condition 6, Code Review's Medium on 302). The pairing is the fixed list in web-session.ts; any other server, prod included, is refused and nothing is sent. A box's sign-in takes no --site at all. --site is only for --pat-file, and only http://localhost or 127.0.0.1. webLogin settles the website before it reads the credential, so a refusal reads and sends nothing. Tests: client/test/web-session.test.ts (5), including that every refused case reads no credential and sends no request; tsc exits 0.Compare8import { handoffText, patFromFile, siteFor, webHandoff, webLogin } from "../src/web-session.ts";
box-grants302abso login --web: a staging website session in an agent's own browser with no secret in its hands. It sends this box's sign-in (or, with --pat-file, a test account's PAT read from that file) to the staging website's /login/handoff and prints only the one-use link it answers, which signs whichever browser opens it in as that person, within a minute. Prod has no website for it: agents never sign in there. Tests: client/test/web-session.test.ts.Compare9
10const SITE = "https://abso-website-staging.chrisazy.workers.dev";
box-grants306abso login --web sends a credential only to the staging website beside the folder's own staging server (Security condition 6, Code Review's Medium on 302). The pairing is the fixed list in web-session.ts; any other server, prod included, is refused and nothing is sent. A box's sign-in takes no --site at all. --site is only for --pat-file, and only http://localhost or 127.0.0.1. webLogin settles the website before it reads the credential, so a refusal reads and sends nothing. Tests: client/test/web-session.test.ts (5), including that every refused case reads no credential and sends no request; tsc exits 0.Compare11const STAGING = "https://abso-staging.chrisazy.workers.dev";
box-grants302abso login --web: a staging website session in an agent's own browser with no secret in its hands. It sends this box's sign-in (or, with --pat-file, a test account's PAT read from that file) to the staging website's /login/handoff and prints only the one-use link it answers, which signs whichever browser opens it in as that person, within a minute. Prod has no website for it: agents never sign in there. Tests: client/test/web-session.test.ts.Compare12const BOX = `abso_bx_${"C".repeat(43)}`;
box-grants306abso login --web sends a credential only to the staging website beside the folder's own staging server (Security condition 6, Code Review's Medium on 302). The pairing is the fixed list in web-session.ts; any other server, prod included, is refused and nothing is sent. A box's sign-in takes no --site at all. --site is only for --pat-file, and only http://localhost or 127.0.0.1. webLogin settles the website before it reads the credential, so a refusal reads and sends nothing. Tests: client/test/web-session.test.ts (5), including that every refused case reads no credential and sends no request; tsc exits 0.Compare13const PAT = `abso_pat_${"A".repeat(40)}`;
box-grants302abso login --web: a staging website session in an agent's own browser with no secret in its hands. It sends this box's sign-in (or, with --pat-file, a test account's PAT read from that file) to the staging website's /login/handoff and prints only the one-use link it answers, which signs whichever browser opens it in as that person, within a minute. Prod has no website for it: agents never sign in there. Tests: client/test/web-session.test.ts.Compare14const NOW = Date.UTC(2026, 9, 16, 9, 0, 0);
box-grants306abso login --web sends a credential only to the staging website beside the folder's own staging server (Security condition 6, Code Review's Medium on 302). The pairing is the fixed list in web-session.ts; any other server, prod included, is refused and nothing is sent. A box's sign-in takes no --site at all. --site is only for --pat-file, and only http://localhost or 127.0.0.1. webLogin settles the website before it reads the credential, so a refusal reads and sends nothing. Tests: client/test/web-session.test.ts (5), including that every refused case reads no credential and sends no request; tsc exits 0.Compare16test("the credential goes only to the staging website beside the folder's staging server (Security condition 6)", () => {
17 assert.equal(siteFor(STAGING, undefined, "box"), SITE);
18 assert.equal(siteFor("https://avcs-staging.chrisazy.workers.dev/", undefined, "pat"), SITE);
19 // A server that isn't staging is refused, prod included, whatever is asked.
20 assert.throws(
21 () => siteFor("https://api.abso.dev", undefined, "box"),
22 /for staging.*never sign in to the website on prod/,
23 );
24 assert.throws(() => siteFor("https://api.abso.dev", "http://localhost:8871", "pat"), /for staging/);
25 // A box's sign-in takes no --site, not even the staging website's own address.
26 assert.throws(() => siteFor(STAGING, SITE, "box"), /isn't taken with a box's sign-in/);
27 assert.throws(() => siteFor(STAGING, "http://localhost:8871", "box"), /isn't taken with a box's sign-in/);
28 // A PAT may name this machine over http, and nothing else.
29 assert.equal(siteFor(STAGING, "http://localhost:8871/x", "pat"), "http://localhost:8871");
30 assert.equal(siteFor(STAGING, "http://127.0.0.1:8871", "pat"), "http://127.0.0.1:8871");
31 for (const elsewhere of ["https://anywhere.example", SITE, "https://localhost:8871", "not a url"])
32 assert.throws(() => siteFor(STAGING, elsewhere, "pat"), /names this machine only/, elsewhere);
33});
35test("a refused handoff reads no credential and sends no request", async () => {
36 const sent: string[] = [];
37 const fetcher = (async (url: string) => (sent.push(url), Response.json({}))) as unknown as typeof fetch;
38 let read = 0;
39 const credential = () => (read++, BOX);
40 for (const asked of [
41 { server: "https://api.abso.dev", site: undefined, kind: "box" as const },
42 { server: STAGING, site: "https://anywhere.example", kind: "box" as const },
43 { server: STAGING, site: SITE, kind: "box" as const },
44 { server: "https://api.abso.dev", site: "http://localhost:8871", kind: "pat" as const },
45 { server: STAGING, site: "https://anywhere.example", kind: "pat" as const },
46 ])
47 await assert.rejects(webLogin({ ...asked, credential, fetcher }), /Nothing was sent/, JSON.stringify(asked));
48 assert.deepEqual(sent, []);
49 assert.equal(read, 0);
50 // Allowed, it goes to the staging website only.
51 await webLogin({ server: STAGING, site: undefined, kind: "pat", credential: () => PAT, fetcher }).catch(() => {});
52 assert.deepEqual(sent, [`${SITE}/login/handoff`]);
box-grants302abso login --web: a staging website session in an agent's own browser with no secret in its hands. It sends this box's sign-in (or, with --pat-file, a test account's PAT read from that file) to the staging website's /login/handoff and prints only the one-use link it answers, which signs whichever browser opens it in as that person, within a minute. Prod has no website for it: agents never sign in there. Tests: client/test/web-session.test.ts.Compare53});
55test("the credential goes in Authorization only, and the answer is the one link and who it signs in as", async () => {
56 const seen: { url: string; authorization: string | null; body: unknown }[] = [];
57 const fetcher = (async (url: string, init: RequestInit) => {
58 seen.push({ url, authorization: new Headers(init.headers).get("authorization"), body: init.body ?? null });
59 return Response.json({
60 url: `${SITE}/login/handoff#${"t".repeat(50)}`,
61 expiresAt: new Date(NOW + 60_000).toISOString(),
62 account: "acct_person1",
63 name: "christopher",
64 sessionEnds: "2026-10-16T21:00:00.000Z",
65 });
66 }) as typeof fetch;
67 const h = await webHandoff(SITE, BOX, fetcher);
68 assert.deepEqual(seen, [{ url: `${SITE}/login/handoff`, authorization: `Bearer ${BOX}`, body: null }]);
box-grants304abso login --web says what the link reaches: a box's only the projects the box was granted, at most as a writer, until the box is revoked or ends (abso 1464, website 1125, Security); a PAT's at most as a writer. The help says the same, and that it writes issues, replies, answers, groups and announcements and changes no members, roles, visibility, keys, boxes or settings. Tests: client/test/web-session.test.ts (4).Compare69 const text = handoffText(h, SITE, true, NOW);
box-grants302abso login --web: a staging website session in an agent's own browser with no secret in its hands. It sends this box's sign-in (or, with --pat-file, a test account's PAT read from that file) to the staging website's /login/handoff and prints only the one-use link it answers, which signs whichever browser opens it in as that person, within a minute. Prod has no website for it: agents never sign in there. Tests: client/test/web-session.test.ts.Compare70 assert.match(text, /within 60 seconds/);
71 assert.match(text, /as christopher, until 2026-10-16T21:00:00.000Z, and works once/);
box-grants304abso login --web says what the link reaches: a box's only the projects the box was granted, at most as a writer, until the box is revoked or ends (abso 1464, website 1125, Security); a PAT's at most as a writer. The help says the same, and that it writes issues, replies, answers, groups and announcements and changes no members, roles, visibility, keys, boxes or settings. Tests: client/test/web-session.test.ts (4).Compare72 assert.match(text, /only to the projects this box was granted, at most as a writer/);
73 assert.match(handoffText(h, SITE, false, NOW), /It reaches at most as a writer:/);
box-grants302abso login --web: a staging website session in an agent's own browser with no secret in its hands. It sends this box's sign-in (or, with --pat-file, a test account's PAT read from that file) to the staging website's /login/handoff and prints only the one-use link it answers, which signs whichever browser opens it in as that person, within a minute. Prod has no website for it: agents never sign in there. Tests: client/test/web-session.test.ts.Compare74 assert.match(text, /\/login\/handoff#t{50}$/);
75 assert.doesNotMatch(text + JSON.stringify(h), /abso_bx_/);
76});
78test("a refusal says why without the credential; an answer that isn't the site's own link is refused", async () => {
79 const echo = (async () =>
80 Response.json({ error: `that key was refused: ${BOX}` }, { status: 401 })) as unknown as typeof fetch;
81 await assert.rejects(webHandoff(SITE, BOX, echo), (err: Error) => {
82 assert.match(err.message, /refused: that key was refused: \[the credential\]/);
83 assert.doesNotMatch(err.message, /abso_bx_/);
84 return true;
85 });
86 const off = (async () => Response.json({ error: "not found" }, { status: 404 })) as unknown as typeof fetch;
87 await assert.rejects(webHandoff(SITE, BOX, off), /doesn't hand out sign-in links/);
88 const elsewhere = (async () =>
89 Response.json({
90 url: "https://elsewhere.example/login/handoff#x",
91 expiresAt: new Date(NOW).toISOString(),
92 account: "acct_x",
93 })) as unknown as typeof fetch;
94 await assert.rejects(webHandoff(SITE, BOX, elsewhere), /isn't a sign-in link/);
95});
97test("--pat-file reads a PAT from its file, and refuses a file that doesn't hold one", () => {
98 const dir = mkdtempSync(join(tmpdir(), "abso-web-"));
99 const good = join(dir, "pat");
100 writeFileSync(good, `abso_pat_${"A".repeat(40)}\n`);
101 assert.equal(patFromFile(good), `abso_pat_${"A".repeat(40)}`);
102 const bad = join(dir, "not");
103 writeFileSync(bad, "hello");
104 assert.throws(() => patFromFile(bad), /doesn't hold a PAT/);
105 assert.throws(() => patFromFile(join(dir, "missing")), /can't read/);
106});