- MCP
- code on this site's /mcp
- CLI
- none: the JSON below is the answer
- JSON
- /christopher/abso-core/files/server/test/decoded-frames-small.test.ts?format=json
72 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 { withDecodedFrames } from "../src/decoded-frames.ts";
4import { logParts, SqliteLog } from "../src/engine-project.ts";
5import { SqliteWriterState, writerFrameDigest } from "../src/writer-host.ts";
6import { memoryStorage } from "./helpers.ts";
8test("decoded frame pages retain views through consumption and remove scratch on all exits", (t) => {
9 const storage = memoryStorage();
10 t.after(() => storage.db.close());
11 const log = new SqliteLog(storage);
12 const json = JSON.stringify({ type: "join", agent: "alice", version: 0 });
13 for (const [part, text] of logParts(json).entries())
14 storage.sql.exec("INSERT INTO log(seq,part,text) VALUES(?,?,?)", 0, part, text);
15 SqliteWriterState.initialize(storage);
16 const before = storage.db.prepare("SELECT * FROM writer_state").all();
17 const input = { from: 0, to: 1, maxEntries: 1, maxBytes: 1000, digest: "" };
18 const result = withDecodedFrames(storage, "decoded-page", log, input, (frames) => {
19 const frame = [...frames][0]!;
20 assert.ok("entry" in frame);
21 assert.equal(frame.entry.type, "join");
22 assert.equal(
23 storage.db.prepare("SELECT COUNT(*) AS n FROM writer_state WHERE namespace = ?").get("decoded-page")!.n,
24 0,
25 );
26 return frame.entry.type;
27 });
28 assert.equal(result.result, "join");
29 assert.equal(result.digest, writerFrameDigest("", 0, json));
30 assert.deepEqual(storage.db.prepare("SELECT * FROM writer_state").all(), before);
31 assert.throws(
32 () =>
33 withDecodedFrames(storage, "decoded-page", log, input, (frames) => {
34 [...frames];
35 throw Error("consumer failure");
36 }),
37 /consumer failure/,
38 );
39 assert.deepEqual(storage.db.prepare("SELECT * FROM writer_state").all(), before);
40});
42test("frames above the small bound still use temporary disk storage", (t) => {
43 const storage = memoryStorage();
44 t.after(() => storage.db.close());
45 const log = new SqliteLog(storage);
46 const agent = "a".repeat(5000);
47 const json = JSON.stringify({ type: "join", agent, version: 0 });
48 for (const [part, text] of logParts(json).entries())
49 storage.sql.exec("INSERT INTO log(seq,part,text) VALUES(?,?,?)", 0, part, text);
50 const result = withDecodedFrames(
51 storage,
52 "large-decoded-page",
53 log,
54 { from: 0, to: 1, maxEntries: 1, maxBytes: 10000, digest: "" },
55 (frames) => {
56 const frame = [...frames][0]!;
57 assert.ok("entry" in frame);
58 assert.ok(
59 Number(
60 storage.db.prepare("SELECT COUNT(*) AS n FROM writer_state WHERE namespace = ?").get("large-decoded-page")!.n,
61 ) > 0,
62 );
63 assert.equal((frame.entry as { agent: string }).agent, agent);
64 return frame.entry.type;
65 },
66 );
67 assert.equal(result.result, "join");
68 assert.equal(
69 storage.db.prepare("SELECT COUNT(*) AS n FROM writer_state WHERE namespace = ?").get("large-decoded-page")!.n,
70 0,
71 );
72});