{"file":"client/test/held-push.test.ts","version":318,"total":131,"from":1,"to":131,"lines":[{"n":1,"text":"// A held push from end to end, as two agents meet it: alice and bob change","atom":"a1627","author":"speed","version":159},{"n":2,"text":"// the same line, bob's push is held, he pulls, settles and pushes again.","atom":"a1627","author":"speed","version":159},{"n":3,"text":"// What each step prints has to be true, and the record has to keep his reason.","atom":"a1638","author":"speed","version":160},{"n":4,"text":"","atom":"a1627","author":"speed","version":159},{"n":5,"text":"import assert from \"node:assert/strict\";","atom":"a1627","author":"speed","version":159},{"n":6,"text":"import { mkdtempSync, readFileSync, rmSync, writeFileSync } from \"node:fs\";","atom":"a1627","author":"speed","version":159},{"n":7,"text":"import { tmpdir } from \"node:os\";","atom":"a1627","author":"speed","version":159},{"n":8,"text":"import { join } from \"node:path\";","atom":"a1627","author":"speed","version":159},{"n":9,"text":"import { after, before, describe, it } from \"node:test\";","atom":"a1627","author":"speed","version":159},{"n":10,"text":"import { main } from \"../src/main.ts\";","atom":"a1627","author":"speed","version":159},{"n":11,"text":"import { type Fake, startFake } from \"./fake-server.ts\";","atom":"a1627","author":"speed","version":159},{"n":12,"text":"","atom":"a1627","author":"speed","version":159},{"n":13,"text":"const TOKEN = \"test-token-not-secret\";","atom":"a1627","author":"speed","version":159},{"n":14,"text":"const ENV = { AVCS_TOKEN: TOKEN, AVCS_HOOK_FORCE: \"1\", AVCS_SERVERS_FILE: \"no-servers.json\" };","atom":"a1627","author":"speed","version":159},{"n":15,"text":"const POLICY = \"# Store policy\\n\\nFree shipping on orders over $50.\\nReturns accepted within 30 days.\\n\";","atom":"a1627","author":"speed","version":159},{"n":16,"text":"const HELD = \"Lower free shipping to $35: half of abandoned carts were between $35 and $50\";","atom":"a1627","author":"speed","version":159},{"n":17,"text":"","atom":"a1627","author":"speed","version":159},{"n":18,"text":"let fake: Fake;","atom":"a1627","author":"speed","version":159},{"n":19,"text":"const dirs: string[] = [];","atom":"a1627","author":"speed","version":159},{"n":20,"text":"before(async () => {","atom":"a1627","author":"speed","version":159},{"n":21,"text":"\tfake = await startFake(0, TOKEN);","atom":"a1627","author":"speed","version":159},{"n":22,"text":"});","atom":"a1627","author":"speed","version":159},{"n":23,"text":"after(async () => {","atom":"a1627","author":"speed","version":159},{"n":24,"text":"\tawait fake.close();","atom":"a1627","author":"speed","version":159},{"n":25,"text":"\tfor (const d of dirs) rmSync(d, { recursive: true, force: true, maxRetries: 5 });","atom":"a1627","author":"speed","version":159},{"n":26,"text":"});","atom":"a1627","author":"speed","version":159},{"n":27,"text":"","atom":"a1627","author":"speed","version":159},{"n":28,"text":"function temp(): string {","atom":"a1627","author":"speed","version":159},{"n":29,"text":"\tconst d = mkdtempSync(join(tmpdir(), \"abso-held-\"));","atom":"a1627","author":"speed","version":159},{"n":30,"text":"\tdirs.push(d);","atom":"a1627","author":"speed","version":159},{"n":31,"text":"\treturn d;","atom":"a1627","author":"speed","version":159},{"n":32,"text":"}","atom":"a1627","author":"speed","version":159},{"n":33,"text":"","atom":"a1627","author":"speed","version":159},{"n":34,"text":"async function run(cwd: string, ...argv: string[]): Promise<{ exit: number; out: string }> {","atom":"a1627","author":"speed","version":159},{"n":35,"text":"\tconst r = await main(argv, { cwd, env: ENV, write: () => {} });","atom":"a1627","author":"speed","version":159},{"n":36,"text":"\treturn { exit: r.exit, out: r.stdout + r.stderr };","atom":"a1627","author":"speed","version":159},{"n":37,"text":"}","atom":"a1627","author":"speed","version":159},{"n":38,"text":"","atom":"a1627","author":"speed","version":159},{"n":39,"text":"let projects = 0;","atom":"a1627","author":"speed","version":159},{"n":40,"text":"/** alice pushes $75; bob's $35 push is held. Answers both folders and bob's held push. */","atom":"a1627","author":"speed","version":159},{"n":41,"text":"async function held(): Promise<{ alice: string; bob: string; refused: string }> {","atom":"a1627","author":"speed","version":159},{"n":42,"text":"\tconst name = `held${++projects}`;","atom":"a1627","author":"speed","version":159},{"n":43,"text":"\tconst alice = temp();","atom":"a1627","author":"speed","version":159},{"n":44,"text":"\twriteFileSync(join(alice, \"store-policy.md\"), POLICY);","atom":"a1627","author":"speed","version":159},{"n":45,"text":"\tassert.equal(","atom":"a1627","author":"speed","version":159},{"n":46,"text":"\t\t(await run(alice, \"init\", \"--server\", fake.url, \"--project\", name, \"--agent\", \"alice\", \"--as-is\")).exit,","atom":"a1627","author":"speed","version":159},{"n":47,"text":"\t\t0,","atom":"a1627","author":"speed","version":159},{"n":48,"text":"\t);","atom":"a1627","author":"speed","version":159},{"n":49,"text":"\tconst bob = temp();","atom":"a1627","author":"speed","version":159},{"n":50,"text":"\tassert.equal((await run(bob, \"join\", name, \"--agent\", \"bob\", \"--server\", fake.url)).exit, 0);","atom":"a1627","author":"speed","version":159},{"n":51,"text":"\twriteFileSync(join(alice, \"store-policy.md\"), POLICY.replace(\"$50\", \"$75\"));","atom":"a1627","author":"speed","version":159},{"n":52,"text":"\twriteFileSync(join(bob, \"store-policy.md\"), POLICY.replace(\"$50\", \"$35\"));","atom":"a1627","author":"speed","version":159},{"n":53,"text":"\tconst pushed = await run(alice, \"push\", \"-m\", \"Raise free shipping to $75: shipping costs rose\");","atom":"a1627","author":"speed","version":159},{"n":54,"text":"\tassert.equal(pushed.exit, 0, pushed.out);","atom":"a1627","author":"speed","version":159},{"n":55,"text":"\tconst refused = await run(bob, \"push\", \"-m\", HELD);","atom":"a1627","author":"speed","version":159},{"n":56,"text":"\tassert.equal(refused.exit, 2, refused.out);","atom":"a1627","author":"speed","version":159},{"n":57,"text":"\treturn { alice, bob, refused: refused.out };","atom":"a1627","author":"speed","version":159},{"n":58,"text":"}","atom":"a1627","author":"speed","version":159},{"n":59,"text":"","atom":"a1627","author":"speed","version":159},{"n":60,"text":"const policy = (dir: string) => readFileSync(join(dir, \"store-policy.md\"), \"utf8\");","atom":"a1627","author":"speed","version":159},{"n":61,"text":"","atom":"a1627","author":"speed","version":159},{"n":62,"text":"describe(\"a held push\", () => {","atom":"a1627","author":"speed","version":159},{"n":63,"text":"\tit(\"says what the pull really writes: a marker block where both changed the same lines\", async () => {","atom":"a1627","author":"speed","version":159},{"n":64,"text":"\t\tconst { bob, refused } = await held();","atom":"a1627","author":"speed","version":159},{"n":65,"text":"\t\tassert.doesNotMatch(refused, /no markers/);","atom":"a1627","author":"speed","version":159},{"n":66,"text":"\t\tassert.match(refused, /Run abso pull: each of those files comes back holding both sides' lines/);","atom":"a1627","author":"speed","version":159},{"n":67,"text":"\t\tassert.equal((await run(bob, \"pull\")).exit, 0);","atom":"a1627","author":"speed","version":159},{"n":68,"text":"\t\tassert.match(policy(bob), /^<<<<<<< yours \\(unpublished\\)$/m, \"the pull wrote a marker block\");","atom":"a1627","author":"speed","version":159},{"n":69,"text":"\t});","atom":"a1638","author":"speed","version":160},{"n":70,"text":"","atom":"a1638","author":"speed","version":160},{"n":71,"text":"\tfor (const how of [\"yours\", \"theirs\", \"both\"] as const) {","atom":"a1638","author":"speed","version":160},{"n":72,"text":"\t\tit(`why names the collision a line was kept from, settled --${how}`, async () => {","atom":"a1638","author":"speed","version":160},{"n":73,"text":"\t\t\tconst { alice, bob } = await held();","atom":"a1638","author":"speed","version":160},{"n":74,"text":"\t\t\tassert.equal((await run(bob, \"pull\")).exit, 0);","atom":"a1638","author":"speed","version":160},{"n":75,"text":"\t\t\tconst settled = await run(bob, \"settle\", \"store-policy.md\", `--${how}`);","atom":"a1638","author":"speed","version":160},{"n":76,"text":"\t\t\tassert.equal(settled.exit, 0, settled.out);","atom":"a1638","author":"speed","version":160},{"n":77,"text":"\t\t\tconst pushed = await run(bob, \"push\", \"-m\", `Settle: keep ${how}`);","atom":"a1638","author":"speed","version":160},{"n":78,"text":"\t\t\tassert.equal(pushed.exit, 0, pushed.out);","atom":"a1638","author":"speed","version":160},{"n":79,"text":"\t\t\tassert.equal((await run(alice, \"pull\")).exit, 0);","atom":"a1638","author":"speed","version":160},{"n":80,"text":"\t\t\tconst why = await run(alice, \"why\", \"store-policy.md:3\");","atom":"a1638","author":"speed","version":160},{"n":81,"text":"\t\t\tassert.equal(why.exit, 0, why.out);","atom":"a1638","author":"speed","version":160},{"n":82,"text":"\t\t\tassert.match(why.out, /It was kept when bob settled a collision between:\\n {2}alice, version 1 by alice/);","atom":"a1638","author":"speed","version":160},{"n":83,"text":"\t\t\tassert.match(why.out, new RegExp(`\\\\n {2}bob, a held push: \"${HELD.replace(/\\$/g, \"\\\\$\")}\"`));","atom":"a1638","author":"speed","version":160},{"n":84,"text":"\t\t});","atom":"a1638","author":"speed","version":160},{"n":85,"text":"\t}","atom":"a1638","author":"speed","version":160},{"n":86,"text":"","atom":"a1638","author":"speed","version":160},{"n":87,"text":"\tit(\"keeps its message: why on the settling line shows it, and so do the change page and the news\", async () => {","atom":"a1638","author":"speed","version":160},{"n":88,"text":"\t\tconst { alice, bob } = await held();","atom":"a1638","author":"speed","version":160},{"n":89,"text":"\t\tassert.equal((await run(bob, \"pull\")).exit, 0);","atom":"a1638","author":"speed","version":160},{"n":90,"text":"\t\twriteFileSync(join(bob, \"store-policy.md\"), POLICY.replace(\"$50\", \"$60\"));","atom":"a1638","author":"speed","version":160},{"n":91,"text":"\t\tconst pushed = await run(bob, \"push\", \"-m\", \"Settle with alice: meet at $60\");","atom":"a1638","author":"speed","version":160},{"n":92,"text":"\t\tassert.equal(pushed.exit, 0, pushed.out);","atom":"a1638","author":"speed","version":160},{"n":93,"text":"\t\tconst why = await run(bob, \"why\", \"store-policy.md:3\");","atom":"a1638","author":"speed","version":160},{"n":94,"text":"\t\tassert.match(","atom":"a1638","author":"speed","version":160},{"n":95,"text":"\t\t\twhy.out,","atom":"a1638","author":"speed","version":160},{"n":96,"text":"\t\t\t/It settled a collision between:\\n {2}alice, version 1 by alice[^\\n]*\\n {2}bob, a held push: \"/,","atom":"a1638","author":"speed","version":160},{"n":97,"text":"\t\t);","atom":"a1638","author":"speed","version":160},{"n":98,"text":"\t\tassert.ok(why.out.includes(HELD), why.out);","atom":"a1638","author":"speed","version":160},{"n":99,"text":"\t\tconst review = await run(alice, \"review\", \"bob\");","atom":"a1638","author":"speed","version":160},{"n":100,"text":"\t\tassert.match(review.out, /Settled: store-policy\\.md \\(rewrote both sides, against alice's version 1\\)\\./);","atom":"a1638","author":"speed","version":160},{"n":101,"text":"\t\tassert.ok(review.out.includes(`Refused 1 time on the way: lines (store-policy.md): \"${HELD}\"`), review.out);","atom":"a1638","author":"speed","version":160},{"n":102,"text":"\t\tconst news = await run(alice, \"news\");","atom":"a1638","author":"speed","version":160},{"n":103,"text":"\t\tassert.ok(news.out.includes(`Its held push said: \"${HELD}\"`), news.out);","atom":"a1638","author":"speed","version":160},{"n":104,"text":"\t});","atom":"a1627","author":"speed","version":159},{"n":105,"text":"","atom":"a1627","author":"speed","version":159},{"n":106,"text":"\tit(\"a pull doesn't drop the news of what a settle kept\", async () => {","atom":"a1651","author":"speed","version":161},{"n":107,"text":"\t\tconst { alice, bob } = await held();","atom":"a1651","author":"speed","version":161},{"n":108,"text":"\t\tassert.equal((await run(bob, \"pull\")).exit, 0);","atom":"a1651","author":"speed","version":161},{"n":109,"text":"\t\tassert.equal((await run(bob, \"settle\", \"store-policy.md\", \"--both\")).exit, 0);","atom":"a1651","author":"speed","version":161},{"n":110,"text":"\t\tassert.equal((await run(bob, \"push\", \"-m\", \"Settle: keep both\")).exit, 0);","atom":"a1651","author":"speed","version":161},{"n":111,"text":"\t\tconst pulled = await run(alice, \"pull\");","atom":"a1651","author":"speed","version":161},{"n":112,"text":"\t\tassert.equal(pulled.exit, 0, pulled.out);","atom":"a1651","author":"speed","version":161},{"n":113,"text":"\t\tconst news = await run(alice, \"news\");","atom":"a1651","author":"speed","version":161},{"n":114,"text":"\t\tassert.match(news.out, /bob settled its collision with your version 1 in store-policy\\.md, pushing version 2/);","atom":"a1651","author":"speed","version":161},{"n":115,"text":"\t});","atom":"a1651","author":"speed","version":161},{"n":116,"text":"","atom":"a1651","author":"speed","version":161},{"n":117,"text":"\tit(\"the change page says what a settle kept in words that read for each choice\", async () => {","atom":"a1627","author":"speed","version":159},{"n":118,"text":"\t\tfor (const [how, said] of [","atom":"a1627","author":"speed","version":159},{"n":119,"text":"\t\t\t[\"yours\", \"kept bob's\"],","atom":"a1627","author":"speed","version":159},{"n":120,"text":"\t\t\t[\"theirs\", \"kept alice's\"],","atom":"a1627","author":"speed","version":159},{"n":121,"text":"\t\t\t[\"both\", \"kept both\"],","atom":"a1627","author":"speed","version":159},{"n":122,"text":"\t\t] as const) {","atom":"a1627","author":"speed","version":159},{"n":123,"text":"\t\t\tconst { alice, bob } = await held();","atom":"a1627","author":"speed","version":159},{"n":124,"text":"\t\t\tassert.equal((await run(bob, \"pull\")).exit, 0);","atom":"a1627","author":"speed","version":159},{"n":125,"text":"\t\t\tassert.equal((await run(bob, \"settle\", \"store-policy.md\", `--${how}`)).exit, 0);","atom":"a1627","author":"speed","version":159},{"n":126,"text":"\t\t\tassert.equal((await run(bob, \"push\", \"-m\", `Settle: keep ${how}`)).exit, 0);","atom":"a1627","author":"speed","version":159},{"n":127,"text":"\t\t\tconst review = await run(alice, \"review\", \"bob\");","atom":"a1627","author":"speed","version":159},{"n":128,"text":"\t\t\tassert.ok(review.out.includes(`Settled: store-policy.md (${said}, against alice's version 1).`), review.out);","atom":"a1627","author":"speed","version":159},{"n":129,"text":"\t\t}","atom":"a1627","author":"speed","version":159},{"n":130,"text":"\t});","atom":"a1627","author":"speed","version":159},{"n":131,"text":"});","atom":"a1627","author":"speed","version":159}],"atoms":[{"atom":"a1627","author":"speed","message":"","time":1791921635514,"timeIso":"2026-10-13T20:00:35.514Z","publish":{"draft":null,"version":159,"agent":"speed","message":"Settles say what they kept in plain words: a held push's hint says the pull writes a marker block, the change page reads \"kept bob's\" or \"rewrote both sides\" rather than \"kept rewrote\", and a line rewritten longer no longer counts as lost","time":1791921932752,"timeIso":"2026-10-13T20:05:32.752Z"}},{"atom":"a1638","author":"speed","message":"","time":1791922236994,"timeIso":"2026-10-13T20:10:36.994Z","publish":{"draft":null,"version":160,"agent":"speed","message":"A held push keeps its message, and why tells every settle: the refusal stores the push's message; why on a line kept by abso settle --yours, --theirs or --both names the collision it was kept from, and both kinds of settle list the settler's held push with its reason; the settle's news and the change page carry it too, and a lone push's change now lists the refusals on its way","time":1791922755559,"timeIso":"2026-10-13T20:19:15.559Z"}},{"atom":"a1651","author":"speed","message":"","time":1791922784645,"timeIso":"2026-10-13T20:19:44.645Z","publish":{"draft":null,"version":161,"agent":"speed","message":"A pull keeps the news of what a settle kept: it used to drop it with the news it makes moot, though the pull only brings the file, not whose side survived","time":1791923200404,"timeIso":"2026-10-13T20:26:40.404Z"}}]}