- MCP
- code on this site's /mcp
- CLI
- none: the JSON below is the answer
- JSON
- /christopher/abso-core/files/src/engine/test/json-string-chunks.test.ts?version=175&format=json
58 linescodex-capacity-chair 100%Last change codex-capacity-chair in version 175, 1 version changed it
You're reading version 175. The newest is 318, and 1 version since then changed this file.
1import assert from "node:assert/strict";
2import { test } from "node:test";
3import { buildBase } from "../build.ts";
4import { Graph } from "../graph.ts";
5import { JsonStringChunks, jsonValueChunks, registerJsonChunkValue } from "../json-value-chunks.ts";
6import { StoredText } from "../stored-text.ts";
7import { SqlState } from "./storage-helper.ts";
9test("chunk-backed JSON strings preserve escaping and split UTF-16 exactly", () => {
10 const values = [
11 "",
12 "ordinary",
13 '"\\\n\r\t\u0000',
14 "\ud800",
15 "\udc00",
16 "\ud800\udc00",
17 "a\ud800b\udc00c",
18 "x".repeat(50000),
19 ];
20 for (const text of values)
21 for (const size of [1, 2, 17, 16384]) {
22 const value = new JsonStringChunks(function* () {
23 yield "";
24 for (let offset = 0; offset < text.length; offset += size) {
25 yield text.slice(offset, offset + size);
26 yield "";
27 }
28 });
29 assert.equal([...jsonValueChunks({ value })].join(""), JSON.stringify({ value: text }));
30 assert.equal(JSON.stringify(value), JSON.stringify(text));
31 }
32});
34test("registered lazy values stream without invoking their whole-value toJSON", () => {
35 const value = {
36 toJSON() {
37 throw Error("whole value forbidden");
38 },
39 };
40 registerJsonChunkValue(value, () => ({ lines: [new JsonStringChunks(() => ["abc", "def"])] }));
41 assert.equal([...jsonValueChunks(value)].join(""), '{"lines":["abcdef"]}');
42 assert.throws(() => [...jsonValueChunks(new JsonStringChunks(() => ["x".repeat(16385)]))], /exceeds bound/);
43});
45for (const length of [60000, 100000])
46 test(`stored atom JSON streams a ${length}-character line without whole reads`, (t) => {
47 const storage = new SqlState();
48 t.after(() => storage.db.close());
49 const graph = new Graph({ storage });
50 const atom = buildBase({ f: `${"x".repeat(length)}\n` }, { author: "writer", message: "init" });
51 graph.add(atom);
52 const stored = graph.atom("a0");
53 const expected = JSON.stringify(stored);
54 t.mock.method(StoredText.prototype, "read", () => {
55 throw Error("whole stored text forbidden");
56 });
57 assert.equal([...jsonValueChunks(stored)].join(""), expected);
58 });