{"draft":null,"from":175,"to":318,"files":[{"path":"client/test/failed-start.test.ts","added":60,"removed":0,"diff":"--- /dev/null\n+++ b/client/test/failed-start.test.ts\n@@ -0,0 +1,60 @@\n+// An init or join that fails against the server leaves the folder as it was, so the same command can run again:\n+// no starting .absoignore or abso.json from init, no .abso/ from join (but a key already here stays).\n+\n+import assert from \"node:assert/strict\";\n+import { existsSync, mkdirSync, mkdtempSync, readdirSync, rmSync, writeFileSync } from \"node:fs\";\n+import { tmpdir } from \"node:os\";\n+import { join } from \"node:path\";\n+import { after, describe, it } from \"node:test\";\n+import { main } from \"../src/main.ts\";\n+\n+// Nothing listens on port 1, so every call fails to connect.\n+const DOWN = \"http://127.0.0.1:1\";\n+const ENV = { ABSO_TOKEN: \"test-token-not-secret\", ABSO_SERVERS_FILE: \"no-servers.json\" };\n+\n+const dirs: string[] = [];\n+after(() => {\n+\tfor (const d of dirs) rmSync(d, { recursive: true, force: true, maxRetries: 5 });\n+});\n+\n+function temp(): string {\n+\tconst d = mkdtempSync(join(tmpdir(), \"abso-failed-start-\"));\n+\tdirs.push(d);\n+\treturn d;\n+}\n+\n+async function run(cwd: string, ...argv: string[]): Promise<number> {\n+\treturn (await main(argv, { cwd, env: ENV, write: () => {} })).exit;\n+}\n+\n+describe(\"a failed start\", () => {\n+\tit(\"init takes back the .absoignore and abso.json it wrote\", async () => {\n+\t\tconst dir = temp();\n+\t\twriteFileSync(join(dir, \"package.json\"), `${JSON.stringify({ scripts: { test: \"node --test\" } })}\\n`);\n+\t\tassert.notEqual(await run(dir, \"init\", \"--server\", DOWN, \"--project\", \"p\", \"--agent\", \"a\"), 0);\n+\t\tassert.deepEqual(readdirSync(dir), [\"package.json\"]);\n+\t});\n+\n+\tit(\"join leaves no .abso folder\", async () => {\n+\t\tconst dir = temp();\n+\t\tassert.notEqual(await run(dir, \"join\", \"p\", \"--server\", DOWN, \"--agent\", \"a\", \"--dir\", dir), 0);\n+\t\tassert.equal(existsSync(join(dir, \".abso\")), false);\n+\t});\n+\n+\tit(\"join keeps a key that was already here\", async () => {\n+\t\tconst dir = temp();\n+\t\tmkdirSync(join(dir, \".abso\"));\n+\t\tconst key = { server: DOWN, key: \"abso_sk_not-a-real-key\", id: \"k_0123abcd\" };\n+\t\twriteFileSync(join(dir, \".abso\", \"key\"), `${JSON.stringify(key)}\\n`);\n+\t\tassert.notEqual(await run(dir, \"join\", \"p\", \"--server\", DOWN, \"--agent\", \"a\", \"--dir\", dir), 0);\n+\t\tassert.deepEqual(readdirSync(join(dir, \".abso\")), [\"key\"]);\n+\t});\n+\n+\tit(\"join with a key it can't read leaves only that key\", async () => {\n+\t\tconst dir = temp();\n+\t\tmkdirSync(join(dir, \".abso\"));\n+\t\twriteFileSync(join(dir, \".abso\", \"key\"), \"{}\\n\");\n+\t\tassert.notEqual(await run(dir, \"join\", \"p\", \"--server\", DOWN, \"--agent\", \"a\", \"--dir\", dir), 0);\n+\t\tassert.deepEqual(readdirSync(join(dir, \".abso\")), [\"key\"]);\n+\t});\n+});"}],"unmatched":[]}