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 101 to 102

Compare

+99 −0 in 3 places
Lines 7–19 at 102 (were 7–17 at 101)
77import { tmpdir } from "node:os";
88import { join } from "node:path";
99import { test } from "node:test";
10+import { parseArgs } from "../src/args.ts";
1011import {
1112 boxPublic,
1213 boxText,
1314 forgetBox,
1415 login,
16+ loginRequest,
1517 logout,
1618 mintFreeName,
1719 mintKey,
Lines 22–28 at 102 (were 20–25 at 101)
2022 writeBox,
2123} from "../src/box.ts";
2224import { serverFrom } from "../src/join-commands.ts";
25+import { main } from "../src/main.ts";
2326
2427const SERVER = "https://staging.abso.example";
2528const CREDENTIAL = "abso_bx_the-secret-credential";
Lines 70–171 at 102 (were 67–72 at 101)
6770 };
6871}
6972
73+test("login grant options validate project lists, roles, limits and duration", () => {
74+ const request = (...words: string[]) =>
75+ loginRequest(
76+ parseArgs("login", words, {
77+ projects: "string",
78+ role: "string",
79+ "max-agents": "string",
80+ days: "string",
81+ }),
82+ );
83+ assert.equal(request(), undefined);
84+ assert.deepEqual(request("--projects", "alpha, beta,alpha", "--max-agents", "1", "--days", "30"), {
85+ projects: [
86+ { project: "alpha", role: "writer" },
87+ { project: "beta", role: "writer" },
88+ ],
89+ max_agents: 1,
90+ days: 30,
91+ });
92+ assert.deepEqual(request("--projects", "alpha", "--role", "reader"), {
93+ projects: [{ project: "alpha", role: "reader" }],
94+ });
95+ assert.deepEqual(request("--projects", "alpha", "--role", "owner"), {
96+ projects: [{ project: "alpha", role: "owner" }],
97+ });
98+ assert.deepEqual(request("--max-agents", "50", "--days", "90"), { max_agents: 50, days: 90 });
99+ for (const words of [
100+ ["--role", "writer"],
101+ ["--projects", ""],
102+ ["--projects", "alpha,"],
103+ ["--projects", "../alpha"],
104+ ["--projects", "alpha", "--role", "admin"],
105+ ["--projects", Array.from({ length: 101 }, (_, i) => `p${i}`).join(",")],
106+ ])
107+ assert.throws(() => request(...words));
108+ for (const flag of ["--max-agents", "--days"]) {
109+ for (const value of ["0", "-1", "1.5", "1e1", "Infinity", "100", "abc", ""])
110+ assert.throws(() => request(flag, value));
111+ }
112+});
114+test("login sends requested grants only at device start and retains the user's actual approval", async () => {
115+ const h = home();
116+ const seen: Seen = [];
117+ const c = clock();
118+ const requested = { projects: [{ project: "abso", role: "owner" as const }], max_agents: 10, days: 90 };
119+ const approved = { projects: [{ project: "abso", role: "reader" }], max_agents: 1 };
120+ const got = await login(
121+ SERVER,
122+ {
123+ request: requested,
124+ fetch: server(
125+ [
126+ [200, started],
127+ [400, { error: "authorization_pending" }],
128+ [200, { box_id: "b_test", box_token: CREDENTIAL, expires_at: EXPIRES, grant: approved }],
129+ ],
130+ seen,
131+ ),
132+ sleep: c.sleep,
133+ now: c.now,
134+ say: () => {},
135+ },
136+ h,
137+ );
138+ assert.ok(seen[0]);
139+ assert.deepEqual((seen[0].body as Record<string, unknown>).requested_grant, requested);
140+ assert.deepEqual(
141+ seen.slice(1).map((call) => call.body),
142+ [{ device_code: started.device_code }, { device_code: started.device_code }],
143+ );
144+ assert.deepEqual(got.grant, approved);
145+ assert.deepEqual(readBox(SERVER, h)?.grant, approved);
146+});
148+test("invalid login grant flags fail before a network request through the CLI", async () => {
149+ const original = globalThis.fetch;
150+ let calls = 0;
151+ globalThis.fetch = (async () => {
152+ calls++;
153+ throw new Error("unexpected request");
154+ }) as typeof fetch;
155+ try {
156+ const result = await main(["login", "--projects", "alpha", "--days", "0", "--no-browser"], {
157+ cwd: home(),
158+ env: {},
159+ write: () => {},
160+ });
161+ assert.equal(result.exit, 1);
162+ assert.match(result.stderr, /--days is from 1 to 90/);
163+ assert.equal(calls, 0);
164+ } finally {
165+ globalThis.fetch = original;
166+ }
167+});
70169test("login shows the code, waits while it's pending, and keeps the credential in the user folder", async () => {
71170 const h = home();
72171 const seen: Seen = [];
MCP
compare on this site's /mcp
CLI
abso diff 101 102 client/test/box.test.ts --json
JSON
/christopher/abso-core/compare/101..102?file=client%2Ftest%2Fbox.test.ts&format=json