{"draft":null,"from":155,"to":156,"files":[{"path":"client/test/server-flag.test.ts","added":51,"removed":2,"diff":"--- a/client/test/server-flag.test.ts\n+++ b/client/test/server-flag.test.ts\n@@ -5,7 +5,9 @@\n // - in a joined folder, --server naming the folder's own server reaches it; another server is refused, never\n //   swapped in, and nothing is sent; outside a joined folder a folder command with --server is refused too;\n // - an explicit --server goes to that server's own Issues Worker, which ABSO_ISSUES_SERVER doesn't redirect;\n-// - a command that picks its server (whoami, box, logout) uses the one named, even inside a folder on another.\n+// - a command that picks its server (whoami, box, logout) uses the one named, even inside a folder on another;\n+// - with nothing named (abso-core issue 9) the server is the joined folder's, else ABSO_SERVER, else prod, whatever\n+//   this box is signed in to (doctor.test.ts has whoami with staging alone and with staging and prod both).\n \n import assert from \"node:assert/strict\";\n import { mkdtempSync, rmSync, writeFileSync } from \"node:fs\";\n@@ -16,7 +18,7 @@\n import { after, before, describe, it } from \"node:test\";\n import { writeConfig } from \"../src/config.ts\";\n import { commandTable, main } from \"../src/main.ts\";\n-import { sameServer, serverHelp, serverUse } from \"../src/server-choice.ts\";\n+import { chooseServer, PROD_SERVER, SERVER_ORDER, sameServer, serverHelp, serverUse } from \"../src/server-choice.ts\";\n \n /** A made-up token: the tests never read the real ~/.abso/token. */\n const TOKEN = \"abso_test-token-for-server-flag\";\n@@ -216,3 +218,50 @@\n \t\tassert.ok(!sameServer(\"https://x.example/a\", \"https://x.example/b\"));\n \t});\n });\n+\n+describe(\"the server when nothing names one\", () => {\n+\tconst STAGING = \"https://staging.abso.example\";\n+\n+\tit(\"is --server, else the joined folder's, else ABSO_SERVER, else prod\", () => {\n+\t\tconst outside = temp(\"outside\");\n+\t\tconst staging = folder(STAGING);\n+\t\tassert.equal(PROD_SERVER, \"https://api.abso.dev\");\n+\t\tassert.equal(chooseServer(undefined, outside, {}), PROD_SERVER, \"nothing named: prod\");\n+\t\tassert.equal(chooseServer(undefined, outside, { ABSO_SERVER: STAGING }), STAGING, \"the environment\");\n+\t\tassert.equal(chooseServer(undefined, outside, { AVCS_SERVER: STAGING }), STAGING, \"its older name\");\n+\t\tassert.equal(chooseServer(undefined, staging, {}), STAGING, \"a joined staging folder\");\n+\t\tassert.equal(chooseServer(undefined, staging, { ABSO_SERVER: \"https://env.example\" }), STAGING, \"folder first\");\n+\t\tassert.equal(chooseServer(PROD_SERVER, staging, { ABSO_SERVER: STAGING }), PROD_SERVER, \"explicit prod\");\n+\t\tassert.equal(chooseServer(STAGING, outside, {}), STAGING, \"explicit staging\");\n+\t\tassert.throws(\n+\t\t\t() => chooseServer(undefined, outside, { ABSO_SERVER: \"staging\" }),\n+\t\t\t/ABSO_SERVER takes an http or https URL/,\n+\t\t);\n+\t});\n+\n+\tit(\"help names the order once for every command that picks its server\", async () => {\n+\t\tassert.equal(\n+\t\t\tSERVER_ORDER,\n+\t\t\t\"--server <url>, else the server of the abso folder you're in, else ABSO_SERVER, else prod (https://api.abso.dev)\",\n+\t\t);\n+\t\tfor (const name of [\"join\", \"init\", \"login\", \"whoami\", \"doctor\", \"box\", \"logout\", \"orgs\", \"org\"])\n+\t\t\tassert.ok(serverHelp(name)?.includes(SERVER_ORDER), name);\n+\t\tassert.ok((await run(process.cwd(), [\"help\"])).stdout.includes(SERVER_ORDER));\n+\t});\n+\n+\tit(\"a joined folder's commands go to its server with nothing named, and ABSO_SERVER doesn't move them\", async () => {\n+\t\tconst root = folder();\n+\t\tclear();\n+\t\tawait run(root, [\"status\"], { ABSO_SERVER: other.url });\n+\t\tassert.ok(home.paths.length > 0);\n+\t\tassert.equal(other.paths.length, 0);\n+\t});\n+\n+\tit(\"whoami in a joined folder looks at the folder's server, and another named there is used as given\", async () => {\n+\t\tconst root = folder();\n+\t\tconst here = await run(root, [\"whoami\"], { ABSO_SERVER: other.url });\n+\t\tassert.ok(here.stdout.includes(`isn't signed in to ${home.url}`), here.stdout);\n+\t\tconst named = await run(root, [\"box\", \"--server\", other.url]);\n+\t\tassert.ok(named.stdout.includes(`isn't signed in to ${other.url}`), named.stdout);\n+\t});\n+});"}],"unmatched":[]}