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 130 to 318

Compare

+146 −2 in 4 places
Lines 5–53 at 318 (were 5–10 at 130)
55import { lines, Repo } from "./helpers.ts";
66import { SqlState } from "./storage-helper.ts";
77
8+test("counter writes avoid rereads while respecting failed writes, rollback and cache bounds", () => {
9+ const source = new SqlState();
10+ try {
11+ const cache = new CachedStateStorage(source, 512, 2);
12+ const before = source.reads;
13+ for (let n = 0; n < 100; n++) {
14+ cache.write("counter", "next", n);
15+ assert.equal(cache.read("counter", "next"), n);
16+ assert.ok(cache.retainedBytes <= 512);
17+ assert.ok(cache.retainedEntries <= 2);
18+ }
19+ assert.equal(source.reads, before);
20+ source.failWrite = source.writes + 1;
21+ assert.throws(() => cache.write("counter", "next", 100), /injected/);
22+ assert.equal(cache.read("counter", "next"), 99);
23+ source.failWrite = Infinity;
24+ assert.throws(
25+ () =>
26+ cache.transaction(() => {
27+ cache.write("counter", "next", 101);
28+ assert.equal(cache.read("counter", "next"), 101);
29+ throw Error("counter rollback");
30+ }),
31+ /counter rollback/,
32+ );
33+ assert.equal(cache.retainedEntries, 0);
34+ assert.equal(cache.read("counter", "next"), 99);
35+ for (let n = 0; n < 20; n++) cache.write("counter", String(n), n);
36+ assert.ok(cache.retainedBytes <= 512);
37+ assert.ok(cache.retainedEntries <= 2);
38+ assert.equal(cache.read("counter", "0"), 0);
39+ const disabled = new CachedStateStorage(source, 0, 0);
40+ disabled.write("counter", "next", 102);
41+ assert.equal(disabled.retainedEntries, 0);
42+ assert.equal(disabled.read("counter", "next"), 102);
43+ cache.write("counter", "negative-zero", -0);
44+ assert.equal(Object.is(cache.read("counter", "negative-zero"), source.read("counter", "negative-zero")), true);
45+ } finally {
46+ source.db.close();
47+ }
48+});
50+// The line-by-line layout, which a graph adopted before packed file history still uses (packFiles: false).
851test("current visibility stops at the first included deletion while history retains every deleter", () => {
952 class ObservedStorage extends SqlState {
1053 pageReads = 0;
Lines 60–66 at 318 (were 17–23 at 130)
1760 try {
1861 const oracle = Repo.init({ "a.txt": "gone\nlive\n" });
1962 const deletion = oracle.draft({ edits: [{ file: "a.txt", old: "gone\n", new: "" }] });
20− const graph = new Graph({ storage });
63+ const graph = new Graph({ storage, packFiles: false });
2164 graph.add(oracle.graph.atom("a0"));
2265 const ids = ["a0"];
2366 for (let seq = 1; seq <= 514; seq++) {
Lines 69–75 at 318 (were 26–32 at 130)
2669 oracle.graph.add(atom);
2770 ids.push(atom.id);
2871 }
29− const reopened = new Graph({ storage });
72+ const reopened = new Graph({ storage, packFiles: false });
3073 const membership = new StableOverlaySet(ids);
3174 const view = new View(reopened, membership);
3275 storage.pageReads = 0;
Lines 462–565 at 318 (were 419–421 at 130)
419462 storage.db.close();
420463 }
421464});
466+test("persistent layout uses ordered successors without retaining deep or wide history frontiers", () => {
467+ for (const shape of ["deep", "wide"] as const) {
468+ const storage = new SqlState();
469+ try {
470+ const oracle = Repo.init({
471+ "a.txt": shape === "deep" ? Array.from({ length: 1024 }, (_, n) => `line ${n}\n`).join("") : "base\n",
472+ });
473+ if (shape === "wide") {
474+ const draft = oracle.draft({ edits: [{ file: "a.txt", old: "base", new: "branch" }] });
475+ for (let seq = 1; seq <= 256; seq++) {
476+ const atom = { ...draft, id: `a${seq}`, seq };
477+ oracle.graph.add(atom);
478+ oracle.shared.add(atom.id);
479+ }
480+ }
481+ const before = oracle.view().text("a.txt");
482+ oracle.edit({ edits: [{ file: "a.txt", old: before, new: "live\n" }] });
483+ const graph = new Graph({ storage, packFiles: false });
484+ for (const id of oracle.shared) graph.add(oracle.graph.atom(id));
485+ const reopened = new Graph({ storage, packFiles: false });
486+ reopened.eachChildN = () => {
487+ throw Error("unordered child collection forbidden");
488+ };
489+ reopened.childrenN = () => {
490+ throw Error("materialized child collection forbidden");
491+ };
492+ const original = reopened.orderedChildrenN.bind(reopened);
493+ let active = 0,
494+ maximum = 0;
495+ reopened.orderedChildrenN = function* (parent: number, after?: number) {
496+ active++;
497+ maximum = Math.max(maximum, active);
498+ try {
499+ yield* original(parent, after);
500+ } finally {
501+ active--;
502+ }
503+ };
504+ const view = new View(reopened, new StableOverlaySet(oracle.shared));
505+ assert.equal(view.text("a.txt"), "live\n");
506+ assert.equal(active, 0);
507+ assert.equal(maximum, 1, "no ordered iterator retained per historical ancestor");
508+ assert.deepEqual(view.sequence("a.txt"), oracle.view().sequence("a.txt"));
509+ } finally {
510+ storage.db.close();
511+ }
512+ }
513+});
515+test("implicit ordered successors avoid priority reads but retain index validation", () => {
516+ class ObservedStorage extends SqlState {
517+ priorityReads = 0;
518+ override read(collection: string, key: string): unknown {
519+ if (collection === "lamport" || collection.startsWith("replacing:")) this.priorityReads++;
520+ return super.read(collection, key);
521+ }
522+ }
523+ const storage = new ObservedStorage();
524+ try {
525+ const oracle = Repo.init({ "a.txt": "one\ntwo\nthree\n" });
526+ const graph = new Graph({ storage });
527+ graph.add(oracle.graph.atom("a0"));
528+ storage.priorityReads = 0;
529+ assert.deepEqual([...graph.orderedChildrenN(0)], [1]);
530+ assert.deepEqual([...graph.orderedChildrenN(0, 1)], []);
531+ assert.deepEqual([...graph.orderedChildrenN(2)], []);
532+ assert.equal(storage.priorityReads, 0, "single-child traversal does not decode sort priority");
533+ storage.remove("ordered-children", "format");
534+ assert.throws(() => [...graph.orderedChildrenN(0)], /fresh adoption/);
535+ } finally {
536+ storage.db.close();
537+ }
538+});
540+test("ordered layout refuses missing format or child metadata instead of dropping history", () => {
541+ const storage = new SqlState();
542+ try {
543+ const oracle = Repo.init({ "a.txt": "one\n" });
544+ const graph = new Graph({ storage, packFiles: false });
545+ graph.add(oracle.graph.atom("a0"));
546+ storage.remove("ordered-children", "format");
547+ assert.throws(
548+ () => new View(new Graph({ storage, packFiles: false }), new StableOverlaySet(["a0"])).text("a.txt"),
549+ /fresh adoption/,
550+ );
551+ assert.throws(
552+ () =>
553+ new Graph({ storage, packFiles: false }).add(
554+ oracle.draft({ edits: [{ file: "a.txt", old: "one", new: "two" }] }),
555+ ),
556+ /fresh adoption/,
557+ );
558+ storage.write("ordered-children", "format", 2);
559+ const parent = graph.startCodeOf("a.txt")!;
560+ storage.remove("ordered-children", JSON.stringify([String(parent), "meta"]));
561+ assert.throws(() => [...graph.orderedChildrenN(parent)], /missing ordered index metadata/);
562+ } finally {
563+ storage.db.close();
564+ }
565+});
MCP
compare on this site's /mcp
CLI
abso diff 130 318 src/engine/test/state-source.test.ts --json
JSON
/christopher/abso-core/compare/130..318?file=src%2Fengine%2Ftest%2Fstate-source.test.ts&format=json