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

Compare

+101 −0 in 1 place
new file, 101 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+ // A scratch rollback drops only what the scratch wrote (abso Capacity): the canonical value written before it, in
36+ // the outer transaction, stays cached and is still right.
37+ assert.equal(storage.retainedEntries, 1, "only the canonical value written before the scratch remains");
38+ assert.equal(storage.read("canonical", "before"), 1);
39+ storage.write("canonical", "after", 2);
40+ });
41+ assert.equal(source.db.prepare("SELECT count(*) AS n FROM state").get()!.n, 2);
42+ assert.equal(storage.retainedEntries, 2, "only the canonical read and successful counter write remain");
43+ assert.equal(storage.read("canonical", "after"), 2);
44+ } finally {
45+ source.db.close();
46+ }
47+});
49+test("projection errors, changed identities and escaping capabilities cannot commit scratch", () => {
50+ const source = new SqlState();
51+ try {
52+ let checks = 0;
53+ assert.throws(
54+ () =>
55+ withProjectionScratch(
56+ source,
57+ () => {
58+ if (++checks === 2) throw new Error("identity changed");
59+ },
60+ (scratch) => {
61+ scratch.write("x", "y", 1);
62+ return 2;
63+ },
64+ ),
65+ /identity changed/,
66+ );
67+ assert.throws(
68+ () =>
69+ withProjectionScratch(
70+ source,
71+ () => {},
72+ (scratch) => {
73+ scratch.write("x", "y", 1);
74+ throw new Error("failed computation");
75+ },
76+ ),
77+ /failed computation/,
78+ );
79+ assert.throws(
80+ () =>
81+ withProjectionScratch(
82+ source,
83+ () => {},
84+ (scratch) => scratch,
85+ ),
86+ /clone|cloned/i,
87+ );
88+ assert.throws(
89+ () =>
90+ withProjectionScratch(
91+ source,
92+ () => {},
93+ () => Promise.resolve(1),
94+ ),
95+ /synchronously/,
96+ );
97+ assert.equal(source.db.prepare("SELECT count(*) AS n FROM state").get()!.n, 0);
98+ } finally {
99+ source.db.close();
100+ }
101+});
MCP
compare on this site's /mcp
CLI
abso diff 116 318 src/engine/test/projection-scratch.test.ts --json
JSON
/christopher/abso-core/compare/116..318?file=src%2Fengine%2Ftest%2Fprojection-scratch.test.ts&format=json