- MCP
- code on this site's /mcp
- CLI
- none: the JSON below is the answer
- JSON
- /christopher/abso-core/files/server/test/atom-list-history.test.ts?format=json
65 linescodex-capacity-chair 100%Last change codex-capacity-chair in version 162, 1 version changed it
1import assert from "node:assert/strict";
2import { test } from "node:test";
3import { Graph } from "../../src/engine/graph.ts";
4import { answer } from "../../worker/project/http.ts";
5import { Project } from "../../worker/project/project.ts";
6import { DiskFirstRuntime } from "../src/disk-first-runtime.ts";
7import { SqliteLog } from "../src/engine-project.ts";
8import { SqliteHistoryState } from "../src/history-state.ts";
9import { memoryStorage } from "./helpers.ts";
11test("large atom lists preserve historical reads after later writes", (t) => {
12 const storage = memoryStorage();
13 t.after(() => storage.db.close());
14 const runtime = () => new DiskFirstRuntime(storage, "list-history", "list-history");
15 const old = Array.from({ length: 300 }, (_, i) => `old line ${i}`).join("\n") + "\n";
16 const current = Array.from({ length: 300 }, (_, i) => `new line ${i}`).join("\n") + "\n";
17 runtime().initialize(
18 (calls) => answer(calls, "init", undefined, { files: { "a.txt": old } }),
19 () => {},
20 );
21 while (!runtime().preparePage(() => {}).ready) {}
22 const before = runtime().read(
23 (calls) => calls.fileAt("a.txt", 0, null),
24 () => {},
25 );
26 assert.equal(
27 runtime().write(
28 (calls) => answer(calls, "record", "alice", { files: { "a.txt": current } }),
29 () => {},
30 ).status,
31 200,
32 );
33 assert.equal(
34 runtime().write(
35 (calls) => answer(calls, "publish", "alice", { message: "Replace all lines" }),
36 () => {},
37 ).status,
38 200,
39 );
40 t.mock.method(Project, "load", () => {
41 throw Error("full history replay forbidden");
42 });
43 assert.deepEqual(
44 runtime().read(
45 (calls) => calls.fileAt("a.txt", 0, null),
46 () => {},
47 ),
48 before,
49 );
50 assert.equal(
51 runtime().read(
52 (calls) => calls.shared().files["a.txt"],
53 () => {},
54 ),
55 current,
56 );
57 assert.ok(
58 (storage.db.prepare("SELECT COUNT(*) AS n FROM writer_state WHERE collection LIKE 'atom-list:%'").get()!
59 .n as number) > 0,
60 );
61 const history = new SqliteHistoryState(storage, "list-history:history", new SqliteLog(storage).seq());
62 const graph = new Graph({ storage: history.at(1, () => {}) });
63 assert.equal(graph.lineText("a0.0"), "old line 0");
64 assert.equal(graph.atom("a0").inserts[0]!.lines[0], "old line 0");
65});