- MCP
- code on this site's /mcp
- CLI
- none: the JSON below is the answer
- JSON
- /christopher/abso-core/files/server/test/engine-project.test.ts?version=151&format=json
37 linesspeed 100%Last change speed in version 150, 1 version changed it
You're reading version 151. The newest is 318, and 1 version since then changed this file.
1import assert from "node:assert/strict";
2import { describe, it } from "node:test";
3import { answer } from "../../worker/project/http.ts";
4import { EngineProject, SqliteLog } from "../src/engine-project.ts";
5import { memoryStorage } from "./helpers.ts";
7describe("the engine over the object's SQLite log", () => {
8 it("serves init, records and pushes through answer(), and holds a collision", () => {
9 const storage = memoryStorage();
10 const p = EngineProject.open(storage);
11 assert.equal(answer(p, "init", undefined, { files: { "a.txt": "one\ntwo\nthree\n" } }).status, 200);
12 for (const agent of ["alice", "bob"]) assert.equal(answer(p, "sync", agent, {}).status, 200);
13 answer(p, "record", "alice", { files: { "a.txt": "one\nTWO by alice\nthree\n" } });
14 answer(p, "record", "bob", { files: { "a.txt": "one\ntwo by bob\nthree\n" } });
15 const first = answer(p, "publish", "alice", { message: "Alice's two" });
16 assert.deepEqual(first, { status: 200, body: { ok: true, version: 1, changes: 1 } });
17 const second = answer(p, "publish", "bob", { message: "Bob's two" }).body as { ok: boolean; collisions: unknown[] };
18 assert.equal(second.ok, false);
19 assert.equal(second.collisions.length, 1);
20 });
22 it("loads the same project back from the log", () => {
23 const storage = memoryStorage();
24 const p = EngineProject.open(storage);
25 answer(p, "init", undefined, { files: { "a.txt": "one\n" } });
26 answer(p, "sync", "alice", {});
27 answer(p, "record", "alice", { files: { "a.txt": "one\ntwo\n" } });
28 answer(p, "publish", "alice", { message: "Add two" });
29 const again = EngineProject.open(storage);
30 assert.equal(again.shared().version, 1);
31 assert.equal(again.shared().files["a.txt"], "one\ntwo\n");
32 const log = new SqliteLog(storage);
33 assert.equal(log.sharedVersion(), 1);
34 assert.deepEqual(log.lastPublish()?.agent, "alice");
35 assert.equal(log.logSize().entries, log.seq());
36 });
37});