testPatchesStopAtAVersionThatCameBack

tcmts.store.test.testPatchesStopAtAVersionThatCameBack · #gk36wm5s · term

A version that comes back (a change undone hashes as the code before it did) is the newest again: what replaced it then doesn't now. Patches lead to it, not on past it, whether recorded now or from before (a store holding a patch out of a version the branch names again).

import { a, b, open, stored } from "#codebase/tcmts/store/test/history";
import assert from "node:assert/strict";

export const testPatchesStopAtAVersionThatCameBack = () => {
  const c = "c".repeat(52);
  const s = open();
  s.putDefs([stored(a, "const f = 1"), stored(b, "const f = 2"), stored(c, "const g = 1")], "5", 2);
  // f is a, then b, then a again
  s.addName("f", a, "term", "add");
  s.addPatch(a, b);
  s.replaceName("f", a, b, "term", "update");
  s.addPatch(b, a);
  s.replaceName("f", b, a, "term", "update");
  assert.equal(s.patched(b), a);
  assert.equal(s.patched(a), a);
  // a patch out of a named version, left from before: it's not followed
  s.db
    .prepare("INSERT INTO patches (branch_id, old_hash, new_hash, ts) VALUES (?, ?, ?, ?)")
    .run(s.branch().id, a, c, 0);
  assert.equal(s.patched(b), a);
  assert.equal(s.patched(a), a);
  // once nothing names it, it's followed to what replaced it
  s.removeName("f", a, "rm");
  assert.equal(s.patched(b), c);
}

uses