Versions 116 to 318
new file, 267 lines
2+// - every command is sorted: one that works on this machine only takes no --server and says so; every other one
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+// - 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).
11+
21+import { chooseServer, PROD_SERVER, SERVER_ORDER, sameServer, serverHelp, serverUse } from "../src/server-choice.ts";
22+
25+
31+
32+/** A server that notes each path it is asked for and answers 500, so a command stops after its first call. */
43+
50+
55+
64+
69+
75+
78+
82+
86+
88+ it("sorts every command: local ones take no --server, every other one does, and help says so alike", async () => {
100+ assert.ok(help.stdout.includes(` ${serverHelp(name)}\n`), `abso ${name} --help names --server`);
105+ for (const c of data.commands.filter((c) => c.name in table)) assert.equal(c.server, serverHelp(c.name), c.name);
109+
118+ assert.match(r.stderr, /works on this machine only and talks to no server, so it takes no --server/);
123+
124+ it("refuses a missing, empty or malformed value before anything is sent, in every family", async () => {
144+ assert.match(empty.stderr, /--server needs a server's URL, like https:\/\/api\.abso\.dev/, argv.join(" "));
145+ for (const bad of ["api.abso.dev", "ftp://api.abso.dev", "https://me@api.abso.dev", "https://x.example/?a=1"]) {
148+ assert.match(r.stderr, /--server takes an http or https URL with no user name, query or fragment/);
153+
154+ it("in a joined folder, reaches the folder's own server and refuses another without sending anything", async () => {
156+ for (const argv of [["status"], ["log"], ["issues"], ["issue", "1"], ["news"], ["waiting"], ["ci"]]) {
158+ const same = await run(root, [...argv, "--server", `${home.url.toUpperCase().replace("HTTP", "http")}/`]);
168+ `this folder is joined on ${home.url}, not ${other.url}, so abso ${argv[0]} won't send its work or key there`,
174+
175+ it("outside a joined folder, a folder command with --server says how to join one there", async () => {
177+ for (const argv of [["status"], ["issue", "new", "A title"], ["ask", "bob", "Why?"], ["news"]]) {
184+
185+ it("an explicit --server takes issues to that server's own Issues Worker, past ABSO_ISSUES_SERVER", async () => {
190+ assert.ok(issuesElsewhere.paths.length > 0, "without --server, ABSO_ISSUES_SERVER names the Issues Worker");
201+
202+ it("a command that picks its server uses the one named, even in a folder on another", async () => {
211+ assert.equal(other.paths.filter((p) => p === "/version").length, 0, "doctor didn't swap in the folder's server");
213+
214+ it("counts two spellings of one server as the same, and different ports or paths as different", () => {
221+
224+
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");
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");
241+
245+ "--server <url>, else the server of the abso folder you're in, else ABSO_SERVER, else prod (https://api.abso.dev)",
247+ for (const name of ["join", "init", "login", "whoami", "doctor", "box", "logout", "orgs", "org"])
251+
252+ it("a joined folder's commands go to its server with nothing named, and ABSO_SERVER doesn't move them", async () => {
259+
260+ it("whoami in a joined folder looks at the folder's server, and another named there is used as given", async () => {
- MCP
- compare on this site's /mcp
- CLI
- abso diff 116 318 client/test/server-flag.test.ts --json
- JSON
- /christopher/abso-core/compare/116..318?file=client%2Ftest%2Fserver-flag.test.ts&format=json