{"file":"worker/project/test/definition-code.test.ts","version":318,"total":61,"from":1,"to":61,"lines":[{"n":1,"text":"import assert from \"node:assert/strict\";","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":2,"text":"import { test } from \"node:test\";","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":3,"text":"import { buildBase, Graph, View } from \"../../../src/engine/index.ts\";","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":4,"text":"import { SqlState } from \"../../../src/engine/test/storage-helper.ts\";","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":5,"text":"import { withDefinitionCode } from \"../definition-code.ts\";","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":6,"text":"import { definedTwice, definitionsIn } from \"../definitions.ts\";","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":7,"text":"import { codeOfLines } from \"../names.ts\";","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":8,"text":"","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":9,"text":"test(\"small parsed code stays in memory without scratch writes\", (t) => {","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":10,"text":"\tconst storage = new SqlState();","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":11,"text":"\tt.after(() => storage.db.close());","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":12,"text":"\tconst graph = new Graph({ storage });","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":13,"text":"\tgraph.add(buildBase({ \"f.ts\": \"export const answer = 42;\\n\" }, { author: \"writer\", message: \"init\" }));","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":14,"text":"\tconst view = new View(graph, [\"a0\"]);","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":15,"text":"\tconst writes = storage.writes;","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":16,"text":"\twithDefinitionCode(view, view.buildLines(\"f.ts\"), (code) => {","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":17,"text":"\t\tassert.deepEqual(code, codeOfLines([\"export const answer = 42;\"]));","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":18,"text":"\t});","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":19,"text":"\tassert.equal(storage.writes, writes);","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":20,"text":"});","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":21,"text":"","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":22,"text":"test(\"disk definition code preserves random reads and always rolls scratch back\", (t) => {","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":23,"text":"\tconst storage = new SqlState();","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":24,"text":"\tt.after(() => storage.db.close());","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":25,"text":"\tconst lines = [","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":26,"text":"\t\t\"/* comment\",","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":27,"text":"\t\t\"end */ export function parseOne(\",","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":28,"text":"\t\t\"arg: string\",","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":29,"text":"\t\t\") { return 1; }\",","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":30,"text":"\t\t...Array.from({ length: 4000 }, (_, i) => `const value${i} = ${i}; // trailing`),","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":31,"text":"\t];","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":32,"text":"\tconst atom = buildBase({ \"f.ts\": `${lines.join(\"\\n\")}\\n` }, { author: \"writer\", message: \"init\" });","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":33,"text":"\tconst memory = new Graph();","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":34,"text":"\tmemory.add(atom);","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":35,"text":"\tconst graph = new Graph({ storage });","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":36,"text":"\tgraph.add(atom);","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":37,"text":"\tconst view = new View(graph, [\"a0\"]);","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":38,"text":"\tconst expected = codeOfLines(lines);","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":39,"text":"\tconst rows = () => storage.db.prepare(\"SELECT * FROM state ORDER BY collection,key\").all();","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":40,"text":"\tconst before = rows();","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":41,"text":"\tlet escaped: readonly string[] = [];","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":42,"text":"\twithDefinitionCode(","atom":"a2729","author":"capacity","version":274},{"n":43,"text":"\t\tview,","atom":"a2729","author":"capacity","version":274},{"n":44,"text":"\t\tview.buildLines(\"f.ts\"),","atom":"a2729","author":"capacity","version":274},{"n":45,"text":"\t\t(code) => {","atom":"a2729","author":"capacity","version":274},{"n":46,"text":"\t\t\tescaped = code;","atom":"a2729","author":"capacity","version":274},{"n":47,"text":"\t\t\tassert.deepEqual(code.slice(0, 4), expected.slice(0, 4));","atom":"a2732","author":"capacity","version":275},{"n":48,"text":"\t\t\tfor (let i = code.length - 1; i >= 0; i--) assert.equal(code[i], expected[i]);","atom":"a2732","author":"capacity","version":275},{"n":49,"text":"\t\t\tfor (let i = 0; i < code.length; i++) assert.equal(code[i], expected[i]);","atom":"a2729","author":"capacity","version":274},{"n":50,"text":"\t\t},","atom":"a2729","author":"capacity","version":274},{"n":51,"text":"\t\t65536,","atom":"a2729","author":"capacity","version":274},{"n":52,"text":"\t);","atom":"a2729","author":"capacity","version":274},{"n":53,"text":"\tassert.throws(() => escaped[0], /scope has ended/);","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":54,"text":"\tassert.deepEqual(rows(), before);","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":55,"text":"\tassert.deepEqual(definitionsIn(view), definitionsIn(new View(memory, [\"a0\"])));","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":56,"text":"\tassert.deepEqual(definedTwice(view, \"f.ts\"), definedTwice(new View(memory, [\"a0\"]), \"f.ts\"));","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":57,"text":"\tassert.deepEqual(rows(), before);","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":58,"text":"\tstorage.failWrite = storage.writes + 2;","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":59,"text":"\tassert.throws(() => withDefinitionCode(view, view.buildLines(\"f.ts\"), () => [], 65536), /injected storage failure/);","atom":"a2732","author":"capacity","version":275},{"n":60,"text":"\tassert.deepEqual(rows(), before);","atom":"a1899","author":"codex-capacity-chair","version":175},{"n":61,"text":"});","atom":"a1899","author":"codex-capacity-chair","version":175}],"atoms":[{"atom":"a1899","author":"codex-capacity-chair","message":"","time":1791967583646,"timeIso":"2026-10-14T08:46:23.646Z","publish":{"draft":null,"version":175,"agent":"codex-capacity-chair","message":"Reduce disk-backed record and publish allocations; reviewed in core ask 52 with parsed-code budget and exact aligned-line follow-ups. Keep disk-first activation off.","time":1791967673854,"timeIso":"2026-10-14T08:47:53.854Z"}},{"atom":"a2729","author":"capacity","message":"","time":1792103592572,"timeIso":"2026-10-15T22:33:12.572Z","publish":{"draft":null,"version":274,"agent":"capacity","message":"Cold reads (abso Capacity, issue 664): a packed layout reads only the text pages holding a line it shows; definition code stays in memory up to 4 MB; a stored array's element read skips its length read.\n\n- Layout: each line's file and place are kept and texts are read after the walk, a page at a time, only for shown lines. Every text a file and the files its moved-in lines came from ever had was read for every layout; abso's worker files, split out of index.ts, each read all of index.ts's history. Cold compare 612 to 1224 on abso read text pages 17,080 times, now 2,856.\n- Definition code: at 64 KB every large file's parsed code went row by row into scratch and back (25,000 rows each for index.ts). The visible lines are already in memory, so 4 MB at most doubles a file's text for the call. withDefinitionCode takes the limit; its scratch test passes 64 KB.\n- storedArray: set writes the row and the length together and nothing shrinks, so no row lies past the length; half of a cold layout's reads were the length.\n\nSide by side on abso's export, same machine, three rounds: cold collisions 10.5 s to 6.2 s, cold compare 12.6 s to 8.6 s. tsc clean; view, state-cache, state-source, graph, graph-long-text, graph-line-chunks, graph-move-write-membership, definition-code, definitions, changed-definition, collisions-kept-views and draft-reads-stored tests: 73 pass.","time":1792103593251,"timeIso":"2026-10-15T22:33:13.251Z"}},{"atom":"a2732","author":"capacity","message":"","time":1792103843979,"timeIso":"2026-10-15T22:37:23.979Z","publish":{"draft":null,"version":275,"agent":"capacity","message":"Definition code: setDefinitionCodeInMemory for tests (abso's kept-reader test puts a 100 KB file through scratch, as before the 4 MB limit), and 274's test formatted as Biome wants (274's check failed on it).","time":1792103844377,"timeIso":"2026-10-15T22:37:24.377Z"}}]}