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 154 to 155

Compare

+218 −0 in 1 place
new file, 218 lines
1+// --server on every command that talks to a server (abso-core issue 10). The rules, each a test:
2+// - every command is sorted: one that works on this machine only takes no --server and says so; every other one
3+// takes it, and help says the same words about it for each kind;
4+// - a missing, empty or malformed value is refused before anything is sent, for every family of command;
5+// - in a joined folder, --server naming the folder's own server reaches it; another server is refused, never
6+// swapped in, and nothing is sent; outside a joined folder a folder command with --server is refused too;
7+// - an explicit --server goes to that server's own Issues Worker, which ABSO_ISSUES_SERVER doesn't redirect;
8+// - a command that picks its server (whoami, box, logout) uses the one named, even inside a folder on another.
9+
10+import assert from "node:assert/strict";
11+import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
12+import { createServer, type Server } from "node:http";
13+import type { AddressInfo } from "node:net";
14+import { tmpdir } from "node:os";
15+import { join } from "node:path";
16+import { after, before, describe, it } from "node:test";
17+import { writeConfig } from "../src/config.ts";
18+import { commandTable, main } from "../src/main.ts";
19+import { sameServer, serverHelp, serverUse } from "../src/server-choice.ts";
21+/** A made-up token: the tests never read the real ~/.abso/token. */
22+const TOKEN = "abso_test-token-for-server-flag";
24+interface Listening {
25+ readonly server: Server;
26+ readonly url: string;
27+ readonly paths: string[];
28+}
30+/** A server that notes each path it is asked for and answers 500, so a command stops after its first call. */
31+async function listen(): Promise<Listening> {
32+ const paths: string[] = [];
33+ const server = createServer((req, res) => {
34+ paths.push(req.url ?? "");
35+ res.writeHead(500, { "content-type": "application/json" });
36+ res.end(JSON.stringify({ error: "a test server" }));
37+ });
38+ await new Promise<void>((done) => server.listen(0, "127.0.0.1", done));
39+ return { server, url: `http://127.0.0.1:${(server.address() as AddressInfo).port}`, paths };
40+}
42+const temps: string[] = [];
43+function temp(name: string): string {
44+ const dir = mkdtempSync(join(tmpdir(), `abso-server-flag-${name}-`));
45+ temps.push(dir);
46+ return dir;
47+}
49+let home: Listening;
50+let other: Listening;
51+let issuesElsewhere: Listening;
52+let env: Record<string, string>;
54+before(async () => {
55+ home = await listen();
56+ other = await listen();
57+ issuesElsewhere = await listen();
58+ const servers = join(temp("servers"), "servers.json");
59+ writeFileSync(servers, "{}");
60+ env = { ABSO_TOKEN: TOKEN, ABSO_SERVERS_FILE: servers };
61+});
63+after(() => {
64+ for (const l of [home, other, issuesElsewhere]) l.server.close();
65+ for (const dir of temps) rmSync(dir, { recursive: true, force: true });
66+});
68+function folder(server = home.url): string {
69+ const root = temp("folder");
70+ writeConfig(root, { server, project: "demo", agent: "alice" });
71+ return root;
72+}
74+const run = (cwd: string, argv: string[], extra: Record<string, string> = {}) =>
75+ main(argv, { cwd, env: { ...env, ...extra }, write: () => {} });
77+function calls(): number {
78+ return home.paths.length + other.paths.length + issuesElsewhere.paths.length;
79+}
81+function clear(): void {
82+ for (const l of [home, other, issuesElsewhere]) l.paths.length = 0;
83+}
85+describe("--server on every command", () => {
86+ it("sorts every command: local ones take no --server, every other one does, and help says so alike", async () => {
87+ const table = commandTable();
88+ const local = Object.keys(table).filter((name) => serverUse(name) === "local");
89+ assert.deepEqual(local.sort(), ["check-ignore", "fix-eol", "pause", "resume", "skill"]);
90+ for (const [name, def] of Object.entries(table)) {
91+ if (serverUse(name) === "local") {
92+ assert.equal(def.flags.server, undefined, name);
93+ assert.equal(serverHelp(name), undefined, name);
94+ continue;
95+ }
96+ assert.equal(def.flags.server, "string", name);
97+ const help = await run(process.cwd(), [name, "--help"]);
98+ assert.ok(help.stdout.includes(` ${serverHelp(name)}\n`), `abso ${name} --help names --server`);
99+ }
100+ const data = JSON.parse((await run(process.cwd(), ["help", "--json"])).stdout) as {
101+ commands: { name: string; server?: string; flags: Record<string, string> }[];
102+ };
103+ for (const c of data.commands.filter((c) => c.name in table)) assert.equal(c.server, serverHelp(c.name), c.name);
104+ const text = (await run(process.cwd(), ["help"])).stdout;
105+ assert.match(text, /Every command that talks to a server takes --server <url>/);
106+ });
108+ it("refuses --server on a command that works on this machine only", async () => {
109+ for (const argv of [
110+ ["skill", "show", "--server", home.url],
111+ ["check-ignore", "a.txt", `--server=${home.url}`],
112+ ["pause", "--server", home.url],
113+ ]) {
114+ const r = await run(folder(), argv);
115+ assert.equal(r.exit, 1, argv.join(" "));
116+ assert.match(r.stderr, /works on this machine only and talks to no server, so it takes no --server/);
117+ }
118+ const words = await run(folder(), ["check-ignore", "--", "--server"]);
119+ assert.doesNotMatch(words.stderr, /takes no --server/, "a path after -- is a path");
120+ });
122+ it("refuses a missing, empty or malformed value before anything is sent, in every family", async () => {
123+ const root = folder();
124+ const outside = temp("outside");
125+ clear();
126+ const families: [string, string[]][] = [
127+ [root, ["status"]],
128+ [root, ["issue", "new", "A title"]],
129+ [root, ["ask", "bob", "Why?"]],
130+ [root, ["news"]],
131+ [root, ["pipeline", "runs"]],
132+ [outside, ["whoami"]],
133+ [outside, ["login"]],
134+ [outside, ["join", "demo"]],
135+ [outside, ["org", "acme"]],
136+ [outside, ["key", "list"]],
137+ ];
138+ for (const [cwd, argv] of families) {
139+ const missing = await run(cwd, [...argv, "--server"]);
140+ assert.match(missing.stderr, /--server needs a value/, argv.join(" "));
141+ const empty = await run(cwd, [...argv, "--server="]);
142+ assert.match(empty.stderr, /--server needs a server's URL, like https:\/\/api\.abso\.dev/, argv.join(" "));
143+ for (const bad of ["api.abso.dev", "ftp://api.abso.dev", "https://me@api.abso.dev", "https://x.example/?a=1"]) {
144+ const r = await run(cwd, [...argv, "--server", bad]);
145+ assert.equal(r.exit, 1, `${argv.join(" ")} --server ${bad}`);
146+ assert.match(r.stderr, /--server takes an http or https URL with no user name, query or fragment/);
147+ }
148+ }
149+ assert.equal(calls(), 0, "nothing was sent");
150+ });
152+ it("in a joined folder, reaches the folder's own server and refuses another without sending anything", async () => {
153+ const root = folder();
154+ for (const argv of [["status"], ["log"], ["issues"], ["issue", "1"], ["news"], ["waiting"], ["ci"]]) {
155+ clear();
156+ const same = await run(root, [...argv, "--server", `${home.url.toUpperCase().replace("HTTP", "http")}/`]);
157+ assert.doesNotMatch(same.stderr, /joined on/, argv.join(" "));
158+ assert.ok(home.paths.length > 0, `abso ${argv.join(" ")} reached the folder's server`);
159+ assert.equal(other.paths.length, 0);
160+ clear();
161+ const refused = await run(root, [...argv, "--server", other.url]);
162+ assert.equal(refused.exit, 1);
163+ assert.match(
164+ refused.stderr,
165+ new RegExp(
166+ `this folder is joined on ${home.url}, not ${other.url}, so abso ${argv[0]} won't send its work or key there`,
167+ ),
168+ );
169+ assert.equal(calls(), 0, `abso ${argv.join(" ")} sent nothing`);
170+ }
171+ });
173+ it("outside a joined folder, a folder command with --server says how to join one there", async () => {
174+ const outside = temp("outside");
175+ for (const argv of [["status"], ["issue", "new", "A title"], ["ask", "bob", "Why?"], ["news"]]) {
176+ const r = await run(outside, [...argv, "--server", home.url]);
177+ assert.equal(r.exit, 1);
178+ assert.match(r.stderr, new RegExp(`abso join <project> --server ${home.url}`));
179+ }
180+ assert.equal(calls(), 0);
181+ });
183+ it("an explicit --server takes issues to that server's own Issues Worker, past ABSO_ISSUES_SERVER", async () => {
184+ const root = folder();
185+ const elsewhere = { ABSO_ISSUES_SERVER: issuesElsewhere.url };
186+ clear();
187+ await run(root, ["issue", "1"], elsewhere);
188+ assert.ok(issuesElsewhere.paths.length > 0, "without --server, ABSO_ISSUES_SERVER names the Issues Worker");
189+ assert.ok(home.paths.every((p) => !p.startsWith("/issues/")));
190+ clear();
191+ await run(root, ["issue", "1", "--server", home.url], elsewhere);
192+ assert.equal(issuesElsewhere.paths.length, 0, "--server isn't redirected");
193+ assert.ok(home.paths.length > 0);
194+ assert.ok(
195+ home.paths.some((p) => p.startsWith("/issues/p/demo/")),
196+ `the open server keeps issues at /issues/p/<project>: ${home.paths}`,
197+ );
198+ });
200+ it("a command that picks its server uses the one named, even in a folder on another", async () => {
201+ const root = folder(other.url);
202+ for (const argv of [["whoami"], ["box"], ["logout"]]) {
203+ const r = await run(root, [...argv, "--server", home.url]);
204+ assert.match(r.stdout, new RegExp(home.url.replace(/\./g, "\\.")), argv.join(" "));
205+ }
206+ clear();
207+ const doctor = await run(root, ["doctor", "--server", home.url]);
208+ assert.match(doctor.stdout, new RegExp(`${home.url.replace(/\./g, "\\.")} answered 500`));
209+ assert.equal(other.paths.filter((p) => p === "/version").length, 0, "doctor didn't swap in the folder's server");
210+ });
212+ it("counts two spellings of one server as the same, and different ports or paths as different", () => {
213+ assert.ok(sameServer("https://API.abso.dev/", "https://api.abso.dev"));
214+ assert.ok(!sameServer("http://127.0.0.1:8787", "http://127.0.0.1:8788"));
215+ assert.ok(!sameServer("http://127.0.0.1:8787", "http://localhost:8787"));
216+ assert.ok(!sameServer("https://x.example/a", "https://x.example/b"));
217+ });
218+});
MCP
compare on this site's /mcp
CLI
abso diff 154 155 client/test/server-flag.test.ts --json
JSON
/christopher/abso-core/compare/154..155?file=client%2Ftest%2Fserver-flag.test.ts&format=json