{"draft":null,"from":7,"to":318,"files":[{"path":"worker/project/test/operation-protocol.test.ts","added":85,"removed":0,"diff":"--- /dev/null\n+++ b/worker/project/test/operation-protocol.test.ts\n@@ -0,0 +1,85 @@\n+import assert from \"node:assert/strict\";\n+import { test } from \"node:test\";\n+import {\n+\tcanonicalJson,\n+\tchunkEntries,\n+\tdigestOperation,\n+\ttype OperationChunk,\n+\ttype ProjectOperation,\n+\tutf8JsonFrames,\n+} from \"../operation-protocol.ts\";\n+import type { Entry } from \"../project-types.ts\";\n+\n+const operation: ProjectOperation = {\n+\tid: \"op-1\",\n+\ttenant: \"tenant-1\",\n+\tproject: \"project-1\",\n+\tincarnation: \"incarnation-1\",\n+\tactor: \"builder\",\n+\tbuild: \"build-1\",\n+\texecutorIdentity: \"trusted-local-executor\",\n+\trootDigest: \"root-0\",\n+\tauthorizationRevision: \"auth-1\",\n+\tpolicyRevision: \"policy-1\",\n+\toperationTime: 20,\n+\tqueuePolicy: { policyRevision: \"policy-1\", checkerReady: false },\n+\tgeneration: 0,\n+\theads: { log: 0, shared: 0, actorMine: 0, actorBase: 0, queueRevision: 0 },\n+\tmessage: \"record and publish\",\n+\tfiles: { \"readme.txt\": \"updated\\n\" },\n+};\n+\n+test(\"canonical request binding ignores object property order and binds every request field\", async () => {\n+\tconst reordered = {\n+\t\t...operation,\n+\t\tfiles: { \"readme.txt\": \"updated\\n\" },\n+\t\theads: { actorBase: 0, actorMine: 0, shared: 0, log: 0, queueRevision: 0 },\n+\t};\n+\tassert.equal(await digestOperation(operation), await digestOperation(reordered));\n+\tassert.notEqual(\n+\t\tawait digestOperation(operation),\n+\t\tawait digestOperation({ ...operation, authorizationRevision: \"revoked\" }),\n+\t);\n+\tassert.notEqual(\n+\t\tawait digestOperation(operation),\n+\t\tawait digestOperation({ ...operation, files: { \"readme.txt\": \"other\\n\" } }),\n+\t);\n+\tassert.notEqual(await digestOperation(operation), await digestOperation({ ...operation, operationTime: 21 }));\n+\tassert.notEqual(\n+\t\tawait digestOperation(operation),\n+\t\tawait digestOperation({ ...operation, queuePolicy: { ...operation.queuePolicy, checkerReady: true } }),\n+\t);\n+\tassert.equal(canonicalJson({ z: 1, a: 2 }), '{\"a\":2,\"z\":1}');\n+});\n+\n+test(\"chunk generator preserves exact order with bounded entries and UTF-8 byte accounting\", async () => {\n+\tconst entries: Entry[] = Array.from({ length: 70 }, (_, index) => ({\n+\t\ttype: \"join\",\n+\t\tagent: `agent-${index}`,\n+\t\tversion: index,\n+\t\ttime: index,\n+\t}));\n+\tconst chunks: OperationChunk[] = [];\n+\tfor await (const chunk of chunkEntries(entries)) chunks.push(chunk);\n+\tassert.deepEqual(\n+\t\tchunks.flatMap((chunk) => chunk.entries),\n+\t\tentries,\n+\t);\n+\tassert.ok(chunks.every((chunk, index) => chunk.index === index && chunk.count <= 32 && chunk.bytes <= 64 * 1024));\n+\tassert.deepEqual(\n+\t\tchunks.map((chunk) => chunk.firstEntry),\n+\t\t[0, 32, 64],\n+\t);\n+\tassert.ok(chunks.every((chunk, index) => index === 0 || chunk.chain !== chunks[index - 1]!.chain));\n+\n+\tconst large: Entry = { type: \"join\", agent: \"🙂\".repeat(8_000), version: 0, time: 1 };\n+\tconst utf8: OperationChunk[] = [];\n+\tfor await (const chunk of chunkEntries([large])) utf8.push(chunk);\n+\tassert.ok(utf8[0]!.bytes > JSON.stringify(large).length);\n+\tassert.ok(utf8[0]!.bytes <= 64 * 1024);\n+\tconst largeEntry: Entry = { type: \"join\", agent: `🙂\\n\"`.repeat(20_000), version: 0, time: 1 };\n+\tconst frames = [...utf8JsonFrames(largeEntry)];\n+\tassert.ok(frames.length > 1);\n+\tassert.ok(frames.every((frame) => frame.bytes <= 64 * 1024));\n+\tassert.deepEqual(JSON.parse(frames.map((frame) => frame.text).join(\"\")), largeEntry);\n+});"}],"unmatched":[]}