10 files, 465 lines added, 26 removed.
--- a/client/src/api.ts
+++ b/client/src/api.ts
@@ -174,7 +174,7 @@
175175 // Which client made the call (#29); the mods send theirs too. 176176 "x-abso-client": `abso-cli/${clientVersion()}`, 177− ...(this.config.token ? { authorization: `Bearer ${this.config.token}` } : {}),
177+ ...(this.config.token && !this.config.visitor ? { authorization: `Bearer ${this.config.token}` } : {}), 178178 ...(contentType ? { "content-type": contentType } : {}), @@ -187,6 +187,9 @@
189189 let res: Response | undefined; 190+ // A visitor folder only reads, and follows no redirect, so nothing it sends goes anywhere it didn't name. 191+ const visitor = this.config.visitor === true; 192+ if (visitor && method !== "GET") throw new ApiError(`${path}: a folder that reads signed out sends only reads`); 190193 const sent = body === undefined ? undefined : JSON.stringify(body); 191194 const timeoutMs = Math.max(atLeastMs, timeoutFor(this.timeoutMs, sent)); 192195 // A connection that never opened is tried once more, IPv4 first (#37, GAME - UI/UX: one IPv6 @@ -198,6 +201,7 @@
199202 headers: this.headers(sent === undefined ? undefined : "application/json"), 200203 ...(sent === undefined ? {} : { body: sent }), 204+ ...(visitor ? { redirect: "error" as const, credentials: "omit" as const } : {}), 201205 signal: AbortSignal.timeout(timeoutMs), --- a/client/src/changes.ts
+++ b/client/src/changes.ts
@@ -29,10 +29,10 @@
2929import { applyMode, PLAIN, readKnownModes, writeKnownModes } from "./modes.ts"; 3030import { refusedText, screenAnswer } from "./safety.ts"; 32−/** The space to read: --draft (where "shared" means shared), else the one this agent is in. */
32+/** The space to read: --draft (where "shared" means shared), else the one this agent is in (shared, in a folder with no agent). */ 3333function space(args: Parsed, agent: string): Where { 3434 const named = str(args, "draft"); 35− if (named === undefined) return { agent };
35+ if (named === undefined) return agent === "" ? { draft: null } : { agent }; 3636 return { draft: named === "shared" ? null : named }; --- a/client/src/config.ts
+++ b/client/src/config.ts
@@ -21,6 +21,11 @@
2121 readonly follow?: string; 2222 /** A reader folder (abso join --reader, #37): it reads everything and records nothing; the server refuses its records too. */ 2323 readonly reader?: boolean; 25+ * A visitor folder (abso join <project> --reader with no sign-in, for a public project): it reads through the 26+ * routes anyone can read and sends no credential. It has no agent; its config holds server, project and this. 28+ readonly visitor?: boolean; 2631export interface Config extends Settings { @@ -44,6 +49,13 @@
4550export function readConfig(root: string, env: Readonly<Record<string, string | undefined>> = process.env): Config { 4651 const raw = JSON.parse(readFileSync(configPath(root), "utf8")) as Partial<Settings>; 52+ if (raw.visitor === true) { 53+ for (const key of ["server", "project"] as const) { 54+ if (typeof raw[key] !== "string" || raw[key] === "") throw new Error(`${configPath(root)} has no "${key}"`); 56+ // No token and no key, whatever the environment or the folder holds: a visitor sends no credential. 57+ return { server: raw.server!, project: raw.project!, agent: "", visitor: true }; 4759 for (const key of ["server", "project", "agent"] as const) { 4860 if (typeof raw[key] !== "string" || raw[key] === "") throw new Error(`${configPath(root)} has no "${key}"`); @@ -58,6 +70,15 @@
73+/** Whether the folder is a visitor's: it reads signed out and sends no credential. Read straight from its config. */ 74+export function isVisitor(root: string): boolean { 76+ return (JSON.parse(readFileSync(configPath(root), "utf8")) as { visitor?: unknown }).visitor === true; 6182/** Whether the folder is a reader (#37): records nothing. Read straight from its config, for the paths that only need this. */ 6283export function isReader(root: string): boolean { @@ -205,11 +226,11 @@
206227export function writeConfig(root: string, settings: Settings): void { 207228 mkdirSync(stateDir(root), { recursive: true }); 208− const { server, project, agent, follow, reader } = settings;
209− writeFileSync(
210− configPath(root),
211− `${JSON.stringify({ server, project, agent, ...(follow ? { follow } : {}), ...(reader ? { reader: true } : {}) }, null, 2)}\n`,
212− );
229+ const { server, project, agent, follow, reader, visitor } = settings; 230+ const written = visitor 231+ ? { server, project, visitor: true } 232+ : { server, project, agent, ...(follow ? { follow } : {}), ...(reader ? { reader: true } : {}) }; 233+ writeFileSync(configPath(root), `${JSON.stringify(written, null, 2)}\n`); 213234 excludeFromGit(root); --- a/client/src/hook.ts
+++ b/client/src/hook.ts
@@ -16,7 +16,7 @@
1616import { homedir } from "node:os"; 1717import { dirname, isAbsolute, join, resolve } from "node:path"; 1818import { Api, type News, newsLines } from "./api.ts"; 19−import { findRoot, isReader, readConfig } from "./config.ts";
19+import { findRoot, isReader, isVisitor, readConfig } from "./config.ts"; 2020import { editBody, newsContext, normalize, spellingText, uncomposedText } from "./core.ts"; 2121import { fromEnv } from "./env-names.ts"; 2222import { forgetKnown, isPaused, loadIgnore, logNews, readKnown, readText, relativeTo, writeKnown } from "./folder.ts"; @@ -91,6 +91,8 @@
9191 outcome = "skipped: recording is paused (abso resume)"; 9292 } else if (isReader(root)) { 9393 outcome = "skipped: this folder is a reader"; 94+ } else if (isVisitor(root)) { 95+ outcome = "skipped: this folder reads signed out"; 9496 } else if (rel === undefined || loadIgnore(root)(rel, false)) { 9597 outcome = "skipped: ignored path"; 9698 } else if (readKnownModes(root).get(rel)?.link != null) { --- a/client/src/join-commands.ts
+++ b/client/src/join-commands.ts
@@ -128,21 +128,54 @@
128128const SITE_OWNER = "christopher"; 131− * Why a join failed signed out. The client reads only as an agent, which needs a
132− * sign-in; a public project is read signed out on the website. Whether the
133− * project is public is asked of the server with no credentials.
131+ * Whether anyone can read the project: its status answers with no credentials. Only the answer's code 132+ * counts, never its body, and no redirect is followed. A private project and a missing one look the same. 135−async function signedOut(server: string, project: string): Promise<string> {
136− let open = false;
134+export async function isPublic(server: string, project: string): Promise<boolean> { 138− const response = await fetch(new URL(`/p/${project}/status`, server), { signal: AbortSignal.timeout(3000) });
139− open = response.ok;
140− } catch {}
141− return open
142− ? `${project} is public: read it at ${siteOf(server)}/${SITE_OWNER}/${project} (every page is also JSON). The client needs a sign-in, even to read: abso login.`
136+ const response = await fetch(new URL(`/p/${encodeURIComponent(project)}/status`, server), { 138+ credentials: "omit", 139+ signal: AbortSignal.timeout(3000), 141+ return response.status === 200; 148+ * Why a join failed signed out. Without --reader, the client reads only as an agent, which needs a 149+ * sign-in; a public project is read signed out on the website, or with abso join --reader. 151+async function signedOut(server: string, project: string): Promise<string> { 152+ return (await isPublic(server, project)) 153+ ? `${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.` 143154 : `This box isn't signed in to ${server}. abso login signs it in.`; 157+/** A folder that reads a public project signed out: no agent, no key, no copy of the files. */ 158+async function joinAsVisitor(root: string, server: string, project: string, env: Env): Promise<Output> { 159+ writeConfig(root, { server, project, agent: "", visitor: true }); 160+ const api = new Api(readConfig(root, env.env)); 161+ let version: number; 163+ version = (await api.status()).version; 165+ rmSync(stateDir(root), { recursive: true, force: true }); 170+ `Joined ${project} to read it signed out, at version ${version}, in ${root}. Nothing is sent with a sign-in, and nothing here is recorded.`, 171+ `This folder holds no copy of the files: abso files lists them, abso show ${version}:<file> prints one, and status, log, blame, why, where, issues, issue and search read the rest.`, 172+ `To work on ${project}: abso login, then abso join ${project} in a new folder.`, 173+ ...(root === resolve(env.cwd) ? [] : [`cd ${relative(env.cwd, root) || root}`]), 175+ json: { project, visitor: true, version, root }, 146179export async function runJoin(args: Parsed, env: Env): Promise<Output> { 147180 if (args.positionals.length !== 1) throw new UsageError("join takes the project name: abso join <project>"); 148181 const project = args.positionals[0]!; @@ -163,7 +196,9 @@
163196 agent = agentFrom(args); 164197 minted = box && !hasKey ? await mintKey(box, project, agent) : undefined; 166− // No --agent: the box's name, or the next free -2, -3.
199+ // No --agent: the box's name, or the next free -2, -3. Not signed in, --reader reads a public project signed out. 200+ if (!box && reader && !hasKey && (await isPublic(server, project))) 201+ return joinAsVisitor(root, server, project, env); 168203 throw new UsageError( 169204 `${await signedOut(server, project)} (A folder that already has a key joins with --agent <name>.)`, --- a/client/src/main.ts
+++ b/client/src/main.ts
@@ -37,7 +37,7 @@
3939} from "./commands.ts"; 40−import { configPath, findRoot, installKey, readConfig, readToken } from "./config.ts";
40+import { configPath, findRoot, installKey, isVisitor, readConfig, readToken } from "./config.ts"; 4141import { newsBlockLines, newsShown, TOKEN_SERVERS } from "./core.ts"; 4242import { checkServer, doctor, doctorText, plainError, realProbe, whoami } from "./doctor.ts"; 4343import { runDraftSync, runLand, runSwitch } from "./drafts.ts"; @@ -53,6 +53,7 @@
5353import { colorsPass, terminalText } from "./terminal-text.ts"; 5454import { runAmend, runDrop, runFollow, runLabel, runLabels, runPluck } from "./versions.ts"; 5555import { runVisibility } from "./visibility-commands.ts"; 56+import { checkVisitor } from "./visitor.ts"; 5758interface CommandDef { 5859 readonly flags: FlagSpec; @@ -291,7 +292,7 @@
291292 flags: { server: "string", agent: "string", dir: "string", reader: "boolean" }, 292293 usage: "abso join <project> [--agent <name>] [--dir <folder>] [--server <url>] [--reader]", 294− "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 publishes.",
295+ "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 publishes. 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.", @@ -913,6 +914,9 @@
913914 const files = bodyFilesHelp(command, def.flags); 914915 return { stdout: `${def.usage}\n ${def.about}\n${files ? ` ${files}\n` : ""}`, stderr: "", exit: EXIT.ok }; 917+ // A folder that reads signed out runs its reads and nothing else, refused before any call. 918+ const root = findRoot(env.cwd); 919+ if (root !== undefined && isVisitor(root)) checkVisitor(command, parsed, readConfig(root, env.env).project); 916920 const args = readBodyFiles(command, parsed, env.cwd, env.readStdin); 917921 takeNews(); // what an earlier call in this process left (tests run many) 918922 const out = await def.run(args, env); --- a/client/src/status-commands.ts
+++ b/client/src/status-commands.ts
@@ -280,6 +280,17 @@
281281export async function runStatus(args: Parsed, env: Env): Promise<Output> { 282282 const { root, config, api } = open(env); 283+ if (config.visitor) { 284+ // A folder that reads signed out: shared's version and whether it's green. It holds no files to compare. 285+ const status = await api.status(); 288+ `Project ${config.project}: shared is at version ${status.version}. This folder reads it signed out, sending no sign-in: status, log, show, files, blame, why, where, issues, issue and search work here. To work on it: abso login, then abso join ${config.project} in a new folder.`, 289+ ...ciText(status.ci ?? undefined, status.version), 291+ json: { project: config.project, version: status.version, visitor: true, ci: status.ci ?? null }, 283294 const short = bool(args, "short"); 284295 const { files: view, ...status } = short ? { ...(await api.status()), files: undefined } : await api.statusAndFiles(); 285296 const clean = CleanFiles.load(root); --- /dev/null
+++ b/client/src/visitor.ts
@@ -0,0 +1,44 @@
1+// A visitor folder: abso join <project> --reader with no sign-in, for a public project. It reads the 2+// project through the routes anyone can read, and sends no credential, whatever the environment holds 3+// (config.ts reads no token for it, and Api sends none and follows no redirect). Which commands it runs 4+// is a list of reads: anything not on it is refused here, before any call, so a new command stays 5+// refused until someone adds it. The server refuses writes from it too; this is so the refusal is plain. 7+import { type Parsed, UsageError } from "./args.ts"; 9+/** The commands a visitor folder runs, each with the flags it takes there. */ 10+export const VISITOR_READS: Readonly<Record<string, readonly string[]>> = { 12+ log: ["limit", "before", "draft", "since", "by", "count"], 14+ files: ["draft", "version"], 15+ blame: ["from", "to", "version", "draft"], 18+ issues: ["open", "status", "agent", "parent", "label", "labels"], 23+/** Commands about this box, not the folder: they work from anywhere, a visitor folder too. */ 24+export const VISITOR_ELSEWHERE: readonly string[] = ["login", "logout"]; 26+/** Flags every command takes. */ 27+const EVERY = new Set(["json", "help"]); 29+export function visitorRefusal(project: string): string { 30+ return `This folder reads ${project} signed out. To work on it: abso login, then abso join ${project} in a new folder.`; 33+/** Refuses, before any call, a command or a flag a visitor folder doesn't run. */ 34+export function checkVisitor(command: string, args: Parsed, project: string): void { 35+ if (VISITOR_ELSEWHERE.includes(command)) return; 36+ const flags = VISITOR_READS[command]; 37+ if (flags === undefined) throw new UsageError(visitorRefusal(project)); 38+ for (const name of args.flags.keys()) 39+ if (!EVERY.has(name) && !flags.includes(name)) 40+ throw new UsageError(`${visitorRefusal(project)} Here, ${command} reads only; --${name} isn't one of its reads.`); 41+ // abso issue new and abso issue draft write: here, issue takes only a number. 42+ if (command === "issue" && !(args.positionals.length === 1 && /^#?\d+$/.test(args.positionals[0]!))) 43+ throw new UsageError(`${visitorRefusal(project)} Here, issue reads one issue: abso issue <N>.`); --- a/client/test/join-signed-out.test.ts
+++ b/client/test/join-signed-out.test.ts
@@ -1,7 +1,7 @@
11// A join with no sign-in says abso login signs the box in. For a public project 2−// it also says where the website shows it, since the client needs a sign-in
3−// even to read. The client runs as its own process with an empty home, so no
4−// sign-in or token on this machine is found.
2+// it also says where the website shows it, and that --reader reads it here 3+// (visitor.test.ts has that folder). The client runs as its own process with an 4+// empty home, so no sign-in or token on this machine is found. 66import assert from "node:assert/strict"; 77import { execFile } from "node:child_process"; @@ -65,7 +65,7 @@
6565 assert.notEqual(run.code, 0); 68− /abso-core is public: read it at http:\/\/127\.0\.0\.1:\d+\/christopher\/abso-core \(every page is also JSON\)\. The client needs a sign-in, even to read: abso login\./,
68+ /abso-core is public: read it at http:\/\/127\.0\.0\.1:\d+\/christopher\/abso-core \(every page is also JSON\), or here with abso join abso-core --reader\. To work on it: abso login\./, --- /dev/null
+++ b/client/test/visitor.test.ts
@@ -0,0 +1,318 @@
1+// A visitor folder: abso join <project> --reader with no sign-in, for a public project. It reads 2+// through the routes anyone can read and sends no credential. The rules, each a test: 3+// - no Authorization header and no cookie go out, with a token in the environment and a box sign-in 4+// present, and no redirect is followed; 5+// - join answers a private project and a missing one alike, by the status answer's code alone; 6+// - the commands it runs are an allow-list, and a new command fails this test until it's sorted; 7+// - its config comes from the command line only, never from an answer; 8+// - what comes back goes through the terminal filter, a 429's text too; 9+// - show prints a file and writes nothing, even for a path outside the folder. 11+import assert from "node:assert/strict"; 12+import { execFile } from "node:child_process"; 13+import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync } from "node:fs"; 14+import { createServer, type IncomingHttpHeaders, type Server } from "node:http"; 15+import type { AddressInfo } from "node:net"; 16+import { tmpdir } from "node:os"; 17+import { join, resolve } from "node:path"; 18+import { after, before, describe, it } from "node:test"; 19+import { writeBox } from "../src/box.ts"; 20+import { writeConfig } from "../src/config.ts"; 21+import { isPublic } from "../src/join-commands.ts"; 22+import { commandTable, main } from "../src/main.ts"; 23+import { VISITOR_ELSEWHERE, VISITOR_READS } from "../src/visitor.ts"; 25+const CLIENT = resolve(import.meta.dirname, "..", "abso.ts"); 27+const TOKEN = "abso_test-token-never-sent"; 28+const CREDENTIAL = "abso_bx_test-credential-never-sent"; 30+/** Every command a visitor folder refuses. A new command fails the allow-list test until it's here or a read. */ 90+// Where the site's redirect points: a visitor never gets here. 91+let elsewhere: Server; 92+let elsewhereUrl: string; 93+const heard: { url: string; headers: IncomingHttpHeaders }[] = []; 94+let elsewhereHeard = 0; 95+const dirs: string[] = []; 96+const temp = (name: string) => { 97+ const dir = mkdtempSync(join(tmpdir(), `abso-test-visitor-${name}-`)); 102+const json = (res: import("node:http").ServerResponse, status: number, body: unknown, headers = {}) => 103+ res.writeHead(status, { "content-type": "application/json", ...headers }).end(JSON.stringify(body)); 106+ elsewhere = createServer((_req, res) => { 108+ json(res, 200, { version: 9, agents: [] }); 110+ await new Promise<void>((done) => elsewhere.listen(0, "127.0.0.1", done)); 111+ elsewhereUrl = `http://127.0.0.1:${(elsewhere.address() as AddressInfo).port}`; 112+ site = createServer((req, res) => { 113+ heard.push({ url: req.url ?? "", headers: req.headers }); 114+ const path = new URL(req.url ?? "/", "http://x").pathname; 115+ if (path === "/p/abso-core/status") 116+ // An answer naming another server: the folder's config never takes it. 117+ return json(res, 200, { version: 3, agents: [], server: "http://answer.example" }); 118+ if (path === "/p/abso-core/file") 119+ return json(res, 200, { path: "a.txt", version: 1, text: `hi ${ESC}]52;c;aGk=\x07 there\n` }); 120+ if (path === "/p/abso-core/log") 124+ { error: `too many signed-out reads from this address: 120 a minute; sign in, or try again ${ESC}[2Jlater` }, 125+ { "Retry-After": "60" }, 127+ if (path === "/p/abso-core/where") 128+ return res.writeHead(302, { location: `${elsewhereUrl}/p/abso-core/where` }).end(); 129+ // A private project answers 401 with a body that looks like a status: only the code counts. 130+ if (path === "/p/private/status") return json(res, 401, { version: 1, agents: [] }); 131+ if (path === "/p/forbidden/status") return json(res, 403, { error: "members only" }); 132+ if (path === "/p/missing/status") return json(res, 404, { error: "no such project" }); 133+ json(res, 401, { error: "sign in" }); 135+ await new Promise<void>((done) => site.listen(0, "127.0.0.1", done)); 136+ url = `http://127.0.0.1:${(site.address() as AddressInfo).port}`; 141+ for (const dir of dirs) rmSync(dir, { recursive: true, force: true }); 144+/** Runs the client as its own process, in `cwd`, with `home` as its home and only the environment given. */ 149+ extra: Record<string, string> = {}, 150+): Promise<{ code: number; stdout: string; stderr: string }> { 151+ const env: Record<string, string> = { 152+ PATH: process.env.PATH ?? "", 155+ AVCS_SERVERS_FILE: "no-servers.json", 156+ ABSO_ISSUES_SERVER: url, 159+ if (process.env.SystemRoot) env.SystemRoot = process.env.SystemRoot; 160+ return new Promise((done) => { 161+ execFile(process.execPath, [CLIENT, ...args], { cwd, env }, (error, stdout, stderr) => 162+ done({ code: typeof error?.code === "number" ? error.code : 0, stdout, stderr }), 167+/** A visitor folder made by abso join, signed out, and the home it was made in. */ 168+async function joined(): Promise<{ root: string; home: string; out: string }> { 169+ const home = temp("home"); 170+ // In a parent of its own, so a test can tell nothing was written beside it. 171+ const root = join(temp("parent"), "folder"); 173+ const run = await client(root, home, ["join", "abso-core", "--reader", "--server", url]); 174+ assert.equal(run.code, 0, run.stderr); 175+ return { root, home, out: run.stdout }; 178+describe("a visitor folder", () => { 179+ it("join --reader, signed out, to a public project writes only its config, from the command line", async () => { 180+ const { root, out } = await joined(); 181+ assert.match(out, /Joined abso-core to read it signed out, at version 3/); 182+ assert.deepEqual(readdirSync(root), [".abso"]); 183+ assert.deepEqual(readdirSync(join(root, ".abso")), ["config.json"]); 184+ // The status answer named another server; the config keeps the one typed. 185+ assert.deepEqual(JSON.parse(readFileSync(join(root, ".abso", "config.json"), "utf8")), { 187+ project: "abso-core", 192+ it("sends no Authorization and no cookie, with a token set and a box sign-in present, and follows no redirect", async () => { 193+ const { root, home } = await joined(); 198+ credential: CREDENTIAL, 199+ grant: { projects: [{ project: "abso-core", role: "writer" }], max_agents: 3 }, 200+ expiresAt: Date.now() + 86_400_000, 204+ const tokens = { ABSO_TOKEN: TOKEN, AVCS_TOKEN: TOKEN }; 207+ assert.equal((await client(root, home, ["status"], tokens)).code, 0); 208+ assert.equal((await client(root, home, ["show", "1:a.txt"], tokens)).code, 0); 209+ const where = await client(root, home, ["where"], tokens); 210+ assert.notEqual(where.code, 0); 211+ assert.ok(heard.length >= 3); 212+ for (const { headers } of heard) { 213+ assert.equal(headers.authorization, undefined); 214+ assert.equal(headers.cookie, undefined); 215+ assert.doesNotMatch(JSON.stringify(headers), /never-sent/); 217+ assert.equal(elsewhereHeard, 0); 220+ it("asks fetch for no redirect and no credentials, join's public check too (a fetch spy)", async () => { 221+ const root = temp("spy"); 222+ writeConfig(root, { server: url, project: "abso-core", agent: "", visitor: true }); 223+ const real = globalThis.fetch; 224+ const calls: RequestInit[] = []; 225+ globalThis.fetch = (async (_input: unknown, init?: RequestInit) => { 226+ calls.push(init ?? {}); 227+ return new Response(JSON.stringify({ version: 3, agents: [] }), { status: 200 }); 230+ const out = await main(["status"], { cwd: root, env: { ABSO_TOKEN: TOKEN }, write: () => {} }); 231+ assert.equal(out.exit, 0, out.stderr); 232+ assert.equal(await isPublic(url, "abso-core"), true); 234+ globalThis.fetch = real; 236+ assert.equal(calls.length, 2); 237+ for (const init of calls) { 238+ assert.equal(init.redirect, "error"); 239+ assert.equal(init.credentials, "omit"); 240+ const headers = new Headers(init.headers); 241+ assert.equal(headers.get("authorization"), null); 242+ assert.equal(headers.get("cookie"), null); 246+ it("join answers a private project, a members-only one and a missing one alike, by the code alone", async () => { 248+ for (const project of ["private", "forbidden", "missing"]) { 249+ const root = temp("closed"); 250+ runs.push({ root, ...(await client(root, temp("home"), ["join", project, "--reader", "--server", url])) }); 252+ for (const run of runs) { 253+ assert.equal(run.code, runs[0]!.code); 254+ assert.notEqual(run.code, 0); 255+ assert.equal(run.stderr, runs[0]!.stderr); 256+ assert.equal(existsSync(join(run.root, ".abso")), false); 258+ assert.match(runs[0]!.stderr, /isn't signed in to .*abso login signs it in/); 261+ it("runs only its reads: every other command is refused before any call, and a new command fails here", async () => { 262+ const sorted = new Set([...Object.keys(VISITOR_READS), ...VISITOR_ELSEWHERE, ...REFUSED]); 263+ for (const name of Object.keys(commandTable())) 266+ `abso ${name} is new: add it to VISITOR_READS if it only reads, else to REFUSED here`, 268+ const root = temp("refuse"); 269+ writeConfig(root, { server: url, project: "abso-core", agent: "", visitor: true }); 270+ const real = globalThis.fetch; 272+ globalThis.fetch = (async () => { 274+ return new Response("{}", { status: 200 }); 278+ ...REFUSED.map((c) => [c]), 279+ ["issue", "new", "a title"], 280+ ["issue", "3", "--comment", "hi"], 281+ ["issues", "--drafts"], 282+ ["blame", "a.txt", "--mine"], 284+ for (const argv of tries) { 285+ const out = await main(argv, { cwd: root, env: { ABSO_TOKEN: TOKEN }, write: () => {} }); 286+ assert.notEqual(out.exit, 0, argv.join(" ")); 287+ assert.match(out.stderr, /This folder reads abso-core signed out\. To work on it: abso login/, argv.join(" ")); 290+ globalThis.fetch = real; 292+ assert.equal(calls, 0); 295+ it("prints what comes back through the terminal filter, a 429's text too", async () => { 296+ const { root, home } = await joined(); 297+ const show = await client(root, home, ["show", "1:a.txt"]); 298+ assert.equal(show.code, 0, show.stderr); 299+ assert.doesNotMatch(show.stdout, /\x1b/); 300+ assert.match(show.stdout, /hi \\x1b\]52;c;aGk=\\x07 there/); 301+ const log = await client(root, home, ["log"]); 302+ assert.notEqual(log.code, 0); 303+ assert.doesNotMatch(log.stderr + log.stdout, /\x1b/); 304+ assert.match(log.stderr, /too many signed-out reads from this address/); 307+ it("show prints a file and writes nothing, even for a path outside the folder", async () => { 308+ const { root, home } = await joined(); 309+ const parent = resolve(root, ".."); 310+ const before = { here: readdirSync(root).sort(), above: readdirSync(parent).sort() }; 311+ await client(root, home, ["show", "1:a.txt"]); 312+ const outside = await client(root, home, ["show", "1:../x"]); 313+ assert.notEqual(outside.code, 0); 314+ assert.deepEqual(readdirSync(root).sort(), before.here); 315+ assert.deepEqual(readdirSync(parent).sort(), before.above); 316+ assert.equal(existsSync(join(parent, "x")), false);