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

Compare

+71 −0 in 1 place
new file, 71 lines
1+import assert from "node:assert/strict";
2+import { test } from "node:test";
3+import { ProjectionLocator } from "../experimental/projection-locator.ts";
4+import { ExperimentalMarkerProjection } from "../experimental/projection-marker.ts";
5+import { ProjectionReader } from "../experimental/projection-reader.ts";
6+import { Graph } from "../graph.ts";
7+import { Repo } from "./helpers.ts";
8+import { SqlState } from "./storage-helper.ts";
9+
10+test("locator streams ordered immutable leaves with bounded first-result reads", () => {
11+ const db = new SqlState();
12+ try {
13+ const index = new ProjectionLocator(db, "iterate", (v) => {
14+ if (typeof v !== "number") throw Error("invalid value");
15+ return v;
16+ });
17+ let root: number | null = null;
18+ for (let id = 511; id >= 0; id--) root = index.set(root, id, id);
19+ const previous = root;
20+ root = index.set(root, 256, -1);
21+ const before = db.reads;
22+ const iterator = index.entries(root);
23+ assert.deepEqual(iterator.next().value, [0, 0]);
24+ assert.ok(db.reads - before <= 9);
25+ iterator.return?.();
26+ assert.deepEqual(
27+ [...index.entries(previous)],
28+ Array.from({ length: 512 }, (_, id) => [id, id]),
29+ );
30+ assert.equal([...index.entries(root)][256]?.[1], -1);
31+ db.write('experimental-locator:"iterate"', String(root), {
32+ format: 1,
33+ kind: "branch",
34+ prefix: "",
35+ children: { 0: root, 1: root },
36+ });
37+ assert.throws(() => index.entries(root).next(), /invalid locator child/);
38+ } finally {
39+ db.db.close();
40+ }
41+});
43+test("projected membership streams without atom payload reads and expires with its scope", () => {
44+ const db = new SqlState();
45+ try {
46+ const repo = Repo.init({ "a.txt": "one\n" });
47+ const atoms = [repo.graph.atom("a0"), repo.edit({ edits: [{ file: "a.txt", old: "one\n", new: "two\n" }] })];
48+ const graph = new Graph({ storage: db });
49+ for (const atom of atoms) graph.add(atom);
50+ const adapter = new ExperimentalMarkerProjection(db, graph, "a.txt", "membership");
51+ let state = adapter.empty();
52+ for (const atom of atoms) state = adapter.apply(state, atom);
53+ let live = true;
54+ const reader = new ProjectionReader(adapter, state, () => {
55+ if (!live) throw Error("expired");
56+ });
57+ const read = db.read.bind(db);
58+ db.read = (collection, key) => {
59+ if (collection === "atoms") throw Error("atom payload read forbidden");
60+ return read(collection, key);
61+ };
62+ assert.deepEqual([...reader.set], ["a0", "a1"]);
63+ assert.equal(reader.set.has("a1"), true);
64+ const iterator = reader.set.values();
65+ assert.equal(iterator.next().value, "a0");
66+ live = false;
67+ assert.throws(() => iterator.next(), /expired/);
68+ } finally {
69+ db.db.close();
70+ }
71+});
MCP
compare on this site's /mcp
CLI
abso diff 90 318 src/engine/test/projection-membership-iterator.test.ts --json
JSON
/christopher/abso-core/compare/90..318?file=src%2Fengine%2Ftest%2Fprojection-membership-iterator.test.ts&format=json