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
56 linescodex-capacity-chair 100%Last change codex-capacity-chair in version 143, 1 version changed it

You're reading version 168. The newest is 318, and 1 version since then changed this file. Go to the newestCompare with 318

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 iterator = reader.visibleLines("f.txt");
25 assert.equal(iterator.next().value?.text, "one");
26 if (end === "source") source = {};
27 else if (end === "nested") {
28 const child = scope.nested();
29 assert.throws(() => reader.text("f.txt"), /stale/);
30 const childGuard = child.guard(graph);
31 childGuard();
32 child.close();
33 assert.throws(childGuard, /expired/);
34 scope.guard(graph)();
35 } else if (end === "graph") {
36 repo.edit({ edits: [{ file: "f.txt", old: "one\ntwo\n", new: "changed\n" }] });
37 graph.add(repo.graph.atom("a1"));
38 } else scope.close();
39 let touched = false;
40 const refuseAccess = () => {
41 touched = true;
42 throw Error("expired reader touched data");
43 };
44 t.mock.method(storage, "read", refuseAccess);
45 t.mock.method(storage, "entries", refuseAccess);
46 t.mock.method(graph, "lineN", refuseAccess);
47 t.mock.method(graph, "textOf", refuseAccess);
48 assert.throws(() => reader.text("f.txt"), /expired|stale/);
49 assert.throws(() => membership.has("a0"), /expired|stale/);
50 assert.throws(() => iterator.next(), /expired|stale/);
51 assert.equal(touched, false);
52 } finally {
53 storage.db.close();
54 }
55 });