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 131 to 132

Compare

+98 −0 in 1 place
new file, 98 lines
1+import assert from "node:assert/strict";
2+import { test } from "node:test";
3+import { withProjectionScratch } from "../projection-scratch.ts";
4+import { CachedStateStorage, type GraphStateStorage } from "../state-source.ts";
5+import { SqlState } from "./storage-helper.ts";
6+
7+test("projection scratch is isolated, detached and rolled back inside canonical transactions", () => {
8+ const source = new SqlState();
9+ const storage = new CachedStateStorage(source);
10+ try {
11+ storage.transaction(() => {
12+ storage.write("canonical", "before", 1);
13+ let escaped: GraphStateStorage | undefined;
14+ const result = withProjectionScratch(
15+ storage,
16+ () => {},
17+ (scratch) => {
18+ escaped = scratch;
19+ scratch.write("canonical", "before", 99);
20+ const inner = withProjectionScratch(
21+ storage,
22+ () => {},
23+ (nested) => {
24+ assert.equal(nested.read("canonical", "before"), undefined);
25+ nested.write("canonical", "before", 101);
26+ return nested.read("canonical", "before");
27+ },
28+ );
29+ assert.equal(inner, 101);
30+ return { value: scratch.read("canonical", "before"), data: new Int32Array([1, 2]) };
31+ },
32+ );
33+ assert.deepEqual(result, { value: 99, data: new Int32Array([1, 2]) });
34+ assert.throws(() => escaped!.write("x", "y", true), /ended/);
35+ assert.equal(storage.read("canonical", "before"), 1);
36+ storage.write("canonical", "after", 2);
37+ });
38+ assert.equal(source.db.prepare("SELECT count(*) AS n FROM state").get()!.n, 2);
39+ assert.equal(storage.retainedEntries, 1);
40+ assert.equal(storage.read("canonical", "after"), 2);
41+ } finally {
42+ source.db.close();
43+ }
44+});
46+test("projection errors, changed identities and escaping capabilities cannot commit scratch", () => {
47+ const source = new SqlState();
48+ try {
49+ let checks = 0;
50+ assert.throws(
51+ () =>
52+ withProjectionScratch(
53+ source,
54+ () => {
55+ if (++checks === 2) throw new Error("identity changed");
56+ },
57+ (scratch) => {
58+ scratch.write("x", "y", 1);
59+ return 2;
60+ },
61+ ),
62+ /identity changed/,
63+ );
64+ assert.throws(
65+ () =>
66+ withProjectionScratch(
67+ source,
68+ () => {},
69+ (scratch) => {
70+ scratch.write("x", "y", 1);
71+ throw new Error("failed computation");
72+ },
73+ ),
74+ /failed computation/,
75+ );
76+ assert.throws(
77+ () =>
78+ withProjectionScratch(
79+ source,
80+ () => {},
81+ (scratch) => scratch,
82+ ),
83+ /clone|cloned/i,
84+ );
85+ assert.throws(
86+ () =>
87+ withProjectionScratch(
88+ source,
89+ () => {},
90+ () => Promise.resolve(1),
91+ ),
92+ /synchronously/,
93+ );
94+ assert.equal(source.db.prepare("SELECT count(*) AS n FROM state").get()!.n, 0);
95+ } finally {
96+ source.db.close();
97+ }
98+});
MCP
compare on this site's /mcp
CLI
abso diff 131 132 src/engine/test/projection-scratch.test.ts --json
JSON
/christopher/abso-core/compare/131..132?file=src%2Fengine%2Ftest%2Fprojection-scratch.test.ts&format=json