{"draft":null,"from":1,"to":318,"files":[{"path":"client/test/join-signed-out.test.ts","added":79,"removed":0,"diff":"--- /dev/null\n+++ b/client/test/join-signed-out.test.ts\n@@ -0,0 +1,79 @@\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, 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+import { mkdtempSync, rmSync } from \"node:fs\";\n+import { createServer, 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 { type Fake, startFake } from \"./fake-server.ts\";\n+\n+const CLIENT = resolve(import.meta.dirname, \"..\", \"abso.ts\");\n+let fake: Fake;\n+// A server where every project is public: status answers signed out, and the agent routes want a sign-in.\n+let open: Server;\n+let openUrl: string;\n+const dirs: string[] = [];\n+const temp = () => {\n+\tconst dir = mkdtempSync(join(tmpdir(), \"abso-test-signed-out-\"));\n+\tdirs.push(dir);\n+\treturn dir;\n+};\n+\n+before(async () => {\n+\tfake = await startFake(0, \"test-token-not-secret\");\n+\topen = createServer((req, res) => {\n+\t\tif (req.method === \"GET\" && /^\\/p\\/[^/]+\\/status$/.test(req.url ?? \"\"))\n+\t\t\treturn res.writeHead(200, { \"content-type\": \"application/json\" }).end('{\"version\":1,\"agents\":[]}');\n+\t\tres.writeHead(401, { \"content-type\": \"application/json\" }).end('{\"error\":\"sign in\"}');\n+\t});\n+\tawait new Promise<void>((done) => open.listen(0, \"127.0.0.1\", done));\n+\topenUrl = `http://127.0.0.1:${(open.address() as AddressInfo).port}`;\n+});\n+after(async () => {\n+\tawait fake.close();\n+\topen.close();\n+\tfor (const dir of dirs) rmSync(dir, { recursive: true, force: true });\n+});\n+\n+/** Runs the client signed out: an empty home, and no token in the environment. */\n+function signedOut(...args: string[]): Promise<{ code: number; stderr: string }> {\n+\tconst home = temp();\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};\n+\tif (process.env.CLAUDE_CONFIG_DIR) env.CLAUDE_CONFIG_DIR = process.env.CLAUDE_CONFIG_DIR;\n+\tif (process.env.SystemRoot) env.SystemRoot = process.env.SystemRoot;\n+\treturn new Promise((done) => {\n+\t\texecFile(process.execPath, [CLIENT, ...args], { cwd: temp(), env }, (error, _stdout, stderr) =>\n+\t\t\tdone({ code: typeof error?.code === \"number\" ? error.code : 0, stderr }),\n+\t\t);\n+\t});\n+}\n+\n+describe(\"join, signed out\", () => {\n+\tit(\"to a public project, as a reader, names its page on the website and abso login\", async () => {\n+\t\tconst run = await signedOut(\"join\", \"abso-core\", \"--agent\", \"qa-reader\", \"--reader\", \"--server\", openUrl);\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\\), or here with abso join abso-core --reader\\. To work on it: abso login\\./,\n+\t\t);\n+\t});\n+\n+\tit(\"to a project that isn't public, keeps to abso login, and says a folder with a key joins with --agent\", async () => {\n+\t\tconst run = await signedOut(\"join\", \"secret\", \"--server\", fake.url);\n+\t\tassert.notEqual(run.code, 0);\n+\t\tassert.match(run.stderr, /isn't signed in to .*abso login signs it in\\./);\n+\t\tassert.doesNotMatch(run.stderr, /is public/);\n+\t\tassert.match(run.stderr, /A folder that already has a key joins with --agent <name>/);\n+\t});\n+});"}],"unmatched":[]}