{"draft":null,"from":175,"to":318,"files":[{"path":"client/test/lost-pull.test.ts","added":88,"removed":0,"diff":"--- /dev/null\n+++ b/client/test/lost-pull.test.ts\n@@ -0,0 +1,88 @@\n+// A pull whose answer never arrives (abso-core 26): the server has moved the agent's base, so later pulls\n+// send only what changed since then. The folder notes the pull it started and, until one is written, the\n+// next pull asks for every file and writes the ones that differ. Status says so in the meantime.\n+\n+import assert from \"node:assert/strict\";\n+import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from \"node:fs\";\n+import { tmpdir } from \"node:os\";\n+import { join } from \"node:path\";\n+import { after, before, describe, it } from \"node:test\";\n+import { main } from \"../src/main.ts\";\n+import { type Fake, startFake } from \"./fake-server.ts\";\n+\n+const TOKEN = \"test-token-not-secret\";\n+const ENV = { AVCS_TOKEN: TOKEN, AVCS_HOOK_FORCE: \"1\", AVCS_SERVERS_FILE: \"no-servers.json\" };\n+\n+let fake: Fake;\n+const dirs: string[] = [];\n+before(async () => {\n+\tfake = await startFake(0, TOKEN);\n+});\n+after(async () => {\n+\tawait fake.close();\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-lost-pull-\"));\n+\tdirs.push(d);\n+\treturn d;\n+}\n+\n+async function run(cwd: string, ...argv: string[]): Promise<{ exit: number; out: string }> {\n+\tconst r = await main(argv, { cwd, env: ENV, write: () => {} });\n+\treturn { exit: r.exit, out: r.stdout + r.stderr };\n+}\n+\n+let projects = 0;\n+/** alice and bob on one project; alice pushes a change and a new file, and bob's pull of them is lost. */\n+async function lost(): Promise<{ alice: string; bob: string }> {\n+\tconst name = `lost${++projects}`;\n+\tconst alice = temp();\n+\twriteFileSync(join(alice, \"a.txt\"), \"one\\n\");\n+\tassert.equal(\n+\t\t(await run(alice, \"init\", \"--server\", fake.url, \"--project\", name, \"--agent\", \"alice\", \"--as-is\")).exit,\n+\t\t0,\n+\t);\n+\tconst bob = temp();\n+\tassert.equal((await run(bob, \"join\", name, \"--agent\", \"bob\", \"--server\", fake.url)).exit, 0);\n+\twriteFileSync(join(alice, \"a.txt\"), \"two\\n\");\n+\twriteFileSync(join(alice, \"b.txt\"), \"new\\n\");\n+\tconst pushed = await run(alice, \"push\", \"-m\", \"Change a.txt and add b.txt\");\n+\tassert.equal(pushed.exit, 0, pushed.out);\n+\tfake.loseSyncAnswers = 1;\n+\tassert.notEqual((await run(bob, \"pull\")).exit, 0, \"the pull whose answer was lost fails\");\n+\treturn { alice, bob };\n+}\n+\n+const text = (dir: string, rel: string) => readFileSync(join(dir, rel), \"utf8\");\n+\n+describe(\"a pull whose answer never arrives\", () => {\n+\tit(\"leaves the folder as it was, and status says a pull didn't finish\", async () => {\n+\t\tconst { bob } = await lost();\n+\t\tassert.equal(text(bob, \"a.txt\"), \"one\\n\");\n+\t\tassert.equal(existsSync(join(bob, \"b.txt\")), false);\n+\t\tconst status = await run(bob, \"status\");\n+\t\tassert.match(status.out, /A pull here didn't finish/);\n+\t});\n+\n+\tit(\"the next pull asks for every file and writes what the lost one would have\", async () => {\n+\t\tconst { bob } = await lost();\n+\t\tconst pulled = await run(bob, \"pull\");\n+\t\tassert.equal(pulled.exit, 0, pulled.out);\n+\t\tassert.match(pulled.out, /The last pull here didn't finish, so this one asked for every file/);\n+\t\tassert.equal(text(bob, \"a.txt\"), \"two\\n\");\n+\t\tassert.equal(text(bob, \"b.txt\"), \"new\\n\");\n+\t\tassert.doesNotMatch((await run(bob, \"status\")).out, /A pull here didn't finish/);\n+\t\tconst again = await run(bob, \"pull\");\n+\t\tassert.doesNotMatch(again.out, /didn't finish/, \"once caught up, pulls are plain again\");\n+\t});\n+\n+\tit(\"keeps work done in the folder meanwhile\", async () => {\n+\t\tconst { bob } = await lost();\n+\t\twriteFileSync(join(bob, \"a.txt\"), \"bob's own\\n\");\n+\t\tconst pulled = await run(bob, \"pull\");\n+\t\tassert.equal(text(bob, \"a.txt\"), \"bob's own\\n\", pulled.out);\n+\t\tassert.equal(text(bob, \"b.txt\"), \"new\\n\");\n+\t});\n+});"}],"unmatched":[]}