- MCP
- code on this site's /mcp
- CLI
- none: the JSON below is the answer
- JSON
- /christopher/abso-core/files/src/engine/test/projection-root.test.ts?format=json
74 linescodex-capacity-chair 100%Last change codex-capacity-chair in version 143, 1 version changed it
1import assert from "node:assert/strict";
2import { test } from "node:test";
3import {
4 createProjectionRoot,
5 type ProjectionIdentity,
6 type ProjectionRoots,
7 readProjectionRoot,
8} from "../experimental/projection-root.ts";
9import { SqlState } from "./storage-helper.ts";
11test("experimental roots bind identity before storage access and remain immutable", () => {
12 const storage = new SqlState();
13 try {
14 const expected: ProjectionIdentity = {
15 database: "db",
16 namespace: "index",
17 sourceGeneration: 1,
18 sourceLength: 2,
19 sourceDigest: "a".repeat(64),
20 membership: "closed:2",
21 registry: "files:1",
22 defaultFile: "f.txt",
23 };
24 const pages: ProjectionRoots = {
25 sequence: 3,
26 sequenceRoot: 0,
27 sequenceNext: 1,
28 locator: 4,
29 children: 5,
30 membership: 6,
31 attributes: null,
32 };
33 const handle = createProjectionRoot(storage, expected, 0, pages);
34 assert.deepEqual(readProjectionRoot(storage, handle, expected), pages);
35 for (const field of Object.keys(expected) as (keyof ProjectionIdentity)[]) {
36 const changed = {
37 ...expected,
38 [field]:
39 typeof expected[field] === "number"
40 ? Number(expected[field]) + 1
41 : field === "sourceDigest"
42 ? "b".repeat(64)
43 : `${expected[field]}:other`,
44 };
45 const reads = storage.reads,
46 writes = storage.writes;
47 assert.throws(() => readProjectionRoot(storage, handle, changed), /identity mismatch/);
48 assert.equal(storage.reads, reads);
49 assert.equal(storage.writes, writes);
50 }
51 assert.throws(() => createProjectionRoot(storage, expected, 0, pages), /already exists/);
52 const copy = readProjectionRoot(storage, handle, expected) as { sequence: number | null };
53 copy.sequence = 999;
54 assert.deepEqual(readProjectionRoot(storage, handle, expected), pages);
55 assert.throws(
56 () =>
57 storage.transaction(() => {
58 createProjectionRoot(storage, expected, 1, pages);
59 throw Error("fail after root");
60 }),
61 /fail after root/,
62 );
63 assert.throws(() => readProjectionRoot(storage, { ...handle, id: 1 }, expected), /invalid projection root record/);
64 storage.write('experimental-projection:["db","index"]:roots', "0", {
65 format: 1,
66 id: 0,
67 identity: expected,
68 roots: { ...pages, locator: -1 },
69 });
70 assert.throws(() => readProjectionRoot(storage, handle, expected), /invalid projection page reference/);
71 } finally {
72 storage.db.close();
73 }
74});