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 156 to 157

Compare

+136 −0 in 1 place
new file, 136 lines
1+import assert from "node:assert/strict";
2+import { mkdtempSync, rmdirSync, unlinkSync } from "node:fs";
3+import { tmpdir } from "node:os";
4+import { join } from "node:path";
5+import { test } from "node:test";
6+import { answer } from "../../worker/project/http.ts";
7+import { MemoryStore, Project } from "../../worker/project/project.ts";
8+import { SqliteLog } from "../src/engine-project.ts";
9+import { SqliteProjectionStore } from "../src/projection-store.ts";
10+import { SqliteWriterHost, SqliteWriterState } from "../src/writer-host.ts";
11+import { memoryStorage } from "./helpers.ts";
13+test("open server adopts and records through its call adapter without full-history loading", (t) => {
14+ const directory = mkdtempSync(join(tmpdir(), "abso-core-writer-"));
15+ const filename = join(directory, "state.sqlite");
16+ let storage = memoryStorage(filename);
17+ const reopen = () => {
18+ storage.db.close();
19+ storage = memoryStorage(filename);
20+ };
21+ t.after(() => {
22+ storage.db.close();
23+ unlinkSync(filename);
24+ rmdirSync(directory);
25+ });
26+ const memory = new MemoryStore();
27+ const oracle = new Project(memory);
28+ oracle.init({ "a.txt": "one\ntwo\n" }, 0);
29+ oracle.record("alice", { "a.txt": "ONE\ntwo\n" }, 1);
30+ oracle.publish("alice", "First", 2);
31+ oracle.move("alice", "a.txt", "b.txt", 3);
32+ oracle.publish("alice", "Move", 4);
33+ new SqliteLog(storage).append(memory.entries);
34+ SqliteWriterState.initialize(storage);
35+ const namespace = "open-server-capacity";
36+ const host = () => new SqliteWriterHost(storage, namespace, undefined, { indexProjectionAtoms: true });
37+ const expected = host().source();
38+ const canonicalBefore = storage.db.prepare("SELECT * FROM log ORDER BY seq, part").all();
39+ t.mock.method(Project, "load", () => {
40+ throw Error("full-history loading forbidden");
41+ });
42+ let from = 0,
43+ digest = "",
44+ ready = false;
45+ while (!ready) {
46+ const page = host().adoptVerifiedPage({ expected, from, digest, maxEntries: 2, maxBytes: 16384 }, () => {});
47+ assert.deepEqual(
48+ host().adoptVerifiedPage({ expected, from, digest, maxEntries: 2, maxBytes: 16384 }, () => {}),
49+ page,
50+ );
51+ from = page.next;
52+ digest = page.digest;
53+ ready = page.ready;
54+ reopen();
55+ }
56+ assert.deepEqual(storage.db.prepare("SELECT * FROM log ORDER BY seq, part").all(), canonicalBefore);
57+ let state = new SqliteWriterState(storage, namespace);
58+ const projection = new SqliteProjectionStore(
59+ { database: "project", namespace: "views", registry: "roots", defaultFile: "a.txt" },
60+ 1,
61+ { indexedAtoms: true },
62+ );
63+ let pages = 0;
64+ while (
65+ !projection.adopt({
66+ state,
67+ expected: host().root(),
68+ currentRoot: () => host().root(),
69+ maxAtoms: 1,
70+ maxVersions: 1,
71+ maxSteps: 2,
72+ }).ready
73+ )
74+ assert.ok(++pages < 1000);
75+ const writer = () => new SqliteWriterHost(storage, namespace, projection, { indexProjectionAtoms: true });
76+ const run = (operation: "record" | "publish", body: unknown, failReceipt = false) =>
77+ writer().runCalls({
78+ expected: writer().source(),
79+ validateAuthority: () => {},
80+ checkerReady: false,
81+ operation: (calls) => answer(calls, operation, "alice", body),
82+ commitReceipt: (result, source) => {
83+ state.write("receipts", operation, { result, source });
84+ if (failReceipt) throw Error("receipt failure");
85+ },
86+ });
87+ const rows = () => ({
88+ log: storage.db.prepare("SELECT * FROM log ORDER BY seq, part").all(),
89+ state: storage.db.prepare("SELECT * FROM writer_state ORDER BY namespace, collection, key, part").all(),
90+ });
91+ const before = rows();
92+ assert.throws(() => run("record", { files: { "b.txt": "failed\n" } }, true), /receipt failure/);
93+ assert.deepEqual(rows(), before);
94+ assert.equal(run("record", { files: { "b.txt": "finished\n" } }).status, 200);
95+ const published = run("publish", { message: "Disk first" });
96+ assert.equal(published.status, 200);
97+ assert.equal((published.body as { ok: boolean }).ok, true);
98+ reopen();
99+ state = new SqliteWriterState(storage, namespace);
100+ const beforeRead = rows();
101+ assert.equal(
102+ writer().readCalls({
103+ expected: writer().source(),
104+ validateAuthority: () => {},
105+ operation: (calls) => calls.shared().files["b.txt"],
106+ }),
107+ "finished\n",
108+ );
109+ assert.deepEqual(rows(), beforeRead);
110+ assert.throws(
111+ () =>
112+ writer().runCalls({
113+ expected,
114+ validateAuthority: () => {},
115+ checkerReady: false,
116+ operation: () => undefined,
117+ commitReceipt: () => {},
118+ }),
119+ /stale/,
120+ );
121+ const committed = rows();
122+ assert.throws(
123+ () =>
124+ writer().runCalls({
125+ expected: writer().source(),
126+ validateAuthority: () => {
127+ throw Error("revoked authority");
128+ },
129+ checkerReady: false,
130+ operation: () => undefined,
131+ commitReceipt: () => {},
132+ }),
133+ /revoked authority/,
134+ );
135+ assert.deepEqual(rows(), committed);
136+});
MCP
compare on this site's /mcp
CLI
abso diff 156 157 server/test/writer-host.test.ts --json
JSON
/christopher/abso-core/compare/156..157?file=server%2Ftest%2Fwriter-host.test.ts&format=json