{"draft":null,"from":174,"to":175,"files":[{"path":"src/engine/test/json-string-chunks.test.ts","added":58,"removed":0,"diff":"--- /dev/null\n+++ b/src/engine/test/json-string-chunks.test.ts\n@@ -0,0 +1,58 @@\n+import assert from \"node:assert/strict\";\n+import { test } from \"node:test\";\n+import { buildBase } from \"../build.ts\";\n+import { Graph } from \"../graph.ts\";\n+import { JsonStringChunks, jsonValueChunks, registerJsonChunkValue } from \"../json-value-chunks.ts\";\n+import { StoredText } from \"../stored-text.ts\";\n+import { SqlState } from \"./storage-helper.ts\";\n+\n+test(\"chunk-backed JSON strings preserve escaping and split UTF-16 exactly\", () => {\n+\tconst values = [\n+\t\t\"\",\n+\t\t\"ordinary\",\n+\t\t'\"\\\\\\n\\r\\t\\u0000',\n+\t\t\"\\ud800\",\n+\t\t\"\\udc00\",\n+\t\t\"\\ud800\\udc00\",\n+\t\t\"a\\ud800b\\udc00c\",\n+\t\t\"x\".repeat(50000),\n+\t];\n+\tfor (const text of values)\n+\t\tfor (const size of [1, 2, 17, 16384]) {\n+\t\t\tconst value = new JsonStringChunks(function* () {\n+\t\t\t\tyield \"\";\n+\t\t\t\tfor (let offset = 0; offset < text.length; offset += size) {\n+\t\t\t\t\tyield text.slice(offset, offset + size);\n+\t\t\t\t\tyield \"\";\n+\t\t\t\t}\n+\t\t\t});\n+\t\t\tassert.equal([...jsonValueChunks({ value })].join(\"\"), JSON.stringify({ value: text }));\n+\t\t\tassert.equal(JSON.stringify(value), JSON.stringify(text));\n+\t\t}\n+});\n+\n+test(\"registered lazy values stream without invoking their whole-value toJSON\", () => {\n+\tconst value = {\n+\t\ttoJSON() {\n+\t\t\tthrow Error(\"whole value forbidden\");\n+\t\t},\n+\t};\n+\tregisterJsonChunkValue(value, () => ({ lines: [new JsonStringChunks(() => [\"abc\", \"def\"])] }));\n+\tassert.equal([...jsonValueChunks(value)].join(\"\"), '{\"lines\":[\"abcdef\"]}');\n+\tassert.throws(() => [...jsonValueChunks(new JsonStringChunks(() => [\"x\".repeat(16385)]))], /exceeds bound/);\n+});\n+\n+for (const length of [60000, 100000])\n+\ttest(`stored atom JSON streams a ${length}-character line without whole reads`, (t) => {\n+\t\tconst storage = new SqlState();\n+\t\tt.after(() => storage.db.close());\n+\t\tconst graph = new Graph({ storage });\n+\t\tconst atom = buildBase({ f: `${\"x\".repeat(length)}\\n` }, { author: \"writer\", message: \"init\" });\n+\t\tgraph.add(atom);\n+\t\tconst stored = graph.atom(\"a0\");\n+\t\tconst expected = JSON.stringify(stored);\n+\t\tt.mock.method(StoredText.prototype, \"read\", () => {\n+\t\t\tthrow Error(\"whole stored text forbidden\");\n+\t\t});\n+\t\tassert.equal([...jsonValueChunks(stored)].join(\"\"), expected);\n+\t});"}],"unmatched":[]}