{"draft":null,"from":3,"to":318,"files":[{"path":"client/test/held-push.test.ts","added":131,"removed":0,"diff":"--- /dev/null\n+++ b/client/test/held-push.test.ts\n@@ -0,0 +1,131 @@\n+// A held push from end to end, as two agents meet it: alice and bob change\n+// the same line, bob's push is held, he pulls, settles and pushes again.\n+// What each step prints has to be true, and the record has to keep his reason.\n+\n+import assert from \"node:assert/strict\";\n+import { 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+const POLICY = \"# Store policy\\n\\nFree shipping on orders over $50.\\nReturns accepted within 30 days.\\n\";\n+const HELD = \"Lower free shipping to $35: half of abandoned carts were between $35 and $50\";\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-held-\"));\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 pushes $75; bob's $35 push is held. Answers both folders and bob's held push. */\n+async function held(): Promise<{ alice: string; bob: string; refused: string }> {\n+\tconst name = `held${++projects}`;\n+\tconst alice = temp();\n+\twriteFileSync(join(alice, \"store-policy.md\"), POLICY);\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, \"store-policy.md\"), POLICY.replace(\"$50\", \"$75\"));\n+\twriteFileSync(join(bob, \"store-policy.md\"), POLICY.replace(\"$50\", \"$35\"));\n+\tconst pushed = await run(alice, \"push\", \"-m\", \"Raise free shipping to $75: shipping costs rose\");\n+\tassert.equal(pushed.exit, 0, pushed.out);\n+\tconst refused = await run(bob, \"push\", \"-m\", HELD);\n+\tassert.equal(refused.exit, 2, refused.out);\n+\treturn { alice, bob, refused: refused.out };\n+}\n+\n+const policy = (dir: string) => readFileSync(join(dir, \"store-policy.md\"), \"utf8\");\n+\n+describe(\"a held push\", () => {\n+\tit(\"says what the pull really writes: a marker block where both changed the same lines\", async () => {\n+\t\tconst { bob, refused } = await held();\n+\t\tassert.doesNotMatch(refused, /no markers/);\n+\t\tassert.match(refused, /Run abso pull: each of those files comes back holding both sides' lines/);\n+\t\tassert.equal((await run(bob, \"pull\")).exit, 0);\n+\t\tassert.match(policy(bob), /^<<<<<<< yours \\(unpublished\\)$/m, \"the pull wrote a marker block\");\n+\t});\n+\n+\tfor (const how of [\"yours\", \"theirs\", \"both\"] as const) {\n+\t\tit(`why names the collision a line was kept from, settled --${how}`, async () => {\n+\t\t\tconst { alice, bob } = await held();\n+\t\t\tassert.equal((await run(bob, \"pull\")).exit, 0);\n+\t\t\tconst settled = await run(bob, \"settle\", \"store-policy.md\", `--${how}`);\n+\t\t\tassert.equal(settled.exit, 0, settled.out);\n+\t\t\tconst pushed = await run(bob, \"push\", \"-m\", `Settle: keep ${how}`);\n+\t\t\tassert.equal(pushed.exit, 0, pushed.out);\n+\t\t\tassert.equal((await run(alice, \"pull\")).exit, 0);\n+\t\t\tconst why = await run(alice, \"why\", \"store-policy.md:3\");\n+\t\t\tassert.equal(why.exit, 0, why.out);\n+\t\t\tassert.match(why.out, /It was kept when bob settled a collision between:\\n {2}alice, version 1 by alice/);\n+\t\t\tassert.match(why.out, new RegExp(`\\\\n {2}bob, a held push: \"${HELD.replace(/\\$/g, \"\\\\$\")}\"`));\n+\t\t});\n+\t}\n+\n+\tit(\"keeps its message: why on the settling line shows it, and so do the change page and the news\", async () => {\n+\t\tconst { alice, bob } = await held();\n+\t\tassert.equal((await run(bob, \"pull\")).exit, 0);\n+\t\twriteFileSync(join(bob, \"store-policy.md\"), POLICY.replace(\"$50\", \"$60\"));\n+\t\tconst pushed = await run(bob, \"push\", \"-m\", \"Settle with alice: meet at $60\");\n+\t\tassert.equal(pushed.exit, 0, pushed.out);\n+\t\tconst why = await run(bob, \"why\", \"store-policy.md:3\");\n+\t\tassert.match(\n+\t\t\twhy.out,\n+\t\t\t/It settled a collision between:\\n {2}alice, version 1 by alice[^\\n]*\\n {2}bob, a held push: \"/,\n+\t\t);\n+\t\tassert.ok(why.out.includes(HELD), why.out);\n+\t\tconst review = await run(alice, \"review\", \"bob\");\n+\t\tassert.match(review.out, /Settled: store-policy\\.md \\(rewrote both sides, against alice's version 1\\)\\./);\n+\t\tassert.ok(review.out.includes(`Refused 1 time on the way: lines (store-policy.md): \"${HELD}\"`), review.out);\n+\t\tconst news = await run(alice, \"news\");\n+\t\tassert.ok(news.out.includes(`Its held push said: \"${HELD}\"`), news.out);\n+\t});\n+\n+\tit(\"a pull doesn't drop the news of what a settle kept\", async () => {\n+\t\tconst { alice, bob } = await held();\n+\t\tassert.equal((await run(bob, \"pull\")).exit, 0);\n+\t\tassert.equal((await run(bob, \"settle\", \"store-policy.md\", \"--both\")).exit, 0);\n+\t\tassert.equal((await run(bob, \"push\", \"-m\", \"Settle: keep both\")).exit, 0);\n+\t\tconst pulled = await run(alice, \"pull\");\n+\t\tassert.equal(pulled.exit, 0, pulled.out);\n+\t\tconst news = await run(alice, \"news\");\n+\t\tassert.match(news.out, /bob settled its collision with your version 1 in store-policy\\.md, pushing version 2/);\n+\t});\n+\n+\tit(\"the change page says what a settle kept in words that read for each choice\", async () => {\n+\t\tfor (const [how, said] of [\n+\t\t\t[\"yours\", \"kept bob's\"],\n+\t\t\t[\"theirs\", \"kept alice's\"],\n+\t\t\t[\"both\", \"kept both\"],\n+\t\t] as const) {\n+\t\t\tconst { alice, bob } = await held();\n+\t\t\tassert.equal((await run(bob, \"pull\")).exit, 0);\n+\t\t\tassert.equal((await run(bob, \"settle\", \"store-policy.md\", `--${how}`)).exit, 0);\n+\t\t\tassert.equal((await run(bob, \"push\", \"-m\", `Settle: keep ${how}`)).exit, 0);\n+\t\t\tconst review = await run(alice, \"review\", \"bob\");\n+\t\t\tassert.ok(review.out.includes(`Settled: store-policy.md (${said}, against alice's version 1).`), review.out);\n+\t\t}\n+\t});\n+});"}],"unmatched":[]}