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
MCP
code on this site's /mcp
CLI
none: the JSON below is the answer
JSON
/christopher/abso-core/files/src/engine/test/projection-read-scope.test.ts?format=json
63 linescodex-capacity-chair 100%Last change codex-capacity-chair in version 175, 2 versions changed it
1import assert from "node:assert/strict";
2import { test } from "node:test";
3import { ExperimentalMarkerProjection } from "../experimental/projection-marker.ts";
4import { ProjectionReadScope } from "../experimental/projection-read-scope.ts";
5import { ProjectionReader } from "../experimental/projection-reader.ts";
6import { Graph } from "../graph.ts";
7import { Repo } from "./helpers.ts";
8import { SqlState } from "./storage-helper.ts";
9
10for (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 });