testABranchOnlyReadChangesNothing
A branch only read (--branch) is what the store reads, text versions and all, and nothing changes any branch:
names, text versions, history, todo, patches and branches stay as they were.
import { a, b, open, stored } from "#codebase/tcmts/store/test/history"; import assert from "node:assert/strict"; export const testABranchOnlyReadChangesNothing = () => { const s = open(); s.putDefs([stored(a, "const f = 1", "One."), stored(b, "const g = 2")], "5", 2); s.addName("f", a, "term", "add"); s.endBatch(); s.createBranch("side"); s.switchBranch("side"); s.addName("g", b, "term", "add"); s.setText( { hash: a, sourceText: "const f = 1 // one", spans: [], reservedNames: [], doc: "Uno." }, "update", ); s.endBatch(); s.switchBranch("main"); const heads = s.branches().map((n) => s.head(n)); s.readOnly("side"); assert.equal(s.branch().name, "side"); assert.deepEqual( s.names().map((n) => n.path), ["f", "g"], ); assert.equal(s.getDef(a)!.doc, "Uno."); assert.equal(s.history(1)[0]?.command, "update"); const refused = /side is only read here \(--branch\)/; assert.throws(() => s.addName("h", b, "term", "add"), refused); assert.throws(() => s.removeName("g", b, "rm"), refused); assert.throws( () => s.setText({ hash: a, sourceText: "const f = 1", spans: [], reservedNames: [] }, "update"), refused, ); assert.throws(() => s.setTodo(a, "broken"), refused); assert.throws(() => s.addPatch(a, b), refused); assert.throws(() => s.createBranch("other"), refused); assert.throws(() => s.switchBranch("main"), refused); assert.throws(() => s.setBranchNames("main", [], "reset"), refused); assert.deepEqual( s.names().map((n) => n.path), ["f", "g"], ); assert.deepEqual( s.names("main").map((n) => n.path), ["f"], ); assert.deepEqual( s.branches().map((n) => s.head(n)), heads, ); assert.equal(s.todos().length, 0); assert.throws(() => s.readOnly("nope"), /no branch named 'nope' \(--branch\)/); }