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
blame on this site's /mcp
CLI
abso blame src/engine/test/packed-files.test.ts --json
JSON
/christopher/abso-core/blame/src/engine/test/packed-files.test.ts?format=json
84 linescapacity 99% · codex-capacity-chair 1%Last change capacity in version 276,

84 lines from 3 changes in 3 versions.

capacity206Each file's line history packed (disk-first 2, lines by file; abso Capacity). A stored graph appends every line written in a file ([n, parent code, writer seq, k, replaces]) and its text, every delete of one of its lines, and every attribute set on it to that file's pages as atoms are added, a run at a time (storedLists appendAll). A view lays a file out from those pages in memory: membership checked once per atom, moves followed from the ones it already resolved, lines moved in from other files read from theirs. Same tree and order as before (packed-files.test.ts checks it against the in-memory graph through edits, deletes and moves). Graphs adopted before have no packs and lay out line by line as before; packFiles: false keeps that path for its tests. On game's export: first shared() 13 s to 2-3.6 s at 20,000 queries, warm 56-82 ms, pathsAt(head) 29-119 ms; files at a version 14 s to 3 s, compare 26 s to 11 s, a path's log 27 s to 4.5 s; every answer the harness finished matches Project.load.Compare1// Each file's line history packed (abso Capacity, Graph.packedLines): a stored graph lays files out from a few pages,
2// and must give exactly what the in-memory graph gives, through edits, deletes, moves between files and back.
3
4import assert from "node:assert/strict";
5import { test } from "node:test";
6import { Graph, View } from "../index.ts";
7import { StableOverlaySet } from "../state-source.ts";
8import { lines, Repo } from "./helpers.ts";
9import { SqlState } from "./storage-helper.ts";
11test("a packed file lays out as the in-memory graph does, at every step, moves included", () => {
12 const oracle = Repo.init({ "a.txt": lines("one", "two", "three", "four"), "b.txt": lines("bee"), "c.txt": "" });
13 const sets: Set<string>[] = [new Set(oracle.shared)];
14 const step = (change: Parameters<Repo["edit"]>[0]) => {
15 oracle.edit(change);
16 sets.push(new Set(oracle.shared));
17 };
18 step({ edits: [{ file: "a.txt", old: "two", new: "TWO" }] });
19 step({ move: { file: "a.txt", start: 1, end: 3, to: "b.txt", at: 1 } });
20 step({ edits: [{ file: "b.txt", old: "TWO", new: "two again" }] });
21 step({ edits: [{ file: "a.txt", old: "four", new: "" }] });
22 step({ move: { file: "b.txt", start: 0, end: 2, to: "c.txt", at: 0 } });
23 step({ edits: [{ file: "c.txt", old: "bee", new: "bee\nafter bee" }] });
24 const storage = new SqlState();
25 try {
codex-capacity-chair128Page deletion history and short-circuit current visibilityCompare26 const graph = new Graph({ storage });
capacity206Each file's line history packed (disk-first 2, lines by file; abso Capacity). A stored graph appends every line written in a file ([n, parent code, writer seq, k, replaces]) and its text, every delete of one of its lines, and every attribute set on it to that file's pages as atoms are added, a run at a time (storedLists appendAll). A view lays a file out from those pages in memory: membership checked once per atom, moves followed from the ones it already resolved, lines moved in from other files read from theirs. Same tree and order as before (packed-files.test.ts checks it against the in-memory graph through edits, deletes and moves). Graphs adopted before have no packs and lay out line by line as before; packFiles: false keeps that path for its tests. On game's export: first shared() 13 s to 2-3.6 s at 20,000 queries, warm 56-82 ms, pathsAt(head) 29-119 ms; files at a version 14 s to 3 s, compare 26 s to 11 s, a path's log 27 s to 4.5 s; every answer the harness finished matches Project.load.Compare27 for (const atom of oracle.graph.atoms()) graph.add(atom);
28 const reopened = new Graph({ storage });
29 assert.equal(reopened.packedFiles, true);
30 for (const [i, set] of sets.entries()) {
31 const packed = new View(reopened, new StableOverlaySet(set));
32 const memory = new View(oracle.graph, set);
33 assert.deepEqual(packed.paths(), memory.paths(), `step ${i}: paths`);
34 for (const path of ["a.txt", "b.txt", "c.txt"]) {
35 assert.equal(packed.text(path), memory.text(path), `step ${i}: ${path}`);
36 assert.deepEqual(packed.sequence(path), memory.sequence(path), `step ${i}: ${path}'s sequence`);
37 assert.deepEqual(packed.attrs(path), memory.attrs(path), `step ${i}: ${path}'s attributes`);
38 }
39 }
40 } finally {
41 storage.db.close();
42 }
43});
45test("a graph made with packFiles off keeps no packed history", () => {
46 const oracle = Repo.init({ "a.txt": lines("one") });
47 const storage = new SqlState();
48 try {
49 const graph = new Graph({ storage, packFiles: false });
50 for (const atom of oracle.graph.atoms()) graph.add(atom);
51 assert.equal(new Graph({ storage }).packedFiles, false);
52 assert.equal(new View(new Graph({ storage }), new StableOverlaySet(oracle.shared)).text("a.txt"), "one\n");
53 } finally {
54 storage.db.close();
55 }
56});
capacity276A stored graph keeps files' decoded line histories between layouts (abso Capacity, issue 664): Graph.packedHistory, under 4 MB. Every view of a file read its whole history from pages again: compare lays each file out once per side, collisions once per draft touching it, and a file whose lines moved in from another reads that one's history too (abso's worker files, split out of index.ts). The history (lines, deletes and crossings, no texts) is decoded once into flat 32-bit arrays, kept under its three lists' lengths, most recently used last, and add() lets every kept history go. abso's index.ts, 46,000 lines of history, takes about 1 MB. Side by side on abso's export, same machine, two rounds, against 273: cold compare 612 to 1224 from 12.4 s to 5.0-6.5 s, cold collisions from 10.4 s to 5.0-6.9 s, cold where from 4.4 s to 1.5-2.6 s. Tests: packed-files.test.ts adds a test that a kept history saves reads, add() lets it go, and the next layout matches the in-memory graph. tsc and Biome clean; view, state-cache, state-source, graph, graph-long-text, graph-line-chunks, graph-move-write-membership, graph-replacement-membership, graph-insertion-storage, packed-files, definition-code, definitions, changed-definition, collisions-kept-views, draft-reads-stored and collision-streaming pass.Compare57
58test("a file's decoded history is kept between views and let go when an atom is added", () => {
59 const oracle = Repo.init({ "a.txt": lines("one", "two", "three"), "b.txt": lines("bee") });
60 const storage = new SqlState();
61 try {
62 const graph = new Graph({ storage });
63 for (const atom of oracle.graph.atoms()) graph.add(atom);
64 const first = new View(graph, new StableOverlaySet(oracle.shared));
65 assert.equal(first.text("a.txt"), "one\ntwo\nthree\n");
66 assert.ok(graph.historyBytes > 0, "the first layout keeps a.txt's history");
67 // Another view of the same file reads only what its membership needs, not the history's pages again.
68 const before = storage.reads;
69 assert.equal(new View(graph, new StableOverlaySet(oracle.shared)).sequence("a.txt").length, 3);
70 const pages = storage.reads - before;
71 const cold = new Graph({ storage });
72 const coldBefore = storage.reads;
73 new View(cold, new StableOverlaySet(oracle.shared)).sequence("a.txt");
74 assert.ok(pages < storage.reads - coldBefore, "the kept history saved reads");
75 // A new atom lets every kept history go; the next layout sees its lines.
76 oracle.edit({ edits: [{ file: "a.txt", old: "two", new: "TWO" }] });
77 graph.add(oracle.graph.atom([...oracle.shared].at(-1)!));
78 assert.equal(graph.historyBytes, 0);
79 const after = new View(graph, new StableOverlaySet(oracle.shared));
80 assert.equal(after.text("a.txt"), new View(oracle.graph, oracle.shared).text("a.txt"));
81 } finally {
82 storage.db.close();
83 }
84});