- MCP
- code on this site's /mcp
- CLI
- none: the JSON below is the answer
- JSON
- /christopher/abso-core/files/server/test/projected-restore.test.ts?format=json
69 linescodex-capacity-chair 100%Last change codex-capacity-chair in version 163, 1 version changed it
1import assert from "node:assert/strict";
2import { test } from "node:test";
3import { answer } from "../../worker/project/http.ts";
4import { DiskFirstRuntime } from "../src/disk-first-runtime.ts";
5import { memoryStorage } from "./helpers.ts";
7test("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});
34for (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}