Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed
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-list-pages.test.ts?format=json
71 linescapacity 100%Last change capacity in version 239, 1 version changed it
1// An atom's long lists (abso Capacity, readonlyPagedArray): a new atom keeps them 256 values to a row (list format 2),
2// and an atom stored before keeps a row per value (list format 1). Both read back whole, in order and by index.
3
4import assert from "node:assert/strict";
5import { test } from "node:test";
6import { buildBase, Graph } from "../index.ts";
7import { lineKey } from "../keys.ts";
8import { storedArray } from "../state-source.ts";
9import type { Atom } from "../types.ts";
10import { SqlState } from "./storage-helper.ts";
12function listAtom(keys: string[]): Atom {
13 return {
14 id: "a1",
15 seq: 1,
16 author: "fixture",
17 message: "lists",
18 time: 1,
19 inserts: [],
20 deletes: [],
21 writes: keys,
22 reads: [],
23 holds: [],
24 needs: [],
25 resolves: [],
26 reasons: [],
27 deps: ["a0"],
28 };
31const keys = Array.from({ length: 600 }, () => lineKey("a0.0"));
33test("a new atom's long list is kept 256 values to a row and reads back whole", () => {
34 const storage = new SqlState();
35 try {
36 const graph = new Graph({ storage });
37 graph.add(buildBase({ "a.txt": "base" }, { author: "fixture", message: "base", time: 0 }));
38 graph.add(listAtom(keys));
39 assert.equal((storage.read("atoms", "1") as { listFormat?: number }).listFormat, 2);
40 assert.equal((storage.read("atom-list:1:writes:pages", "2") as unknown[]).length, 600 - 512);
41 assert.equal(storage.read("atom-list:1:writes", "0"), undefined, "no row per value");
42 const writes = new Graph({ storage }).atom("a1").writes;
43 assert.deepEqual([...writes], keys);
44 assert.equal(writes.length, 600);
45 assert.equal(writes[300], keys[300]);
46 assert.equal(writes[600], undefined);
47 } finally {
48 storage.db.close();
49 }
50});
52test("an atom stored before pages, a row per value, still reads back whole", () => {
53 const storage = new SqlState();
54 try {
55 const graph = new Graph({ storage });
56 graph.add(buildBase({ "a.txt": "base" }, { author: "fixture", message: "base", time: 0 }));
57 graph.add(listAtom(keys));
58 // Rewrite it as list format 1 kept it: a row per value and no pages.
59 const record = storage.read("atoms", "1") as Record<string, unknown>;
60 for (let page = 0; page < 3; page++) storage.remove("atom-list:1:writes:pages", String(page));
61 storage.remove("atom-list:1:writes:meta", "length");
62 const rows = storedArray<string>(storage, "atom-list:1:writes");
63 for (const key of keys) rows.push(key);
64 storage.write("atoms", "1", { ...record, listFormat: 1 });
65 const writes = new Graph({ storage }).atom("a1").writes;
66 assert.deepEqual([...writes], keys);
67 assert.equal(writes[599], keys[599]);
68 } finally {
69 storage.db.close();
70 }
71});