- MCP
- code on this site's /mcp
- CLI
- none: the JSON below is the answer
- JSON
- /christopher/abso-core/files/server/test/streamed-large-history.test.ts?format=json
72 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 { MemoryStore, Project } from "../../worker/project/project.ts";
4import { SqliteLog } from "../src/engine-project.ts";
5import { SqliteHistoryHost } from "../src/history-host.ts";
6import { advanceWriterRoot, SqliteWriterHost, SqliteWriterState } from "../src/writer-host.ts";
7import { memoryStorage } from "./helpers.ts";
9test("history prepares an oversized entry and preserves it after later publication", (t) => {
10 const storage = memoryStorage();
11 t.after(() => storage.db.close());
12 const memory = new MemoryStore();
13 const oracle = new Project(memory);
14 oracle.init({ "a.txt": "x".repeat(8100000) }, 0);
15 const initialText = oracle.files()["a.txt"];
16 const log = new SqliteLog(storage);
17 log.append(memory.entries);
18 SqliteWriterState.initialize(storage);
19 const writer = new SqliteWriterHost(storage, "writer");
20 writer.adoptPage(0, { maxEntries: 32, maxBytes: log.adoptionPageBytes(0) }, () => {});
21 const root = writer.root();
22 t.mock.method(log, "boundedFrame", () => {
23 throw Error("whole canonical frame forbidden");
24 });
25 t.mock.method(Project, "load", () => {
26 throw Error("whole history forbidden");
27 });
28 const history = new SqliteHistoryHost(storage, "streamed-history");
29 while (
30 !history.prepare(
31 log,
32 root,
33 () => root,
34 () => {},
35 ).ready
36 ) {}
37 oracle.record("alice", { "b.txt": "after\n" }, 1);
38 oracle.publish("alice", "change", 2);
39 log.append(memory.entries.slice(root.logLength));
40 const committed = advanceWriterRoot(log, root, writer.source());
41 history.advance(
42 log,
43 root,
44 committed,
45 () => committed,
46 () => {},
47 );
48 assert.deepEqual(
49 history.read(
50 committed,
51 () => committed,
52 () => {},
53 committed.logLength,
54 (p) => p.files(),
55 ),
56 oracle.files(),
57 );
58 assert.equal(
59 history.read(
60 committed,
61 () => committed,
62 () => {},
63 1,
64 (p) => p.files(),
65 )["a.txt"],
66 initialText,
67 );
68 assert.equal(
69 storage.db.prepare("SELECT COUNT(*) AS n FROM writer_state WHERE namespace='streamed-history:decoded'").get()!.n,
70 0,
71 );
72});