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/lamport-pages.test.ts?format=json
48 linescapacity 100%Last change capacity in version 228, 1 version changed it
1// A stored graph's lamport numbers (abso Capacity, Graph.#lamportPages): a fresh graph keeps them 256 to a row, and a
2// graph that already keeps them a row each goes on doing so. Both answer every atom's lamport as the in-memory graph.
3
4import assert from "node:assert/strict";
5import { test } from "node:test";
6import { Graph } from "../index.ts";
7import { storedArray } from "../state-source.ts";
8import { lines, Repo } from "./helpers.ts";
9import { SqlState } from "./storage-helper.ts";
11function history() {
12 const oracle = Repo.init({ "a.txt": lines("one", "two", "three"), "b.txt": "" });
13 oracle.edit({ edits: [{ file: "a.txt", old: "two", new: "TWO" }] });
14 oracle.edit({ move: { file: "a.txt", start: 1, end: 2, to: "b.txt", at: 0 } });
15 oracle.edit({ edits: [{ file: "a.txt", old: "three", new: "three\nfour" }] });
16 return oracle;
19test("a fresh stored graph keeps lamport numbers in pages and reopens with them", () => {
20 const oracle = history();
21 const storage = new SqlState();
22 const original = new Graph({ storage });
23 for (const atom of oracle.graph.atoms()) original.add(atom);
24 assert.equal(storage.read("lamport:meta", "length"), undefined, "no row each");
25 assert.equal(storage.read("lamport-pages:meta", "length"), oracle.graph.size);
26 const reopened = new Graph({ storage });
27 for (const atom of oracle.graph.atoms()) assert.equal(reopened.lamport(atom.id), oracle.graph.lamport(atom.id));
28 assert.deepEqual([...reopened.movers()], [...oracle.graph.movers()]);
29});
31test("a graph that keeps lamport numbers a row each goes on reading and writing rows", () => {
32 const oracle = history();
33 const atoms = [...oracle.graph.atoms()];
34 const storage = new SqlState();
35 const original = new Graph({ storage });
36 for (const atom of atoms.slice(0, -1)) original.add(atom);
37 // As a graph adopted before pages: the same numbers a row each, and no pages.
38 const rows = storedArray<number>(storage, "lamport");
39 for (let seq = 0; seq < atoms.length - 1; seq++) rows.push(original.lamportOfSeq(seq));
40 storage.remove("lamport-pages:meta", "length");
41 storage.remove("lamport-pages:meta", "format");
42 const reopened = new Graph({ storage });
43 for (const atom of atoms.slice(0, -1)) assert.equal(reopened.lamport(atom.id), oracle.graph.lamport(atom.id));
44 reopened.add(atoms.at(-1)!);
45 assert.equal(storage.read("lamport:meta", "length"), atoms.length, "the new atom gets a row");
46 assert.equal(reopened.lamport(atoms.at(-1)!.id), oracle.graph.lamport(atoms.at(-1)!.id));
47 assert.equal(storage.read("lamport-pages:meta", "length"), undefined);
48});