- MCP
- code on this site's /mcp
- CLI
- none: the JSON below is the answer
- JSON
- /christopher/abso-core/files/server/test/streamed-writer-adoption.test.ts?format=json
48 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 { SqliteWriterHost, SqliteWriterState } from "../src/writer-host.ts";
6import { memoryStorage } from "./helpers.ts";
8test("writer adoption streams canonical frames and preserves exact page retries", (t) => {
9 const storage = memoryStorage();
10 t.after(() => storage.db.close());
11 const memory = new MemoryStore();
12 const oracle = new Project(memory);
13 oracle.init({ "a.txt": "one\n" }, 0);
14 oracle.record("alice", { "a.txt": "two\n" }, 1);
15 oracle.publish("alice", "change", 2);
16 new SqliteLog(storage).append(memory.entries);
17 SqliteWriterState.initialize(storage);
18 const host = () => new SqliteWriterHost(storage, "streamed-writer");
19 const expected = host().source();
20 const canonical = storage.db.prepare("SELECT * FROM log ORDER BY seq,part").all();
21 t.mock.method(SqliteLog.prototype, "boundedFrame", () => {
22 throw Error("whole frame reconstruction forbidden");
23 });
24 t.mock.method(Project, "load", () => {
25 throw Error("full history forbidden");
26 });
27 let from = 0,
28 digest = "";
29 while (from < expected.logLength) {
30 const input = { expected, from, digest, maxEntries: 2, maxBytes: 100000 };
31 const page = host().adoptVerifiedPage(input, () => {});
32 assert.deepEqual(
33 host().adoptVerifiedPage(input, () => {}),
34 page,
35 );
36 from = page.next;
37 digest = page.digest;
38 }
39 assert.deepEqual(
40 host().readCalls({ expected, validateAuthority: () => {}, operation: (calls) => calls.shared().files }),
41 oracle.files(),
42 );
43 assert.deepEqual(storage.db.prepare("SELECT * FROM log ORDER BY seq,part").all(), canonical);
44 assert.equal(
45 storage.db.prepare("SELECT COUNT(*) AS n FROM writer_state WHERE namespace='streamed-writer:decoded'").get()!.n,
46 0,
47 );
48});