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

Compare

+57 −0 in 1 place
new file, 57 lines
1+import assert from "node:assert/strict";
2+import { describe, it } from "node:test";
3+import { answer } from "../../worker/project/http.ts";
4+import { EngineProject, SqliteLog } from "../src/engine-project.ts";
5+import { memoryStorage } from "./helpers.ts";
6+
7+describe("the engine over the object's SQLite log", () => {
8+ it("extracts feed events without retaining a page of canonical payloads", (t) => {
9+ const storage = memoryStorage();
10+ t.after(() => storage.db.close());
11+ const project = EngineProject.open(storage);
12+ answer(project, "init", undefined, { files: { "a.txt": "one\n" } });
13+ answer(project, "sync", "alice", {});
14+ answer(project, "record", "alice", { files: { "a.txt": "two\n" } });
15+ answer(project, "publish", "alice", { message: "Changed" });
16+ const expected = project.feed(0, 500);
17+ const original = SqliteLog.prototype.since;
18+ let reads = 0;
19+ t.mock.method(SqliteLog.prototype, "since", function (this: SqliteLog, from: number, limit: number) {
20+ assert.equal(limit, 1, "feed must release each canonical payload before reading another");
21+ reads++;
22+ return original.call(this, from, limit);
23+ });
24+ assert.deepEqual(project.feed(0, 500), expected);
25+ assert.equal(reads, expected.next);
26+ assert.deepEqual(project.feed(1, 2).events, expected.events.slice(1, 3));
27+ });
28+ it("serves init, records and pushes through answer(), and holds a collision", () => {
29+ const storage = memoryStorage();
30+ const p = EngineProject.open(storage);
31+ assert.equal(answer(p, "init", undefined, { files: { "a.txt": "one\ntwo\nthree\n" } }).status, 200);
32+ for (const agent of ["alice", "bob"]) assert.equal(answer(p, "sync", agent, {}).status, 200);
33+ answer(p, "record", "alice", { files: { "a.txt": "one\nTWO by alice\nthree\n" } });
34+ answer(p, "record", "bob", { files: { "a.txt": "one\ntwo by bob\nthree\n" } });
35+ const first = answer(p, "publish", "alice", { message: "Alice's two" });
36+ assert.deepEqual(first, { status: 200, body: { ok: true, version: 1, changes: 1 } });
37+ const second = answer(p, "publish", "bob", { message: "Bob's two" }).body as { ok: boolean; collisions: unknown[] };
38+ assert.equal(second.ok, false);
39+ assert.equal(second.collisions.length, 1);
40+ });
42+ it("loads the same project back from the log", () => {
43+ const storage = memoryStorage();
44+ const p = EngineProject.open(storage);
45+ answer(p, "init", undefined, { files: { "a.txt": "one\n" } });
46+ answer(p, "sync", "alice", {});
47+ answer(p, "record", "alice", { files: { "a.txt": "one\ntwo\n" } });
48+ answer(p, "publish", "alice", { message: "Add two" });
49+ const again = EngineProject.open(storage);
50+ assert.equal(again.shared().version, 1);
51+ assert.equal(again.shared().files["a.txt"], "one\ntwo\n");
52+ const log = new SqliteLog(storage);
53+ assert.equal(log.sharedVersion(), 1);
54+ assert.deepEqual(log.lastPublish()?.agent, "alice");
55+ assert.equal(log.logSize().entries, log.seq());
56+ });
57+});
MCP
compare on this site's /mcp
CLI
abso diff 5 318 server/test/engine-project.test.ts --json
JSON
/christopher/abso-core/compare/5..318?file=server%2Ftest%2Fengine-project.test.ts&format=json