{"file":"src/engine/test/build.test.ts","version":318,"total":549,"from":1,"to":549,"lines":[{"n":1,"text":"// Building atoms from edits: matching, hunks, keys, modes, deps, errors.","atom":"a0","author":"init","version":0},{"n":2,"text":"","atom":"a0","author":"init","version":0},{"n":3,"text":"import assert from \"node:assert/strict\";","atom":"a0","author":"init","version":0},{"n":4,"text":"import { describe, it } from \"node:test\";","atom":"a0","author":"init","version":0},{"n":5,"text":"import {","atom":"a0","author":"init","version":0},{"n":6,"text":"\ttype Atom,","atom":"a0","author":"init","version":0},{"n":7,"text":"\tbuildAtom,","atom":"a0","author":"init","version":0},{"n":8,"text":"\tbuildBase,","atom":"a0","author":"init","version":0},{"n":9,"text":"\tcanonicalText,","atom":"a0","author":"init","version":0},{"n":10,"text":"\tcheckDraft,","atom":"a0","author":"init","version":0},{"n":11,"text":"\tconflicts,","atom":"a0","author":"init","version":0},{"n":12,"text":"\tdrop,","atom":"a0","author":"init","version":0},{"n":13,"text":"\tEngineError,","atom":"a0","author":"init","version":0},{"n":14,"text":"\tGraph,","atom":"a0","author":"init","version":0},{"n":15,"text":"\tgapKey,","atom":"a0","author":"init","version":0},{"n":16,"text":"\tlineKey,","atom":"a0","author":"init","version":0},{"n":17,"text":"\ttype Mode,","atom":"a0","author":"init","version":0},{"n":18,"text":"\tproject,","atom":"a0","author":"init","version":0},{"n":19,"text":"\tView,","atom":"a0","author":"init","version":0},{"n":20,"text":"} from \"../index.ts\";","atom":"a0","author":"init","version":0},{"n":21,"text":"import { lines, Repo, Rng } from \"./helpers.ts\";","atom":"a0","author":"init","version":0},{"n":22,"text":"","atom":"a0","author":"init","version":0},{"n":23,"text":"const FIVE = lines(\"one\", \"two\", \"three\", \"four\", \"five\");","atom":"a0","author":"init","version":0},{"n":24,"text":"","atom":"a0","author":"init","version":0},{"n":25,"text":"describe(\"replacement\", () => {","atom":"a0","author":"init","version":0},{"n":26,"text":"\tit(\"deletes the old lines, hangs the new ones off the last deleted line, and writes each deleted line\", () => {","atom":"a0","author":"init","version":0},{"n":27,"text":"\t\tconst repo = Repo.init({ \"f.txt\": FIVE });","atom":"a0","author":"init","version":0},{"n":28,"text":"\t\tconst atom = repo.edit({ edits: [{ file: \"f.txt\", old: \"two\\nthree\\n\", new: \"TWO\\nTHREE\\nextra\\n\" }] });","atom":"a0","author":"init","version":0},{"n":29,"text":"\t\tassert.deepEqual(atom.deletes, [\"a0.1\", \"a0.2\"]);","atom":"a0","author":"init","version":0},{"n":30,"text":"\t\tassert.deepEqual(atom.inserts, [{ file: \"f.txt\", parent: \"a0.2\", lines: [\"TWO\", \"THREE\", \"extra\"] }]);","atom":"a0","author":"init","version":0},{"n":31,"text":"\t\tassert.deepEqual(atom.writes, [lineKey(\"a0.1\"), lineKey(\"a0.2\")]);","atom":"a0","author":"init","version":0},{"n":32,"text":"\t\tassert.deepEqual(atom.reads, []);","atom":"a0","author":"init","version":0},{"n":33,"text":"\t\tassert.deepEqual(atom.holds, []);","atom":"a0","author":"init","version":0},{"n":34,"text":"\t\tassert.equal(repo.text(\"f.txt\"), lines(\"one\", \"TWO\", \"THREE\", \"extra\", \"four\", \"five\"));","atom":"a0","author":"init","version":0},{"n":35,"text":"\t});","atom":"a0","author":"init","version":0},{"n":36,"text":"","atom":"a0","author":"init","version":0},{"n":37,"text":"\tit(\"does not depend on the writer of the line below the last deleted one\", () => {","atom":"a0","author":"init","version":0},{"n":38,"text":"\t\tconst repo = Repo.init({ \"f.txt\": FIVE });","atom":"a0","author":"init","version":0},{"n":39,"text":"\t\tconst four = repo.edit({ edits: [{ file: \"f.txt\", old: \"four\", new: \"FOUR\" }] });","atom":"a0","author":"init","version":0},{"n":40,"text":"\t\t// Replacing two..three: the next visible line after \"three\" is four's replacement.","atom":"a0","author":"init","version":0},{"n":41,"text":"\t\tconst atom = repo.edit({ edits: [{ file: \"f.txt\", old: \"two\\nthree\\n\", new: \"x\\n\" }] });","atom":"a0","author":"init","version":0},{"n":42,"text":"\t\tassert.deepEqual(atom.deps, [\"a0\"]);","atom":"a0","author":"init","version":0},{"n":43,"text":"\t\tassert.equal(repo.text(\"f.txt\"), lines(\"one\", \"x\", \"FOUR\", \"five\"));","atom":"a0","author":"init","version":0},{"n":44,"text":"\t\t// Its closure has the old \"four\" below it, and dropping four's edit keeps it.","atom":"a0","author":"init","version":0},{"n":45,"text":"\t\tassert.equal(repo.text(\"f.txt\", repo.graph.closure(atom.id)), lines(\"one\", \"x\", \"four\", \"five\"));","atom":"a0","author":"init","version":0},{"n":46,"text":"\t\tassert.deepEqual(drop(repo.graph, repo.shared, four.id).removed, [four.id]);","atom":"a0","author":"init","version":0},{"n":47,"text":"\t});","atom":"a0","author":"init","version":0},{"n":48,"text":"","atom":"a0","author":"init","version":0},{"n":49,"text":"\tit(\"a deletion-only hunk inserts nothing and has no placement deps\", () => {","atom":"a0","author":"init","version":0},{"n":50,"text":"\t\tconst repo = Repo.init({ \"f.txt\": FIVE });","atom":"a0","author":"init","version":0},{"n":51,"text":"\t\trepo.edit({ edits: [{ file: \"f.txt\", old: \"four\", new: \"FOUR\" }] });","atom":"a0","author":"init","version":0},{"n":52,"text":"\t\tconst atom = repo.edit({ edits: [{ file: \"f.txt\", old: \"three\\n\", new: \"\" }] });","atom":"a0","author":"init","version":0},{"n":53,"text":"\t\tassert.deepEqual(atom.inserts, []);","atom":"a0","author":"init","version":0},{"n":54,"text":"\t\tassert.deepEqual(atom.deps, [\"a0\"]);","atom":"a0","author":"init","version":0},{"n":55,"text":"\t});","atom":"a0","author":"init","version":0},{"n":56,"text":"","atom":"a0","author":"init","version":0},{"n":57,"text":"\tit(\"claims only the lines the line diff changes, not unchanged context inside old\", () => {","atom":"a0","author":"init","version":0},{"n":58,"text":"\t\tconst repo = Repo.init({ \"f.txt\": FIVE });","atom":"a0","author":"init","version":0},{"n":59,"text":"\t\tconst atom = repo.edit({ edits: [{ file: \"f.txt\", old: \"two\\nthree\\nfour\\n\", new: \"TWO\\nthree\\nFOUR\\n\" }] });","atom":"a0","author":"init","version":0},{"n":60,"text":"\t\tassert.deepEqual(atom.deletes, [\"a0.1\", \"a0.3\"]);","atom":"a0","author":"init","version":0},{"n":61,"text":"\t\tassert.deepEqual(atom.writes, [lineKey(\"a0.1\"), lineKey(\"a0.3\")]);","atom":"a0","author":"init","version":0},{"n":62,"text":"\t\tassert.deepEqual(","atom":"a0","author":"init","version":0},{"n":63,"text":"\t\t\tatom.inserts.map((r) => r.parent),","atom":"a0","author":"init","version":0},{"n":64,"text":"\t\t\t[\"a0.1\", \"a0.3\"],","atom":"a0","author":"init","version":0},{"n":65,"text":"\t\t);","atom":"a0","author":"init","version":0},{"n":66,"text":"\t});","atom":"a0","author":"init","version":0},{"n":67,"text":"});","atom":"a0","author":"init","version":0},{"n":68,"text":"","atom":"a0","author":"init","version":0},{"n":69,"text":"describe(\"pure insertion modes\", () => {","atom":"a0","author":"init","version":0},{"n":70,"text":"\tconst insert = (mode: Mode): Atom => {","atom":"a0","author":"init","version":0},{"n":71,"text":"\t\tconst repo = Repo.init({ \"f.txt\": FIVE });","atom":"a0","author":"init","version":0},{"n":72,"text":"\t\treturn repo.edit({ edits: [{ file: \"f.txt\", old: \"two\\nthree\\n\", new: \"two\\nnew\\nthree\\n\", mode }] });","atom":"a0","author":"init","version":0},{"n":73,"text":"\t};","atom":"a0","author":"init","version":0},{"n":74,"text":"","atom":"a0","author":"init","version":0},{"n":75,"text":"\tit(\"both: writes the gap, reads the line above and the line below\", () => {","atom":"a0","author":"init","version":0},{"n":76,"text":"\t\tconst atom = insert(\"both\");","atom":"a0","author":"init","version":0},{"n":77,"text":"\t\tassert.deepEqual(atom.inserts, [{ file: \"f.txt\", parent: \"a0.1\", lines: [\"new\"] }]);","atom":"a0","author":"init","version":0},{"n":78,"text":"\t\tassert.deepEqual(atom.writes, [gapKey(\"a0.1\")]);","atom":"a0","author":"init","version":0},{"n":79,"text":"\t\tassert.deepEqual(atom.reads, [lineKey(\"a0.1\"), lineKey(\"a0.2\")]);","atom":"a0","author":"init","version":0},{"n":80,"text":"\t\tassert.deepEqual(atom.holds, []);","atom":"a0","author":"init","version":0},{"n":81,"text":"\t});","atom":"a0","author":"init","version":0},{"n":82,"text":"","atom":"a0","author":"init","version":0},{"n":83,"text":"\tit(\"after: reads only the line above\", () => {","atom":"a0","author":"init","version":0},{"n":84,"text":"\t\tconst atom = insert(\"after\");","atom":"a0","author":"init","version":0},{"n":85,"text":"\t\tassert.deepEqual(atom.writes, [gapKey(\"a0.1\")]);","atom":"a0","author":"init","version":0},{"n":86,"text":"\t\tassert.deepEqual(atom.reads, [lineKey(\"a0.1\")]);","atom":"a0","author":"init","version":0},{"n":87,"text":"\t});","atom":"a0","author":"init","version":0},{"n":88,"text":"","atom":"a0","author":"init","version":0},{"n":89,"text":"\tit(\"before: reads only the line below, still hangs off the line above and depends on its writer\", () => {","atom":"a0","author":"init","version":0},{"n":90,"text":"\t\tconst atom = insert(\"before\");","atom":"a0","author":"init","version":0},{"n":91,"text":"\t\tassert.deepEqual(atom.inserts, [{ file: \"f.txt\", parent: \"a0.1\", lines: [\"new\"] }]);","atom":"a0","author":"init","version":0},{"n":92,"text":"\t\tassert.deepEqual(atom.writes, [gapKey(\"a0.1\")]);","atom":"a0","author":"init","version":0},{"n":93,"text":"\t\tassert.deepEqual(atom.reads, [lineKey(\"a0.2\")]);","atom":"a0","author":"init","version":0},{"n":94,"text":"\t\tassert.deepEqual(atom.deps, [\"a0\"]);","atom":"a0","author":"init","version":0},{"n":95,"text":"\t});","atom":"a0","author":"init","version":0},{"n":96,"text":"","atom":"a0","author":"init","version":0},{"n":97,"text":"\tit(\"at the edge of a file, after and before read the one neighbour there is\", () => {","atom":"a0","author":"init","version":0},{"n":98,"text":"\t\tconst repo = Repo.init({ \"f.txt\": FIVE });","atom":"a0","author":"init","version":0},{"n":99,"text":"\t\tconst top = repo.draft({ edits: [{ file: \"f.txt\", start: 0, end: 0, lines: [\"zero\"], mode: \"after\" }] });","atom":"a0","author":"init","version":0},{"n":100,"text":"\t\tassert.deepEqual(top.writes, [gapKey(\"^f.txt\")]);","atom":"a0","author":"init","version":0},{"n":101,"text":"\t\tassert.deepEqual(top.reads, [lineKey(\"a0.0\")]);","atom":"a0","author":"init","version":0},{"n":102,"text":"\t\tconst bottom = repo.draft({ edits: [{ file: \"f.txt\", start: 5, end: 5, lines: [\"six\"], mode: \"before\" }] });","atom":"a0","author":"init","version":0},{"n":103,"text":"\t\tassert.deepEqual(bottom.writes, [gapKey(\"a0.4\")]);","atom":"a0","author":"init","version":0},{"n":104,"text":"\t\tassert.deepEqual(bottom.reads, [lineKey(\"a0.4\")]);","atom":"a0","author":"init","version":0},{"n":105,"text":"\t\t// So an insertion at the top conflicts with deleting the whole file concurrently.","atom":"a0","author":"init","version":0},{"n":106,"text":"\t\trepo.edit({ edits: [{ file: \"f.txt\", old: FIVE, new: \"\" }] }, [\"a0\"]);","atom":"a0","author":"init","version":0},{"n":107,"text":"\t\trepo.edit({ edits: [{ file: \"f.txt\", start: 0, end: 0, lines: [\"// header\"], mode: \"after\" }] }, [\"a0\"]);","atom":"a0","author":"init","version":0},{"n":108,"text":"\t\tassert.equal(conflicts(repo.graph, repo.shared).length, 1);","atom":"a0","author":"init","version":0},{"n":109,"text":"\t});","atom":"a0","author":"init","version":0},{"n":110,"text":"","atom":"a0","author":"init","version":0},{"n":111,"text":"\tit(\"wide: also holds every line of old and the gaps between them\", () => {","atom":"a0","author":"init","version":0},{"n":112,"text":"\t\tconst atom = insert(\"wide\");","atom":"a0","author":"init","version":0},{"n":113,"text":"\t\tassert.deepEqual(atom.reads, [lineKey(\"a0.1\"), lineKey(\"a0.2\")]);","atom":"a0","author":"init","version":0},{"n":114,"text":"\t\tassert.deepEqual(atom.holds, [gapKey(\"a0.1\"), lineKey(\"a0.1\"), lineKey(\"a0.2\")]);","atom":"a0","author":"init","version":0},{"n":115,"text":"\t});","atom":"a0","author":"init","version":0},{"n":116,"text":"","atom":"a0","author":"init","version":0},{"n":117,"text":"\tit(\"at the top of a file it writes the start gap and reads only the line below\", () => {","atom":"a0","author":"init","version":0},{"n":118,"text":"\t\tconst repo = Repo.init({ \"f.txt\": FIVE });","atom":"a0","author":"init","version":0},{"n":119,"text":"\t\tconst atom = repo.edit({ edits: [{ file: \"f.txt\", old: \"one\\n\", new: \"zero\\none\\n\" }] });","atom":"a0","author":"init","version":0},{"n":120,"text":"\t\tassert.deepEqual(atom.inserts, [{ file: \"f.txt\", parent: \"^f.txt\", lines: [\"zero\"] }]);","atom":"a0","author":"init","version":0},{"n":121,"text":"\t\tassert.deepEqual(atom.writes, [gapKey(\"^f.txt\")]);","atom":"a0","author":"init","version":0},{"n":122,"text":"\t\tassert.deepEqual(atom.reads, [lineKey(\"a0.0\")]);","atom":"a0","author":"init","version":0},{"n":123,"text":"\t});","atom":"a0","author":"init","version":0},{"n":124,"text":"","atom":"a0","author":"init","version":0},{"n":125,"text":"\tit(\"at the end of a file it reads only the line above\", () => {","atom":"a0","author":"init","version":0},{"n":126,"text":"\t\tconst repo = Repo.init({ \"f.txt\": FIVE });","atom":"a0","author":"init","version":0},{"n":127,"text":"\t\tconst atom = repo.edit({ edits: [{ file: \"f.txt\", old: \"five\\n\", new: \"five\\nsix\\n\" }] });","atom":"a0","author":"init","version":0},{"n":128,"text":"\t\tassert.deepEqual(atom.writes, [gapKey(\"a0.4\")]);","atom":"a0","author":"init","version":0},{"n":129,"text":"\t\tassert.deepEqual(atom.reads, [lineKey(\"a0.4\")]);","atom":"a0","author":"init","version":0},{"n":130,"text":"\t\tassert.equal(repo.text(\"f.txt\"), `${FIVE}six\\n`);","atom":"a696","author":"pinch","version":78},{"n":131,"text":"\t});","atom":"a0","author":"init","version":0},{"n":132,"text":"});","atom":"a0","author":"init","version":0},{"n":133,"text":"","atom":"a0","author":"init","version":0},{"n":134,"text":"describe(\"matching old text\", () => {","atom":"a0","author":"init","version":0},{"n":135,"text":"\tit(\"widens a match inside a line to the whole line\", () => {","atom":"a0","author":"init","version":0},{"n":136,"text":"\t\tconst repo = Repo.init({ \"f.txt\": FIVE });","atom":"a0","author":"init","version":0},{"n":137,"text":"\t\tconst atom = repo.edit({ edits: [{ file: \"f.txt\", old: \"hre\", new: \"HRE\" }] });","atom":"a0","author":"init","version":0},{"n":138,"text":"\t\tassert.deepEqual(atom.deletes, [\"a0.2\"]);","atom":"a0","author":"init","version":0},{"n":139,"text":"\t\tassert.equal(repo.text(\"f.txt\"), lines(\"one\", \"two\", \"tHREe\", \"four\", \"five\"));","atom":"a0","author":"init","version":0},{"n":140,"text":"\t});","atom":"a0","author":"init","version":0},{"n":141,"text":"","atom":"a0","author":"init","version":0},{"n":142,"text":"\tit(\"widens a match across two partial lines\", () => {","atom":"a0","author":"init","version":0},{"n":143,"text":"\t\tconst repo = Repo.init({ \"f.txt\": FIVE });","atom":"a0","author":"init","version":0},{"n":144,"text":"\t\trepo.edit({ edits: [{ file: \"f.txt\", old: \"ree\\nfo\", new: \"REE\\nFO\" }] });","atom":"a0","author":"init","version":0},{"n":145,"text":"\t\tassert.equal(repo.text(\"f.txt\"), lines(\"one\", \"two\", \"thREE\", \"FOur\", \"five\"));","atom":"a0","author":"init","version":0},{"n":146,"text":"\t});","atom":"a0","author":"init","version":0},{"n":147,"text":"","atom":"a0","author":"init","version":0},{"n":148,"text":"\tit(\"joins the next line when the replacement removes a line break, like plain text does\", () => {","atom":"a0","author":"init","version":0},{"n":149,"text":"\t\tconst repo = Repo.init({ \"f.txt\": FIVE });","atom":"a0","author":"init","version":0},{"n":150,"text":"\t\tconst atom = repo.edit({ edits: [{ file: \"f.txt\", old: \"two\\n\", new: \"two \" }] });","atom":"a0","author":"init","version":0},{"n":151,"text":"\t\tassert.deepEqual(atom.deletes, [\"a0.1\", \"a0.2\"]);","atom":"a0","author":"init","version":0},{"n":152,"text":"\t\tassert.equal(repo.text(\"f.txt\"), lines(\"one\", \"two three\", \"four\", \"five\"));","atom":"a0","author":"init","version":0},{"n":153,"text":"\t\t// At the end of the file there is no next line; a file always ends with a newline, so it is a no-op.","atom":"a0","author":"init","version":0},{"n":154,"text":"\t\tassert.throws(() => repo.draft({ edits: [{ file: \"f.txt\", old: \"five\\n\", new: \"five\" }] }), { code: \"empty-atom\" });","atom":"a0","author":"init","version":0},{"n":155,"text":"\t\trepo.edit({ edits: [{ file: \"f.txt\", old: \"four\\nfive\\n\", new: \"four\\nfive and more\" }] });","atom":"a0","author":"init","version":0},{"n":156,"text":"\t\tassert.equal(repo.text(\"f.txt\"), lines(\"one\", \"two three\", \"four\", \"five and more\"));","atom":"a0","author":"init","version":0},{"n":157,"text":"\t});","atom":"a0","author":"init","version":0},{"n":158,"text":"","atom":"a0","author":"init","version":0},{"n":159,"text":"\tit(\"normalizes CRLF in old and new\", () => {","atom":"a0","author":"init","version":0},{"n":160,"text":"\t\tconst repo = Repo.init({ \"f.txt\": \"one\\r\\ntwo\\r\\n\" });","atom":"a0","author":"init","version":0},{"n":161,"text":"\t\trepo.edit({ edits: [{ file: \"f.txt\", old: \"one\\r\\ntwo\", new: \"uno\\r\\ndos\" }] });","atom":"a0","author":"init","version":0},{"n":162,"text":"\t\tassert.equal(repo.text(\"f.txt\"), \"uno\\ndos\\n\");","atom":"a0","author":"init","version":0},{"n":163,"text":"\t});","atom":"a0","author":"init","version":0},{"n":164,"text":"","atom":"a0","author":"init","version":0},{"n":165,"text":"\tit(\"rejects text that is missing, ambiguous, or empty in a non-empty file\", () => {","atom":"a0","author":"init","version":0},{"n":166,"text":"\t\tconst repo = Repo.init({ \"f.txt\": lines(\"x\", \"x\", \"y\") });","atom":"a0","author":"init","version":0},{"n":167,"text":"\t\tconst view = repo.view();","atom":"a0","author":"init","version":0},{"n":168,"text":"\t\tconst build = (old: string) => () =>","atom":"a0","author":"init","version":0},{"n":169,"text":"\t\t\tbuildAtom(view, { author: \"a\", message: \"m\", edits: [{ file: \"f.txt\", old, new: \"z\" }] });","atom":"a0","author":"init","version":0},{"n":170,"text":"\t\tassert.throws(build(\"nope\"), { code: \"no-match\" });","atom":"a0","author":"init","version":0},{"n":171,"text":"\t\tassert.throws(build(\"x\"), { code: \"ambiguous-match\" });","atom":"a0","author":"init","version":0},{"n":172,"text":"\t\tassert.throws(build(\"\"), { code: \"ambiguous-match\" });","atom":"a0","author":"init","version":0},{"n":173,"text":"\t\tassert.doesNotThrow(build(\"x\\ny\"));","atom":"a0","author":"init","version":0},{"n":174,"text":"\t});","atom":"a0","author":"init","version":0},{"n":175,"text":"","atom":"a0","author":"init","version":0},{"n":176,"text":"\tit(\"rejects overlapping edits in one atom\", () => {","atom":"a0","author":"init","version":0},{"n":177,"text":"\t\tconst repo = Repo.init({ \"f.txt\": FIVE });","atom":"a0","author":"init","version":0},{"n":178,"text":"\t\tassert.throws(","atom":"a0","author":"init","version":0},{"n":179,"text":"\t\t\t() =>","atom":"a0","author":"init","version":0},{"n":180,"text":"\t\t\t\trepo.draft({","atom":"a0","author":"init","version":0},{"n":181,"text":"\t\t\t\t\tedits: [","atom":"a0","author":"init","version":0},{"n":182,"text":"\t\t\t\t\t\t{ file: \"f.txt\", old: \"two\\nthree\", new: \"a\" },","atom":"a0","author":"init","version":0},{"n":183,"text":"\t\t\t\t\t\t{ file: \"f.txt\", old: \"three\\nfour\", new: \"b\" },","atom":"a0","author":"init","version":0},{"n":184,"text":"\t\t\t\t\t],","atom":"a0","author":"init","version":0},{"n":185,"text":"\t\t\t\t}),","atom":"a0","author":"init","version":0},{"n":186,"text":"\t\t\t{ code: \"overlapping-edits\" },","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":"\t// Step 1 widens a partial match to whole lines, and line endings are","atom":"a0","author":"init","version":0},{"n":191,"text":"\t// normalized, so an accepted text edit must project exactly like plain string","atom":"a0","author":"init","version":0},{"n":192,"text":"\t// replacement followed by that normalization, for any unique substring:","atom":"a0","author":"init","version":0},{"n":193,"text":"\t// mid-line starts and ends, spans across line breaks, the final newline,","atom":"a0","author":"init","version":0},{"n":194,"text":"\t// CRLF in the new text, and empty new text.","atom":"a0","author":"init","version":0},{"n":195,"text":"\tit(\"projects exactly like plain string replacement, for arbitrary unique substrings (seeded)\", () => {","atom":"a0","author":"init","version":0},{"n":196,"text":"\t\tconst alphabet = [\"a\", \"b\", \"c\", \" \", \"\\n\", \"\\n\"];","atom":"a0","author":"init","version":0},{"n":197,"text":"\t\tlet checked = 0;","atom":"a0","author":"init","version":0},{"n":198,"text":"\t\tlet noops = 0;","atom":"a0","author":"init","version":0},{"n":199,"text":"\t\tfor (let seed = 1; seed <= 3000; seed++) {","atom":"a0","author":"init","version":0},{"n":200,"text":"\t\t\tconst rng = new Rng(seed);","atom":"a0","author":"init","version":0},{"n":201,"text":"\t\t\tlet text = \"\";","atom":"a0","author":"init","version":0},{"n":202,"text":"\t\t\tfor (let i = rng.range(1, 14); i > 0; i--) text += rng.pick(alphabet);","atom":"a0","author":"init","version":0},{"n":203,"text":"\t\t\ttext = canonicalText(text);","atom":"a0","author":"init","version":0},{"n":204,"text":"\t\t\tif (text === \"\") continue;","atom":"a0","author":"init","version":0},{"n":205,"text":"\t\t\tconst s = rng.int(text.length);","atom":"a0","author":"init","version":0},{"n":206,"text":"\t\t\tconst e = rng.range(s + 1, text.length);","atom":"a0","author":"init","version":0},{"n":207,"text":"\t\t\tconst old = text.slice(s, e);","atom":"a0","author":"init","version":0},{"n":208,"text":"\t\t\tif (text.indexOf(old, text.indexOf(old) + 1) >= 0) continue;","atom":"a0","author":"init","version":0},{"n":209,"text":"\t\t\tlet replacement = \"\";","atom":"a0","author":"init","version":0},{"n":210,"text":"\t\t\tfor (let i = rng.range(0, 5); i > 0; i--) replacement += rng.pick(alphabet);","atom":"a0","author":"init","version":0},{"n":211,"text":"\t\t\tif (rng.chance(0.2)) replacement = replacement.replace(/\\n/g, \"\\r\\n\");","atom":"a0","author":"init","version":0},{"n":212,"text":"\t\t\tconst expected = canonicalText(text.slice(0, s) + replacement + text.slice(e));","atom":"a0","author":"init","version":0},{"n":213,"text":"\t\t\tconst graph = new Graph();","atom":"a0","author":"init","version":0},{"n":214,"text":"\t\t\tgraph.add(buildBase({ f: text }, { author: \"import\", message: \"snapshot\" }));","atom":"a0","author":"init","version":0},{"n":215,"text":"\t\t\tconst set = new Set([\"a0\"]);","atom":"a0","author":"init","version":0},{"n":216,"text":"\t\t\tconst context = `seed ${seed}: ${JSON.stringify({ text, old, replacement })}`;","atom":"a0","author":"init","version":0},{"n":217,"text":"\t\t\tlet atom;","atom":"a0","author":"init","version":0},{"n":218,"text":"\t\t\ttry {","atom":"a0","author":"init","version":0},{"n":219,"text":"\t\t\t\tatom = buildAtom(new View(graph, set), {","atom":"a0","author":"init","version":0},{"n":220,"text":"\t\t\t\t\tauthor: \"x\",","atom":"a0","author":"init","version":0},{"n":221,"text":"\t\t\t\t\tmessage: \"x\",","atom":"a0","author":"init","version":0},{"n":222,"text":"\t\t\t\t\tedits: [{ file: \"f\", old, new: replacement }],","atom":"a0","author":"init","version":0},{"n":223,"text":"\t\t\t\t});","atom":"a0","author":"init","version":0},{"n":224,"text":"\t\t\t} catch (err) {","atom":"a0","author":"init","version":0},{"n":225,"text":"\t\t\t\t// A no-op (after normalization) is the only acceptable refusal.","atom":"a0","author":"init","version":0},{"n":226,"text":"\t\t\t\tassert.ok(","atom":"a0","author":"init","version":0},{"n":227,"text":"\t\t\t\t\terr instanceof EngineError && err.code === \"empty-atom\" && expected === text,","atom":"a0","author":"init","version":0},{"n":228,"text":"\t\t\t\t\t`${context}: ${String(err)}`,","atom":"a0","author":"init","version":0},{"n":229,"text":"\t\t\t\t);","atom":"a0","author":"init","version":0},{"n":230,"text":"\t\t\t\tnoops++;","atom":"a0","author":"init","version":0},{"n":231,"text":"\t\t\t\tcontinue;","atom":"a0","author":"init","version":0},{"n":232,"text":"\t\t\t}","atom":"a0","author":"init","version":0},{"n":233,"text":"\t\t\tgraph.add(atom);","atom":"a0","author":"init","version":0},{"n":234,"text":"\t\t\tset.add(atom.id);","atom":"a0","author":"init","version":0},{"n":235,"text":"\t\t\tassert.equal(new View(graph, set).text(\"f\"), expected, context);","atom":"a0","author":"init","version":0},{"n":236,"text":"\t\t\tchecked++;","atom":"a0","author":"init","version":0},{"n":237,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":238,"text":"\t\tassert.ok(checked > 1500, `only ${checked} edits checked`);","atom":"a0","author":"init","version":0},{"n":239,"text":"\t\tassert.ok(noops > 0);","atom":"a0","author":"init","version":0},{"n":240,"text":"\t});","atom":"a0","author":"init","version":0},{"n":241,"text":"","atom":"a0","author":"init","version":0},{"n":242,"text":"\tit(\"rejects an edit that changes and claims nothing\", () => {","atom":"a0","author":"init","version":0},{"n":243,"text":"\t\tconst repo = Repo.init({ \"f.txt\": FIVE });","atom":"a0","author":"init","version":0},{"n":244,"text":"\t\tassert.throws(() => repo.draft({ edits: [{ file: \"f.txt\", old: \"two\", new: \"two\" }] }), { code: \"empty-atom\" });","atom":"a0","author":"init","version":0},{"n":245,"text":"\t\t// The same no-op in wide mode is a claim on the span.","atom":"a0","author":"init","version":0},{"n":246,"text":"\t\tconst claim = repo.draft({ edits: [{ file: \"f.txt\", old: \"two\", new: \"two\", mode: \"wide\" }] });","atom":"a0","author":"init","version":0},{"n":247,"text":"\t\tassert.deepEqual(claim.holds, [lineKey(\"a0.1\")]);","atom":"a0","author":"init","version":0},{"n":248,"text":"\t});","atom":"a0","author":"init","version":0},{"n":249,"text":"});","atom":"a0","author":"init","version":0},{"n":250,"text":"","atom":"a0","author":"init","version":0},{"n":251,"text":"describe(\"splice edits\", () => {","atom":"a0","author":"init","version":0},{"n":252,"text":"\tit(\"replace visible lines by index, diffing old against new\", () => {","atom":"a0","author":"init","version":0},{"n":253,"text":"\t\tconst repo = Repo.init({ \"f.txt\": FIVE });","atom":"a0","author":"init","version":0},{"n":254,"text":"\t\tconst atom = repo.edit({ edits: [{ file: \"f.txt\", start: 1, end: 3, lines: [\"two\", \"TRES\"] }] });","atom":"a0","author":"init","version":0},{"n":255,"text":"\t\tassert.deepEqual(atom.deletes, [\"a0.2\"]);","atom":"a0","author":"init","version":0},{"n":256,"text":"\t\tassert.equal(repo.text(\"f.txt\"), lines(\"one\", \"two\", \"TRES\", \"four\", \"five\"));","atom":"a0","author":"init","version":0},{"n":257,"text":"\t});","atom":"a0","author":"init","version":0},{"n":258,"text":"","atom":"a0","author":"init","version":0},{"n":259,"text":"\tit(\"insert at start === end, including the very top and bottom\", () => {","atom":"a0","author":"init","version":0},{"n":260,"text":"\t\tconst repo = Repo.init({ \"f.txt\": FIVE });","atom":"a0","author":"init","version":0},{"n":261,"text":"\t\trepo.edit({ edits: [{ file: \"f.txt\", start: 0, end: 0, lines: [\"zero\"] }] });","atom":"a0","author":"init","version":0},{"n":262,"text":"\t\trepo.edit({ edits: [{ file: \"f.txt\", start: 6, end: 6, lines: [\"six\"] }] });","atom":"a0","author":"init","version":0},{"n":263,"text":"\t\tassert.equal(repo.text(\"f.txt\"), lines(\"zero\", \"one\", \"two\", \"three\", \"four\", \"five\", \"six\"));","atom":"a0","author":"init","version":0},{"n":264,"text":"\t});","atom":"a0","author":"init","version":0},{"n":265,"text":"","atom":"a0","author":"init","version":0},{"n":266,"text":"\tit(\"a large edit is still a minimal line diff: changing the ends of 2100 lines deletes two\", () => {","atom":"a0","author":"init","version":0},{"n":267,"text":"\t\tconst n = 2100;","atom":"a0","author":"init","version":0},{"n":268,"text":"\t\tconst base = Array.from({ length: n }, (_, i) => `line ${i}`);","atom":"a0","author":"init","version":0},{"n":269,"text":"\t\tconst repo = Repo.init({ \"big.txt\": lines(...base) });","atom":"a0","author":"init","version":0},{"n":270,"text":"\t\tconst next = [...base];","atom":"a0","author":"init","version":0},{"n":271,"text":"\t\tnext[0] = \"FIRST\";","atom":"a0","author":"init","version":0},{"n":272,"text":"\t\tnext[n - 1] = \"LAST\";","atom":"a0","author":"init","version":0},{"n":273,"text":"\t\tconst draft = repo.draft({ edits: [{ file: \"big.txt\", start: 0, end: n, lines: next }] });","atom":"a0","author":"init","version":0},{"n":274,"text":"\t\tassert.deepEqual(draft.deletes, [\"a0.0\", `a0.${n - 1}`]);","atom":"a0","author":"init","version":0},{"n":275,"text":"\t\t// So a concurrent edit to the middle of the file does not collide with it.","atom":"a0","author":"init","version":0},{"n":276,"text":"\t\tconst middle = repo.draft({ edits: [{ file: \"big.txt\", old: \"line 1000\\n\", new: \"line one thousand\\n\" }] }, [\"a0\"]);","atom":"a0","author":"init","version":0},{"n":277,"text":"\t\tassert.deepEqual(","atom":"a0","author":"init","version":0},{"n":278,"text":"\t\t\tdraft.writes.filter((k) => middle.writes.includes(k)),","atom":"a0","author":"init","version":0},{"n":279,"text":"\t\t\t[],","atom":"a0","author":"init","version":0},{"n":280,"text":"\t\t);","atom":"a0","author":"init","version":0},{"n":281,"text":"\t});","atom":"a0","author":"init","version":0},{"n":282,"text":"","atom":"a0","author":"init","version":0},{"n":283,"text":"\tit(\"reject bad ranges and lines with breaks\", () => {","atom":"a0","author":"init","version":0},{"n":284,"text":"\t\tconst repo = Repo.init({ \"f.txt\": FIVE });","atom":"a0","author":"init","version":0},{"n":285,"text":"\t\tassert.throws(() => repo.draft({ edits: [{ file: \"f.txt\", start: 3, end: 2, lines: [] }] }), { code: \"bad-range\" });","atom":"a0","author":"init","version":0},{"n":286,"text":"\t\tassert.throws(() => repo.draft({ edits: [{ file: \"f.txt\", start: 0, end: 9, lines: [] }] }), { code: \"bad-range\" });","atom":"a0","author":"init","version":0},{"n":287,"text":"\t\tassert.throws(() => repo.draft({ edits: [{ file: \"f.txt\", start: 0, end: 1, lines: [\"a\\nb\"] }] }), {","atom":"a0","author":"init","version":0},{"n":288,"text":"\t\t\tcode: \"bad-edit\",","atom":"a0","author":"init","version":0},{"n":289,"text":"\t\t});","atom":"a0","author":"init","version":0},{"n":290,"text":"\t});","atom":"a0","author":"init","version":0},{"n":291,"text":"});","atom":"a0","author":"init","version":0},{"n":292,"text":"","atom":"a0","author":"init","version":0},{"n":293,"text":"describe(\"several edits in one atom\", () => {","atom":"a0","author":"init","version":0},{"n":294,"text":"\tit(\"numbers inserted lines across all runs, in file then position order\", () => {","atom":"a0","author":"init","version":0},{"n":295,"text":"\t\tconst repo = Repo.init({ \"a.txt\": lines(\"a1\", \"a2\"), \"b.txt\": lines(\"b1\") });","atom":"a0","author":"init","version":0},{"n":296,"text":"\t\tconst atom = repo.edit({","atom":"a0","author":"init","version":0},{"n":297,"text":"\t\t\tedits: [","atom":"a0","author":"init","version":0},{"n":298,"text":"\t\t\t\t{ file: \"b.txt\", old: \"b1\\n\", new: \"b1\\nB\\n\" },","atom":"a0","author":"init","version":0},{"n":299,"text":"\t\t\t\t{ file: \"a.txt\", old: \"a2\\n\", new: \"a2\\nA2\\n\" },","atom":"a0","author":"init","version":0},{"n":300,"text":"\t\t\t\t{ file: \"a.txt\", old: \"a1\\n\", new: \"A1\\n\" },","atom":"a0","author":"init","version":0},{"n":301,"text":"\t\t\t],","atom":"a0","author":"init","version":0},{"n":302,"text":"\t\t});","atom":"a0","author":"init","version":0},{"n":303,"text":"\t\tassert.deepEqual(","atom":"a0","author":"init","version":0},{"n":304,"text":"\t\t\tatom.inserts.map((r) => [r.file, r.parent, r.lines]),","atom":"a0","author":"init","version":0},{"n":305,"text":"\t\t\t[","atom":"a0","author":"init","version":0},{"n":306,"text":"\t\t\t\t[\"b.txt\", \"a0.2\", [\"B\"]],","atom":"a0","author":"init","version":0},{"n":307,"text":"\t\t\t\t[\"a.txt\", \"a0.0\", [\"A1\"]],","atom":"a0","author":"init","version":0},{"n":308,"text":"\t\t\t\t[\"a.txt\", \"a0.1\", [\"A2\"]],","atom":"a0","author":"init","version":0},{"n":309,"text":"\t\t\t],","atom":"a0","author":"init","version":0},{"n":310,"text":"\t\t);","atom":"a0","author":"init","version":0},{"n":311,"text":"\t\tassert.deepEqual(repo.graph.linesOf(atom.id), [`${atom.id}.0`, `${atom.id}.1`, `${atom.id}.2`]);","atom":"a0","author":"init","version":0},{"n":312,"text":"\t\tassert.equal(repo.graph.line(`${atom.id}.1`)!.text, \"A1\");","atom":"a0","author":"init","version":0},{"n":313,"text":"\t\tassert.deepEqual(repo.files(), { \"a.txt\": lines(\"A1\", \"a2\", \"A2\"), \"b.txt\": lines(\"b1\", \"B\") });","atom":"a0","author":"init","version":0},{"n":314,"text":"\t});","atom":"a0","author":"init","version":0},{"n":315,"text":"","atom":"a0","author":"init","version":0},{"n":316,"text":"\tit(\"two insertions into the same gap keep their text order\", () => {","atom":"a0","author":"init","version":0},{"n":317,"text":"\t\tconst repo = Repo.init({ \"f.txt\": FIVE });","atom":"a0","author":"init","version":0},{"n":318,"text":"\t\tconst atom = repo.edit({","atom":"a0","author":"init","version":0},{"n":319,"text":"\t\t\tedits: [","atom":"a0","author":"init","version":0},{"n":320,"text":"\t\t\t\t{ file: \"f.txt\", start: 2, end: 2, lines: [\"first\"] },","atom":"a0","author":"init","version":0},{"n":321,"text":"\t\t\t\t{ file: \"f.txt\", start: 2, end: 2, lines: [\"second\"] },","atom":"a0","author":"init","version":0},{"n":322,"text":"\t\t\t\t{ file: \"f.txt\", start: 2, end: 3, lines: [\"third\", \"THREE\"] },","atom":"a0","author":"init","version":0},{"n":323,"text":"\t\t\t],","atom":"a0","author":"init","version":0},{"n":324,"text":"\t\t});","atom":"a0","author":"init","version":0},{"n":325,"text":"\t\tassert.equal(atom.inserts.length, 3);","atom":"a0","author":"init","version":0},{"n":326,"text":"\t\tassert.equal(repo.text(\"f.txt\"), lines(\"one\", \"two\", \"first\", \"second\", \"third\", \"THREE\", \"four\", \"five\"));","atom":"a0","author":"init","version":0},{"n":327,"text":"\t});","atom":"a0","author":"init","version":0},{"n":328,"text":"});","atom":"a0","author":"init","version":0},{"n":329,"text":"","atom":"a0","author":"init","version":0},{"n":330,"text":"describe(\"files\", () => {","atom":"a0","author":"init","version":0},{"n":331,"text":"\tit(\"creates a file with an empty old text, deletes it by deleting every line, and recreates it\", () => {","atom":"a0","author":"init","version":0},{"n":332,"text":"\t\tconst repo = Repo.init({ \"f.txt\": FIVE });","atom":"a0","author":"init","version":0},{"n":333,"text":"\t\tconst created = repo.edit({ edits: [{ file: \"g.txt\", old: \"\", new: \"g1\\ng2\" }] });","atom":"a0","author":"init","version":0},{"n":334,"text":"\t\tassert.deepEqual(created.deps, []);","atom":"a0","author":"init","version":0},{"n":335,"text":"\t\tassert.equal(repo.text(\"g.txt\"), \"g1\\ng2\\n\");","atom":"a0","author":"init","version":0},{"n":336,"text":"\t\tconst edited = repo.edit({ edits: [{ file: \"g.txt\", old: \"g2\", new: \"G2\" }] });","atom":"a0","author":"init","version":0},{"n":337,"text":"\t\tconst removed = repo.edit({ edits: [{ file: \"g.txt\", old: \"g1\\nG2\\n\", new: \"\" }] });","atom":"a0","author":"init","version":0},{"n":338,"text":"\t\tassert.deepEqual(removed.deps, [edited.id]);","atom":"a1064","author":"codex-capacity-chair","version":124},{"n":339,"text":"\t\tassert.deepEqual(repo.graph.closureOf(removed.deps), repo.graph.closureOf([created.id, edited.id]));","atom":"a1064","author":"codex-capacity-chair","version":124},{"n":340,"text":"\t\tassert.equal(repo.view().hasFile(\"g.txt\"), false);","atom":"a0","author":"init","version":0},{"n":341,"text":"\t\tassert.deepEqual(Object.keys(repo.files()), [\"f.txt\"]);","atom":"a0","author":"init","version":0},{"n":342,"text":"\t\tassert.deepEqual(repo.view().knownPaths(), [\"f.txt\", \"g.txt\"]);","atom":"a0","author":"init","version":0},{"n":343,"text":"\t\t// Recreating lands in front of the tombstones. It depends on the atom whose","atom":"a0","author":"init","version":0},{"n":344,"text":"\t\t// lines hang off the start (gap rule) and on the deletions: it relies on","atom":"a0","author":"init","version":0},{"n":345,"text":"\t\t// the file being empty, so its closure shows only the new text.","atom":"a0","author":"init","version":0},{"n":346,"text":"\t\tconst again = repo.edit({ edits: [{ file: \"g.txt\", old: \"\", new: \"fresh\\n\" }] });","atom":"a0","author":"init","version":0},{"n":347,"text":"\t\tassert.deepEqual(again.deps, [removed.id]);","atom":"a1064","author":"codex-capacity-chair","version":124},{"n":348,"text":"\t\tassert.deepEqual(repo.graph.closureOf(again.deps), repo.graph.closureOf([created.id, edited.id, removed.id]));","atom":"a1064","author":"codex-capacity-chair","version":124},{"n":349,"text":"\t\tassert.equal(repo.text(\"g.txt\"), \"fresh\\n\");","atom":"a0","author":"init","version":0},{"n":350,"text":"\t\tassert.equal(repo.text(\"g.txt\", repo.graph.closure(again.id)), \"fresh\\n\");","atom":"a0","author":"init","version":0},{"n":351,"text":"\t});","atom":"a0","author":"init","version":0},{"n":352,"text":"","atom":"a0","author":"init","version":0},{"n":353,"text":"\tit(\"a path may start with '^' (its start node is '^^...')\", () => {","atom":"a0","author":"init","version":0},{"n":354,"text":"\t\tconst graph = new Graph();","atom":"a0","author":"init","version":0},{"n":355,"text":"\t\tgraph.add(","atom":"a0","author":"init","version":0},{"n":356,"text":"\t\t\tbuildBase({ \"^notes.txt\": lines(\"one\"), \"a.txt\": lines(\"a\") }, { author: \"import\", message: \"snapshot\" }),","atom":"a0","author":"init","version":0},{"n":357,"text":"\t\t);","atom":"a0","author":"init","version":0},{"n":358,"text":"\t\tconst set = new Set([\"a0\"]);","atom":"a0","author":"init","version":0},{"n":359,"text":"\t\tassert.equal(new View(graph, set).text(\"^notes.txt\"), lines(\"one\"));","atom":"a0","author":"init","version":0},{"n":360,"text":"\t\tassert.deepEqual(graph.atom(\"a0\").writes, [gapKey(\"^^notes.txt\"), gapKey(\"^a.txt\")]);","atom":"a0","author":"init","version":0},{"n":361,"text":"\t\tconst edit = buildAtom(new View(graph, set), {","atom":"a0","author":"init","version":0},{"n":362,"text":"\t\t\tauthor: \"x\",","atom":"a0","author":"init","version":0},{"n":363,"text":"\t\t\tmessage: \"x\",","atom":"a0","author":"init","version":0},{"n":364,"text":"\t\t\tedits: [{ file: \"^notes.txt\", old: \"one\", new: \"ONE\" }],","atom":"a0","author":"init","version":0},{"n":365,"text":"\t\t});","atom":"a0","author":"init","version":0},{"n":366,"text":"\t\tgraph.add(edit);","atom":"a0","author":"init","version":0},{"n":367,"text":"\t\tset.add(edit.id);","atom":"a0","author":"init","version":0},{"n":368,"text":"\t\tconst top = buildAtom(new View(graph, set), {","atom":"a0","author":"init","version":0},{"n":369,"text":"\t\t\tauthor: \"x\",","atom":"a0","author":"init","version":0},{"n":370,"text":"\t\t\tmessage: \"x\",","atom":"a0","author":"init","version":0},{"n":371,"text":"\t\t\tedits: [{ file: \"^notes.txt\", start: 0, end: 0, lines: [\"zero\"] }],","atom":"a0","author":"init","version":0},{"n":372,"text":"\t\t});","atom":"a0","author":"init","version":0},{"n":373,"text":"\t\tgraph.add(top);","atom":"a0","author":"init","version":0},{"n":374,"text":"\t\tset.add(top.id);","atom":"a0","author":"init","version":0},{"n":375,"text":"\t\tassert.equal(project(graph, set)[\"^notes.txt\"], lines(\"zero\", \"ONE\"));","atom":"a0","author":"init","version":0},{"n":376,"text":"\t\tassert.deepEqual(new View(Graph.fromJSON(JSON.parse(JSON.stringify(graph))), set).files(), project(graph, set));","atom":"a0","author":"init","version":0},{"n":377,"text":"\t});","atom":"a0","author":"init","version":0},{"n":378,"text":"","atom":"a0","author":"init","version":0},{"n":379,"text":"\tit(\"the base snapshot skips empty files and writes each file start gap\", () => {","atom":"a0","author":"init","version":0},{"n":380,"text":"\t\tconst repo = Repo.init({ \"b.txt\": \"b\\n\", \"a.txt\": \"a\\n\", \"empty.txt\": \"\" });","atom":"a0","author":"init","version":0},{"n":381,"text":"\t\tconst a0 = repo.graph.atom(\"a0\");","atom":"a0","author":"init","version":0},{"n":382,"text":"\t\tassert.deepEqual(","atom":"a0","author":"init","version":0},{"n":383,"text":"\t\t\ta0.inserts.map((r) => r.file),","atom":"a0","author":"init","version":0},{"n":384,"text":"\t\t\t[\"a.txt\", \"b.txt\"],","atom":"a0","author":"init","version":0},{"n":385,"text":"\t\t);","atom":"a0","author":"init","version":0},{"n":386,"text":"\t\tassert.deepEqual(a0.writes, [gapKey(\"^a.txt\"), gapKey(\"^b.txt\")]);","atom":"a0","author":"init","version":0},{"n":387,"text":"\t\tassert.equal(repo.graph.lamport(\"a0\"), 0);","atom":"a0","author":"init","version":0},{"n":388,"text":"\t});","atom":"a0","author":"init","version":0},{"n":389,"text":"});","atom":"a0","author":"init","version":0},{"n":390,"text":"","atom":"a0","author":"init","version":0},{"n":391,"text":"describe(\"explicit claims\", () => {","atom":"a0","author":"init","version":0},{"n":392,"text":"\tit(\"reliesOn holds lines anywhere and depends on their writers\", () => {","atom":"a0","author":"init","version":0},{"n":393,"text":"\t\tconst repo = Repo.init({ \"f.txt\": FIVE, \"g.txt\": lines(\"g\") });","atom":"a0","author":"init","version":0},{"n":394,"text":"\t\tconst g2 = repo.edit({ edits: [{ file: \"g.txt\", old: \"g\", new: \"G\" }] });","atom":"a0","author":"init","version":0},{"n":395,"text":"\t\tconst atom = repo.edit({","atom":"a0","author":"init","version":0},{"n":396,"text":"\t\t\tedits: [{ file: \"f.txt\", old: \"one\", new: \"ONE\" }],","atom":"a0","author":"init","version":0},{"n":397,"text":"\t\t\treliesOn: [{ file: \"g.txt\", start: 0, end: 1 }],","atom":"a0","author":"init","version":0},{"n":398,"text":"\t\t});","atom":"a0","author":"init","version":0},{"n":399,"text":"\t\tassert.deepEqual(atom.holds, [lineKey(`${g2.id}.0`)]);","atom":"a0","author":"init","version":0},{"n":400,"text":"\t\tassert.deepEqual(atom.deps, [g2.id]);","atom":"a1064","author":"codex-capacity-chair","version":124},{"n":401,"text":"\t\tassert.deepEqual(repo.graph.closureOf(atom.deps), repo.graph.closureOf([\"a0\", g2.id]));","atom":"a1064","author":"codex-capacity-chair","version":124},{"n":402,"text":"\t});","atom":"a0","author":"init","version":0},{"n":403,"text":"","atom":"a0","author":"init","version":0},{"n":404,"text":"\tit(\"reliesOn a range of lines also holds the gaps between them\", () => {","atom":"a0","author":"init","version":0},{"n":405,"text":"\t\tconst repo = Repo.init({ \"f.txt\": FIVE });","atom":"a0","author":"init","version":0},{"n":406,"text":"\t\tconst atom = repo.draft({ reliesOn: [{ file: \"f.txt\", start: 1, end: 4 }] });","atom":"a0","author":"init","version":0},{"n":407,"text":"\t\tassert.deepEqual(atom.holds, [gapKey(\"a0.1\"), gapKey(\"a0.2\"), lineKey(\"a0.1\"), lineKey(\"a0.2\"), lineKey(\"a0.3\")]);","atom":"a0","author":"init","version":0},{"n":408,"text":"\t});","atom":"a0","author":"init","version":0},{"n":409,"text":"","atom":"a0","author":"init","version":0},{"n":410,"text":"\tit(\"rejects empty or out-of-range ranges\", () => {","atom":"a0","author":"init","version":0},{"n":411,"text":"\t\tconst repo = Repo.init({ \"f.txt\": FIVE });","atom":"a0","author":"init","version":0},{"n":412,"text":"\t\tassert.throws(() => repo.draft({ spans: [{ file: \"f.txt\", start: 2, end: 2 }] }), { code: \"bad-range\" });","atom":"a0","author":"init","version":0},{"n":413,"text":"\t\tassert.throws(() => repo.draft({ reliesOn: [{ file: \"f.txt\", start: 4, end: 6 }] }), { code: \"bad-range\" });","atom":"a0","author":"init","version":0},{"n":414,"text":"\t\tassert.throws(() => repo.draft({ reliesOn: [{ file: \"nope.txt\", start: 0, end: 1 }] }), { code: \"bad-range\" });","atom":"a0","author":"init","version":0},{"n":415,"text":"\t});","atom":"a0","author":"init","version":0},{"n":416,"text":"","atom":"a0","author":"init","version":0},{"n":417,"text":"\tit(\"needs and resolves must be atoms in the view; reasons must point at real atoms\", () => {","atom":"a0","author":"init","version":0},{"n":418,"text":"\t\tconst repo = Repo.init({ \"f.txt\": FIVE });","atom":"a0","author":"init","version":0},{"n":419,"text":"\t\tconst x = repo.edit({ edits: [{ file: \"f.txt\", old: \"one\", new: \"ONE\" }] });","atom":"a0","author":"init","version":0},{"n":420,"text":"\t\tassert.throws(() => repo.draft({ needs: [\"a99\"] }), { code: \"unknown-atom\" });","atom":"a0","author":"init","version":0},{"n":421,"text":"\t\tassert.throws(() => repo.draft({ needs: [x.id] }, [\"a0\"]), { code: \"not-in-view\" });","atom":"a0","author":"init","version":0},{"n":422,"text":"\t\tassert.throws(() => repo.draft({ resolves: [x.id] }, [\"a0\"]), { code: \"not-in-view\" });","atom":"a0","author":"init","version":0},{"n":423,"text":"\t\tassert.throws(() => repo.draft({ reasons: [{ to: \"a42\", kind: \"together\", text: \"\" }] }), { code: \"unknown-atom\" });","atom":"a0","author":"init","version":0},{"n":424,"text":"\t\tassert.throws(() => repo.draft({ reasons: [{ to: x.id, kind: \"nope\" as \"together\", text: \"\" }] }), {","atom":"a0","author":"init","version":0},{"n":425,"text":"\t\t\tcode: \"bad-edit\",","atom":"a0","author":"init","version":0},{"n":426,"text":"\t\t});","atom":"a0","author":"init","version":0},{"n":427,"text":"\t\t// An atom with only needs is allowed: it ties others together (a label head, say).","atom":"a0","author":"init","version":0},{"n":428,"text":"\t\tconst tie = repo.edit({ message: \"feature\", needs: [x.id] });","atom":"a0","author":"init","version":0},{"n":429,"text":"\t\tassert.deepEqual(tie.deps, [x.id]);","atom":"a0","author":"init","version":0},{"n":430,"text":"\t\tassert.deepEqual(repo.graph.atom(tie.id).inserts, []);","atom":"a0","author":"init","version":0},{"n":431,"text":"\t});","atom":"a0","author":"init","version":0},{"n":432,"text":"});","atom":"a0","author":"init","version":0},{"n":433,"text":"","atom":"a0","author":"init","version":0},{"n":434,"text":"describe(\"derived dependencies\", () => {","atom":"a0","author":"init","version":0},{"n":435,"text":"\tit(\"gap rule: an insertion depends on every atom whose lines hang off the same line, and on nothing below\", () => {","atom":"a0","author":"init","version":0},{"n":436,"text":"\t\tconst repo = Repo.init({ \"f.txt\": FIVE });","atom":"a0","author":"init","version":0},{"n":437,"text":"\t\tconst added = repo.edit({ edits: [{ file: \"f.txt\", old: \"two\\n\", new: \"two\\nmid\\n\" }] });","atom":"a0","author":"init","version":0},{"n":438,"text":"\t\tconst removed = repo.edit({ edits: [{ file: \"f.txt\", old: \"mid\\n\", new: \"\" }] });","atom":"a0","author":"init","version":0},{"n":439,"text":"\t\tconst three = repo.edit({ edits: [{ file: \"f.txt\", old: \"three\", new: \"THREE\" }] });","atom":"a0","author":"init","version":0},{"n":440,"text":"\t\t// Inserting after \"two\": the gap holds mid (a tombstone hanging off \"two\") and then THREE.","atom":"a0","author":"init","version":0},{"n":441,"text":"\t\tconst atom = repo.edit({ edits: [{ file: \"f.txt\", old: \"two\\n\", new: \"two\\nnew\\n\", mode: \"after\" }] });","atom":"a0","author":"init","version":0},{"n":442,"text":"\t\tassert.deepEqual(atom.deps, [added.id]);","atom":"a1064","author":"codex-capacity-chair","version":124},{"n":443,"text":"\t\tassert.deepEqual(repo.graph.closureOf(atom.deps), repo.graph.closureOf([\"a0\", added.id]));","atom":"a1064","author":"codex-capacity-chair","version":124},{"n":444,"text":"\t\tassert.equal(repo.text(\"f.txt\"), lines(\"one\", \"two\", \"new\", \"THREE\", \"four\", \"five\"));","atom":"a0","author":"init","version":0},{"n":445,"text":"\t\t// It outranks mid, so it sits directly after \"two\" in any set; in its own","atom":"a0","author":"init","version":0},{"n":446,"text":"\t\t// closure mid is back (the deletion isn't in it) and stays below it.","atom":"a0","author":"init","version":0},{"n":447,"text":"\t\tassert.equal(","atom":"a0","author":"init","version":0},{"n":448,"text":"\t\t\trepo.text(\"f.txt\", repo.graph.closure(atom.id)),","atom":"a0","author":"init","version":0},{"n":449,"text":"\t\t\tlines(\"one\", \"two\", \"new\", \"mid\", \"three\", \"four\", \"five\"),","atom":"a0","author":"init","version":0},{"n":450,"text":"\t\t);","atom":"a0","author":"init","version":0},{"n":451,"text":"\t\tassert.deepEqual(drop(repo.graph, repo.shared, removed.id).removed, [removed.id]);","atom":"a0","author":"init","version":0},{"n":452,"text":"\t\tassert.deepEqual(drop(repo.graph, repo.shared, three.id).removed, [three.id]);","atom":"a0","author":"init","version":0},{"n":453,"text":"\t});","atom":"a0","author":"init","version":0},{"n":454,"text":"","atom":"a0","author":"init","version":0},{"n":455,"text":"\tit(\"editing unrelated lines bottom-up gives the same independent atoms as top-down\", () => {","atom":"a0","author":"init","version":0},{"n":456,"text":"\t\tconst SIX = lines(\"l1\", \"l2\", \"l3\", \"l4\", \"l5\", \"l6\");","atom":"a0","author":"init","version":0},{"n":457,"text":"\t\tconst topDown = Repo.init({ \"f.txt\": SIX });","atom":"a0","author":"init","version":0},{"n":458,"text":"\t\tconst down = [1, 2, 3, 4, 5, 6].map((i) =>","atom":"a0","author":"init","version":0},{"n":459,"text":"\t\t\ttopDown.edit({ edits: [{ file: \"f.txt\", old: `l${i}`, new: `L${i}` }] }),","atom":"a0","author":"init","version":0},{"n":460,"text":"\t\t);","atom":"a0","author":"init","version":0},{"n":461,"text":"\t\tconst bottomUp = Repo.init({ \"f.txt\": SIX });","atom":"a0","author":"init","version":0},{"n":462,"text":"\t\tconst up = [6, 5, 4, 3, 2, 1].map((i) => bottomUp.edit({ edits: [{ file: \"f.txt\", old: `l${i}`, new: `L${i}` }] }));","atom":"a0","author":"init","version":0},{"n":463,"text":"\t\tassert.equal(bottomUp.text(\"f.txt\"), topDown.text(\"f.txt\"));","atom":"a0","author":"init","version":0},{"n":464,"text":"\t\tassert.deepEqual(","atom":"a0","author":"init","version":0},{"n":465,"text":"\t\t\tdown.map((a) => a.deps),","atom":"a0","author":"init","version":0},{"n":466,"text":"\t\t\tdown.map(() => [\"a0\"]),","atom":"a0","author":"init","version":0},{"n":467,"text":"\t\t);","atom":"a0","author":"init","version":0},{"n":468,"text":"\t\tassert.deepEqual(","atom":"a0","author":"init","version":0},{"n":469,"text":"\t\t\tup.map((a) => a.deps),","atom":"a0","author":"init","version":0},{"n":470,"text":"\t\t\tup.map(() => [\"a0\"]),","atom":"a0","author":"init","version":0},{"n":471,"text":"\t\t);","atom":"a0","author":"init","version":0},{"n":472,"text":"\t\t// Dropping the edit to l6 leaves the edit to l5 (and the rest) alone.","atom":"a0","author":"init","version":0},{"n":473,"text":"\t\tconst { set, removed } = drop(bottomUp.graph, bottomUp.shared, up[0]!.id);","atom":"a0","author":"init","version":0},{"n":474,"text":"\t\tassert.deepEqual(removed, [up[0]!.id]);","atom":"a0","author":"init","version":0},{"n":475,"text":"\t\tassert.equal(bottomUp.text(\"f.txt\", set), lines(\"L1\", \"L2\", \"L3\", \"L4\", \"L5\", \"l6\"));","atom":"a0","author":"init","version":0},{"n":476,"text":"\t});","atom":"a0","author":"init","version":0},{"n":477,"text":"","atom":"a0","author":"init","version":0},{"n":478,"text":"\tit(\"a live insert into a gap with an unresolved conflict depends on both sides of it\", () => {","atom":"a0","author":"init","version":0},{"n":479,"text":"\t\t// Kept on purpose (docs/prototype.md, \"Dependencies\"): without the gap","atom":"a0","author":"init","version":0},{"n":480,"text":"\t\t// rule N would conflict with A on G:X, and live edits must not collide.","atom":"a0","author":"init","version":0},{"n":481,"text":"\t\tconst repo = Repo.init({ \"f.txt\": lines(\"X\", \"Y\") });","atom":"a0","author":"init","version":0},{"n":482,"text":"\t\tconst A = repo.edit({ message: \"A after X\", edits: [{ file: \"f.txt\", old: \"X\\n\", new: \"X\\nA\\n\" }] }, [\"a0\"]);","atom":"a0","author":"init","version":0},{"n":483,"text":"\t\tconst B = repo.edit({ message: \"B after X\", edits: [{ file: \"f.txt\", old: \"X\\n\", new: \"X\\nB\\n\" }] }, [\"a0\"]);","atom":"a0","author":"init","version":0},{"n":484,"text":"\t\tassert.equal(repo.text(\"f.txt\"), lines(\"X\", \"B\", \"A\", \"Y\"));","atom":"a0","author":"init","version":0},{"n":485,"text":"\t\tconst draft = repo.draft({ message: \"N after X\", edits: [{ file: \"f.txt\", start: 1, end: 1, lines: [\"N\"] }] });","atom":"a0","author":"init","version":0},{"n":486,"text":"\t\tassert.deepEqual(repo.check(draft).conflicts, []);","atom":"a0","author":"init","version":0},{"n":487,"text":"\t\tconst N = repo.edit({ message: \"N after X\", edits: [{ file: \"f.txt\", start: 1, end: 1, lines: [\"N\"] }] });","atom":"a0","author":"init","version":0},{"n":488,"text":"\t\tassert.deepEqual(N.deps, [A.id, B.id]);","atom":"a1064","author":"codex-capacity-chair","version":124},{"n":489,"text":"\t\tassert.deepEqual(repo.graph.closureOf(N.deps), repo.graph.closureOf([\"a0\", A.id, B.id]));","atom":"a1064","author":"codex-capacity-chair","version":124},{"n":490,"text":"\t\tassert.equal(repo.text(\"f.txt\"), lines(\"X\", \"N\", \"B\", \"A\", \"Y\"));","atom":"a0","author":"init","version":0},{"n":491,"text":"\t\tassert.deepEqual(","atom":"a0","author":"init","version":0},{"n":492,"text":"\t\t\tconflicts(repo.graph, repo.shared).map((c) => c.atoms),","atom":"a0","author":"init","version":0},{"n":493,"text":"\t\t\t[[A.id, B.id]],","atom":"a0","author":"init","version":0},{"n":494,"text":"\t\t);","atom":"a0","author":"init","version":0},{"n":495,"text":"\t\t// Dropping a side takes N along; resolving the conflict keeps everything.","atom":"a0","author":"init","version":0},{"n":496,"text":"\t\tassert.deepEqual(drop(repo.graph, repo.shared, A.id).removed, [A.id, N.id]);","atom":"a0","author":"init","version":0},{"n":497,"text":"\t\trepo.edit({","atom":"a0","author":"init","version":0},{"n":498,"text":"\t\t\tmessage: \"keep both, A first\",","atom":"a0","author":"init","version":0},{"n":499,"text":"\t\t\tresolves: [A.id, B.id],","atom":"a0","author":"init","version":0},{"n":500,"text":"\t\t\tedits: [{ file: \"f.txt\", old: \"B\\nA\\n\", new: \"A\\nB\\n\" }],","atom":"a0","author":"init","version":0},{"n":501,"text":"\t\t});","atom":"a0","author":"init","version":0},{"n":502,"text":"\t\tassert.equal(repo.text(\"f.txt\"), lines(\"X\", \"N\", \"A\", \"B\", \"Y\"));","atom":"a0","author":"init","version":0},{"n":503,"text":"\t});","atom":"a0","author":"init","version":0},{"n":504,"text":"","atom":"a0","author":"init","version":0},{"n":505,"text":"\tit(\"implicit-read rule: changing a line someone inserted next to depends on that insert\", () => {","atom":"a0","author":"init","version":0},{"n":506,"text":"\t\tconst repo = Repo.init({ \"f.txt\": FIVE });","atom":"a0","author":"init","version":0},{"n":507,"text":"\t\tconst between = repo.edit({ edits: [{ file: \"f.txt\", old: \"two\\n\", new: \"two\\nbetween\\n\" }] });","atom":"a0","author":"init","version":0},{"n":508,"text":"\t\tassert.ok(between.reads.includes(lineKey(\"a0.2\")));","atom":"a0","author":"init","version":0},{"n":509,"text":"\t\t// Deleting \"three\" (the line below the insert) touches nothing the insert wrote,","atom":"a0","author":"init","version":0},{"n":510,"text":"\t\t// but it changes a line the insert read: a sequential edit, so a dependency.","atom":"a0","author":"init","version":0},{"n":511,"text":"\t\tconst atom = repo.edit({ edits: [{ file: \"f.txt\", old: \"three\\n\", new: \"\" }] });","atom":"a0","author":"init","version":0},{"n":512,"text":"\t\tassert.deepEqual(atom.deps, [between.id]);","atom":"a1064","author":"codex-capacity-chair","version":124},{"n":513,"text":"\t\tassert.deepEqual(repo.graph.closureOf(atom.deps), repo.graph.closureOf([\"a0\", between.id]));","atom":"a1064","author":"codex-capacity-chair","version":124},{"n":514,"text":"\t\tassert.deepEqual(","atom":"a0","author":"init","version":0},{"n":515,"text":"\t\t\tcheckDraft(repo.graph, repo.shared, repo.draft({ edits: [{ file: \"f.txt\", old: \"four\\n\", new: \"\" }] })).conflicts,","atom":"a0","author":"init","version":0},{"n":516,"text":"\t\t\t[],","atom":"a0","author":"init","version":0},{"n":517,"text":"\t\t);","atom":"a0","author":"init","version":0},{"n":518,"text":"\t});","atom":"a0","author":"init","version":0},{"n":519,"text":"","atom":"a0","author":"init","version":0},{"n":520,"text":"\tit(\"gap rule: claiming a gap someone inserted into (even if their lines are gone) depends on them\", () => {","atom":"a0","author":"init","version":0},{"n":521,"text":"\t\tconst repo = Repo.init({ \"f.txt\": FIVE });","atom":"a0","author":"init","version":0},{"n":522,"text":"\t\tconst added = repo.edit({ edits: [{ file: \"f.txt\", old: \"two\\n\", new: \"two\\nmid\\n\" }] });","atom":"a0","author":"init","version":0},{"n":523,"text":"\t\tconst removed = repo.edit({ edits: [{ file: \"f.txt\", old: \"mid\\n\", new: \"\" }] });","atom":"a0","author":"init","version":0},{"n":524,"text":"\t\t// A wide edit over two..three holds G:two, which `added` wrote.","atom":"a0","author":"init","version":0},{"n":525,"text":"\t\tconst draft = repo.draft({ edits: [{ file: \"f.txt\", old: \"two\\nthree\\n\", new: \"two\\nTHREE\\n\", mode: \"wide\" }] });","atom":"a0","author":"init","version":0},{"n":526,"text":"\t\tassert.ok(draft.holds.includes(gapKey(\"a0.1\")));","atom":"a0","author":"init","version":0},{"n":527,"text":"\t\tassert.ok(draft.deps.includes(added.id));","atom":"a0","author":"init","version":0},{"n":528,"text":"\t\tassert.ok(!draft.deps.includes(removed.id));","atom":"a0","author":"init","version":0},{"n":529,"text":"\t\tassert.deepEqual(repo.check(draft).conflicts, []);","atom":"a0","author":"init","version":0},{"n":530,"text":"\t});","atom":"a0","author":"init","version":0},{"n":531,"text":"","atom":"a0","author":"init","version":0},{"n":532,"text":"\tit(\"does not depend on the rest of its view\", () => {","atom":"a0","author":"init","version":0},{"n":533,"text":"\t\tconst repo = Repo.init({ \"f.txt\": FIVE, \"g.txt\": lines(\"g\") });","atom":"a0","author":"init","version":0},{"n":534,"text":"\t\trepo.edit({ edits: [{ file: \"g.txt\", old: \"g\", new: \"G\" }] });","atom":"a0","author":"init","version":0},{"n":535,"text":"\t\trepo.edit({ edits: [{ file: \"f.txt\", old: \"five\", new: \"FIVE\" }] });","atom":"a0","author":"init","version":0},{"n":536,"text":"\t\tconst atom = repo.edit({ edits: [{ file: \"f.txt\", old: \"one\", new: \"ONE\" }] });","atom":"a0","author":"init","version":0},{"n":537,"text":"\t\tassert.deepEqual(atom.deps, [\"a0\"]);","atom":"a0","author":"init","version":0},{"n":538,"text":"\t});","atom":"a0","author":"init","version":0},{"n":539,"text":"","atom":"a0","author":"init","version":0},{"n":540,"text":"\tit(\"builds against any closed set, and refuses one that is not closed\", () => {","atom":"a0","author":"init","version":0},{"n":541,"text":"\t\tconst repo = Repo.init({ \"f.txt\": FIVE });","atom":"a0","author":"init","version":0},{"n":542,"text":"\t\tconst x = repo.edit({ edits: [{ file: \"f.txt\", old: \"one\", new: \"ONE\" }] });","atom":"a0","author":"init","version":0},{"n":543,"text":"\t\tconst y = repo.edit({ edits: [{ file: \"f.txt\", old: \"ONE\", new: \"uno\" }] });","atom":"a0","author":"init","version":0},{"n":544,"text":"\t\tassert.throws(() => new View(repo.graph, [\"a0\", y.id]), { code: \"not-closed\" });","atom":"a0","author":"init","version":0},{"n":545,"text":"\t\tconst old = repo.draft({ edits: [{ file: \"f.txt\", old: \"one\", new: \"eins\" }] }, [\"a0\"]);","atom":"a0","author":"init","version":0},{"n":546,"text":"\t\tassert.deepEqual(old.deps, [\"a0\"]);","atom":"a0","author":"init","version":0},{"n":547,"text":"\t\tassert.ok(!old.deps.includes(x.id));","atom":"a0","author":"init","version":0},{"n":548,"text":"\t});","atom":"a0","author":"init","version":0},{"n":549,"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":"a696","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":"a1064","author":"codex-capacity-chair","message":"","time":1791835619038,"timeIso":"2026-10-12T20:06:59.038Z","publish":{"draft":null,"version":124,"agent":"codex-capacity-chair","message":"Reduce implicit dependencies to their maximal frontier","time":1791836238914,"timeIso":"2026-10-12T20:17:18.914Z"}}]}