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 142 to 143

Compare

+49 −0 in 1 place
new file, 49 lines
1+import assert from "node:assert/strict";
2+import { test } from "node:test";
3+import { ProjectionLocator } from "../experimental/projection-locator.ts";
4+import { SqlState } from "./storage-helper.ts";
5+
6+const decode = (value: unknown): number => {
7+ if (!Number.isSafeInteger(value)) throw Error("invalid payload");
8+ return value as number;
9+};
10+test("experimental locator preserves sparse old roots and rejects corrupt storage", () => {
11+ const storage = new SqlState();
12+ try {
13+ const index = new ProjectionLocator(storage, "test", decode),
14+ keys = [0, 0xffffffff, 16, 1, 0x80000000, 255, 256];
15+ let root: number | null = null;
16+ const versions: number[] = [];
17+ for (const id of keys) {
18+ root = index.set(root, id, id);
19+ versions.push(root);
20+ }
21+ for (let i = 0; i < versions.length; i++)
22+ for (let j = 0; j < keys.length; j++)
23+ assert.equal(index.get(versions[i]!, keys[j]!), j <= i ? keys[j] : undefined);
24+ const before = JSON.stringify(storage.db.prepare("SELECT * FROM state ORDER BY collection,key").all());
25+ storage.failWrite = storage.writes + 3;
26+ assert.throws(() => index.set(root, 42, 42), /injected/);
27+ assert.equal(JSON.stringify(storage.db.prepare("SELECT * FROM state ORDER BY collection,key").all()), before);
28+ storage.failWrite = Infinity;
29+ for (const id of [-1, 2 ** 32, 0.5, NaN]) assert.throws(() => index.get(root, id), /identity limit/);
30+ const collection = 'experimental-locator:"test"',
31+ saved = storage.read(collection, String(root));
32+ for (const corrupt of [
33+ { format: 2, kind: "leaf", prefix: "00000000", value: 0 },
34+ { format: 1, kind: "leaf", prefix: "0", value: 0 },
35+ { format: 1, kind: "branch", prefix: "", children: { "0": root, f: 0 } },
36+ { format: 1, kind: "branch", prefix: "", children: { "00": 0, f: 1 } },
37+ ]) {
38+ storage.write(collection, String(root), corrupt);
39+ assert.throws(() => index.get(root, 0), /invalid locator/);
40+ }
41+ storage.write(collection, String(root), saved);
42+ assert.equal(index.get(root, 16), 16);
43+ const leaf = index.set(null, 7, 7);
44+ storage.write(collection, String(leaf), { format: 1, kind: "leaf", prefix: "00000007", value: "bad" });
45+ assert.throws(() => index.get(leaf, 7), /invalid payload/);
46+ } finally {
47+ storage.db.close();
48+ }
49+});
MCP
compare on this site's /mcp
CLI
abso diff 142 143 src/engine/test/projection-locator.test.ts --json
JSON
/christopher/abso-core/compare/142..143?file=src%2Fengine%2Ftest%2Fprojection-locator.test.ts&format=json