testLeftoverScratchFileIsReplaced
A file tcm update left behind holding only what's saved (here, what's one side of a conflict since) is
replaced by a conflict's edit; one holding work that isn't saved isn't, and what's in the way is named.
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 testLeftoverScratchFileIsReplaced = () => { const { dir, tcm } = withConflicts("merge leftover"); const scratch = path.join(dir, "scratch.ts"); // what the last update (theirs, on main) left assert.match(fs.readFileSync(scratch, "utf8"), /const a = 100;/); assert.match(tcm("edit", "lib.k", "--file", "scratch.ts"), /^wrote lib\.k to scratch\.ts$/m); assert.match(fs.readFileSync(scratch, "utf8"), /<<<<<<< ours \(s\)/); fs.writeFileSync(scratch, "// tcm: namespace lib\nexport const other = (): number => 5;\n"); const refused = tcmIn(dir, "edit", "lib.k", "--file", "scratch.ts"); assert.notEqual(refused.status, 0); assert.match( refused.out, /scratch\.ts holds work that isn't saved \(lib\.other\): save it first .*--force to replace it/, ); assert.match(fs.readFileSync(scratch, "utf8"), /other/, "left as it was"); }