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

Compare

+106 −0 in 2 places
Lines 3–56 at 318 (were 3–8 at 128)
33import { CachedStateStorage } from "../state-source.ts";
44import { SqlState } from "./storage-helper.ts";
55
6+test("numeric cache pages are detached on first and repeated reads, and rollback invalidates them", () => {
7+ const source = new SqlState();
8+ try {
9+ const cache = new CachedStateStorage(source, 4096, 4);
10+ cache.write("numbers", "page", [1, 2, 3]);
11+ (cache.read("numbers", "page") as number[])[0] = 99;
12+ assert.deepEqual(cache.read("numbers", "page"), [1, 2, 3]);
13+ (cache.read("numbers", "page") as number[]).push(4);
14+ assert.deepEqual(cache.read("numbers", "page"), [1, 2, 3]);
15+ assert.throws(
16+ () =>
17+ cache.transaction(() => {
18+ cache.write("numbers", "page", [8]);
19+ assert.deepEqual(cache.read("numbers", "page"), [8]);
20+ throw new Error("rollback numeric page");
21+ }),
22+ /rollback numeric page/,
23+ );
24+ assert.equal(cache.retainedBytes, 0);
25+ assert.deepEqual(cache.read("numbers", "page"), [1, 2, 3]);
26+ cache.remove("numbers", "page");
27+ assert.equal(cache.read("numbers", "page"), undefined);
28+ } finally {
29+ source.db.close();
30+ }
31+});
33+test("cached scalar metadata and bounded numeric pages need no JSON decode on hits", (t) => {
34+ const source = new SqlState();
35+ try {
36+ const cache = new CachedStateStorage(source, 8192, 8);
37+ const values = [undefined, null, true, "metadata", 42, Array.from({ length: 256 }, (_, n) => n)];
38+ for (let i = 0; i < values.length; i++) {
39+ cache.write("rows", String(i), values[i]);
40+ cache.read("rows", String(i));
41+ }
42+ const reads = source.reads;
43+ t.mock.method(JSON, "parse", () => {
44+ throw new Error("cache hit unexpectedly decoded JSON");
45+ });
46+ for (let i = 0; i < values.length; i++) assert.deepEqual(cache.read("rows", String(i)), values[i]);
47+ assert.equal(source.reads, reads);
48+ assert.ok(cache.retainedBytes <= 8192);
49+ } finally {
50+ source.db.close();
51+ }
52+});
654test("bounded writer cache copies values, invalidates writes and clears after rollback", () => {
755 const source = new SqlState();
856 const cache = new CachedStateStorage(source, 1024, 3);
Lines 105–165 at 318 (were 57–59 at 128)
57105 assert.equal(cache.retainedBytes, 0);
58106 source.db.close();
59107});
109+test("a rollback drops only what its transaction wrote; a nested commit's writes go with an outer rollback (abso Capacity)", () => {
110+ const source = new SqlState();
111+ try {
112+ const cache = new CachedStateStorage(source, 8192, 16);
113+ source.write("rows", "kept", "k");
114+ source.write("rows", "inner", "i0");
115+ source.write("rows", "outer", "o0");
116+ for (const key of ["kept", "inner", "outer"]) cache.read("rows", key);
117+ const reads = source.reads;
118+ // A projection scratch scope: rolled back on purpose, and the rows read around it stay cached.
119+ assert.throws(
120+ () =>
121+ cache.transaction(() => {
122+ cache.write("scratch", "x", "temporary");
123+ throw new Error("scratch rollback");
124+ }),
125+ /scratch rollback/,
126+ );
127+ assert.equal(cache.read("rows", "kept"), "k");
128+ assert.equal(source.reads, reads, "the rows read before were not read again");
129+ assert.equal(cache.read("scratch", "x"), undefined);
130+ // A nested transaction commits, then the outer one rolls back: both writes are undone, and the cache forgets both.
131+ assert.throws(
132+ () =>
133+ cache.transaction(() => {
134+ cache.write("rows", "outer", "o1");
135+ cache.transaction(() => cache.write("rows", "inner", "i1"));
136+ assert.equal(cache.read("rows", "inner"), "i1");
137+ throw new Error("outer rollback");
138+ }),
139+ /outer rollback/,
140+ );
141+ assert.equal(cache.read("rows", "inner"), "i0");
142+ assert.equal(cache.read("rows", "outer"), "o0");
143+ assert.equal(cache.read("rows", "kept"), "k");
144+ } finally {
145+ source.db.close();
146+ }
147+});
149+test("a row over the per-row limit is read but not kept, and pushes nothing out (abso Capacity)", () => {
150+ const source = new SqlState();
151+ try {
152+ const cache = new CachedStateStorage(source, 8192, 64, 1024);
153+ source.write("rows", "small", "s");
154+ source.write("rows", "big", "x".repeat(2000));
155+ cache.read("rows", "small");
156+ const reads = source.reads;
157+ assert.equal((cache.read("rows", "big") as string).length, 2000);
158+ assert.equal(cache.read("rows", "small"), "s");
159+ assert.equal(source.reads, reads + 1, "the big row was read from storage once and the small one stayed cached");
160+ assert.equal((cache.read("rows", "big") as string).length, 2000);
161+ assert.equal(source.reads, reads + 2, "the big row isn't kept");
162+ } finally {
163+ source.db.close();
164+ }
165+});
MCP
compare on this site's /mcp
CLI
abso diff 128 318 src/engine/test/state-cache.test.ts --json
JSON
/christopher/abso-core/compare/128..318?file=src%2Fengine%2Ftest%2Fstate-cache.test.ts&format=json