- MCP
- code on this site's /mcp
- CLI
- none: the JSON below is the answer
- JSON
- /christopher/abso-core/files/src/engine/test/reachability-scratch.test.ts?format=json
79 linescodex-capacity-chair 100%Last change codex-capacity-chair in version 139, 1 version changed it
1import assert from "node:assert/strict";
2import { test } from "node:test";
3import { buildBase, Graph } from "../index.ts";
4import { CachedStateStorage } from "../state-source.ts";
5import type { Atom } from "../types.ts";
6import { SqlState } from "./storage-helper.ts";
8test("persistent reachability uses rollback scratch across deep shared ancestry and graph append", () => {
9 const source = new SqlState();
10 try {
11 const storage = new CachedStateStorage(source, 8192, 32);
12 const graph = new Graph({ storage });
13 const oracle = new Graph();
14 const add = (atom: Atom) => {
15 graph.add(atom);
16 oracle.add(atom);
17 };
18 add(buildBase({ "a.txt": "base\n" }, { author: "fixture", message: "base", time: 0 }));
19 for (let seq = 1; seq <= 513; seq++)
20 add({
21 id: `a${seq}`,
22 seq,
23 author: "fixture",
24 message: "branch",
25 time: seq,
26 inserts: seq === 1 ? [{ file: "b.txt", parent: "^b.txt", lines: ["other"] }] : [],
27 deletes: [],
28 writes: [],
29 reads: [],
30 holds: [],
31 needs: [],
32 resolves: [],
33 reasons: [],
34 deps: seq === 1 ? [] : seq === 2 ? ["a1"] : [`a${seq - 1}`, `a${seq - 2}`],
35 });
36 const before = source.db.prepare("SELECT * FROM state ORDER BY collection, key").all();
37 for (const target of ["a0", "a1", "a127", "a512", "a513"]) {
38 assert.equal(graph.dependsOn("a513", target), oracle.dependsOn("a513", target));
39 assert.deepEqual(source.db.prepare("SELECT * FROM state ORDER BY collection, key").all(), before);
40 }
41 const atom: Atom = {
42 id: "a514",
43 seq: 514,
44 author: "fixture",
45 message: "append through ancestor",
46 time: 514,
47 inserts: [{ file: "b.txt", parent: "a1.0", lines: ["next"] }],
48 deletes: [],
49 writes: [],
50 reads: [],
51 holds: [],
52 needs: [],
53 resolves: [],
54 reasons: [],
55 deps: ["a513"],
56 };
57 source.failWrite = source.writes + 3;
58 assert.throws(() => graph.add(atom), /injected storage failure/);
59 assert.deepEqual(source.db.prepare("SELECT * FROM state ORDER BY collection, key").all(), before);
60 source.failWrite = Infinity;
61 const reopened = new Graph({ storage: new CachedStateStorage(source) });
62 assert.throws(
63 () => reopened.add({ ...atom, inserts: [{ file: "a.txt", parent: "a0.0", lines: ["invalid"] }] }),
64 /not in its closure/,
65 );
66 assert.deepEqual(source.db.prepare("SELECT * FROM state ORDER BY collection, key").all(), before);
67 reopened.add(atom);
68 oracle.add(atom);
69 assert.equal(reopened.lineCount, oracle.lineCount);
70 assert.equal(reopened.size, oracle.size);
71 assert.equal(reopened.dependsOn("a514", "a1"), true);
72 assert.equal(
73 source.db.prepare("SELECT count(*) AS n FROM state WHERE collection LIKE 'projection-scratch:%'").get()!.n,
74 0,
75 );
76 } finally {
77 source.db.close();
78 }
79});