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

Compare

+69 −0 in 1 place
new file, 69 lines
1+import assert from "node:assert/strict";
2+import { test } from "node:test";
3+import { answer } from "../../worker/project/http.ts";
4+import { DiskFirstRuntime } from "../src/disk-first-runtime.ts";
5+import { memoryStorage } from "./helpers.ts";
6+
7+test("disk runtime restores unpublished files and preserves published history", (t) => {
8+ const storage = memoryStorage();
9+ t.after(() => storage.db.close());
10+ const runtime = () => new DiskFirstRuntime(storage, "restore", "restore");
11+ runtime().initialize(
12+ (c) => answer(c, "init", undefined, { files: { "a.txt": "original\n", "b.txt": "kept\n" } }),
13+ () => {},
14+ );
15+ while (!runtime().preparePage(() => {}).ready) {}
16+ const call = (op: string, body: unknown) =>
17+ runtime().write(
18+ (c) => answer(c, op, "alice", body),
19+ () => {},
20+ );
21+ assert.equal(call("record", { files: { "a.txt": "changed\n", "b.txt": "different\n" } }).status, 200);
22+ const result = call("restore", { all: true });
23+ assert.equal(result.status, 200, JSON.stringify(result));
24+ assert.deepEqual((result.body as { files: unknown }).files, { "a.txt": "original\n", "b.txt": "kept\n" });
25+ assert.deepEqual(
26+ runtime().read(
27+ (c) => c.shared().files,
28+ () => {},
29+ ),
30+ { "a.txt": "original\n", "b.txt": "kept\n" },
31+ );
32+});
34+for (const queued of [false, true]) {
35+ test(`disk restore preserves ${queued ? "queued" : "untargeted"} edits`, (t) => {
36+ const storage = memoryStorage();
37+ t.after(() => storage.db.close());
38+ const runtime = () => new DiskFirstRuntime(storage, "partial", "partial");
39+ runtime().initialize(
40+ (c) =>
41+ answer(c, "init", undefined, {
42+ files: { "avcs.json": JSON.stringify({ queue: queued }), "a.txt": "original\n", "b.txt": "original b\n" },
43+ }),
44+ () => {},
45+ );
46+ while (!runtime().preparePage(() => {}).ready) {}
47+ const call = (op: string, body: unknown) =>
48+ runtime().write(
49+ (c) => {
50+ c.setCheckerReady(true);
51+ return answer(c, op, "alice", body);
52+ },
53+ () => {},
54+ );
55+ assert.equal(call("record", { files: { "b.txt": "preserved\n" } }).status, 200);
56+ if (queued) {
57+ const published = call("publish", { message: "queued work" });
58+ assert.equal(published.status, 200, JSON.stringify(published));
59+ assert.equal((published.body as { queued?: number }).queued, 1);
60+ }
61+ assert.equal(call("record", { files: { "a.txt": "discard me\n" } }).status, 200);
62+ const restored = call("restore", queued ? { all: true } : { files: ["a.txt"] });
63+ assert.equal(restored.status, 200, JSON.stringify(restored));
64+ assert.deepEqual((restored.body as { files: unknown }).files, { "a.txt": "original\n" });
65+ const synced = call("sync", {});
66+ assert.equal(synced.status, 200, JSON.stringify(synced));
67+ assert.equal((synced.body as { files: Record<string, string> }).files["b.txt"], "preserved\n");
68+ });
69+}
MCP
compare on this site's /mcp
CLI
abso diff 3 318 server/test/projected-restore.test.ts --json
JSON
/christopher/abso-core/compare/3..318?file=server%2Ftest%2Fprojected-restore.test.ts&format=json