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

Compare

+79 −0 in 1 place
new file, 79 lines
1+import assert from "node:assert/strict";
2+import { test } from "node:test";
3+import { ChildCounts } from "../child-counts.ts";
4+import { Graph } from "../graph.ts";
5+import { CachedStateStorage } from "../state-source.ts";
6+import { Repo } from "./helpers.ts";
7+import { SqlState } from "./storage-helper.ts";
8+
9+test("child counts cross pages, reopen and roll back with the canonical transaction", () => {
10+ const source = new SqlState();
11+ try {
12+ const cache = new CachedStateStorage(source);
13+ const counts = new ChildCounts(cache);
14+ for (let n = 0; n < 513; n++) cache.transaction(() => counts.append(n));
15+ cache.transaction(() => counts.increment(255, 513));
16+ assert.equal(new ChildCounts(cache).at(255, 513), 1);
17+ assert.equal(counts.at(256, 513), 0);
18+ assert.throws(
19+ () =>
20+ cache.transaction(() => {
21+ counts.increment(255, 513);
22+ counts.append(513);
23+ throw new Error("rollback");
24+ }),
25+ /rollback/,
26+ );
27+ assert.equal(counts.at(255, 513), 1);
28+ assert.equal(counts.at(512, 513), 0);
29+ assert.equal(cache.retainedEntries > 0, true);
30+ } finally {
31+ source.db.close();
32+ }
33+});
35+test("child counts reject missing, relocated, truncated and inconsistent zero-count pages", () => {
36+ const source = new SqlState();
37+ try {
38+ const counts = new ChildCounts(source);
39+ counts.append(0);
40+ counts.append(1);
41+ counts.increment(0, 2);
42+ const original = source.read("ordered-child-counts", "0") as Record<string, unknown>;
43+ for (const changed of [
44+ { ...original, counts: [0, 0] },
45+ { ...original, counts: [1] },
46+ { ...original, page: 1 },
47+ { ...original, format: 2 },
48+ { ...original, digest: "invalid" },
49+ ]) {
50+ source.write("ordered-child-counts", "0", changed);
51+ assert.throws(() => counts.at(0, 2), /invalid ordered child count page/);
52+ }
53+ source.remove("ordered-child-counts", "0");
54+ assert.throws(() => counts.at(0, 2), /invalid ordered child count page/);
55+ } finally {
56+ source.db.close();
57+ }
58+});
60+test("graph rejects the previous ordered format and count corruption before empty-child shortcuts", () => {
61+ const source = new SqlState();
62+ try {
63+ const repo = Repo.init({ "a.txt": "one\ntwo\n" });
64+ const graph = new Graph({ storage: source });
65+ graph.add(repo.graph.atom("a0"));
66+ assert.deepEqual([...graph.orderedChildrenN(0)], [1]);
67+ source.write("ordered-children", "format", 1);
68+ assert.throws(() => [...graph.orderedChildrenN(0)], /fresh adoption/);
69+ source.write("ordered-children", "format", 2);
70+ new ChildCounts(source).increment(0, 2);
71+ assert.throws(() => [...graph.orderedChildrenN(0)], /ordered child index count mismatch/);
72+ const page = source.read("ordered-child-counts", "0") as { counts: number[] };
73+ page.counts[0] = 0;
74+ source.write("ordered-child-counts", "0", page);
75+ assert.throws(() => [...graph.orderedChildrenN(0)], /invalid ordered child count page/);
76+ } finally {
77+ source.db.close();
78+ }
79+});
MCP
compare on this site's /mcp
CLI
abso diff 2 318 src/engine/test/child-counts.test.ts --json
JSON
/christopher/abso-core/compare/2..318?file=src%2Fengine%2Ftest%2Fchild-counts.test.ts&format=json