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 156 --json
JSON
/christopher/abso-core/versions/156?format=json

With nothing naming a server, the client now uses prod (https://api.abso.dev). Every command picks its server in one order: --server, else the joined folder's own server, else ABSO_SERVER, else prod. Which servers this box is signed in to no longer picks one, so a box signed in to staging and prod both, or to staging alone, goes to prod instead of refusing or quietly using staging; staging is a deliberate --server, a joined staging folder, or ABSO_SERVER. An explicit choice is used as given. A malformed ABSO_SERVER is refused like a malformed --server. When this box isn't signed in to the chosen server but is to others, whoami and join name them and how to pick one. Help states the order for every command that picks its server. For abso-core issue 9.

of shared·speed··Not checked

Version 155 · Files at version 156

8 files, 151 lines added, 99 removed.

--- a/client/src/doctor.ts
+++ b/client/src/doctor.ts
@@ -3,12 +3,10 @@
33// when one fails. Neither prints a credential. plainError words the commonest failures the same way.
44
55import { ApiError } from "./api-error.ts";
6−import { UsageError } from "./args.ts";
76import { type Answer, type BoxRecord, boxGet, boxText, originOf, readBox, signedInServers } from "./box.ts";
87import { builtCopy } from "./client-version.ts";
98import { type Config, credentialLabel, findRoot, readConfig } from "./config.ts";
10−import { TOKEN_SERVERS } from "./core.ts";
11−import { fromEnv } from "./env-names.ts";
9+import { sameServer } from "./server-choice.ts";
1210
1311/** The lowest Node major each kind of copy runs on: the npm package is built for 20, a checkout runs its .ts as is. */
1412export function nodeNeeded(built: boolean): number {
@@ -43,25 +41,13 @@
4341}
4442
4543/**
46− * The server whoami and doctor look at, in the order join picks one: --server, then ABSO_SERVER, then this
47− * folder's server, then the one this box signed in to with abso login, then https://api.abso.dev. A box signed
48− * in to more than one server has to say which.
44+ * The servers other than `server` this box is signed in to, as one sentence for a refusal or a report to end
45+ * with, naming how to use one: a box signed in elsewhere is never used for `server` by itself.
4946 */
50−export function checkServer(
51− flag: string | undefined,
52− cwd: string,
53− env: Readonly<Record<string, string | undefined>>,
54− home?: string,
55− now = Date.now(),
56−): string {
57− const named = flag ?? fromEnv(env, "SERVER");
58− if (named) return named;
59− const folder = folderOf(cwd, env)?.config?.server;
60− if (folder) return folder;
61− const signedIn = signedInServers(home, now);
62− if (signedIn.length > 1)
63− throw new UsageError(`this box is signed in to ${signedIn.join(" and ")}: say which with --server <url>`);
64− return signedIn[0] ?? TOKEN_SERVERS[0]!;
47+export function elsewhereText(server: string, command: string, home?: string, now = Date.now()): string {
48+ const others = signedInServers(home, now).filter((s) => !sameServer(s, originOf(server)));
49+ if (others.length === 0) return "";
50+ return ` This box is signed in to ${others.join(" and ")}: ${command} --server <url> uses ${others.length === 1 ? "it" : "one"}.`;
6551}
6652
6753const day = (ms: number) => new Date(ms).toISOString().slice(0, 16).replace("T", " ");
@@ -102,7 +88,9 @@
10288 const record = readBox(server, probe.home);
10389 let box: Record<string, unknown> | null = null;
10490 if (!record) {
105− lines.push(`This box isn't signed in to ${originOf(server)}. Run abso login.`);
91+ lines.push(
92+ `This box isn't signed in to ${originOf(server)}. Run abso login.${elsewhereText(server, "abso whoami", probe.home, probe.now)}`,
93+ );
10694 } else {
10795 const answer = await serverBox(record, probe);
10896 const [first, ...rest] = boxText(record, server, probe.now).split("\n");
@@ -155,7 +143,6 @@
155143 cwd: string,
156144 env: Readonly<Record<string, string | undefined>>,
157145 probe: Probe,
158− explicit = false,
159146): Promise<Check[]> {
160147 const checks: Check[] = [];
161148 const need = nodeNeeded(probe.built);
@@ -171,8 +158,8 @@
171158 );
172159
173160 const folder = folderOf(cwd, env);
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);
161+ // Chosen as every command chooses (server-choice.ts): --server, else the folder's own, else ABSO_SERVER, else prod.
162+ const target = server;
176163 const origin = originOf(target);
177164 let reachable = false;
178165 const started = Date.now();
--- a/client/src/join-commands.ts
+++ b/client/src/join-commands.ts
@@ -5,13 +5,13 @@
55import { Api, ApiError } from "./api.ts";
66import { bool, type Parsed, str, UsageError } from "./args.ts";
77import { writeKnownBlobs } from "./blobs.ts";
8−import { defaultAgentName, mintFreeName, mintKey, readBox, signedInServers } from "./box.ts";
8+import { defaultAgentName, mintFreeName, mintKey, readBox } from "./box.ts";
99import { STARTING_ABSOIGNORE } from "./check-ignore.ts";
1010import { CLIENT_DIR } from "./client-version.ts";
1111import { type Env, type Output, plural } from "./command-env.ts";
1212import { leftOutText, syncFolder, uploadBlobs } from "./commands.ts";
1313import { findRoot, installKey, readConfig, type Settings, tokenFor, writeConfig } from "./config.ts";
14−import { TOKEN_SERVERS } from "./core.ts";
14+import { elsewhereText } from "./doctor.ts";
1515import { fromEnv } from "./env-names.ts";
1616import { clearKnown, loadIgnore, readFolder, writeKnown } from "./folder.ts";
1717import { modInstalled } from "./install.ts";
@@ -19,19 +19,12 @@
1919import { siteOf } from "./orgs.ts";
2020import { projectFileName, readProjectFile, startingProjectFileText, writeStartingProjectFile } from "./project-file.ts";
2121import { refusedText } from "./safety.ts";
22+import { chooseServer, serverFlag } from "./server-choice.ts";
2223import { OLD_STATE_DIR, STATE_DIR, stateDir } from "./state-dir.ts";
2324
24−/**
25− * The server to join or start on: --server, then ABSO_SERVER, then the server this box is signed in
26− * to (abso login wrote it), then https://api.abso.dev. A box signed in to more than one server has to say which.
27− */
28−export function serverFrom(args: Parsed, env: Pick<Env, "env">, home?: string): string {
29− const named = str(args, "server") ?? fromEnv(env.env, "SERVER");
30− if (named) return named;
31− const signedIn = signedInServers(home);
32− if (signedIn.length > 1)
33− throw new UsageError(`this box is signed in to ${signedIn.join(" and ")}: say which with --server <url>`);
34− return signedIn[0] ?? TOKEN_SERVERS[0]!;
25+/** The server to join or start on, in the order every command picks one (server-choice.ts chooseServer). */
26+export function serverFrom(args: Parsed, env: Pick<Env, "env" | "cwd">): string {
27+ return chooseServer(serverFlag(args), env.cwd, env.env);
3528}
3629
3730const NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
@@ -150,7 +143,7 @@
150143async function signedOut(server: string, project: string): Promise<string> {
151144 return (await isPublic(server, project))
152145 ? `${project} is public: read it at ${siteOf(server)}/${SITE_OWNER}/${project} (every page is also JSON), or here with abso join ${project} --reader. To work on it: abso login.`
153− : `This box isn't signed in to ${server}. abso login signs it in.`;
146+ : `This box isn't signed in to ${server}. abso login signs it in.${elsewhereText(server, `abso join ${project}`)}`;
154147}
155148
156149/** A folder that reads a public project signed out: no agent, no key, no copy of the files. */
--- a/client/src/main.ts
+++ b/client/src/main.ts
@@ -38,8 +38,8 @@
3838 takeNews,
3939} from "./commands.ts";
4040import { configPath, findRoot, installKey, isVisitor, readConfig, readToken } from "./config.ts";
41−import { newsBlockLines, newsShown, TOKEN_SERVERS } from "./core.ts";
42−import { checkServer, doctor, doctorText, plainError, realProbe, whoami } from "./doctor.ts";
41+import { newsBlockLines, newsShown } from "./core.ts";
42+import { doctor, doctorText, plainError, realProbe, whoami } from "./doctor.ts";
4343import { runDraftSync, runLand, runSwitch } from "./drafts.ts";
4444import { runExport } from "./export.ts";
4545import { runBlame, runWhere, runWho, runWhy } from "./history.ts";
@@ -49,7 +49,15 @@
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";
52+import {
53+ checkFolderServer,
54+ chooseServer,
55+ localRefusal,
56+ SERVER_ORDER,
57+ serverFlag,
58+ serverHelp,
59+ serverUse,
60+} from "./server-choice.ts";
5361import { installSkill, SKILL, skillPath } from "./skill.ts";
5462import { colorsPass, terminalText } from "./terminal-text.ts";
5563import { runAmend, runDrop, runFollow, runLabel, runLabels, runPluck } from "./versions.ts";
@@ -65,13 +73,9 @@
6573 readonly run: (args: Parsed, env: Env) => Promise<Output>;
6674}
6775
68−/** The server login, box and logout act on: --server, the folder's, or outside a folder abso.dev's (TOKEN_SERVERS[0]). */
69−export function boxServer(args: Parsed, env: Pick<Env, "cwd">): string {
70− const flag = str(args, "server");
71− if (flag) return flag;
72− const root = findRoot(env.cwd);
73− if (!root) return TOKEN_SERVERS[0]!;
74− return (JSON.parse(readFileSync(configPath(root), "utf8")) as { server: string }).server;
76+/** The server login, box, logout, orgs, org, whoami and doctor act on, in the order every command picks one (server-choice.ts). */
77+export function boxServer(args: Parsed, env: Pick<Env, "cwd" | "env">): string {
78+ return chooseServer(serverFlag(args), env.cwd, env.env);
7579}
7680
7781async function runKeyInstall(args: Parsed, env: Env): Promise<Output> {
@@ -96,7 +100,7 @@
96100 flags: { server: "string", project: "string", agent: "string", "as-is": "boolean", org: "string" },
97101 usage: "abso init [folder] --project <name> --agent <name> [--as-is] [--org <org>]",
98102 about:
99− "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.",
103+ "Create a project on the server from a folder's text files 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.",
100104 run: (args, env) => {
101105 const org = str(args, "org");
102106 return org === undefined ? runInit(args, env) : initInOrg(org, boxServer(args, env));
@@ -186,7 +190,7 @@
186190 usage:
187191 "abso login [--no-browser] [--projects <name,name>] [--role <reader|writer|owner>] [--max-agents <1-50>] [--days <1-90>]",
188192 about:
189− "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.",
193+ "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. No browser opens with --no-browser or ABSO_NO_BROWSER, over SSH, under CI, or on Linux without a display.",
190194 run: async (args, env) => {
191195 const server = boxServer(args, env);
192196 const open =
@@ -219,9 +223,9 @@
219223 flags: { server: "string" },
220224 usage: "abso whoami",
221225 about:
222− "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.",
226+ "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.",
223227 run: async (args, env) => {
224− const out = await whoami(checkServer(str(args, "server"), env.cwd, env.env), env.cwd, env.env, realProbe());
228+ const out = await whoami(boxServer(args, env), env.cwd, env.env, realProbe());
225229 return { text: out.text, json: out.json };
226230 },
227231 },
@@ -229,15 +233,9 @@
229233 flags: { server: "string" },
230234 usage: "abso doctor",
231235 about:
232− "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.",
236+ "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.",
233237 run: async (args, env) => {
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− );
238+ const checks = await doctor(boxServer(args, env), env.cwd, env.env, realProbe());
241239 const failed = checks.some((c) => c.result === "fail");
242240 return { text: doctorText(checks), json: { checks }, ...(failed ? { exit: EXIT.error } : {}) };
243241 },
@@ -308,7 +306,7 @@
308306 flags: { server: "string", agent: "string", dir: "string", reader: "boolean" },
309307 usage: "abso join <project> [--agent <name>] [--dir <folder>] [--reader]",
310308 about:
311− "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.",
309+ "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. --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.",
312310 run: runJoin,
313311 },
314312 record: {
@@ -811,7 +809,9 @@
811809const HELP_INTRO = "abso: version control for agents. This is its command-line client.";
812810const HELP_NOTE =
813811 "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.";
812+ "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. The server is " +
813+ SERVER_ORDER +
814+ ": which servers this box is signed in to plays no part.";
815815
816816/** A command's flags: its own, and --server for every command that talks to a server (server-choice.ts). */
817817function flagsOf(name: string, def: CommandDef): FlagSpec {
--- a/client/src/server-choice.ts
+++ b/client/src/server-choice.ts
@@ -8,15 +8,47 @@
88// - A command that works on this machine only ("local") takes no --server, and says so.
99// A value that isn't an http or https URL (a user name, a query or a fragment included) is refused before any
1010// call, as is an empty one.
11+//
12+// When nothing names a server (abso-core issue 9), every command picks it in one order (chooseServer):
13+// 1. --server <url>;
14+// 2. the server of the joined folder the command runs in (its .abso/config.json);
15+// 3. ABSO_SERVER (or the older AVCS_SERVER);
16+// 4. prod, https://api.abso.dev.
17+// Which servers this box is signed in to plays no part: signed in to staging and prod both, or to staging
18+// alone, a command with nothing named goes to prod, and staging is a deliberate --server, folder or ABSO_SERVER.
1119
1220import { readFileSync } from "node:fs";
1321import { type Parsed, UsageError } from "./args.ts";
1422import { configPath, findRoot } from "./config.ts";
15−import { serverBase } from "./core.ts";
23+import { serverBase, TOKEN_SERVERS } from "./core.ts";
24+import { fromEnv } from "./env-names.ts";
1625
1726/** How a command uses a server: its joined folder's, one it picks, or none. */
1827export type ServerUse = "folder" | "chosen" | "local";
1928
29+/** The server a command goes to when nothing names one: prod. */
30+export const PROD_SERVER = TOKEN_SERVERS[0]!;
32+/** The order of precedence, in the words help uses. */
33+export const SERVER_ORDER = `--server <url>, else the server of the abso folder you're in, else ABSO_SERVER, else prod (${PROD_SERVER})`;
35+/**
36+ * The server a command goes to: `flag` (checked by serverFlag), else the joined folder's, else ABSO_SERVER
37+ * (checked here), else prod. An explicit choice is returned as given, never swapped for another.
38+ */
39+export function chooseServer(
40+ flag: string | undefined,
41+ cwd: string,
42+ env: Readonly<Record<string, string | undefined>>,
43+): string {
44+ if (flag !== undefined) return flag;
45+ const folder = folderServer(cwd);
46+ if (folder !== undefined) return folder;
47+ const named = fromEnv(env, "SERVER");
48+ if (named !== undefined) return checkedServer(named, env.ABSO_SERVER ? "ABSO_SERVER" : "AVCS_SERVER");
49+ return PROD_SERVER;
50+}
2052/** The commands that pick a server for themselves rather than use a joined folder's. */
2153const CHOSEN: ReadonlySet<string> = new Set([
2254 "init",
@@ -101,7 +133,7 @@
101133 case "chosen":
102134 return command === "key"
103135 ? "--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.";
136+ : `--server <url>: the server to use, as given, never swapped for another. The order: ${SERVER_ORDER}. This box's sign-in for one server is never sent to another.`;
105137 }
106138}
107139
--- a/client/test/box.test.ts
+++ b/client/test/box.test.ts
@@ -383,27 +383,22 @@
383383 assert.equal(forgetBox(SERVER, h), false);
384384});
385385
386−test("join and init pick the server: --server, ABSO_SERVER, the box's sign-in, then api.abso.dev", () => {
386+test("join and init pick the server in the one order: --server, the folder's, ABSO_SERVER, then prod", () => {
387387 const h = home();
388+ const outside = home();
388389 const args = (server?: string) => ({ positionals: [], flags: new Map(server ? [["server", server]] : []) });
389− const none = { env: {} };
390− assert.equal(serverFrom(args(), none, h), "https://api.abso.dev", "nothing signed in: the abso API");
390+ const none = { env: {}, cwd: outside };
391+ assert.equal(serverFrom(args(), none), "https://api.abso.dev", "nothing named: prod");
391392 writeBox({ ...record, expiresAt: Date.now() + 1e6 }, h);
392393 assert.deepEqual(signedInServers(h), [SERVER]);
393− assert.equal(serverFrom(args(), none, h), SERVER, "the server abso login signed this box in to");
394+ assert.equal(serverFrom(args(), none), "https://api.abso.dev", "a sign-in elsewhere doesn't pick the server");
394395 assert.deepEqual(signedInServers(h, Date.now() + 2e6), [], "an expired sign-in doesn't count");
395− assert.equal(serverFrom(args(), { env: { ABSO_SERVER: "https://env.example" } }, h), "https://env.example");
396+ assert.equal(serverFrom(args(), { ...none, env: { ABSO_SERVER: "https://env.example" } }), "https://env.example");
396397 assert.equal(
397− serverFrom(args("https://flag.example"), { env: { ABSO_SERVER: "https://env.example" } }, h),
398+ serverFrom(args("https://flag.example"), { ...none, env: { ABSO_SERVER: "https://env.example" } }),
398399 "https://flag.example",
399400 );
400− writeBox({ ...record, server: "https://other.abso.example", expiresAt: Date.now() + 1e6 }, h);
401− writeBox({ ...record, expiresAt: Date.now() + 1e6 }, h);
402− assert.throws(
403− () => serverFrom(args(), none, h),
404− /signed in to https:\/\/other\.abso\.example and https:\/\/staging\.abso\.example: say which with --server/,
405− );
406− assert.equal(serverFrom(args(SERVER), none, h), SERVER, "--server settles it");
401+ assert.equal(serverFrom(args(SERVER), none), SERVER, "--server is used as given");
407402});
408403
409404test("join with no --agent takes the box's name, skips names this box holds, and moves past a taken one", async () => {
--- a/client/test/client.test.ts
+++ b/client/test/client.test.ts
@@ -2846,9 +2846,12 @@
28462846 it("abso login, box and logout outside a folder act on https://api.abso.dev", () => {
28472847 const outside = mkdtempSync(join(tmpdir(), "abso-login-"));
28482848 try {
2849− assert.equal(boxServer(parseArgs("login", [], { server: "string" }), { cwd: outside }), "https://api.abso.dev");
2849+ assert.equal(
2850+ boxServer(parseArgs("login", [], { server: "string" }), { cwd: outside, env: {} }),
2851+ "https://api.abso.dev",
2852+ );
28502853 const given = parseArgs("login", ["--server", "https://example.test"], { server: "string" });
2851− assert.equal(boxServer(given, { cwd: outside }), "https://example.test");
2854+ assert.equal(boxServer(given, { cwd: outside, env: {} }), "https://example.test");
28522855 } finally {
28532856 rmSync(outside, { recursive: true, force: true });
28542857 }
--- a/client/test/doctor.test.ts
+++ b/client/test/doctor.test.ts
@@ -8,7 +8,7 @@
88import { test } from "node:test";
99import { ApiError } from "../src/api-error.ts";
1010import { writeBox } from "../src/box.ts";
11−import { checkServer, doctor, doctorText, nodeNeeded, type Probe, plainError, whoami } from "../src/doctor.ts";
11+import { doctor, doctorText, nodeNeeded, type Probe, plainError, whoami } from "../src/doctor.ts";
1212
1313const SERVER = "https://staging.abso.example";
1414const CREDENTIAL = "abso_bx_the-secret-credential";
@@ -228,25 +228,18 @@
228228 assert.equal(plainError(new Error("anything else"), true), undefined);
229229});
230230
231−test("whoami and doctor pick the server as join does: --server, ABSO_SERVER, the folder's, the box's sign-in, then abso.dev", () => {
231+test("whoami with nothing named shows prod, and names the other servers this box is signed in to", async () => {
232232 const outside = temp("outside");
233− const empty = temp("home");
234− assert.equal(checkServer(undefined, outside, {}, empty, NOW), "https://api.abso.dev");
235233 const home = temp("home");
236234 writeBox(box(), home);
237− assert.equal(checkServer(undefined, outside, {}, home, NOW), SERVER);
238− assert.equal(checkServer(undefined, folder(), {}, empty, NOW), SERVER);
239− assert.equal(checkServer(undefined, outside, { ABSO_SERVER: "http://env.example" }, home, NOW), "http://env.example");
240− assert.equal(
241− checkServer("http://flag.example", folder(), { ABSO_SERVER: "http://env.example" }, home, NOW),
242− "http://flag.example",
235+ const fetcher = server({ "/box": [200, { revoked_at: null }] });
236+ const prod = await whoami("https://api.abso.dev", outside, {}, probe(fetcher, home));
237+ assert.match(
238+ prod.text,
239+ /This box isn't signed in to https:\/\/api\.abso\.dev\. Run abso login\. This box is signed in to https:\/\/staging\.abso\.example: abso whoami --server <url> uses it\./,
243240 );
244− const expired = temp("home");
245− writeBox(box(NOW - 1), expired);
246− assert.equal(checkServer(undefined, outside, {}, expired, NOW), "https://api.abso.dev");
247241 writeBox({ ...box(), server: "https://api.abso.dev" }, home);
248− assert.throws(
249− () => checkServer(undefined, outside, {}, home, NOW),
250− /signed in to .* and .*: say which with --server/,
251− );
242+ const both = await whoami("https://api.abso.dev", outside, {}, probe(fetcher, home));
243+ assert.match(both.text, /Signed in to https:\/\/api\.abso\.dev as box b_0123abcd/);
244+ assert.equal(both.json.server, "https://api.abso.dev");
252245});
--- a/client/test/server-flag.test.ts
+++ b/client/test/server-flag.test.ts
@@ -5,7 +5,9 @@
55// - in a joined folder, --server naming the folder's own server reaches it; another server is refused, never
66// swapped in, and nothing is sent; outside a joined folder a folder command with --server is refused too;
77// - 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.
8+// - a command that picks its server (whoami, box, logout) uses the one named, even inside a folder on another;
9+// - with nothing named (abso-core issue 9) the server is the joined folder's, else ABSO_SERVER, else prod, whatever
10+// this box is signed in to (doctor.test.ts has whoami with staging alone and with staging and prod both).
1012import assert from "node:assert/strict";
1113import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
@@ -16,7 +18,7 @@
1618import { after, before, describe, it } from "node:test";
1719import { writeConfig } from "../src/config.ts";
1820import { commandTable, main } from "../src/main.ts";
19−import { sameServer, serverHelp, serverUse } from "../src/server-choice.ts";
21+import { chooseServer, PROD_SERVER, SERVER_ORDER, sameServer, serverHelp, serverUse } from "../src/server-choice.ts";
2022
2123/** A made-up token: the tests never read the real ~/.abso/token. */
2224const TOKEN = "abso_test-token-for-server-flag";
@@ -216,3 +218,50 @@
216218 assert.ok(!sameServer("https://x.example/a", "https://x.example/b"));
217219 });
218220});
222+describe("the server when nothing names one", () => {
223+ const STAGING = "https://staging.abso.example";
225+ it("is --server, else the joined folder's, else ABSO_SERVER, else prod", () => {
226+ const outside = temp("outside");
227+ const staging = folder(STAGING);
228+ assert.equal(PROD_SERVER, "https://api.abso.dev");
229+ assert.equal(chooseServer(undefined, outside, {}), PROD_SERVER, "nothing named: prod");
230+ assert.equal(chooseServer(undefined, outside, { ABSO_SERVER: STAGING }), STAGING, "the environment");
231+ assert.equal(chooseServer(undefined, outside, { AVCS_SERVER: STAGING }), STAGING, "its older name");
232+ assert.equal(chooseServer(undefined, staging, {}), STAGING, "a joined staging folder");
233+ assert.equal(chooseServer(undefined, staging, { ABSO_SERVER: "https://env.example" }), STAGING, "folder first");
234+ assert.equal(chooseServer(PROD_SERVER, staging, { ABSO_SERVER: STAGING }), PROD_SERVER, "explicit prod");
235+ assert.equal(chooseServer(STAGING, outside, {}), STAGING, "explicit staging");
236+ assert.throws(
237+ () => chooseServer(undefined, outside, { ABSO_SERVER: "staging" }),
238+ /ABSO_SERVER takes an http or https URL/,
239+ );
240+ });
242+ it("help names the order once for every command that picks its server", async () => {
243+ assert.equal(
244+ SERVER_ORDER,
245+ "--server <url>, else the server of the abso folder you're in, else ABSO_SERVER, else prod (https://api.abso.dev)",
246+ );
247+ for (const name of ["join", "init", "login", "whoami", "doctor", "box", "logout", "orgs", "org"])
248+ assert.ok(serverHelp(name)?.includes(SERVER_ORDER), name);
249+ assert.ok((await run(process.cwd(), ["help"])).stdout.includes(SERVER_ORDER));
250+ });
252+ it("a joined folder's commands go to its server with nothing named, and ABSO_SERVER doesn't move them", async () => {
253+ const root = folder();
254+ clear();
255+ await run(root, ["status"], { ABSO_SERVER: other.url });
256+ assert.ok(home.paths.length > 0);
257+ assert.equal(other.paths.length, 0);
258+ });
260+ it("whoami in a joined folder looks at the folder's server, and another named there is used as given", async () => {
261+ const root = folder();
262+ const here = await run(root, ["whoami"], { ABSO_SERVER: other.url });
263+ assert.ok(here.stdout.includes(`isn't signed in to ${home.url}`), here.stdout);
264+ const named = await run(root, ["box", "--server", other.url]);
265+ assert.ok(named.stdout.includes(`isn't signed in to ${other.url}`), named.stdout);
266+ });
267+});