Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed

Versions 301 to 302

Compare

+71 −0 in 1 place
new file, 71 lines
1+// abso login --web: a staging website session handed to a browser as a one-use link, with no secret printed.
2+
3+import assert from "node:assert/strict";
4+import { mkdtempSync, writeFileSync } from "node:fs";
5+import { tmpdir } from "node:os";
6+import { join } from "node:path";
7+import { test } from "node:test";
8+import { handoffText, patFromFile, siteFor, webHandoff } from "../src/web-session.ts";
9+
10+const SITE = "https://abso-website-staging.chrisazy.workers.dev";
11+const BOX = `abso_bx_${"C".repeat(43)}`;
12+const NOW = Date.UTC(2026, 9, 16, 9, 0, 0);
14+test("the website is the staging one beside the server, or --site; prod has none, since agents never sign in there", () => {
15+ assert.equal(siteFor("https://abso-staging.chrisazy.workers.dev"), SITE);
16+ assert.equal(siteFor("https://avcs-staging.chrisazy.workers.dev/"), SITE);
17+ assert.throws(() => siteFor("https://api.abso.dev"), /for staging.*never sign in to the website on prod/);
18+ assert.equal(siteFor("https://api.abso.dev", "http://localhost:8871/x"), "http://localhost:8871");
19+ assert.throws(() => siteFor("https://api.abso.dev", "http://elsewhere.example"), /https/);
20+});
22+test("the credential goes in Authorization only, and the answer is the one link and who it signs in as", async () => {
23+ const seen: { url: string; authorization: string | null; body: unknown }[] = [];
24+ const fetcher = (async (url: string, init: RequestInit) => {
25+ seen.push({ url, authorization: new Headers(init.headers).get("authorization"), body: init.body ?? null });
26+ return Response.json({
27+ url: `${SITE}/login/handoff#${"t".repeat(50)}`,
28+ expiresAt: new Date(NOW + 60_000).toISOString(),
29+ account: "acct_person1",
30+ name: "christopher",
31+ sessionEnds: "2026-10-16T21:00:00.000Z",
32+ });
33+ }) as typeof fetch;
34+ const h = await webHandoff(SITE, BOX, fetcher);
35+ assert.deepEqual(seen, [{ url: `${SITE}/login/handoff`, authorization: `Bearer ${BOX}`, body: null }]);
36+ const text = handoffText(h, SITE, NOW);
37+ assert.match(text, /within 60 seconds/);
38+ assert.match(text, /as christopher, until 2026-10-16T21:00:00.000Z, and works once/);
39+ assert.match(text, /\/login\/handoff#t{50}$/);
40+ assert.doesNotMatch(text + JSON.stringify(h), /abso_bx_/);
41+});
43+test("a refusal says why without the credential; an answer that isn't the site's own link is refused", async () => {
44+ const echo = (async () =>
45+ Response.json({ error: `that key was refused: ${BOX}` }, { status: 401 })) as unknown as typeof fetch;
46+ await assert.rejects(webHandoff(SITE, BOX, echo), (err: Error) => {
47+ assert.match(err.message, /refused: that key was refused: \[the credential\]/);
48+ assert.doesNotMatch(err.message, /abso_bx_/);
49+ return true;
50+ });
51+ const off = (async () => Response.json({ error: "not found" }, { status: 404 })) as unknown as typeof fetch;
52+ await assert.rejects(webHandoff(SITE, BOX, off), /doesn't hand out sign-in links/);
53+ const elsewhere = (async () =>
54+ Response.json({
55+ url: "https://elsewhere.example/login/handoff#x",
56+ expiresAt: new Date(NOW).toISOString(),
57+ account: "acct_x",
58+ })) as unknown as typeof fetch;
59+ await assert.rejects(webHandoff(SITE, BOX, elsewhere), /isn't a sign-in link/);
60+});
62+test("--pat-file reads a PAT from its file, and refuses a file that doesn't hold one", () => {
63+ const dir = mkdtempSync(join(tmpdir(), "abso-web-"));
64+ const good = join(dir, "pat");
65+ writeFileSync(good, `abso_pat_${"A".repeat(40)}\n`);
66+ assert.equal(patFromFile(good), `abso_pat_${"A".repeat(40)}`);
67+ const bad = join(dir, "not");
68+ writeFileSync(bad, "hello");
69+ assert.throws(() => patFromFile(bad), /doesn't hold a PAT/);
70+ assert.throws(() => patFromFile(join(dir, "missing")), /can't read/);
71+});
MCP
compare on this site's /mcp
CLI
abso diff 301 302 client/test/web-session.test.ts --json
JSON
/christopher/abso-core/compare/301..302?file=client%2Ftest%2Fweb-session.test.ts&format=json