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

+63 −0 in 1 place
new file, 63 lines
1+import assert from "node:assert/strict";
2+import { test } from "node:test";
3+import { ExperimentalMarkerProjection } from "../experimental/projection-marker.ts";
4+import { ProjectionReadScope } from "../experimental/projection-read-scope.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+for (const end of ["commit", "rollback", "source", "nested", "graph"] as const) {
11+ test(`projected reads reject stale methods, membership and iterator resume after ${end}`, (t) => {
12+ const storage = new SqlState();
13+ try {
14+ const repo = Repo.init({ "f.txt": "one\ntwo\n" });
15+ const graph = new Graph();
16+ graph.add(repo.graph.atom("a0"));
17+ const adapter = new ExperimentalMarkerProjection(storage, graph, "f.txt", "scope-test");
18+ const state = adapter.apply(adapter.empty(), graph.atom("a0"));
19+ let source = {};
20+ const scope = new ProjectionReadScope(graph, () => source);
21+ assert.throws(() => scope.guard(new Graph()), /mismatch/);
22+ const reader = new ProjectionReader(adapter, state, scope.guard(graph));
23+ const membership = reader.set;
24+ const heldLine = reader.buildLines("f.txt")[0]!;
25+ const chunkSource = reader.lineChunks("f.txt").next().value!;
26+ const chunks = chunkSource()[Symbol.iterator]();
27+ assert.equal(chunks.next().value, "one");
28+ const iterator = reader.visibleLines("f.txt");
29+ assert.equal(iterator.next().value?.text, "one");
30+ if (end === "source") source = {};
31+ else if (end === "nested") {
32+ const child = scope.nested();
33+ assert.throws(() => reader.text("f.txt"), /stale/);
34+ const childGuard = child.guard(graph);
35+ childGuard();
36+ child.close();
37+ assert.throws(childGuard, /expired/);
38+ scope.guard(graph)();
39+ } else if (end === "graph") {
40+ repo.edit({ edits: [{ file: "f.txt", old: "one\ntwo\n", new: "changed\n" }] });
41+ graph.add(repo.graph.atom("a1"));
42+ } else scope.close();
43+ let touched = false;
44+ const refuseAccess = () => {
45+ touched = true;
46+ throw Error("expired reader touched data");
47+ };
48+ t.mock.method(storage, "read", refuseAccess);
49+ t.mock.method(storage, "entries", refuseAccess);
50+ t.mock.method(graph, "lineN", refuseAccess);
51+ t.mock.method(graph, "textOf", refuseAccess);
52+ assert.throws(() => reader.text("f.txt"), /expired|stale/);
53+ assert.throws(() => heldLine.text, /expired|stale/);
54+ assert.throws(() => chunks.next(), /expired|stale/);
55+ assert.throws(() => chunkSource()[Symbol.iterator]().next(), /expired|stale/);
56+ assert.throws(() => membership.has("a0"), /expired|stale/);
57+ assert.throws(() => iterator.next(), /expired|stale/);
58+ assert.equal(touched, false);
59+ } finally {
60+ storage.db.close();
61+ }
62+ });
63+}
MCP
compare on this site's /mcp
CLI
abso diff 2 318 src/engine/test/projection-read-scope.test.ts --json
JSON
/christopher/abso-core/compare/2..318?file=src%2Fengine%2Ftest%2Fprojection-read-scope.test.ts&format=json