{"version":86,"agent":"pinch","message":"Read a public project signed out: abso join <project> --reader with no sign-in makes a folder that reads it. The folder holds only its settings (server, project, visitor), sends no sign-in whatever the environment or the box holds, follows no redirect, and runs status, log, show, files, blame, why, where, issues, issue and search; every other command is refused before any call, from an allow-list a new command has to join. join answers a private project and a missing one alike, by the status answer's code alone. Tests in client/test/visitor.test.ts.","time":1791616980022,"timeIso":"2026-10-10T07:23:00.022Z","changes":11,"change":889,"files":["client/src/api.ts","client/src/changes.ts","client/src/config.ts","client/src/hook.ts","client/src/join-commands.ts","client/src/main.ts","client/src/status-commands.ts","client/src/visitor.ts","client/test/join-signed-out.test.ts","client/test/visitor.test.ts"],"draft":null,"diff":[{"path":"client/src/api.ts","added":5,"removed":1,"diff":"--- a/client/src/api.ts\n+++ b/client/src/api.ts\n@@ -174,7 +174,7 @@\n \t\treturn {\n \t\t\t// Which client made the call (#29); the mods send theirs too.\n \t\t\t\"x-abso-client\": `abso-cli/${clientVersion()}`,\n-\t\t\t...(this.config.token ? { authorization: `Bearer ${this.config.token}` } : {}),\n+\t\t\t...(this.config.token && !this.config.visitor ? { authorization: `Bearer ${this.config.token}` } : {}),\n \t\t\t...(contentType ? { \"content-type\": contentType } : {}),\n \t\t};\n \t}\n@@ -187,6 +187,9 @@\n \t\tatLeastMs = 0,\n \t): Promise<T> {\n \t\tlet res: Response | undefined;\n+\t\t// A visitor folder only reads, and follows no redirect, so nothing it sends goes anywhere it didn't name.\n+\t\tconst visitor = this.config.visitor === true;\n+\t\tif (visitor && method !== \"GET\") throw new ApiError(`${path}: a folder that reads signed out sends only reads`);\n \t\tconst sent = body === undefined ? undefined : JSON.stringify(body);\n \t\tconst timeoutMs = Math.max(atLeastMs, timeoutFor(this.timeoutMs, sent));\n \t\t// A connection that never opened is tried once more, IPv4 first (#37, GAME - UI/UX: one IPv6\n@@ -198,6 +201,7 @@\n \t\t\t\t\tmethod,\n \t\t\t\t\theaders: this.headers(sent === undefined ? undefined : \"application/json\"),\n \t\t\t\t\t...(sent === undefined ? {} : { body: sent }),\n+\t\t\t\t\t...(visitor ? { redirect: \"error\" as const, credentials: \"omit\" as const } : {}),\n \t\t\t\t\tsignal: AbortSignal.timeout(timeoutMs),\n \t\t\t\t});\n \t\t\t} catch (err) {"},{"path":"client/src/changes.ts","added":2,"removed":2,"diff":"--- a/client/src/changes.ts\n+++ b/client/src/changes.ts\n@@ -29,10 +29,10 @@\n import { applyMode, PLAIN, readKnownModes, writeKnownModes } from \"./modes.ts\";\n import { refusedText, screenAnswer } from \"./safety.ts\";\n \n-/** The space to read: --draft (where \"shared\" means shared), else the one this agent is in. */\n+/** The space to read: --draft (where \"shared\" means shared), else the one this agent is in (shared, in a folder with no agent). */\n function space(args: Parsed, agent: string): Where {\n \tconst named = str(args, \"draft\");\n-\tif (named === undefined) return { agent };\n+\tif (named === undefined) return agent === \"\" ? { draft: null } : { agent };\n \treturn { draft: named === \"shared\" ? null : named };\n }\n "},{"path":"client/src/config.ts","added":26,"removed":5,"diff":"--- a/client/src/config.ts\n+++ b/client/src/config.ts\n@@ -21,6 +21,11 @@\n \treadonly follow?: string;\n \t/** A reader folder (abso join --reader, #37): it reads everything and records nothing; the server refuses its records too. */\n \treadonly reader?: boolean;\n+\t/**\n+\t * A visitor folder (abso join <project> --reader with no sign-in, for a public project): it reads through the\n+\t * routes anyone can read and sends no credential. It has no agent; its config holds server, project and this.\n+\t */\n+\treadonly visitor?: boolean;\n }\n \n export interface Config extends Settings {\n@@ -44,6 +49,13 @@\n \n export function readConfig(root: string, env: Readonly<Record<string, string | undefined>> = process.env): Config {\n \tconst raw = JSON.parse(readFileSync(configPath(root), \"utf8\")) as Partial<Settings>;\n+\tif (raw.visitor === true) {\n+\t\tfor (const key of [\"server\", \"project\"] as const) {\n+\t\t\tif (typeof raw[key] !== \"string\" || raw[key] === \"\") throw new Error(`${configPath(root)} has no \"${key}\"`);\n+\t\t}\n+\t\t// No token and no key, whatever the environment or the folder holds: a visitor sends no credential.\n+\t\treturn { server: raw.server!, project: raw.project!, agent: \"\", visitor: true };\n+\t}\n \tfor (const key of [\"server\", \"project\", \"agent\"] as const) {\n \t\tif (typeof raw[key] !== \"string\" || raw[key] === \"\") throw new Error(`${configPath(root)} has no \"${key}\"`);\n \t}\n@@ -58,6 +70,15 @@\n \t};\n }\n \n+/** Whether the folder is a visitor's: it reads signed out and sends no credential. Read straight from its config. */\n+export function isVisitor(root: string): boolean {\n+\ttry {\n+\t\treturn (JSON.parse(readFileSync(configPath(root), \"utf8\")) as { visitor?: unknown }).visitor === true;\n+\t} catch {\n+\t\treturn false;\n+\t}\n+}\n+\n /** Whether the folder is a reader (#37): records nothing. Read straight from its config, for the paths that only need this. */\n export function isReader(root: string): boolean {\n \ttry {\n@@ -205,11 +226,11 @@\n \n export function writeConfig(root: string, settings: Settings): void {\n \tmkdirSync(stateDir(root), { recursive: true });\n-\tconst { server, project, agent, follow, reader } = settings;\n-\twriteFileSync(\n-\t\tconfigPath(root),\n-\t\t`${JSON.stringify({ server, project, agent, ...(follow ? { follow } : {}), ...(reader ? { reader: true } : {}) }, null, 2)}\\n`,\n-\t);\n+\tconst { server, project, agent, follow, reader, visitor } = settings;\n+\tconst written = visitor\n+\t\t? { server, project, visitor: true }\n+\t\t: { server, project, agent, ...(follow ? { follow } : {}), ...(reader ? { reader: true } : {}) };\n+\twriteFileSync(configPath(root), `${JSON.stringify(written, null, 2)}\\n`);\n \texcludeFromGit(root);\n }\n "},{"path":"client/src/hook.ts","added":3,"removed":1,"diff":"--- a/client/src/hook.ts\n+++ b/client/src/hook.ts\n@@ -16,7 +16,7 @@\n import { homedir } from \"node:os\";\n import { dirname, isAbsolute, join, resolve } from \"node:path\";\n import { Api, type News, newsLines } from \"./api.ts\";\n-import { findRoot, isReader, readConfig } from \"./config.ts\";\n+import { findRoot, isReader, isVisitor, readConfig } from \"./config.ts\";\n import { editBody, newsContext, normalize, spellingText, uncomposedText } from \"./core.ts\";\n import { fromEnv } from \"./env-names.ts\";\n import { forgetKnown, isPaused, loadIgnore, logNews, readKnown, readText, relativeTo, writeKnown } from \"./folder.ts\";\n@@ -91,6 +91,8 @@\n \t\t\toutcome = \"skipped: recording is paused (abso resume)\";\n \t\t} else if (isReader(root)) {\n \t\t\toutcome = \"skipped: this folder is a reader\";\n+\t\t} else if (isVisitor(root)) {\n+\t\t\toutcome = \"skipped: this folder reads signed out\";\n \t\t} else if (rel === undefined || loadIgnore(root)(rel, false)) {\n \t\t\toutcome = \"skipped: ignored path\";\n \t\t} else if (readKnownModes(root).get(rel)?.link != null) {"},{"path":"client/src/join-commands.ts","added":46,"removed":11,"diff":"--- a/client/src/join-commands.ts\n+++ b/client/src/join-commands.ts\n@@ -128,21 +128,54 @@\n const SITE_OWNER = \"christopher\";\n \n /**\n- * Why a join failed signed out. The client reads only as an agent, which needs a\n- * sign-in; a public project is read signed out on the website. Whether the\n- * project is public is asked of the server with no credentials.\n+ * Whether anyone can read the project: its status answers with no credentials. Only the answer's code\n+ * counts, never its body, and no redirect is followed. A private project and a missing one look the same.\n  */\n-async function signedOut(server: string, project: string): Promise<string> {\n-\tlet open = false;\n+export async function isPublic(server: string, project: string): Promise<boolean> {\n \ttry {\n-\t\tconst response = await fetch(new URL(`/p/${project}/status`, server), { signal: AbortSignal.timeout(3000) });\n-\t\topen = response.ok;\n-\t} catch {}\n-\treturn open\n-\t\t? `${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.`\n+\t\tconst response = await fetch(new URL(`/p/${encodeURIComponent(project)}/status`, server), {\n+\t\t\tredirect: \"error\",\n+\t\t\tcredentials: \"omit\",\n+\t\t\tsignal: AbortSignal.timeout(3000),\n+\t\t});\n+\t\treturn response.status === 200;\n+\t} catch {\n+\t\treturn false;\n+\t}\n+}\n+\n+/**\n+ * Why a join failed signed out. Without --reader, the client reads only as an agent, which needs a\n+ * sign-in; a public project is read signed out on the website, or with abso join --reader.\n+ */\n+async function signedOut(server: string, project: string): Promise<string> {\n+\treturn (await isPublic(server, project))\n+\t\t? `${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.`\n \t\t: `This box isn't signed in to ${server}. abso login signs it in.`;\n }\n \n+/** A folder that reads a public project signed out: no agent, no key, no copy of the files. */\n+async function joinAsVisitor(root: string, server: string, project: string, env: Env): Promise<Output> {\n+\twriteConfig(root, { server, project, agent: \"\", visitor: true });\n+\tconst api = new Api(readConfig(root, env.env));\n+\tlet version: number;\n+\ttry {\n+\t\tversion = (await api.status()).version;\n+\t} catch (error) {\n+\t\trmSync(stateDir(root), { recursive: true, force: true });\n+\t\tthrow error;\n+\t}\n+\treturn {\n+\t\ttext: [\n+\t\t\t`Joined ${project} to read it signed out, at version ${version}, in ${root}. Nothing is sent with a sign-in, and nothing here is recorded.`,\n+\t\t\t`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.`,\n+\t\t\t`To work on ${project}: abso login, then abso join ${project} in a new folder.`,\n+\t\t\t...(root === resolve(env.cwd) ? [] : [`cd ${relative(env.cwd, root) || root}`]),\n+\t\t].join(\"\\n\"),\n+\t\tjson: { project, visitor: true, version, root },\n+\t};\n+}\n+\n export async function runJoin(args: Parsed, env: Env): Promise<Output> {\n \tif (args.positionals.length !== 1) throw new UsageError(\"join takes the project name: abso join <project>\");\n \tconst project = args.positionals[0]!;\n@@ -163,7 +196,9 @@\n \t\tagent = agentFrom(args);\n \t\tminted = box && !hasKey ? await mintKey(box, project, agent) : undefined;\n \t} else {\n-\t\t// No --agent: the box's name, or the next free -2, -3.\n+\t\t// No --agent: the box's name, or the next free -2, -3. Not signed in, --reader reads a public project signed out.\n+\t\tif (!box && reader && !hasKey && (await isPublic(server, project)))\n+\t\t\treturn joinAsVisitor(root, server, project, env);\n \t\tif (!box)\n \t\t\tthrow new UsageError(\n \t\t\t\t`${await signedOut(server, project)} (A folder that already has a key joins with --agent <name>.)`,"},{"path":"client/src/main.ts","added":6,"removed":2,"diff":"--- a/client/src/main.ts\n+++ b/client/src/main.ts\n@@ -37,7 +37,7 @@\n \trunSync,\n \ttakeNews,\n } from \"./commands.ts\";\n-import { configPath, findRoot, installKey, readConfig, readToken } from \"./config.ts\";\n+import { configPath, findRoot, installKey, isVisitor, readConfig, readToken } from \"./config.ts\";\n import { newsBlockLines, newsShown, TOKEN_SERVERS } from \"./core.ts\";\n import { checkServer, doctor, doctorText, plainError, realProbe, whoami } from \"./doctor.ts\";\n import { runDraftSync, runLand, runSwitch } from \"./drafts.ts\";\n@@ -53,6 +53,7 @@\n import { colorsPass, terminalText } from \"./terminal-text.ts\";\n import { runAmend, runDrop, runFollow, runLabel, runLabels, runPluck } from \"./versions.ts\";\n import { runVisibility } from \"./visibility-commands.ts\";\n+import { checkVisitor } from \"./visitor.ts\";\n \n interface CommandDef {\n \treadonly flags: FlagSpec;\n@@ -291,7 +292,7 @@\n \t\tflags: { server: \"string\", agent: \"string\", dir: \"string\", reader: \"boolean\" },\n \t\tusage: \"abso join <project> [--agent <name>] [--dir <folder>] [--server <url>] [--reader]\",\n \t\tabout:\n-\t\t\t\"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.\",\n+\t\t\t\"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.\",\n \t\trun: runJoin,\n \t},\n \trecord: {\n@@ -913,6 +914,9 @@\n \t\t\tconst files = bodyFilesHelp(command, def.flags);\n \t\t\treturn { stdout: `${def.usage}\\n  ${def.about}\\n${files ? `  ${files}\\n` : \"\"}`, stderr: \"\", exit: EXIT.ok };\n \t\t}\n+\t\t// A folder that reads signed out runs its reads and nothing else, refused before any call.\n+\t\tconst root = findRoot(env.cwd);\n+\t\tif (root !== undefined && isVisitor(root)) checkVisitor(command, parsed, readConfig(root, env.env).project);\n \t\tconst args = readBodyFiles(command, parsed, env.cwd, env.readStdin);\n \t\ttakeNews(); // what an earlier call in this process left (tests run many)\n \t\tconst out = await def.run(args, env);"},{"path":"client/src/status-commands.ts","added":11,"removed":0,"diff":"--- a/client/src/status-commands.ts\n+++ b/client/src/status-commands.ts\n@@ -280,6 +280,17 @@\n \n export async function runStatus(args: Parsed, env: Env): Promise<Output> {\n \tconst { root, config, api } = open(env);\n+\tif (config.visitor) {\n+\t\t// A folder that reads signed out: shared's version and whether it's green. It holds no files to compare.\n+\t\tconst status = await api.status();\n+\t\treturn {\n+\t\t\ttext: [\n+\t\t\t\t`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.`,\n+\t\t\t\t...ciText(status.ci ?? undefined, status.version),\n+\t\t\t].join(\"\\n\"),\n+\t\t\tjson: { project: config.project, version: status.version, visitor: true, ci: status.ci ?? null },\n+\t\t};\n+\t}\n \tconst short = bool(args, \"short\");\n \tconst { files: view, ...status } = short ? { ...(await api.status()), files: undefined } : await api.statusAndFiles();\n \tconst clean = CleanFiles.load(root);"},{"path":"client/src/visitor.ts","added":44,"removed":0,"diff":"--- /dev/null\n+++ b/client/src/visitor.ts\n@@ -0,0 +1,44 @@\n+// A visitor folder: abso join <project> --reader with no sign-in, for a public project. It reads the\n+// project through the routes anyone can read, and sends no credential, whatever the environment holds\n+// (config.ts reads no token for it, and Api sends none and follows no redirect). Which commands it runs\n+// is a list of reads: anything not on it is refused here, before any call, so a new command stays\n+// refused until someone adds it. The server refuses writes from it too; this is so the refusal is plain.\n+\n+import { type Parsed, UsageError } from \"./args.ts\";\n+\n+/** The commands a visitor folder runs, each with the flags it takes there. */\n+export const VISITOR_READS: Readonly<Record<string, readonly string[]>> = {\n+\tstatus: [],\n+\tlog: [\"limit\", \"before\", \"draft\", \"since\", \"by\", \"count\"],\n+\tshow: [\"draft\"],\n+\tfiles: [\"draft\", \"version\"],\n+\tblame: [\"from\", \"to\", \"version\", \"draft\"],\n+\twhy: [\"draft\"],\n+\twhere: [],\n+\tissues: [\"open\", \"status\", \"agent\", \"parent\", \"label\", \"labels\"],\n+\tissue: [],\n+\tsearch: [\"limit\"],\n+};\n+\n+/** Commands about this box, not the folder: they work from anywhere, a visitor folder too. */\n+export const VISITOR_ELSEWHERE: readonly string[] = [\"login\", \"logout\"];\n+\n+/** Flags every command takes. */\n+const EVERY = new Set([\"json\", \"help\"]);\n+\n+export function visitorRefusal(project: string): string {\n+\treturn `This folder reads ${project} signed out. To work on it: abso login, then abso join ${project} in a new folder.`;\n+}\n+\n+/** Refuses, before any call, a command or a flag a visitor folder doesn't run. */\n+export function checkVisitor(command: string, args: Parsed, project: string): void {\n+\tif (VISITOR_ELSEWHERE.includes(command)) return;\n+\tconst flags = VISITOR_READS[command];\n+\tif (flags === undefined) throw new UsageError(visitorRefusal(project));\n+\tfor (const name of args.flags.keys())\n+\t\tif (!EVERY.has(name) && !flags.includes(name))\n+\t\t\tthrow new UsageError(`${visitorRefusal(project)} Here, ${command} reads only; --${name} isn't one of its reads.`);\n+\t// abso issue new and abso issue draft write: here, issue takes only a number.\n+\tif (command === \"issue\" && !(args.positionals.length === 1 && /^#?\\d+$/.test(args.positionals[0]!)))\n+\t\tthrow new UsageError(`${visitorRefusal(project)} Here, issue reads one issue: abso issue <N>.`);\n+}"},{"path":"client/test/join-signed-out.test.ts","added":4,"removed":4,"diff":"--- a/client/test/join-signed-out.test.ts\n+++ b/client/test/join-signed-out.test.ts\n@@ -1,7 +1,7 @@\n // A join with no sign-in says abso login signs the box in. For a public project\n-// it also says where the website shows it, since the client needs a sign-in\n-// even to read. The client runs as its own process with an empty home, so no\n-// sign-in or token on this machine is found.\n+// it also says where the website shows it, and that --reader reads it here\n+// (visitor.test.ts has that folder). The client runs as its own process with an\n+// empty home, so no sign-in or token on this machine is found.\n \n import assert from \"node:assert/strict\";\n import { execFile } from \"node:child_process\";\n@@ -65,7 +65,7 @@\n \t\tassert.notEqual(run.code, 0);\n \t\tassert.match(\n \t\t\trun.stderr,\n-\t\t\t/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\\./,\n+\t\t\t/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\\./,\n \t\t);\n \t});\n "},{"path":"client/test/visitor.test.ts","added":318,"removed":0,"diff":"--- /dev/null\n+++ b/client/test/visitor.test.ts\n@@ -0,0 +1,318 @@\n+// A visitor folder: abso join <project> --reader with no sign-in, for a public project. It reads\n+// through the routes anyone can read and sends no credential. The rules, each a test:\n+// - no Authorization header and no cookie go out, with a token in the environment and a box sign-in\n+//   present, and no redirect is followed;\n+// - join answers a private project and a missing one alike, by the status answer's code alone;\n+// - the commands it runs are an allow-list, and a new command fails this test until it's sorted;\n+// - its config comes from the command line only, never from an answer;\n+// - what comes back goes through the terminal filter, a 429's text too;\n+// - show prints a file and writes nothing, even for a path outside the folder.\n+\n+import assert from \"node:assert/strict\";\n+import { execFile } from \"node:child_process\";\n+import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync } from \"node:fs\";\n+import { createServer, type IncomingHttpHeaders, type Server } from \"node:http\";\n+import type { AddressInfo } from \"node:net\";\n+import { tmpdir } from \"node:os\";\n+import { join, resolve } from \"node:path\";\n+import { after, before, describe, it } from \"node:test\";\n+import { writeBox } from \"../src/box.ts\";\n+import { writeConfig } from \"../src/config.ts\";\n+import { isPublic } from \"../src/join-commands.ts\";\n+import { commandTable, main } from \"../src/main.ts\";\n+import { VISITOR_ELSEWHERE, VISITOR_READS } from \"../src/visitor.ts\";\n+\n+const CLIENT = resolve(import.meta.dirname, \"..\", \"abso.ts\");\n+const ESC = \"\\x1b\";\n+const TOKEN = \"abso_test-token-never-sent\";\n+const CREDENTIAL = \"abso_bx_test-credential-never-sent\";\n+\n+/** Every command a visitor folder refuses. A new command fails the allow-list test until it's here or a read. */\n+const REFUSED = [\n+\t\"init\",\n+\t\"key\",\n+\t\"box\",\n+\t\"whoami\",\n+\t\"doctor\",\n+\t\"orgs\",\n+\t\"org\",\n+\t\"skill\",\n+\t\"join\",\n+\t\"record\",\n+\t\"publish\",\n+\t\"bisect\",\n+\t\"reader\",\n+\t\"settle\",\n+\t\"sync\",\n+\t\"run\",\n+\t\"serve\",\n+\t\"mv\",\n+\t\"review\",\n+\t\"note\",\n+\t\"notes\",\n+\t\"ask\",\n+\t\"waiting\",\n+\t\"answer\",\n+\t\"ack\",\n+\t\"reply\",\n+\t\"unqueue\",\n+\t\"visibility\",\n+\t\"ci\",\n+\t\"shot\",\n+\t\"prep\",\n+\t\"fetch\",\n+\t\"pause\",\n+\t\"resume\",\n+\t\"logs\",\n+\t\"switch\",\n+\t\"land\",\n+\t\"draft-sync\",\n+\t\"diff\",\n+\t\"restore\",\n+\t\"export\",\n+\t\"announce\",\n+\t\"start\",\n+\t\"news\",\n+\t\"fix-eol\",\n+\t\"who\",\n+\t\"drop\",\n+\t\"pluck\",\n+\t\"amend\",\n+\t\"label\",\n+\t\"labels\",\n+\t\"follow\",\n+\t\"check-ignore\",\n+\t\"pipeline\",\n+];\n+\n+let site: Server;\n+let url: string;\n+// Where the site's redirect points: a visitor never gets here.\n+let elsewhere: Server;\n+let elsewhereUrl: string;\n+const heard: { url: string; headers: IncomingHttpHeaders }[] = [];\n+let elsewhereHeard = 0;\n+const dirs: string[] = [];\n+const temp = (name: string) => {\n+\tconst dir = mkdtempSync(join(tmpdir(), `abso-test-visitor-${name}-`));\n+\tdirs.push(dir);\n+\treturn dir;\n+};\n+\n+const json = (res: import(\"node:http\").ServerResponse, status: number, body: unknown, headers = {}) =>\n+\tres.writeHead(status, { \"content-type\": \"application/json\", ...headers }).end(JSON.stringify(body));\n+\n+before(async () => {\n+\telsewhere = createServer((_req, res) => {\n+\t\telsewhereHeard++;\n+\t\tjson(res, 200, { version: 9, agents: [] });\n+\t});\n+\tawait new Promise<void>((done) => elsewhere.listen(0, \"127.0.0.1\", done));\n+\telsewhereUrl = `http://127.0.0.1:${(elsewhere.address() as AddressInfo).port}`;\n+\tsite = createServer((req, res) => {\n+\t\theard.push({ url: req.url ?? \"\", headers: req.headers });\n+\t\tconst path = new URL(req.url ?? \"/\", \"http://x\").pathname;\n+\t\tif (path === \"/p/abso-core/status\")\n+\t\t\t// An answer naming another server: the folder's config never takes it.\n+\t\t\treturn json(res, 200, { version: 3, agents: [], server: \"http://answer.example\" });\n+\t\tif (path === \"/p/abso-core/file\")\n+\t\t\treturn json(res, 200, { path: \"a.txt\", version: 1, text: `hi ${ESC}]52;c;aGk=\\x07 there\\n` });\n+\t\tif (path === \"/p/abso-core/log\")\n+\t\t\treturn json(\n+\t\t\t\tres,\n+\t\t\t\t429,\n+\t\t\t\t{ error: `too many signed-out reads from this address: 120 a minute; sign in, or try again ${ESC}[2Jlater` },\n+\t\t\t\t{ \"Retry-After\": \"60\" },\n+\t\t\t);\n+\t\tif (path === \"/p/abso-core/where\")\n+\t\t\treturn res.writeHead(302, { location: `${elsewhereUrl}/p/abso-core/where` }).end();\n+\t\t// A private project answers 401 with a body that looks like a status: only the code counts.\n+\t\tif (path === \"/p/private/status\") return json(res, 401, { version: 1, agents: [] });\n+\t\tif (path === \"/p/forbidden/status\") return json(res, 403, { error: \"members only\" });\n+\t\tif (path === \"/p/missing/status\") return json(res, 404, { error: \"no such project\" });\n+\t\tjson(res, 401, { error: \"sign in\" });\n+\t});\n+\tawait new Promise<void>((done) => site.listen(0, \"127.0.0.1\", done));\n+\turl = `http://127.0.0.1:${(site.address() as AddressInfo).port}`;\n+});\n+after(() => {\n+\tsite.close();\n+\telsewhere.close();\n+\tfor (const dir of dirs) rmSync(dir, { recursive: true, force: true });\n+});\n+\n+/** Runs the client as its own process, in `cwd`, with `home` as its home and only the environment given. */\n+function client(\n+\tcwd: string,\n+\thome: string,\n+\targs: string[],\n+\textra: Record<string, string> = {},\n+): Promise<{ code: number; stdout: string; stderr: string }> {\n+\tconst env: Record<string, string> = {\n+\t\tPATH: process.env.PATH ?? \"\",\n+\t\tHOME: home,\n+\t\tUSERPROFILE: home,\n+\t\tAVCS_SERVERS_FILE: \"no-servers.json\",\n+\t\tABSO_ISSUES_SERVER: url,\n+\t\t...extra,\n+\t};\n+\tif (process.env.SystemRoot) env.SystemRoot = process.env.SystemRoot;\n+\treturn new Promise((done) => {\n+\t\texecFile(process.execPath, [CLIENT, ...args], { cwd, env }, (error, stdout, stderr) =>\n+\t\t\tdone({ code: typeof error?.code === \"number\" ? error.code : 0, stdout, stderr }),\n+\t\t);\n+\t});\n+}\n+\n+/** A visitor folder made by abso join, signed out, and the home it was made in. */\n+async function joined(): Promise<{ root: string; home: string; out: string }> {\n+\tconst home = temp(\"home\");\n+\t// In a parent of its own, so a test can tell nothing was written beside it.\n+\tconst root = join(temp(\"parent\"), \"folder\");\n+\tmkdirSync(root);\n+\tconst run = await client(root, home, [\"join\", \"abso-core\", \"--reader\", \"--server\", url]);\n+\tassert.equal(run.code, 0, run.stderr);\n+\treturn { root, home, out: run.stdout };\n+}\n+\n+describe(\"a visitor folder\", () => {\n+\tit(\"join --reader, signed out, to a public project writes only its config, from the command line\", async () => {\n+\t\tconst { root, out } = await joined();\n+\t\tassert.match(out, /Joined abso-core to read it signed out, at version 3/);\n+\t\tassert.deepEqual(readdirSync(root), [\".abso\"]);\n+\t\tassert.deepEqual(readdirSync(join(root, \".abso\")), [\"config.json\"]);\n+\t\t// The status answer named another server; the config keeps the one typed.\n+\t\tassert.deepEqual(JSON.parse(readFileSync(join(root, \".abso\", \"config.json\"), \"utf8\")), {\n+\t\t\tserver: url,\n+\t\t\tproject: \"abso-core\",\n+\t\t\tvisitor: true,\n+\t\t});\n+\t});\n+\n+\tit(\"sends no Authorization and no cookie, with a token set and a box sign-in present, and follows no redirect\", async () => {\n+\t\tconst { root, home } = await joined();\n+\t\twriteBox(\n+\t\t\t{\n+\t\t\t\tserver: url,\n+\t\t\t\tid: \"b_0123abcd\",\n+\t\t\t\tcredential: CREDENTIAL,\n+\t\t\t\tgrant: { projects: [{ project: \"abso-core\", role: \"writer\" }], max_agents: 3 },\n+\t\t\t\texpiresAt: Date.now() + 86_400_000,\n+\t\t\t},\n+\t\t\thome,\n+\t\t);\n+\t\tconst tokens = { ABSO_TOKEN: TOKEN, AVCS_TOKEN: TOKEN };\n+\t\theard.length = 0;\n+\t\telsewhereHeard = 0;\n+\t\tassert.equal((await client(root, home, [\"status\"], tokens)).code, 0);\n+\t\tassert.equal((await client(root, home, [\"show\", \"1:a.txt\"], tokens)).code, 0);\n+\t\tconst where = await client(root, home, [\"where\"], tokens);\n+\t\tassert.notEqual(where.code, 0);\n+\t\tassert.ok(heard.length >= 3);\n+\t\tfor (const { headers } of heard) {\n+\t\t\tassert.equal(headers.authorization, undefined);\n+\t\t\tassert.equal(headers.cookie, undefined);\n+\t\t\tassert.doesNotMatch(JSON.stringify(headers), /never-sent/);\n+\t\t}\n+\t\tassert.equal(elsewhereHeard, 0);\n+\t});\n+\n+\tit(\"asks fetch for no redirect and no credentials, join's public check too (a fetch spy)\", async () => {\n+\t\tconst root = temp(\"spy\");\n+\t\twriteConfig(root, { server: url, project: \"abso-core\", agent: \"\", visitor: true });\n+\t\tconst real = globalThis.fetch;\n+\t\tconst calls: RequestInit[] = [];\n+\t\tglobalThis.fetch = (async (_input: unknown, init?: RequestInit) => {\n+\t\t\tcalls.push(init ?? {});\n+\t\t\treturn new Response(JSON.stringify({ version: 3, agents: [] }), { status: 200 });\n+\t\t}) as typeof fetch;\n+\t\ttry {\n+\t\t\tconst out = await main([\"status\"], { cwd: root, env: { ABSO_TOKEN: TOKEN }, write: () => {} });\n+\t\t\tassert.equal(out.exit, 0, out.stderr);\n+\t\t\tassert.equal(await isPublic(url, \"abso-core\"), true);\n+\t\t} finally {\n+\t\t\tglobalThis.fetch = real;\n+\t\t}\n+\t\tassert.equal(calls.length, 2);\n+\t\tfor (const init of calls) {\n+\t\t\tassert.equal(init.redirect, \"error\");\n+\t\t\tassert.equal(init.credentials, \"omit\");\n+\t\t\tconst headers = new Headers(init.headers);\n+\t\t\tassert.equal(headers.get(\"authorization\"), null);\n+\t\t\tassert.equal(headers.get(\"cookie\"), null);\n+\t\t}\n+\t});\n+\n+\tit(\"join answers a private project, a members-only one and a missing one alike, by the code alone\", async () => {\n+\t\tconst runs = [];\n+\t\tfor (const project of [\"private\", \"forbidden\", \"missing\"]) {\n+\t\t\tconst root = temp(\"closed\");\n+\t\t\truns.push({ root, ...(await client(root, temp(\"home\"), [\"join\", project, \"--reader\", \"--server\", url])) });\n+\t\t}\n+\t\tfor (const run of runs) {\n+\t\t\tassert.equal(run.code, runs[0]!.code);\n+\t\t\tassert.notEqual(run.code, 0);\n+\t\t\tassert.equal(run.stderr, runs[0]!.stderr);\n+\t\t\tassert.equal(existsSync(join(run.root, \".abso\")), false);\n+\t\t}\n+\t\tassert.match(runs[0]!.stderr, /isn't signed in to .*abso login signs it in/);\n+\t});\n+\n+\tit(\"runs only its reads: every other command is refused before any call, and a new command fails here\", async () => {\n+\t\tconst sorted = new Set([...Object.keys(VISITOR_READS), ...VISITOR_ELSEWHERE, ...REFUSED]);\n+\t\tfor (const name of Object.keys(commandTable()))\n+\t\t\tassert.ok(\n+\t\t\t\tsorted.has(name),\n+\t\t\t\t`abso ${name} is new: add it to VISITOR_READS if it only reads, else to REFUSED here`,\n+\t\t\t);\n+\t\tconst root = temp(\"refuse\");\n+\t\twriteConfig(root, { server: url, project: \"abso-core\", agent: \"\", visitor: true });\n+\t\tconst real = globalThis.fetch;\n+\t\tlet calls = 0;\n+\t\tglobalThis.fetch = (async () => {\n+\t\t\tcalls++;\n+\t\t\treturn new Response(\"{}\", { status: 200 });\n+\t\t}) as typeof fetch;\n+\t\ttry {\n+\t\t\tconst tries = [\n+\t\t\t\t...REFUSED.map((c) => [c]),\n+\t\t\t\t[\"issue\", \"new\", \"a title\"],\n+\t\t\t\t[\"issue\", \"3\", \"--comment\", \"hi\"],\n+\t\t\t\t[\"issues\", \"--drafts\"],\n+\t\t\t\t[\"blame\", \"a.txt\", \"--mine\"],\n+\t\t\t];\n+\t\t\tfor (const argv of tries) {\n+\t\t\t\tconst out = await main(argv, { cwd: root, env: { ABSO_TOKEN: TOKEN }, write: () => {} });\n+\t\t\t\tassert.notEqual(out.exit, 0, argv.join(\" \"));\n+\t\t\t\tassert.match(out.stderr, /This folder reads abso-core signed out\\. To work on it: abso login/, argv.join(\" \"));\n+\t\t\t}\n+\t\t} finally {\n+\t\t\tglobalThis.fetch = real;\n+\t\t}\n+\t\tassert.equal(calls, 0);\n+\t});\n+\n+\tit(\"prints what comes back through the terminal filter, a 429's text too\", async () => {\n+\t\tconst { root, home } = await joined();\n+\t\tconst show = await client(root, home, [\"show\", \"1:a.txt\"]);\n+\t\tassert.equal(show.code, 0, show.stderr);\n+\t\tassert.doesNotMatch(show.stdout, /\\x1b/);\n+\t\tassert.match(show.stdout, /hi \\\\x1b\\]52;c;aGk=\\\\x07 there/);\n+\t\tconst log = await client(root, home, [\"log\"]);\n+\t\tassert.notEqual(log.code, 0);\n+\t\tassert.doesNotMatch(log.stderr + log.stdout, /\\x1b/);\n+\t\tassert.match(log.stderr, /too many signed-out reads from this address/);\n+\t});\n+\n+\tit(\"show prints a file and writes nothing, even for a path outside the folder\", async () => {\n+\t\tconst { root, home } = await joined();\n+\t\tconst parent = resolve(root, \"..\");\n+\t\tconst before = { here: readdirSync(root).sort(), above: readdirSync(parent).sort() };\n+\t\tawait client(root, home, [\"show\", \"1:a.txt\"]);\n+\t\tconst outside = await client(root, home, [\"show\", \"1:../x\"]);\n+\t\tassert.notEqual(outside.code, 0);\n+\t\tassert.deepEqual(readdirSync(root).sort(), before.here);\n+\t\tassert.deepEqual(readdirSync(parent).sort(), before.above);\n+\t\tassert.equal(existsSync(join(parent, \"x\")), false);\n+\t});\n+});"}],"ci":null}