- MCP
- code on this site's /mcp
- CLI
- none: the JSON below is the answer
- JSON
- /christopher/abso-core/files/src/engine/test/graph-validation-scratch.test.ts?format=json
47 linescodex-capacity-chair 100%Last change codex-capacity-chair in version 162, 1 version changed it
1import assert from "node:assert/strict";
2import { test } from "node:test";
3import { buildBase, Graph } from "../index.ts";
4import type { Atom } from "../types.ts";
5import { SqlState } from "./storage-helper.ts";
7test("persistent atom validation uses rollback scratch for memberships", () => {
8 const storage = new SqlState();
9 try {
10 const graph = new Graph({ storage });
11 graph.add(buildBase({ "a.txt": "base" }, { author: "fixture", message: "base", time: 0 }));
12 const atom: Atom = {
13 id: "a1",
14 seq: 1,
15 author: "fixture",
16 message: "next",
17 time: 1,
18 inserts: [],
19 deletes: [],
20 writes: [],
21 reads: [],
22 holds: [],
23 needs: [],
24 resolves: [],
25 reasons: [],
26 deps: ["a0"],
27 };
28 const before = storage.db.prepare("SELECT * FROM state ORDER BY collection,key").all();
29 assert.throws(() => graph.add({ ...atom, deps: ["a0", "a0"] }), /listed twice/);
30 assert.deepEqual(storage.db.prepare("SELECT * FROM state ORDER BY collection,key").all(), before);
31 let scratchWrites = 0;
32 const write = storage.write.bind(storage);
33 storage.write = (collection, key, value) => {
34 if (collection.startsWith("projection-scratch:") && collection.endsWith(":deps")) scratchWrites++;
35 write(collection, key, value);
36 };
37 graph.add(atom);
38 assert.ok(scratchWrites > 0);
39 assert.equal(
40 storage.db.prepare("SELECT COUNT(*) AS n FROM state WHERE collection LIKE 'projection-scratch:%'").get()!.n,
41 0,
42 );
43 assert.equal(new Graph({ storage }).size, 2);
44 } finally {
45 storage.db.close();
46 }
47});