{"draft":null,"from":7,"to":318,"files":[{"path":"server/test/json-chunk-cursor.test.ts","added":43,"removed":0,"diff":"--- /dev/null\n+++ b/server/test/json-chunk-cursor.test.ts\n@@ -0,0 +1,43 @@\n+import assert from \"node:assert/strict\";\n+import { test } from \"node:test\";\n+import { JsonChunkCursor } from \"../src/json-chunk-cursor.ts\";\n+\n+test(\"JSON strings decode exactly across every input boundary\", () => {\n+\tconst values = [\"\", \"plain\", 'quotes\" and slash\\\\', \"\\n\\r\\t\\b\\f\", \"\\uD83D\\uDE00\", \"\\uD800\", \"\\uDC00\"];\n+\tconst encoded = values.map((value) => JSON.stringify(value));\n+\tencoded.push('\"\\\\uD83D\\\\uDE00\\\\u0000\\\\/\"');\n+\tfor (const json of encoded)\n+\t\tfor (let split = 0; split <= json.length; split++) {\n+\t\t\tconst cursor = new JsonChunkCursor([json.slice(0, split), \"\", json.slice(split), \",\"]);\n+\t\t\tassert.equal([...cursor.stringChunks()].join(\"\"), JSON.parse(json));\n+\t\t\tassert.equal(cursor.take(), \",\");\n+\t\t\tassert.equal(cursor.peek(), undefined);\n+\t\t}\n+\tfor (const invalid of ['\"unterminated', '\"\\\\x\"', '\"\\\\u12xz\"', '\"\\\\u123', '\"raw\\ncontrol\"']) {\n+\t\tconst cursor = new JsonChunkCursor(invalid.split(\"\"));\n+\t\tassert.throws(() => [...cursor.stringChunks()], /JSON/);\n+\t}\n+});\n+\n+test(\"long JSON strings decode in fixed-size output chunks\", () => {\n+\tlet closed = false;\n+\tconst cursor = new JsonChunkCursor(\n+\t\t(function* () {\n+\t\t\ttry {\n+\t\t\t\tyield '\"';\n+\t\t\t\tfor (let i = 0; i < 500; i++) yield \"x\".repeat(16384);\n+\t\t\t\tyield '\"';\n+\t\t\t} finally {\n+\t\t\t\tclosed = true;\n+\t\t\t}\n+\t\t})(),\n+\t);\n+\tlet count = 0;\n+\tfor (const chunk of cursor.stringChunks()) {\n+\t\tassert.ok(chunk.length <= 16384);\n+\t\tcount += chunk.length;\n+\t}\n+\tassert.equal(count, 8192000);\n+\tcursor.close();\n+\tassert.equal(closed, true);\n+});"}],"unmatched":[]}