{"file":"src/engine/test/moves.test.ts","version":318,"total":364,"from":1,"to":364,"lines":[{"n":1,"text":"// Moves (#28): a line is its id, not its place. A move gives lines a new","atom":"a0","author":"init","version":0},{"n":2,"text":"// parent, possibly in another file, and edits name ids, so an edit made","atom":"a0","author":"init","version":0},{"n":3,"text":"// before or after a move follows the moved lines.","atom":"a0","author":"init","version":0},{"n":4,"text":"//   PROP_SEED=<seed> PROP_CASES=1 node --test src/engine/test/moves.test.ts","atom":"a0","author":"init","version":0},{"n":5,"text":"","atom":"a0","author":"init","version":0},{"n":6,"text":"import assert from \"node:assert/strict\";","atom":"a0","author":"init","version":0},{"n":7,"text":"import { describe, it } from \"node:test\";","atom":"a0","author":"init","version":0},{"n":8,"text":"import { type Atom, type AtomId, conflicts, Graph, View } from \"../index.ts\";","atom":"a1074","author":"codex-capacity-chair","version":126},{"n":9,"text":"import { StableOverlaySet } from \"../state-source.ts\";","atom":"a1074","author":"codex-capacity-chair","version":126},{"n":10,"text":"import { lines, Repo, Rng } from \"./helpers.ts\";","atom":"a0","author":"init","version":0},{"n":11,"text":"import { SqlState } from \"./storage-helper.ts\";","atom":"a1074","author":"codex-capacity-chair","version":126},{"n":12,"text":"","atom":"a0","author":"init","version":0},{"n":13,"text":"const BASE_SEED = Number(process.env.PROP_SEED ?? 20261004);","atom":"a700","author":"pinch","version":78},{"n":14,"text":"const CASES = Number(process.env.PROP_CASES ?? 200);","atom":"a700","author":"pinch","version":78},{"n":15,"text":"","atom":"a0","author":"init","version":0},{"n":16,"text":"const FN = [\"function area(r) {\", \"  const pi = 3.14;\", \"  return pi * r * r;\", \"}\"];","atom":"a0","author":"init","version":0},{"n":17,"text":"const START = {","atom":"a0","author":"init","version":0},{"n":18,"text":"\t\"shapes.js\": lines(\"// shapes\", ...FN, \"\", \"function other() {\", \"  return 1;\", \"}\"),","atom":"a0","author":"init","version":0},{"n":19,"text":"\t\"geometry.js\": lines(\"// geometry\", \"export {};\"),","atom":"a0","author":"init","version":0},{"n":20,"text":"};","atom":"a0","author":"init","version":0},{"n":21,"text":"/** shapes.js with area() moved out. */","atom":"a0","author":"init","version":0},{"n":22,"text":"const SHAPES_AFTER = lines(\"// shapes\", \"\", \"function other() {\", \"  return 1;\", \"}\");","atom":"a0","author":"init","version":0},{"n":23,"text":"","atom":"a0","author":"init","version":0},{"n":24,"text":"/** Move area() (shapes.js lines 1-4) to the end of geometry.js. */","atom":"a0","author":"init","version":0},{"n":25,"text":"function moveArea(repo: Repo, against?: Iterable<AtomId>): Atom {","atom":"a0","author":"init","version":0},{"n":26,"text":"\treturn repo.draft({ move: { file: \"shapes.js\", start: 1, end: 5, to: \"geometry.js\", at: 2 } }, against);","atom":"a0","author":"init","version":0},{"n":27,"text":"}","atom":"a0","author":"init","version":0},{"n":28,"text":"","atom":"a0","author":"init","version":0},{"n":29,"text":"function accept(repo: Repo, atom: Atom): Atom {","atom":"a0","author":"init","version":0},{"n":30,"text":"\trepo.graph.add(atom);","atom":"a0","author":"init","version":0},{"n":31,"text":"\trepo.shared.add(atom.id);","atom":"a0","author":"init","version":0},{"n":32,"text":"\treturn atom;","atom":"a0","author":"init","version":0},{"n":33,"text":"}","atom":"a0","author":"init","version":0},{"n":34,"text":"","atom":"a0","author":"init","version":0},{"n":35,"text":"/** Two atoms built against the same base, both accepted: the merge. */","atom":"a0","author":"init","version":0},{"n":36,"text":"function concurrently(","atom":"a0","author":"init","version":0},{"n":37,"text":"\trepo: Repo,","atom":"a0","author":"init","version":0},{"n":38,"text":"\ta: (base: AtomId[]) => Atom,","atom":"a0","author":"init","version":0},{"n":39,"text":"\tb: (base: AtomId[]) => Atom,","atom":"a0","author":"init","version":0},{"n":40,"text":"): { first: Atom; second: Atom } {","atom":"a0","author":"init","version":0},{"n":41,"text":"\tconst base = [...repo.shared];","atom":"a0","author":"init","version":0},{"n":42,"text":"\tconst first = accept(repo, a(base));","atom":"a0","author":"init","version":0},{"n":43,"text":"\tconst second = accept(repo, b(base));","atom":"a0","author":"init","version":0},{"n":44,"text":"\treturn { first, second };","atom":"a0","author":"init","version":0},{"n":45,"text":"}","atom":"a0","author":"init","version":0},{"n":46,"text":"","atom":"a0","author":"init","version":0},{"n":47,"text":"describe(\"moves\", () => {","atom":"a0","author":"init","version":0},{"n":48,"text":"\tit(\"moves lines to another file, keeping their ids\", () => {","atom":"a0","author":"init","version":0},{"n":49,"text":"\t\tconst repo = Repo.init(START);","atom":"a0","author":"init","version":0},{"n":50,"text":"\t\tconst before = repo","atom":"a0","author":"init","version":0},{"n":51,"text":"\t\t\t.view()","atom":"a0","author":"init","version":0},{"n":52,"text":"\t\t\t.lines(\"shapes.js\")","atom":"a0","author":"init","version":0},{"n":53,"text":"\t\t\t.slice(1, 5)","atom":"a0","author":"init","version":0},{"n":54,"text":"\t\t\t.map((l) => l.id);","atom":"a0","author":"init","version":0},{"n":55,"text":"\t\taccept(repo, moveArea(repo));","atom":"a0","author":"init","version":0},{"n":56,"text":"\t\tassert.equal(repo.text(\"shapes.js\"), SHAPES_AFTER);","atom":"a0","author":"init","version":0},{"n":57,"text":"\t\tassert.equal(repo.text(\"geometry.js\"), lines(\"// geometry\", \"export {};\", ...FN));","atom":"a0","author":"init","version":0},{"n":58,"text":"\t\tconst view = repo.view();","atom":"a0","author":"init","version":0},{"n":59,"text":"\t\tassert.deepEqual(","atom":"a0","author":"init","version":0},{"n":60,"text":"\t\t\tview","atom":"a0","author":"init","version":0},{"n":61,"text":"\t\t\t\t.lines(\"geometry.js\")","atom":"a0","author":"init","version":0},{"n":62,"text":"\t\t\t\t.slice(2)","atom":"a0","author":"init","version":0},{"n":63,"text":"\t\t\t\t.map((l) => l.id),","atom":"a0","author":"init","version":0},{"n":64,"text":"\t\t\tbefore,","atom":"a0","author":"init","version":0},{"n":65,"text":"\t\t);","atom":"a0","author":"init","version":0},{"n":66,"text":"\t\tassert.equal(view.fileOf(before[2]!), \"geometry.js\");","atom":"a0","author":"init","version":0},{"n":67,"text":"\t});","atom":"a0","author":"init","version":0},{"n":68,"text":"","atom":"a0","author":"init","version":0},{"n":69,"text":"\tit(\"an edit made before the move, to the body, the first line or the last line, follows the moved lines\", () => {","atom":"a0","author":"init","version":0},{"n":70,"text":"\t\tfor (const [old, now] of [","atom":"a0","author":"init","version":0},{"n":71,"text":"\t\t\t[\"  return pi * r * r;\", \"  return pi * r ** 2;\"],","atom":"a0","author":"init","version":0},{"n":72,"text":"\t\t\t[\"function area(r) {\", \"function area(r = 1) {\"],","atom":"a0","author":"init","version":0},{"n":73,"text":"\t\t\t[\"}\\n\\nfunction other\", \"} // area\\n\\nfunction other\"],","atom":"a0","author":"init","version":0},{"n":74,"text":"\t\t] as const) {","atom":"a0","author":"init","version":0},{"n":75,"text":"\t\t\tconst repo = Repo.init(START);","atom":"a0","author":"init","version":0},{"n":76,"text":"\t\t\tconcurrently(","atom":"a0","author":"init","version":0},{"n":77,"text":"\t\t\t\trepo,","atom":"a0","author":"init","version":0},{"n":78,"text":"\t\t\t\t(base) => repo.draft({ edits: [{ file: \"shapes.js\", old, new: now }] }, base),","atom":"a0","author":"init","version":0},{"n":79,"text":"\t\t\t\t(base) => moveArea(repo, base),","atom":"a0","author":"init","version":0},{"n":80,"text":"\t\t\t);","atom":"a0","author":"init","version":0},{"n":81,"text":"\t\t\tassert.deepEqual(conflicts(repo.graph, repo.shared), [], old);","atom":"a0","author":"init","version":0},{"n":82,"text":"\t\t\tassert.equal(repo.text(\"shapes.js\"), SHAPES_AFTER, old);","atom":"a0","author":"init","version":0},{"n":83,"text":"\t\t\tconst fn = FN.map((l) => (l === old.split(\"\\n\")[0] ? now.split(\"\\n\")[0]! : l));","atom":"a0","author":"init","version":0},{"n":84,"text":"\t\t\tassert.equal(repo.text(\"geometry.js\"), lines(\"// geometry\", \"export {};\", ...fn), old);","atom":"a0","author":"init","version":0},{"n":85,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":86,"text":"\t});","atom":"a0","author":"init","version":0},{"n":87,"text":"","atom":"a0","author":"init","version":0},{"n":88,"text":"\tit(\"an edit made after the move, against a view without it, follows too (either order is the same set)\", () => {","atom":"a0","author":"init","version":0},{"n":89,"text":"\t\tconst repo = Repo.init(START);","atom":"a0","author":"init","version":0},{"n":90,"text":"\t\tconcurrently(","atom":"a0","author":"init","version":0},{"n":91,"text":"\t\t\trepo,","atom":"a0","author":"init","version":0},{"n":92,"text":"\t\t\t(base) => moveArea(repo, base),","atom":"a0","author":"init","version":0},{"n":93,"text":"\t\t\t(base) =>","atom":"a0","author":"init","version":0},{"n":94,"text":"\t\t\t\trepo.draft({ edits: [{ file: \"shapes.js\", old: \"  const pi = 3.14;\", new: \"  const pi = Math.PI;\" }] }, base),","atom":"a0","author":"init","version":0},{"n":95,"text":"\t\t);","atom":"a0","author":"init","version":0},{"n":96,"text":"\t\tassert.deepEqual(conflicts(repo.graph, repo.shared), []);","atom":"a0","author":"init","version":0},{"n":97,"text":"\t\tassert.equal(","atom":"a0","author":"init","version":0},{"n":98,"text":"\t\t\trepo.text(\"geometry.js\"),","atom":"a0","author":"init","version":0},{"n":99,"text":"\t\t\tlines(\"// geometry\", \"export {};\", \"function area(r) {\", \"  const pi = Math.PI;\", \"  return pi * r * r;\", \"}\"),","atom":"a0","author":"init","version":0},{"n":100,"text":"\t\t);","atom":"a0","author":"init","version":0},{"n":101,"text":"\t});","atom":"a0","author":"init","version":0},{"n":102,"text":"","atom":"a0","author":"init","version":0},{"n":103,"text":"\tit(\"lines inserted inside the moved block go with it\", () => {","atom":"a0","author":"init","version":0},{"n":104,"text":"\t\tconst repo = Repo.init(START);","atom":"a0","author":"init","version":0},{"n":105,"text":"\t\tconcurrently(","atom":"a0","author":"init","version":0},{"n":106,"text":"\t\t\trepo,","atom":"a0","author":"init","version":0},{"n":107,"text":"\t\t\t(base) =>","atom":"a0","author":"init","version":0},{"n":108,"text":"\t\t\t\trepo.draft(","atom":"a0","author":"init","version":0},{"n":109,"text":"\t\t\t\t\t{","atom":"a0","author":"init","version":0},{"n":110,"text":"\t\t\t\t\t\tedits: [","atom":"a0","author":"init","version":0},{"n":111,"text":"\t\t\t\t\t\t\t{ file: \"shapes.js\", old: \"  const pi = 3.14;\\n\", new: \"  const pi = 3.14;\\n  // area of a circle\\n\" },","atom":"a0","author":"init","version":0},{"n":112,"text":"\t\t\t\t\t\t],","atom":"a0","author":"init","version":0},{"n":113,"text":"\t\t\t\t\t},","atom":"a0","author":"init","version":0},{"n":114,"text":"\t\t\t\t\tbase,","atom":"a0","author":"init","version":0},{"n":115,"text":"\t\t\t\t),","atom":"a0","author":"init","version":0},{"n":116,"text":"\t\t\t(base) => moveArea(repo, base),","atom":"a0","author":"init","version":0},{"n":117,"text":"\t\t);","atom":"a0","author":"init","version":0},{"n":118,"text":"\t\tassert.deepEqual(conflicts(repo.graph, repo.shared), []);","atom":"a0","author":"init","version":0},{"n":119,"text":"\t\tassert.equal(repo.text(\"shapes.js\"), SHAPES_AFTER);","atom":"a0","author":"init","version":0},{"n":120,"text":"\t\tassert.match(repo.text(\"geometry.js\"), /const pi = 3\\.14;\\n {2}\\/\\/ area of a circle\\n/);","atom":"a0","author":"init","version":0},{"n":121,"text":"\t});","atom":"a0","author":"init","version":0},{"n":122,"text":"","atom":"a0","author":"init","version":0},{"n":123,"text":"\tit(\"inserting just above the moved block collides with the move: it is unclear which place the line meant\", () => {","atom":"a0","author":"init","version":0},{"n":124,"text":"\t\tconst repo = Repo.init(START);","atom":"a0","author":"init","version":0},{"n":125,"text":"\t\tconcurrently(","atom":"a0","author":"init","version":0},{"n":126,"text":"\t\t\trepo,","atom":"a0","author":"init","version":0},{"n":127,"text":"\t\t\t(base) =>","atom":"a0","author":"init","version":0},{"n":128,"text":"\t\t\t\trepo.draft({ edits: [{ file: \"shapes.js\", start: 1, end: 1, lines: [\"/** The area of a circle. */\"] }] }, base),","atom":"a0","author":"init","version":0},{"n":129,"text":"\t\t\t(base) => moveArea(repo, base),","atom":"a0","author":"init","version":0},{"n":130,"text":"\t\t);","atom":"a0","author":"init","version":0},{"n":131,"text":"\t\tassert.equal(conflicts(repo.graph, repo.shared).length, 1);","atom":"a0","author":"init","version":0},{"n":132,"text":"\t});","atom":"a0","author":"init","version":0},{"n":133,"text":"","atom":"a0","author":"init","version":0},{"n":134,"text":"\tit(\"a line deleted at its old place is deleted at its new one, with no collision\", () => {","atom":"a0","author":"init","version":0},{"n":135,"text":"\t\tconst repo = Repo.init(START);","atom":"a0","author":"init","version":0},{"n":136,"text":"\t\tconcurrently(","atom":"a0","author":"init","version":0},{"n":137,"text":"\t\t\trepo,","atom":"a0","author":"init","version":0},{"n":138,"text":"\t\t\t(base) => repo.draft({ edits: [{ file: \"shapes.js\", old: `${FN.join(\"\\n\")}\\n`, new: \"\" }] }, base),","atom":"a700","author":"pinch","version":78},{"n":139,"text":"\t\t\t(base) => moveArea(repo, base),","atom":"a0","author":"init","version":0},{"n":140,"text":"\t\t);","atom":"a0","author":"init","version":0},{"n":141,"text":"\t\tassert.deepEqual(conflicts(repo.graph, repo.shared), []);","atom":"a0","author":"init","version":0},{"n":142,"text":"\t\tassert.equal(repo.text(\"shapes.js\"), SHAPES_AFTER);","atom":"a0","author":"init","version":0},{"n":143,"text":"\t\tassert.equal(repo.text(\"geometry.js\"), lines(\"// geometry\", \"export {};\"));","atom":"a0","author":"init","version":0},{"n":144,"text":"\t});","atom":"a0","author":"init","version":0},{"n":145,"text":"","atom":"a0","author":"init","version":0},{"n":146,"text":"\tit(\"two moves of the same lines collide\", () => {","atom":"a0","author":"init","version":0},{"n":147,"text":"\t\tconst repo = Repo.init(START);","atom":"a0","author":"init","version":0},{"n":148,"text":"\t\tconcurrently(","atom":"a0","author":"init","version":0},{"n":149,"text":"\t\t\trepo,","atom":"a0","author":"init","version":0},{"n":150,"text":"\t\t\t(base) => moveArea(repo, base),","atom":"a0","author":"init","version":0},{"n":151,"text":"\t\t\t(base) => repo.draft({ move: { file: \"shapes.js\", start: 1, end: 5, to: \"shapes.js\", at: 9 } }, base),","atom":"a0","author":"init","version":0},{"n":152,"text":"\t\t);","atom":"a0","author":"init","version":0},{"n":153,"text":"\t\tconst found = conflicts(repo.graph, repo.shared);","atom":"a0","author":"init","version":0},{"n":154,"text":"\t\tassert.equal(found.length, 1);","atom":"a0","author":"init","version":0},{"n":155,"text":"\t\tassert.ok(found[0]!.keys.some((k) => k.key.startsWith(\"P:\")));","atom":"a0","author":"init","version":0},{"n":156,"text":"\t});","atom":"a0","author":"init","version":0},{"n":157,"text":"","atom":"a0","author":"init","version":0},{"n":158,"text":"\tit(\"a whole file renamed: every line moves, and an edit to it lands in the new file\", () => {","atom":"a0","author":"init","version":0},{"n":159,"text":"\t\tconst repo = Repo.init(START);","atom":"a0","author":"init","version":0},{"n":160,"text":"\t\tconcurrently(","atom":"a0","author":"init","version":0},{"n":161,"text":"\t\t\trepo,","atom":"a0","author":"init","version":0},{"n":162,"text":"\t\t\t(base) => repo.draft({ edits: [{ file: \"shapes.js\", old: \"  return 1;\", new: \"  return 2;\" }] }, base),","atom":"a0","author":"init","version":0},{"n":163,"text":"\t\t\t(base) => repo.draft({ move: { file: \"shapes.js\", start: 0, end: 9, to: \"circle.js\", at: 0 } }, base),","atom":"a0","author":"init","version":0},{"n":164,"text":"\t\t);","atom":"a0","author":"init","version":0},{"n":165,"text":"\t\tassert.deepEqual(conflicts(repo.graph, repo.shared), []);","atom":"a0","author":"init","version":0},{"n":166,"text":"\t\tconst view = repo.view();","atom":"a0","author":"init","version":0},{"n":167,"text":"\t\tassert.equal(view.hasFile(\"shapes.js\"), false);","atom":"a0","author":"init","version":0},{"n":168,"text":"\t\tassert.equal(view.text(\"circle.js\"), START[\"shapes.js\"].replace(\"return 1;\", \"return 2;\"));","atom":"a0","author":"init","version":0},{"n":169,"text":"\t\tassert.deepEqual(view.paths(), [\"circle.js\", \"geometry.js\"]);","atom":"a0","author":"init","version":0},{"n":170,"text":"\t});","atom":"a0","author":"init","version":0},{"n":171,"text":"","atom":"a0","author":"init","version":0},{"n":172,"text":"\tit(\"a block moved within a file, up or down, with a concurrent edit inside it\", () => {","atom":"a0","author":"init","version":0},{"n":173,"text":"\t\tfor (const at of [0, 9]) {","atom":"a0","author":"init","version":0},{"n":174,"text":"\t\t\tconst repo = Repo.init(START);","atom":"a0","author":"init","version":0},{"n":175,"text":"\t\t\tconcurrently(","atom":"a0","author":"init","version":0},{"n":176,"text":"\t\t\t\trepo,","atom":"a0","author":"init","version":0},{"n":177,"text":"\t\t\t\t(base) =>","atom":"a0","author":"init","version":0},{"n":178,"text":"\t\t\t\t\trepo.draft(","atom":"a0","author":"init","version":0},{"n":179,"text":"\t\t\t\t\t\t{ edits: [{ file: \"shapes.js\", old: \"  return pi * r * r;\", new: \"  return pi * r * r; // m^2\" }] },","atom":"a0","author":"init","version":0},{"n":180,"text":"\t\t\t\t\t\tbase,","atom":"a0","author":"init","version":0},{"n":181,"text":"\t\t\t\t\t),","atom":"a0","author":"init","version":0},{"n":182,"text":"\t\t\t\t(base) => repo.draft({ move: { file: \"shapes.js\", start: 1, end: 5, to: \"shapes.js\", at } }, base),","atom":"a0","author":"init","version":0},{"n":183,"text":"\t\t\t);","atom":"a0","author":"init","version":0},{"n":184,"text":"\t\t\tassert.deepEqual(conflicts(repo.graph, repo.shared), []);","atom":"a0","author":"init","version":0},{"n":185,"text":"\t\t\tconst fn = lines(...FN).replace(\"r * r;\", \"r * r; // m^2\");","atom":"a0","author":"init","version":0},{"n":186,"text":"\t\t\tassert.equal(repo.text(\"shapes.js\"), at === 0 ? fn + SHAPES_AFTER : SHAPES_AFTER + fn);","atom":"a0","author":"init","version":0},{"n":187,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":188,"text":"\t});","atom":"a0","author":"init","version":0},{"n":189,"text":"","atom":"a0","author":"init","version":0},{"n":190,"text":"\tit(\"a file split in two: edits to either part, made apart, land in the right file\", () => {","atom":"a0","author":"init","version":0},{"n":191,"text":"\t\tconst repo = Repo.init(START);","atom":"a0","author":"init","version":0},{"n":192,"text":"\t\tconst base = [...repo.shared];","atom":"a0","author":"init","version":0},{"n":193,"text":"\t\taccept(repo, repo.draft({ move: { file: \"shapes.js\", start: 5, end: 9, to: \"other.js\", at: 0 } }, base));","atom":"a0","author":"init","version":0},{"n":194,"text":"\t\taccept(repo, repo.draft({ edits: [{ file: \"shapes.js\", old: \"3.14\", new: \"Math.PI\" }] }, base));","atom":"a0","author":"init","version":0},{"n":195,"text":"\t\taccept(repo, repo.draft({ edits: [{ file: \"shapes.js\", old: \"return 1;\", new: \"return 2;\" }] }, base));","atom":"a0","author":"init","version":0},{"n":196,"text":"\t\tassert.deepEqual(conflicts(repo.graph, repo.shared), []);","atom":"a0","author":"init","version":0},{"n":197,"text":"\t\tassert.equal(repo.text(\"shapes.js\"), lines(\"// shapes\", ...FN).replace(\"3.14\", \"Math.PI\"));","atom":"a0","author":"init","version":0},{"n":198,"text":"\t\tassert.equal(repo.text(\"other.js\"), lines(\"\", \"function other() {\", \"  return 2;\", \"}\"));","atom":"a0","author":"init","version":0},{"n":199,"text":"\t});","atom":"a0","author":"init","version":0},{"n":200,"text":"","atom":"a0","author":"init","version":0},{"n":201,"text":"\tit(\"two files merged into one: the second file's lines move under the end of the first, and edits follow\", () => {","atom":"a0","author":"init","version":0},{"n":202,"text":"\t\tconst repo = Repo.init(START);","atom":"a0","author":"init","version":0},{"n":203,"text":"\t\tconst base = [...repo.shared];","atom":"a0","author":"init","version":0},{"n":204,"text":"\t\taccept(repo, repo.draft({ move: { file: \"geometry.js\", start: 0, end: 2, to: \"shapes.js\", at: 9 } }, base));","atom":"a0","author":"init","version":0},{"n":205,"text":"\t\taccept(repo, repo.draft({ edits: [{ file: \"geometry.js\", old: \"export {};\", new: \"export { area };\" }] }, base));","atom":"a0","author":"init","version":0},{"n":206,"text":"\t\tassert.deepEqual(conflicts(repo.graph, repo.shared), []);","atom":"a0","author":"init","version":0},{"n":207,"text":"\t\tassert.equal(repo.view().hasFile(\"geometry.js\"), false);","atom":"a0","author":"init","version":0},{"n":208,"text":"\t\tassert.equal(repo.text(\"shapes.js\"), START[\"shapes.js\"] + lines(\"// geometry\", \"export { area };\"));","atom":"a0","author":"init","version":0},{"n":209,"text":"\t});","atom":"a0","author":"init","version":0},{"n":210,"text":"","atom":"a0","author":"init","version":0},{"n":211,"text":"\tit(\"moves stack: a moved block can move again, and a later edit follows both\", () => {","atom":"a0","author":"init","version":0},{"n":212,"text":"\t\tconst repo = Repo.init(START);","atom":"a0","author":"init","version":0},{"n":213,"text":"\t\taccept(repo, moveArea(repo));","atom":"a0","author":"init","version":0},{"n":214,"text":"\t\trepo.edit({ move: { file: \"geometry.js\", start: 2, end: 6, to: \"circle.js\", at: 0 } });","atom":"a0","author":"init","version":0},{"n":215,"text":"\t\trepo.edit({ edits: [{ file: \"circle.js\", old: \"3.14\", new: \"3.14159\" }] });","atom":"a0","author":"init","version":0},{"n":216,"text":"\t\tassert.equal(repo.text(\"circle.js\"), lines(...FN).replace(\"3.14\", \"3.14159\"));","atom":"a0","author":"init","version":0},{"n":217,"text":"\t\tassert.equal(repo.text(\"geometry.js\"), lines(\"// geometry\", \"export {};\"));","atom":"a0","author":"init","version":0},{"n":218,"text":"\t\tassert.equal(repo.text(\"shapes.js\"), SHAPES_AFTER);","atom":"a0","author":"init","version":0},{"n":219,"text":"\t});","atom":"a0","author":"init","version":0},{"n":220,"text":"","atom":"a0","author":"init","version":0},{"n":221,"text":"\tit(\"moves that loop lines into each other lose no lines\", () => {","atom":"a0","author":"init","version":0},{"n":222,"text":"\t\t// Hand-made: two moves made apart, each putting one line under the other.","atom":"a0","author":"init","version":0},{"n":223,"text":"\t\tconst repo = Repo.init({ \"f.txt\": lines(\"x\", \"m\", \"y\", \"n\") });","atom":"a0","author":"init","version":0},{"n":224,"text":"\t\tconst mk = (line: string, parent: string): Atom => {","atom":"a0","author":"init","version":0},{"n":225,"text":"\t\t\tconst id = repo.graph.nextId();","atom":"a0","author":"init","version":0},{"n":226,"text":"\t\t\treturn {","atom":"a0","author":"init","version":0},{"n":227,"text":"\t\t\t\tid,","atom":"a0","author":"init","version":0},{"n":228,"text":"\t\t\t\tseq: repo.graph.size,","atom":"a0","author":"init","version":0},{"n":229,"text":"\t\t\t\tauthor: \"a\",","atom":"a0","author":"init","version":0},{"n":230,"text":"\t\t\t\tmessage: \"loop\",","atom":"a0","author":"init","version":0},{"n":231,"text":"\t\t\t\ttime: 0,","atom":"a0","author":"init","version":0},{"n":232,"text":"\t\t\t\tinserts: [],","atom":"a0","author":"init","version":0},{"n":233,"text":"\t\t\t\tdeletes: [],","atom":"a0","author":"init","version":0},{"n":234,"text":"\t\t\t\twrites: [`G:${parent}`, `P:${line}`],","atom":"a0","author":"init","version":0},{"n":235,"text":"\t\t\t\treads: [],","atom":"a0","author":"init","version":0},{"n":236,"text":"\t\t\t\tholds: [],","atom":"a0","author":"init","version":0},{"n":237,"text":"\t\t\t\tneeds: [],","atom":"a0","author":"init","version":0},{"n":238,"text":"\t\t\t\tresolves: [],","atom":"a0","author":"init","version":0},{"n":239,"text":"\t\t\t\treasons: [],","atom":"a0","author":"init","version":0},{"n":240,"text":"\t\t\t\tdeps: [\"a0\"],","atom":"a0","author":"init","version":0},{"n":241,"text":"\t\t\t\tmoves: [{ line, parent }],","atom":"a0","author":"init","version":0},{"n":242,"text":"\t\t\t};","atom":"a0","author":"init","version":0},{"n":243,"text":"\t\t};","atom":"a0","author":"init","version":0},{"n":244,"text":"\t\taccept(repo, mk(\"a0.0\", \"a0.2\"));","atom":"a0","author":"init","version":0},{"n":245,"text":"\t\taccept(repo, mk(\"a0.2\", \"a0.0\"));","atom":"a0","author":"init","version":0},{"n":246,"text":"\t\tconst text = repo.text(\"f.txt\");","atom":"a0","author":"init","version":0},{"n":247,"text":"\t\tassert.deepEqual(text.split(\"\\n\").filter(Boolean).sort(), [\"m\", \"n\", \"x\", \"y\"]);","atom":"a0","author":"init","version":0},{"n":248,"text":"\t\tclass BoundedReads extends SqlState {","atom":"a1074","author":"codex-capacity-chair","version":126},{"n":249,"text":"\t\t\toverride read(collection: string, key: string): unknown {","atom":"a1074","author":"codex-capacity-chair","version":126},{"n":250,"text":"\t\t\t\tif (this.reads > 10_000) throw new Error(\"relocation cycle did not terminate\");","atom":"a1074","author":"codex-capacity-chair","version":126},{"n":251,"text":"\t\t\t\treturn super.read(collection, key);","atom":"a1074","author":"codex-capacity-chair","version":126},{"n":252,"text":"\t\t\t}","atom":"a1074","author":"codex-capacity-chair","version":126},{"n":253,"text":"\t\t}","atom":"a1074","author":"codex-capacity-chair","version":126},{"n":254,"text":"\t\tconst storage = new BoundedReads();","atom":"a1074","author":"codex-capacity-chair","version":126},{"n":255,"text":"\t\ttry {","atom":"a1074","author":"codex-capacity-chair","version":126},{"n":256,"text":"\t\t\tconst stored = new Graph({ storage });","atom":"a1074","author":"codex-capacity-chair","version":126},{"n":257,"text":"\t\t\tfor (let seq = 0; seq < repo.graph.size; seq++) stored.add(repo.graph.atom(repo.graph.idOfSeq(seq)));","atom":"a1074","author":"codex-capacity-chair","version":126},{"n":258,"text":"\t\t\tconst reopened = new Graph({ storage });","atom":"a1074","author":"codex-capacity-chair","version":126},{"n":259,"text":"\t\t\tassert.equal(new View(reopened, repo.shared).text(\"f.txt\"), text);","atom":"a1074","author":"codex-capacity-chair","version":126},{"n":260,"text":"\t\t\tassert.equal(new View(reopened, new StableOverlaySet(repo.shared)).text(\"f.txt\"), text);","atom":"a1074","author":"codex-capacity-chair","version":126},{"n":261,"text":"\t\t} finally {","atom":"a1074","author":"codex-capacity-chair","version":126},{"n":262,"text":"\t\t\tstorage.db.close();","atom":"a1074","author":"codex-capacity-chair","version":126},{"n":263,"text":"\t\t}","atom":"a1074","author":"codex-capacity-chair","version":126},{"n":264,"text":"\t});","atom":"a0","author":"init","version":0},{"n":265,"text":"","atom":"a0","author":"init","version":0},{"n":266,"text":"\tit(\"rejects a move onto itself or out of range\", () => {","atom":"a0","author":"init","version":0},{"n":267,"text":"\t\tconst repo = Repo.init(START);","atom":"a0","author":"init","version":0},{"n":268,"text":"\t\tassert.throws(() => repo.draft({ move: { file: \"shapes.js\", start: 1, end: 5, to: \"shapes.js\", at: 3 } }), {","atom":"a0","author":"init","version":0},{"n":269,"text":"\t\t\tcode: \"bad-range\",","atom":"a0","author":"init","version":0},{"n":270,"text":"\t\t});","atom":"a0","author":"init","version":0},{"n":271,"text":"\t\tassert.throws(() => repo.draft({ move: { file: \"shapes.js\", start: 1, end: 5, to: \"shapes.js\", at: 5 } }), {","atom":"a0","author":"init","version":0},{"n":272,"text":"\t\t\tcode: \"bad-range\",","atom":"a0","author":"init","version":0},{"n":273,"text":"\t\t});","atom":"a0","author":"init","version":0},{"n":274,"text":"\t\tassert.throws(() => repo.draft({ move: { file: \"shapes.js\", start: 4, end: 4, to: \"x.js\", at: 0 } }), {","atom":"a0","author":"init","version":0},{"n":275,"text":"\t\t\tcode: \"bad-range\",","atom":"a0","author":"init","version":0},{"n":276,"text":"\t\t});","atom":"a0","author":"init","version":0},{"n":277,"text":"\t\tassert.throws(() => repo.draft({ move: { file: \"shapes.js\", start: 1, end: 2, to: \"geometry.js\", at: 3 } }), {","atom":"a0","author":"init","version":0},{"n":278,"text":"\t\t\tcode: \"bad-range\",","atom":"a0","author":"init","version":0},{"n":279,"text":"\t\t});","atom":"a0","author":"init","version":0},{"n":280,"text":"\t\tassert.throws(","atom":"a0","author":"init","version":0},{"n":281,"text":"\t\t\t() =>","atom":"a0","author":"init","version":0},{"n":282,"text":"\t\t\t\trepo.draft({","atom":"a0","author":"init","version":0},{"n":283,"text":"\t\t\t\t\tmove: { file: \"shapes.js\", start: 1, end: 2, to: \"x.js\", at: 0 },","atom":"a0","author":"init","version":0},{"n":284,"text":"\t\t\t\t\tedits: [{ file: \"geometry.js\", old: \"export\", new: \"x\" }],","atom":"a0","author":"init","version":0},{"n":285,"text":"\t\t\t\t}),","atom":"a0","author":"init","version":0},{"n":286,"text":"\t\t\t{ code: \"bad-edit\" },","atom":"a0","author":"init","version":0},{"n":287,"text":"\t\t);","atom":"a0","author":"init","version":0},{"n":288,"text":"\t});","atom":"a0","author":"init","version":0},{"n":289,"text":"});","atom":"a0","author":"init","version":0},{"n":290,"text":"","atom":"a0","author":"init","version":0},{"n":291,"text":"describe(\"moves, property\", () => {","atom":"a0","author":"init","version":0},{"n":292,"text":"\tconst word = (rng: Rng): string =>","atom":"a0","author":"init","version":0},{"n":293,"text":"\t\trng.pick([\"a\", \"b\", \"c\", \"x\", \"y\", \"}\", \"\", \"let q = 1;\", \"return z;\"]) +","atom":"a0","author":"init","version":0},{"n":294,"text":"\t\t(rng.chance(0.5) ? String(rng.int(9)) : \"\");","atom":"a0","author":"init","version":0},{"n":295,"text":"","atom":"a0","author":"init","version":0},{"n":296,"text":"\tit(\"random edits and moves, one after another, agree with editing plain text\", () => {","atom":"a0","author":"init","version":0},{"n":297,"text":"\t\tfor (let c = 0; c < CASES; c++) {","atom":"a0","author":"init","version":0},{"n":298,"text":"\t\t\tconst seed = BASE_SEED + c;","atom":"a0","author":"init","version":0},{"n":299,"text":"\t\t\tconst rng = new Rng(seed);","atom":"a0","author":"init","version":0},{"n":300,"text":"\t\t\tconst names = [\"a.txt\", \"b.txt\", \"c.txt\"];","atom":"a0","author":"init","version":0},{"n":301,"text":"\t\t\tconst plain: Record<string, string[]> = {};","atom":"a0","author":"init","version":0},{"n":302,"text":"\t\t\tconst files: Record<string, string> = {};","atom":"a0","author":"init","version":0},{"n":303,"text":"\t\t\tfor (const f of names.slice(0, 2)) {","atom":"a0","author":"init","version":0},{"n":304,"text":"\t\t\t\tplain[f] = Array.from({ length: rng.range(1, 8) }, () => word(rng));","atom":"a0","author":"init","version":0},{"n":305,"text":"\t\t\t\tfiles[f] = lines(...plain[f]!);","atom":"a0","author":"init","version":0},{"n":306,"text":"\t\t\t}","atom":"a0","author":"init","version":0},{"n":307,"text":"\t\t\tplain[\"c.txt\"] = [];","atom":"a0","author":"init","version":0},{"n":308,"text":"\t\t\tconst repo = Repo.init(files);","atom":"a0","author":"init","version":0},{"n":309,"text":"\t\t\tfor (let step = 0; step < 12; step++) {","atom":"a0","author":"init","version":0},{"n":310,"text":"\t\t\t\tconst from = rng.pick(names.filter((f) => plain[f]!.length > 0));","atom":"a0","author":"init","version":0},{"n":311,"text":"\t\t\t\tconst n = plain[from]!.length;","atom":"a0","author":"init","version":0},{"n":312,"text":"\t\t\t\tif (rng.chance(0.5)) {","atom":"a0","author":"init","version":0},{"n":313,"text":"\t\t\t\t\tconst start = rng.int(n);","atom":"a0","author":"init","version":0},{"n":314,"text":"\t\t\t\t\tconst end = rng.range(start + 1, n);","atom":"a0","author":"init","version":0},{"n":315,"text":"\t\t\t\t\tconst to = rng.pick(names);","atom":"a0","author":"init","version":0},{"n":316,"text":"\t\t\t\t\tconst len = plain[to]!.length;","atom":"a0","author":"init","version":0},{"n":317,"text":"\t\t\t\t\tlet at = rng.int(len + 1);","atom":"a0","author":"init","version":0},{"n":318,"text":"\t\t\t\t\tif (to === from && at >= start && at <= end)","atom":"a0","author":"init","version":0},{"n":319,"text":"\t\t\t\t\t\tat = start > 0 ? rng.int(start) : end < len ? rng.range(end + 1, len) : -1;","atom":"a0","author":"init","version":0},{"n":320,"text":"\t\t\t\t\tif (at < 0) continue;","atom":"a0","author":"init","version":0},{"n":321,"text":"\t\t\t\t\trepo.edit({ move: { file: from, start, end, to, at } });","atom":"a0","author":"init","version":0},{"n":322,"text":"\t\t\t\t\tconst block = plain[from]!.splice(start, end - start);","atom":"a0","author":"init","version":0},{"n":323,"text":"\t\t\t\t\tconst where = to === from && at > end ? at - block.length : at;","atom":"a0","author":"init","version":0},{"n":324,"text":"\t\t\t\t\tplain[to]!.splice(where, 0, ...block);","atom":"a0","author":"init","version":0},{"n":325,"text":"\t\t\t\t} else {","atom":"a0","author":"init","version":0},{"n":326,"text":"\t\t\t\t\tconst start = rng.int(n + 1);","atom":"a0","author":"init","version":0},{"n":327,"text":"\t\t\t\t\tconst end = rng.range(start, Math.min(n, start + 2));","atom":"a0","author":"init","version":0},{"n":328,"text":"\t\t\t\t\tconst add = Array.from({ length: rng.int(3) }, () => word(rng));","atom":"a0","author":"init","version":0},{"n":329,"text":"\t\t\t\t\tif (end - start === add.length && plain[from]!.slice(start, end).every((l, i) => l === add[i])) continue;","atom":"a0","author":"init","version":0},{"n":330,"text":"\t\t\t\t\trepo.edit({ edits: [{ file: from, start, end, lines: add }] });","atom":"a0","author":"init","version":0},{"n":331,"text":"\t\t\t\t\tplain[from]!.splice(start, end - start, ...add);","atom":"a0","author":"init","version":0},{"n":332,"text":"\t\t\t\t}","atom":"a0","author":"init","version":0},{"n":333,"text":"\t\t\t\tfor (const f of names) assert.equal(repo.text(f), lines(...plain[f]!), `seed ${seed}, step ${step}, ${f}`);","atom":"a0","author":"init","version":0},{"n":334,"text":"\t\t\t}","atom":"a0","author":"init","version":0},{"n":335,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":336,"text":"\t});","atom":"a0","author":"init","version":0},{"n":337,"text":"","atom":"a0","author":"init","version":0},{"n":338,"text":"\tit(\"a move and an edit inside the moved block, made apart, compose: the edited block lands at the new place\", () => {","atom":"a0","author":"init","version":0},{"n":339,"text":"\t\tfor (let c = 0; c < CASES; c++) {","atom":"a0","author":"init","version":0},{"n":340,"text":"\t\t\tconst seed = BASE_SEED + c;","atom":"a0","author":"init","version":0},{"n":341,"text":"\t\t\tconst rng = new Rng(seed);","atom":"a0","author":"init","version":0},{"n":342,"text":"\t\t\tconst a = Array.from({ length: rng.range(3, 10) }, (_, i) => `a${i}`);","atom":"a0","author":"init","version":0},{"n":343,"text":"\t\t\tconst b = Array.from({ length: rng.range(0, 4) }, (_, i) => `b${i}`);","atom":"a0","author":"init","version":0},{"n":344,"text":"\t\t\tconst repo = Repo.init(b.length ? { \"a.txt\": lines(...a), \"b.txt\": lines(...b) } : { \"a.txt\": lines(...a) });","atom":"a0","author":"init","version":0},{"n":345,"text":"\t\t\tconst start = rng.int(a.length);","atom":"a0","author":"init","version":0},{"n":346,"text":"\t\t\tconst end = rng.range(start + 1, a.length);","atom":"a0","author":"init","version":0},{"n":347,"text":"\t\t\tconst at = rng.int(b.length + 1);","atom":"a0","author":"init","version":0},{"n":348,"text":"\t\t\t// An edit that replaces at least one line of the block, staying inside it.","atom":"a0","author":"init","version":0},{"n":349,"text":"\t\t\tconst es = rng.range(start, end - 1);","atom":"a0","author":"init","version":0},{"n":350,"text":"\t\t\tconst ee = rng.range(es + 1, end);","atom":"a0","author":"init","version":0},{"n":351,"text":"\t\t\tconst add = Array.from({ length: rng.int(3) }, (_, i) => `new${i}`);","atom":"a0","author":"init","version":0},{"n":352,"text":"\t\t\tconcurrently(","atom":"a0","author":"init","version":0},{"n":353,"text":"\t\t\t\trepo,","atom":"a0","author":"init","version":0},{"n":354,"text":"\t\t\t\t(base) => repo.draft({ move: { file: \"a.txt\", start, end, to: \"b.txt\", at } }, base),","atom":"a0","author":"init","version":0},{"n":355,"text":"\t\t\t\t(base) => repo.draft({ edits: [{ file: \"a.txt\", start: es, end: ee, lines: add }] }, base),","atom":"a0","author":"init","version":0},{"n":356,"text":"\t\t\t);","atom":"a0","author":"init","version":0},{"n":357,"text":"\t\t\tconst msg = `seed ${seed}`;","atom":"a0","author":"init","version":0},{"n":358,"text":"\t\t\tassert.deepEqual(conflicts(repo.graph, repo.shared), [], msg);","atom":"a0","author":"init","version":0},{"n":359,"text":"\t\t\tconst block = [...a.slice(start, es), ...add, ...a.slice(ee, end)];","atom":"a0","author":"init","version":0},{"n":360,"text":"\t\t\tassert.equal(repo.text(\"a.txt\"), lines(...a.slice(0, start), ...a.slice(end)), msg);","atom":"a0","author":"init","version":0},{"n":361,"text":"\t\t\tassert.equal(repo.text(\"b.txt\"), lines(...b.slice(0, at), ...block, ...b.slice(at)), msg);","atom":"a0","author":"init","version":0},{"n":362,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":363,"text":"\t});","atom":"a0","author":"init","version":0},{"n":364,"text":"});","atom":"a0","author":"init","version":0}],"atoms":[{"atom":"a0","author":"init","message":"Start the project","time":1791506895507,"timeIso":"2026-10-09T00:48:15.507Z","publish":{"draft":null,"version":0,"agent":"init","message":"Start the project","time":1791506895507,"timeIso":"2026-10-09T00:48:15.507Z"}},{"atom":"a700","author":"pinch","message":"","time":1791611690170,"timeIso":"2026-10-10T05:54:50.170Z","publish":{"draft":null,"version":78,"agent":"pinch","message":"Biome is silent: about 90 hints cleared. String joins as templates, dotted keys, unused imports, variables and a private method removed, optional chains (one kept boolean with === true), the preset field instead of the deprecated recommended. Two rules off where they don't fit: noExplicitAny in the hook modules, whose engine types come from the host, and noTemplateCurlyInString in tests, which hold source text as data.","time":1791612106058,"timeIso":"2026-10-10T06:01:46.058Z"}},{"atom":"a1074","author":"codex-capacity-chair","message":"","time":1791837487244,"timeIso":"2026-10-12T20:38:07.244Z","publish":{"draft":null,"version":126,"agent":"codex-capacity-chair","message":"Identify suppressed relocation cycles across persistent reads","time":1791837654331,"timeIso":"2026-10-12T20:40:54.331Z"}}]}