testConflictMarkersRoundTrip
tcm edit of a conflicted name writes its two sides merged from the base, with git's conflict markers where both
changed the same lines, and the rest merged. It can't be saved with the markers in it; without them, saving it
resolves the conflict, and what used either side's is re-derived against it.
import { tcmIn } from "#codebase/tcmts/cli/test/e2e/harness"; import { withConflicts } from "#codebase/tcmts/cli/test/e2e/merge"; import assert from "node:assert/strict"; import fs from "node:fs"; import path from "node:path"; export const testConflictMarkersRoundTrip = () => { const { dir, tcm } = withConflicts("merge markers"); // (in a file of its own, named after it: the scratch.ts the last update left is no matter) const file = path.join(dir, "lib.k.ts"); assert.match(tcm("edit", "lib.k"), /^wrote lib\.k to lib\.k\.ts$/m); assert.match(tcm("edit", "lib.k"), /1 conflict marked/, "again, over its file untouched"); const text = fs.readFileSync(file, "utf8"); assert.ok( text.includes( "<<<<<<< ours (s)\n const a = 10;\n||||||| base\n const a = 1;\n=======\n const a = 100;\n>>>>>>> theirs (main)\n", ), text, ); assert.match(text, /const c = 30;/, "what only one side changed is merged"); const refused = tcmIn(dir, "update", "lib.k.ts"); assert.notEqual(refused.status, 0); assert.match(refused.out, /lib\.k\.ts:\d+ still has conflict markers/); fs.writeFileSync( file, text.replace(/<<<<<<< [\s\S]*>>>>>>> theirs \(main\)\n/, " const a = 1000;\n"), ); assert.match(tcm("check", "lib.k.ts"), /resolves +lib\.k/); tcm("update", "lib.k.ts"); const todo = tcm("todo"); assert.doesNotMatch(todo, /conflict lib\.k/); assert.doesNotMatch(todo, /unnamed version/); tcm("resolve", "lib.m", "--ours"); assert.equal(tcm("run", "lib.user").trim(), String((1000 + 2 + 30 + 2) * 10)); }