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
MCP
show on this site's /mcp
CLI
abso show 155 --json
JSON
/christopher/abso-core/versions/155?format=json

Every command that talks to a server now takes --server <url>, parsed and checked in one place (client/src/server-choice.ts). A missing, empty or malformed value is refused before anything is sent. In a joined folder, --server must be the folder's own server: another one is refused rather than swapped in, so a folder's work and key go only to the server it was joined on. Commands that pick their own server (join, init, login, whoami, doctor, box, logout, orgs, org, key) use the named one as given; doctor no longer swaps in the folder's server over an explicit one, and an explicit --server takes issues to that server's own Issues Worker instead of ABSO_ISSUES_SERVER. The five local-only commands refuse --server and say why. Help shows the same --server line for every command of a kind. For abso-core issue 10.

of shared·speed··Not checked

Version 154 · Files at version 155

7 files, 393 lines added, 22 removed.

--- a/client/src/command-env.ts
+++ b/client/src/command-env.ts
@@ -25,6 +25,11 @@
2525 readonly runKind?: RunKind;
2626 /** What a -file flag of - reads: stdin, unless a test gives it. */
2727 readonly readStdin?: () => string;
28+ /**
29+ * The server --server named, checked (server-choice.ts), when the command was given one. It is used as given,
30+ * so no environment setting redirects it (ABSO_ISSUES_SERVER included).
31+ */
32+ readonly server?: string;
2833}
2934
3035export function plural(n: number, word: string): string {
--- a/client/src/doctor.ts
+++ b/client/src/doctor.ts
@@ -155,6 +155,7 @@
155155 cwd: string,
156156 env: Readonly<Record<string, string | undefined>>,
157157 probe: Probe,
158+ explicit = false,
158159): Promise<Check[]> {
159160 const checks: Check[] = [];
160161 const need = nodeNeeded(probe.built);
@@ -170,8 +171,8 @@
170171 );
171172
172173 const folder = folderOf(cwd, env);
173− // The folder's own server when there is one: it's the one its commands talk to.
174− const target = folder?.config?.server ?? server;
174+ // The folder's own server when there is one (it's the one its commands talk to), unless --server named one.
175+ const target = explicit ? server : (folder?.config?.server ?? server);
175176 const origin = originOf(target);
176177 let reachable = false;
177178 const started = Date.now();
--- a/client/src/issues.ts
+++ b/client/src/issues.ts
@@ -36,7 +36,10 @@
3636/** The folder, with its Api pointed at the Issues Worker: the token goes only where tokenGoesTo allows, as for the avcs server. */
3737function openIssues(env: Env): { root: string; config: Config; api: Api } {
3838 const { root, config, api } = open(env);
39− const server = fromEnv(env.env, "ISSUES_SERVER") || issuesServerFor(config.server, readMachineServers(env.env));
39+ // An explicit --server goes to that server's own Issues Worker: ABSO_ISSUES_SERVER doesn't redirect it.
40+ const server =
41+ (env.server === undefined ? fromEnv(env.env, "ISSUES_SERVER") : undefined) ||
42+ issuesServerFor(config.server, readMachineServers(env.env));
4043 if (server === undefined)
4144 throw new UsageError(
4245 `${config.server} has no Issues Worker beside it that abso knows; ~/.abso/servers.json or ABSO_ISSUES_SERVER names one`,
--- a/client/src/main.ts
+++ b/client/src/main.ts
@@ -49,6 +49,7 @@
4949import { initInOrg, runOrg, runOrgs } from "./orgs.ts";
5050import { runUnqueue } from "./queue.ts";
5151import { runNote, runNotes, runReview } from "./review.ts";
52+import { checkFolderServer, localRefusal, serverFlag, serverHelp, serverUse } from "./server-choice.ts";
5253import { installSkill, SKILL, skillPath } from "./skill.ts";
5354import { colorsPass, terminalText } from "./terminal-text.ts";
5455import { runAmend, runDrop, runFollow, runLabel, runLabels, runPluck } from "./versions.ts";
@@ -93,7 +94,7 @@
9394const COMMANDS: Readonly<Record<string, CommandDef>> = {
9495 init: {
9596 flags: { server: "string", project: "string", agent: "string", "as-is": "boolean", org: "string" },
96− usage: "abso init [folder] [--server <url>] --project <name> --agent <name> [--as-is] [--org <org>]",
97+ usage: "abso init [folder] --project <name> --agent <name> [--as-is] [--org <org>]",
9798 about:
9899 "Create a project on the server from a folder's text files (the server is chosen as abso join chooses it). The folder becomes that agent's folder. It writes a starting .absoignore, and, when the folder has no avcs.json and package.json gives a check or a build to guess, an avcs.json (setup, check, build and out): what the server's CI runs on each new version of shared. Without one, CI runs what it can guess itself, or nothing. --as-is writes neither: the folder goes up exactly as it is (an import). --org <org> makes it an organization's project: for now that is done on the website, and abso says where.",
99100 run: (args, env) => {
@@ -183,7 +184,7 @@
183184 days: "string",
184185 },
185186 usage:
186− "abso login [--server <url>] [--no-browser] [--projects <name,name>] [--role <reader|writer|owner>] [--max-agents <1-50>] [--days <1-90>]",
187+ "abso login [--no-browser] [--projects <name,name>] [--role <reader|writer|owner>] [--max-agents <1-50>] [--days <1-90>]",
187188 about:
188189 "Sign this box in once: it opens the approve page in your browser with the code filled in, prints the link and the code too, and waits while a person approves the code on the website, choosing the projects, the highest role and how many agents. Then abso join in any of those projects gives each agent its own key, with no approval. The box's sign-in is kept in your user folder, never in a project folder, and is never printed. Without --server, the folder's server, or https://api.abso.dev outside a folder. No browser opens with --no-browser or ABSO_NO_BROWSER, over SSH, under CI, or on Linux without a display.",
189190 run: async (args, env) => {
@@ -205,7 +206,7 @@
205206 },
206207 box: {
207208 flags: { server: "string" },
208− usage: "abso box [--server <url>]",
209+ usage: "abso box",
209210 about:
210211 "What this box's sign-in allows: its projects, the highest role its agents may have, how many agents it has made and may make, and when it expires. Never the credential.",
211212 run: async (args, env) => {
@@ -216,7 +217,7 @@
216217 },
217218 whoami: {
218219 flags: { server: "string" },
219− usage: "abso whoami [--server <url>]",
220+ usage: "abso whoami",
220221 about:
221222 "Who and where you're signed in: this box's sign-in, as the server sees it (so a revoked one shows), its projects, roles and expiry, and this folder's project, agent and kind of key. Never a credential. The server is --server, else ABSO_SERVER, else this folder's, else the one this box signed in to with abso login, else https://api.abso.dev.",
222223 run: async (args, env) => {
@@ -226,18 +227,24 @@
226227 },
227228 doctor: {
228229 flags: { server: "string" },
229− usage: "abso doctor [--server <url>]",
230+ usage: "abso doctor",
230231 about:
231232 "Checks what commands need, one line each: Node's version, that the server answers, this box's sign-in (present, unexpired, accepted), and this folder's key against its project. A failed check says what to do next, and the exit is 1. Never prints a credential. It picks the server as whoami does.",
232233 run: async (args, env) => {
233− const checks = await doctor(checkServer(str(args, "server"), env.cwd, env.env), env.cwd, env.env, realProbe());
234+ const checks = await doctor(
235+ checkServer(str(args, "server"), env.cwd, env.env),
236+ env.cwd,
237+ env.env,
238+ realProbe(),
239+ str(args, "server") !== undefined,
240+ );
234241 const failed = checks.some((c) => c.result === "fail");
235242 return { text: doctorText(checks), json: { checks }, ...(failed ? { exit: EXIT.error } : {}) };
236243 },
237244 },
238245 logout: {
239246 flags: { server: "string" },
240− usage: "abso logout [--server <url>]",
247+ usage: "abso logout",
241248 about:
242249 "End this box's sign-in on the server and forget it here. Keys its agents already have stop working with it.",
243250 run: async (args, env) => {
@@ -255,7 +262,7 @@
255262 },
256263 orgs: {
257264 flags: { server: "string" },
258− usage: "abso orgs [--server <url>]",
265+ usage: "abso orgs",
259266 about:
260267 "Your organizations and your role in each, and invitations waiting for you. It reads as the person who approved this box's sign-in (abso login).",
261268 run: (args, env) => runOrgs(boxServer(args, env)),
@@ -299,7 +306,7 @@
299306 },
300307 join: {
301308 flags: { server: "string", agent: "string", dir: "string", reader: "boolean" },
302− usage: "abso join <project> [--agent <name>] [--dir <folder>] [--server <url>] [--reader]",
309+ usage: "abso join <project> [--agent <name>] [--dir <folder>] [--reader]",
303310 about:
304311 "Join a project as a new agent and write its shared files into a folder: --dir, else here when this folder is empty, else ./<project> (which has to be new or empty). Without --agent the agent is named after this box (the name abso login gave it, lower-cased), or the next free <name>-2, <name>-3; that needs the box signed in with abso login. The server is --server, else ABSO_SERVER, else the one this box signed in to with abso login, else https://api.abso.dev. --reader joins as a reader: it reads everything and records nothing, and the server refuses its edits, records and pushes. With --reader and no sign-in, a public project is joined to read signed out: the folder holds only its settings, sends no sign-in, and runs status, log, show, files, blame, why, where, issues, issue and search; every other command is refused.",
305312 run: runJoin,
@@ -803,12 +810,21 @@
803810
804811const HELP_INTRO = "abso: version control for agents. This is its command-line client.";
805812const HELP_NOTE =
806− "Every command takes --json. Settings live in .abso/config.json (.avcs/config.json in a folder from before the rename). The token comes from ABSO_TOKEN, or else ~/.abso/token (or ~/.avcs/token from before).";
813+ "Every command takes --json. Settings live in .abso/config.json (.avcs/config.json in a folder from before the rename). The token comes from ABSO_TOKEN, or else ~/.abso/token (or ~/.avcs/token from before). " +
814+ "Every command that talks to a server takes --server <url>; one that works only on this machine (skill, check-ignore, pause, resume, fix-eol) doesn't. In a joined folder --server must be the folder's own server: another is refused, never swapped in. An explicit --server is used as given, and no setting redirects it.";
807815
816+/** A command's flags: its own, and --server for every command that talks to a server (server-choice.ts). */
817+function flagsOf(name: string, def: CommandDef): FlagSpec {
818+ return serverUse(name) === "local" ? def.flags : { ...def.flags, server: "string" };
819+}
808821/** Every command as help shows it, in order: the table's, then the three it doesn't hold. */
809−function helpEntries(): { name: string; usage: string; about: string; flags: FlagSpec }[] {
822+function helpEntries(): { name: string; usage: string; about: string; flags: FlagSpec; server?: string }[] {
810823 return [
811− ...Object.entries(COMMANDS).map(([name, c]) => ({ name, usage: c.usage, about: c.about, flags: c.flags })),
824+ ...Object.entries(COMMANDS).map(([name, c]) => {
825+ const server = serverHelp(name);
826+ return { name, usage: c.usage, about: c.about, flags: flagsOf(name, c), ...(server ? { server } : {}) };
827+ }),
812828 {
813829 name: "hook",
814830 usage: "abso hook",
@@ -832,7 +848,11 @@
832848}
833849
834850function help(): string {
835− const entries = helpEntries().flatMap((c) => [` ${c.usage}`, ` ${c.about}`]);
851+ const entries = helpEntries().flatMap((c) => [
852+ ` ${c.usage}`,
853+ ` ${c.about}`,
854+ ...(c.server ? [` ${c.server}`] : []),
855+ ]);
836856 return [HELP_INTRO, "", ...entries, "", HELP_NOTE].join("\n");
837857}
838858
@@ -864,7 +884,7 @@
864884export function commandTable(): Readonly<
865885 Record<string, { readonly flags: FlagSpec; readonly usage: string; readonly about: string }>
866886> {
867− return COMMANDS;
887+ return Object.fromEntries(Object.entries(COMMANDS).map(([name, c]) => [name, { ...c, flags: flagsOf(name, c) }]));
868888}
869889
870890function newsBlock(news: readonly string[]): string[] {
@@ -932,21 +952,34 @@
932952 );
933953 const gitOnly = gitOnlyForm(command, argv.slice(1));
934954 if (gitOnly) throw new UsageError(gitOnly);
935− const parsed = parseArgs(command, argv.slice(1), withBodyFiles(command, def.flags), def.rest);
955+ const use = serverUse(command);
956+ const words = argv.includes("--") ? argv.slice(1, argv.indexOf("--")) : argv.slice(1);
957+ if (use === "local" && words.some((w) => w === "--server" || w.startsWith("--server=")))
958+ throw new UsageError(localRefusal(command));
959+ const parsed = parseArgs(command, argv.slice(1), withBodyFiles(command, flagsOf(command, def)), def.rest);
936960 if ((command === "push" || command === "pull") && parsed.positionals.length > 0)
937961 throw new UsageError(
938962 `abso ${command} takes no remote or branch: it ${command === "push" ? "adds your draft to shared" : "brings shared into this folder"}. A named draft is abso switch <name>.`,
939963 );
940964 if (bool(parsed, "help")) {
941965 const files = bodyFilesHelp(command, def.flags);
942− return { stdout: `${def.usage}\n ${def.about}\n${files ? ` ${files}\n` : ""}`, stderr: "", exit: EXIT.ok };
966+ const server = serverHelp(command);
967+ return {
968+ stdout: `${def.usage}\n ${def.about}\n${server ? ` ${server}\n` : ""}${files ? ` ${files}\n` : ""}`,
969+ stderr: "",
970+ exit: EXIT.ok,
971+ };
943972 }
973+ // --server is checked before anything is read or sent: a bad value, or (for a command on a joined folder)
974+ // a server that isn't the folder's own, is refused here.
975+ const named = use === "local" ? undefined : serverFlag(parsed);
976+ if (named !== undefined && use === "folder") checkFolderServer(command, named, env.cwd);
944977 // A folder that reads signed out runs its reads and nothing else, refused before any call.
945978 const root = findRoot(env.cwd);
946979 if (root !== undefined && isVisitor(root)) checkVisitor(command, parsed, readConfig(root, env.env).project);
947980 const args = readBodyFiles(command, parsed, env.cwd, env.readStdin);
948981 takeNews(); // what an earlier call in this process left (tests run many)
949− const out = await def.run(args, env);
982+ const out = await def.run(args, named === undefined ? env : { ...env, server: named });
950983 const exit = out.exit ?? EXIT.ok;
951984 // Every command that took news while recording prints it (#37, News Report).
952985 const news = takeNews();
--- /dev/null
+++ b/client/src/server-choice.ts
@@ -0,0 +1,111 @@
1+// The --server flag (abso-core issue 10). Every command that talks to a server takes --server <url>, parsed and
2+// checked here the same way for all of them:
3+// - A command that works on a joined folder ("folder") talks only to that folder's server. --server there must
4+// name that same server; another one is refused, never swapped in, so the folder's work and key never go to
5+// a server it wasn't joined on. Outside a joined folder it is refused too, with how to join one there.
6+// - A command that picks a server for itself ("chosen": join, init, login, whoami and the rest about this box)
7+// uses the one --server names, as given.
8+// - A command that works on this machine only ("local") takes no --server, and says so.
9+// A value that isn't an http or https URL (a user name, a query or a fragment included) is refused before any
10+// call, as is an empty one.
12+import { readFileSync } from "node:fs";
13+import { type Parsed, UsageError } from "./args.ts";
14+import { configPath, findRoot } from "./config.ts";
15+import { serverBase } from "./core.ts";
17+/** How a command uses a server: its joined folder's, one it picks, or none. */
18+export type ServerUse = "folder" | "chosen" | "local";
20+/** The commands that pick a server for themselves rather than use a joined folder's. */
21+const CHOSEN: ReadonlySet<string> = new Set([
22+ "init",
23+ "join",
24+ "key",
25+ "login",
26+ "box",
27+ "whoami",
28+ "doctor",
29+ "logout",
30+ "orgs",
31+ "org",
32+]);
34+/** The commands that never talk to a server. */
35+const LOCAL: ReadonlySet<string> = new Set(["skill", "check-ignore", "pause", "resume", "fix-eol"]);
37+/** How `command` uses a server. Anything not named above works on a joined folder. */
38+export function serverUse(command: string): ServerUse {
39+ return CHOSEN.has(command) ? "chosen" : LOCAL.has(command) ? "local" : "folder";
40+}
42+const EXAMPLE = "https://api.abso.dev";
44+/** `value` as a server, or a refusal naming where it came from (--server, ABSO_SERVER). */
45+export function checkedServer(value: string, from: string): string {
46+ const v = value.trim();
47+ if (v === "") throw new UsageError(`${from} needs a server's URL, like ${EXAMPLE}`);
48+ if (serverBase(v) === undefined)
49+ throw new UsageError(
50+ `${from} takes an http or https URL with no user name, query or fragment, like ${EXAMPLE} (got ${JSON.stringify(value)})`,
51+ );
52+ return v;
53+}
55+/** The server --server names, checked, or undefined when it isn't given. */
56+export function serverFlag(args: Parsed): string | undefined {
57+ const v = args.flags.get("server");
58+ return typeof v === "string" ? checkedServer(v, "--server") : undefined;
59+}
61+/** Whether two servers are the same one: the same scheme, host, port and path, ignoring case and a trailing slash. */
62+export function sameServer(a: string, b: string): boolean {
63+ return (serverBase(a) ?? a.trim()) === (serverBase(b) ?? b.trim());
64+}
66+/** The server in the .abso/config.json of the folder `cwd` is in, or undefined outside one (or when it can't be read). */
67+export function folderServer(cwd: string): string | undefined {
68+ const root = findRoot(cwd);
69+ if (root === undefined) return undefined;
70+ try {
71+ const server = (JSON.parse(readFileSync(configPath(root), "utf8")) as { server?: unknown }).server;
72+ return typeof server === "string" && server !== "" ? server : undefined;
73+ } catch {
74+ return undefined;
75+ }
76+}
78+/**
79+ * For a command that works on a joined folder: refuses a --server that isn't the folder's own server, and one
80+ * given outside a joined folder. Nothing is sent before this.
81+ */
82+export function checkFolderServer(command: string, flag: string, cwd: string): void {
83+ const own = folderServer(cwd);
84+ if (own === undefined)
85+ throw new UsageError(
86+ `abso ${command} works on a joined folder, and ${cwd} isn't in one. To work with ${flag}: abso join <project> --server ${flag}, or abso init --server ${flag} for a new project.`,
87+ );
88+ if (!sameServer(own, flag))
89+ throw new UsageError(
90+ `this folder is joined on ${own}, not ${flag}, so abso ${command} won't send its work or key there. Run it in a folder joined on ${flag} (abso join <project> --server ${flag}).`,
91+ );
92+}
94+/** What help says about --server for a command, the same words for every command of a kind. */
95+export function serverHelp(command: string): string | undefined {
96+ switch (serverUse(command)) {
97+ case "local":
98+ return undefined;
99+ case "folder":
100+ return "--server <url>: this folder's own server, which it uses anyway. Another server is refused, never swapped in, so the folder's work and key go only to the server it was joined on.";
101+ case "chosen":
102+ return command === "key"
103+ ? "--server <url>: the server the key is for; without it, this folder's. It is used as given, never swapped for another."
104+ : "--server <url>: the server to use, as given, never swapped for another. Each server gets only its own sign-in.";
105+ }
106+}
108+/** The refusal for --server on a command that works on this machine only. */
109+export function localRefusal(command: string): string {
110+ return `abso ${command} works on this machine only and talks to no server, so it takes no --server`;
111+}
--- a/client/src/visitor.ts
+++ b/client/src/visitor.ts
@@ -23,8 +23,8 @@
2323/** Commands about this box, not the folder: they work from anywhere, a visitor folder too. */
2424export const VISITOR_ELSEWHERE: readonly string[] = ["login", "logout"];
2525
26−/** Flags every command takes. */
27−const EVERY = new Set(["json", "help"]);
26+/** Flags every command takes (--server is checked against the folder's own server before this, in main.ts). */
27+const EVERY = new Set(["json", "help", "server"]);
2828
2929export function visitorRefusal(project: string): string {
3030 return `This folder reads ${project} signed out. To work on it: abso login, then abso join ${project} in a new folder.`;
--- /dev/null
+++ b/client/test/server-flag.test.ts
@@ -0,0 +1,218 @@
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+});