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 116 to 318

Compare

+171 −0 in 1 place
new file, 171 lines
1+// abso init and join sign in with the box sign-in, and use this machine's ~/.abso/token only with --token-file. A
2+// project is never made or joined with a shared credential that happened to be in a file, and both say what they sign
3+// in with. The client runs as its own process with its own home, so nothing on this machine is read.
4+
5+import assert from "node:assert/strict";
6+import { execFile } from "node:child_process";
7+import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
8+import { createServer, type IncomingHttpHeaders, type Server } from "node:http";
9+import type { AddressInfo } from "node:net";
10+import { tmpdir } from "node:os";
11+import { join, resolve } from "node:path";
12+import { after, before, describe, it } from "node:test";
13+import { parseArgs } from "../src/args.ts";
14+import { writeBox } from "../src/box.ts";
15+import { tokenCredential } from "../src/join-commands.ts";
16+import { type Fake, startFake } from "./fake-server.ts";
18+const CLIENT = resolve(import.meta.dirname, "..", "abso.ts");
19+const TOKEN = "file-token-not-secret";
20+const CREDENTIAL = "abso_bx_box-credential-not-secret";
21+let fake: Fake;
22+// Stands in for a server that takes box sign-ins: it notes each request, then answers 500 so the run stops there.
23+let boxes: Server;
24+let boxesUrl: string;
25+const heard: { url: string; headers: IncomingHttpHeaders }[] = [];
26+const dirs: string[] = [];
27+const temp = () => {
28+ const dir = mkdtempSync(join(tmpdir(), "abso-test-init-credential-"));
29+ dirs.push(dir);
30+ return dir;
31+};
33+before(async () => {
34+ fake = await startFake(0, TOKEN);
35+ boxes = createServer((req, res) => {
36+ heard.push({ url: req.url ?? "", headers: req.headers });
37+ res.writeHead(500, { "content-type": "application/json" }).end('{"error":"stop here"}');
38+ });
39+ await new Promise<void>((done) => boxes.listen(0, "127.0.0.1", done));
40+ boxesUrl = `http://127.0.0.1:${(boxes.address() as AddressInfo).port}`;
41+});
42+after(async () => {
43+ await fake.close();
44+ boxes.close();
45+ for (const dir of dirs) rmSync(dir, { recursive: true, force: true });
46+});
48+/** A home holding a token file, and a box sign-in for `boxFor` when given. */
49+function home(boxFor?: string): string {
50+ const dir = temp();
51+ mkdirSync(join(dir, ".abso"), { recursive: true });
52+ writeFileSync(join(dir, ".abso", "token"), `${TOKEN}\n`);
53+ if (boxFor)
54+ writeBox(
55+ {
56+ server: boxFor,
57+ id: "b_0123abcd",
58+ credential: CREDENTIAL,
59+ grant: { projects: [], scopes: [{ kind: "member-all", role: "owner" }] },
60+ expiresAt: Date.now() + 86_400_000,
61+ },
62+ dir,
63+ );
64+ return dir;
65+}
67+function client(
68+ homeDir: string,
69+ cwd: string,
70+ ...args: string[]
71+): Promise<{ code: number; stdout: string; stderr: string }> {
72+ const env: Record<string, string> = {
73+ PATH: process.env.PATH ?? "",
74+ HOME: homeDir,
75+ USERPROFILE: homeDir,
76+ AVCS_SERVERS_FILE: "no-servers.json",
77+ ABSO_NO_BROWSER: "1",
78+ };
79+ if (process.env.CLAUDE_CONFIG_DIR) env.CLAUDE_CONFIG_DIR = process.env.CLAUDE_CONFIG_DIR;
80+ if (process.env.SystemRoot) env.SystemRoot = process.env.SystemRoot;
81+ return new Promise((done) => {
82+ execFile(process.execPath, [CLIENT, ...args], { cwd, env }, (error, stdout, stderr) =>
83+ done({ code: typeof error?.code === "number" ? error.code : 0, stdout, stderr }),
84+ );
85+ });
86+}
88+function folder(): string {
89+ const dir = temp();
90+ writeFileSync(join(dir, "a.txt"), "hi\n");
91+ return dir;
92+}
94+const FLAGS = { "token-file": "boolean" } as const;
96+describe("what init and join sign in with", () => {
97+ it("the token file only with --token-file, never into a folder with a key; ABSO_TOKEN as given", () => {
98+ const server = "http://127.0.0.1:1";
99+ const file = () => TOKEN;
100+ const none = parseArgs("init", [], FLAGS);
101+ const asked = parseArgs("init", ["--token-file"], FLAGS);
102+ assert.equal(tokenCredential(none, {}, server, temp(), file), undefined, "a token file alone is not used");
103+ assert.deepEqual(tokenCredential(asked, {}, server, temp(), file), {
104+ token: TOKEN,
105+ words: "the token file, ~/.abso/token, as --token-file asks",
106+ });
107+ assert.throws(() => tokenCredential(asked, {}, server, temp(), () => undefined), /this machine has none/);
108+ const keyed = temp();
109+ mkdirSync(join(keyed, ".abso"));
110+ writeFileSync(join(keyed, ".abso", "key"), "{}");
111+ assert.throws(() => tokenCredential(asked, {}, server, keyed, file), /already has a key/);
112+ assert.equal(tokenCredential(none, { ABSO_TOKEN: "env-token" }, server, temp(), file)?.words, "ABSO_TOKEN");
113+ });
115+ it("init with a token file and a box sign-in, no flag: signs in with the box, and says so", async () => {
116+ const run = await client(home(boxesUrl), folder(), "init", "--project", "made", "--server", boxesUrl);
117+ assert.match(run.stderr, /Signing in with this box's sign-in, b_0123abcd\./);
118+ assert.ok(heard.length > 0);
119+ assert.ok(
120+ heard.every((h) => h.headers.authorization === `Box ${CREDENTIAL}`),
121+ "every request carried the box's sign-in",
122+ );
123+ assert.ok(
124+ heard.every((h) => !String(h.headers.authorization).includes(TOKEN)),
125+ "the token file was never sent",
126+ );
127+ });
129+ it("init with only a token file, no flag: refused before anything is made, naming --token-file", async () => {
130+ const run = await client(home(), folder(), "init", "--project", "unasked", "--agent", "me", "--server", fake.url);
131+ assert.notEqual(run.code, 0);
132+ assert.match(run.stderr, /abso login signs it in\. ~\/\.abso\/token is used only with --token-file\./);
133+ const status = await fetch(`${fake.url}/p/unasked/status`, { headers: { authorization: `Bearer ${TOKEN}` } });
134+ assert.equal(status.status, 404, "no project was made");
135+ });
137+ it("init and join with --token-file: sign in with the file, and say so", async () => {
138+ const homeDir = home();
139+ const made = await client(
140+ homeDir,
141+ folder(),
142+ "init",
143+ "--project",
144+ "asked",
145+ "--agent",
146+ "me",
147+ "--token-file",
148+ "--server",
149+ fake.url,
150+ );
151+ assert.equal(made.code, 0, made.stderr);
152+ assert.match(made.stderr, /Signing in with the token file, ~\/\.abso\/token, as --token-file asks\./);
153+ assert.match(made.stdout, /Created project asked/);
154+ const unasked = await client(homeDir, temp(), "join", "asked", "--agent", "other", "--server", fake.url);
155+ assert.notEqual(unasked.code, 0, "join without the flag sends no token");
156+ assert.match(unasked.stderr, /~\/\.abso\/token is used only with --token-file\./);
157+ const joined = await client(
158+ homeDir,
159+ temp(),
160+ "join",
161+ "asked",
162+ "--agent",
163+ "other",
164+ "--token-file",
165+ "--server",
166+ fake.url,
167+ );
168+ assert.equal(joined.code, 0, joined.stderr);
169+ assert.match(joined.stderr, /Signing in with the token file/);
170+ });
171+});
MCP
compare on this site's /mcp
CLI
abso diff 116 318 client/test/init-credential.test.ts --json
JSON
/christopher/abso-core/compare/116..318?file=client%2Ftest%2Finit-credential.test.ts&format=json