testTextMergeThatDoesntTypecheckIsQuiet

tcmts.cli.test.e2e.merge.testTextMergeThatDoesntTypecheckIsQuiet · #2zjrvegp · term

A definition both sides edited apart whose text merge doesn't typecheck stays a conflict, and the merge says so without the type errors (tcm todo and tcm check have them): tcm edit writes the merged text, no markers in it, to fix, and says it doesn't typecheck.

import { okIn, tcmIn, tempDir } from "#codebase/tcmts/cli/test/e2e/harness";
import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";

export const testTextMergeThatDoesntTypecheckIsQuiet = () => {
  const dir = tempDir("merge quiet");
  const tcm = (...args: string[]) => okIn(dir, ...args);
  const k = (a: string, c: string) =>
    `// tcm: namespace lib\nexport const k = (): number => {\n  const a: number | string = ${a};\n  const b = 2;\n  const c = ${c};\n  return Number(a) + b + c;\n};\n`;
  const update = (code: string) => {
    fs.writeFileSync(path.join(dir, "scratch.ts"), code);
    tcm("update");
  };
  tcm("init");
  update(k("1", "3"));
  tcm("branch", "s");
  tcm("switch", "s");
  update(k('"1"', "3"));
  tcm("switch", "main");
  update(k("1", "a.toFixed().length"));
  tcm("switch", "s");
  const merged = tcmIn(dir, "merge", "main");
  assert.equal(merged.status, 1, merged.out);
  assert.match(merged.out, /conflict lib\.k/);
  assert.doesNotMatch(merged.out, /error TS|has problems/);
  // (checked as `tcm check` checks it: it really doesn't typecheck)
  assert.match(
    tcm("edit", "lib.k"),
    /no lines both changed, but it doesn't typecheck: `tcm check lib\.k\.ts` says why/,
  );
  const text = fs.readFileSync(path.join(dir, "lib.k.ts"), "utf8");
  assert.match(text, /= "1";[\s\S]*a\.toFixed\(\)/);
  assert.doesNotMatch(text, /<<<<<<<|>>>>>>>/);
}

uses