- MCP
- code on this site's /mcp
- CLI
- none: the JSON below is the answer
- JSON
- /christopher/abso-core/files/src/engine/test/graph-atom-lists.test.ts?format=json
51 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 { lineKey } from "../keys.ts";
5import type { Atom } from "../types.ts";
6import { SqlState } from "./storage-helper.ts";
8test("large persisted atom lists stay out of metadata and read incrementally", () => {
9 const storage = new SqlState();
10 try {
11 const graph = new Graph({ storage });
12 graph.add(buildBase({ "a.txt": "base" }, { author: "fixture", message: "base", time: 0 }));
13 const keys = Array.from({ length: 513 }, () => lineKey("a0.0"));
14 const atom: Atom = {
15 id: "a1",
16 seq: 1,
17 author: "fixture",
18 message: "lists",
19 time: 1,
20 inserts: [],
21 deletes: [],
22 writes: keys,
23 reads: keys,
24 holds: keys,
25 needs: [],
26 resolves: [],
27 reasons: [],
28 deps: ["a0"],
29 };
30 graph.add(atom);
31 assert.ok(JSON.stringify(storage.read("atoms", "1")).length < 2048);
32 let items = 0;
33 const read = storage.read.bind(storage);
34 storage.read = (collection, key) => {
35 if (collection.startsWith("atom-list:") && !collection.endsWith(":meta")) items++;
36 return read(collection, key);
37 };
38 const saved = new Graph({ storage }).atom("a1");
39 assert.equal(items, 0);
40 assert.equal(saved.writes.length, 513);
41 assert.equal(items, 0);
42 assert.equal(saved.writes[512], keys[512]);
43 assert.equal(items, 1);
44 assert.throws(() => {
45 (saved.writes as string[])[0] = "changed";
46 }, /read-only/);
47 assert.deepEqual([...saved.writes], keys);
48 } finally {
49 storage.db.close();
50 }
51});