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

Versions 116 to 318

Compare

+84 −0 in 1 place
new file, 84 lines
1+// 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+
4+import assert from "node:assert/strict";
5+import { test } from "node:test";
6+import { Graph, View } from "../index.ts";
7+import { StableOverlaySet } from "../state-source.ts";
8+import { lines, Repo } from "./helpers.ts";
9+import { SqlState } from "./storage-helper.ts";
11+test("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 {
26+ const graph = new Graph({ storage });
27+ 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+});
45+test("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+});
58+test("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+});
MCP
compare on this site's /mcp
CLI
abso diff 116 318 src/engine/test/packed-files.test.ts --json
JSON
/christopher/abso-core/compare/116..318?file=src%2Fengine%2Ftest%2Fpacked-files.test.ts&format=json