From 542a3d904eb6a9c9ddecd190d5cfa0cfac7abc49 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Mon, 12 Oct 2026 01:11:18 +0200 Subject: [PATCH] cultcache-ts test: the deep codec document uses a slot codec that writes N nested arrays (a self-recursive list codec has no finite type name) Co-Authored-By: Claude Sonnet 5.5 --- packages/cultcache-ts/test/payload-depth.test.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/cultcache-ts/test/payload-depth.test.ts b/packages/cultcache-ts/test/payload-depth.test.ts index 5572692e..7d8c1ca1 100644 --- a/packages/cultcache-ts/test/payload-depth.test.ts +++ b/packages/cultcache-ts/test/payload-depth.test.ts @@ -248,16 +248,20 @@ test("a user formatter's bytes are its own: a 0x91 grey image round-trips, while assert.throws(() => encodeDocumentPayload(anything, nest(L + 1)), CultCachePayloadDepthError); assert.throws(() => decodeDocumentPayload(anything, documentPayloadFromBytes(arrays(L + 1))), CultCachePayloadDepthError); - type Tree = unknown[]; - const tree: codecs.Codec = codecs.lazy(() => codecs.list(tree)); + // A slot that writes `depth` nested arrays, so a codec document can be made as deep as the test needs. + const nested: codecs.Codec = { + typeName: "System.Object", + encode: (depth) => nest(depth), + decode: (raw) => (raw as unknown[]).length, + }; const coded = defineDocumentType({ type: "t.coded", schemaId: "t.coded.v0", schema: z.any(), name: "id", - codec: codecs.slots<{ id: string; inner: Tree }>({ 0: ["id", codecs.string], 1: ["inner", tree] }, "T.Coded"), + codec: codecs.slots<{ id: string; depth: number }>({ 0: ["id", codecs.string], 1: ["depth", nested] }, "T.Coded"), }); - assert.doesNotThrow(() => encodeDocumentPayload(coded, { id: "a", inner: nest(L - 1) as Tree })); - assert.throws(() => encodeDocumentPayload(coded, { id: "a", inner: nest(L) as Tree }), CultCachePayloadDepthError); + assert.doesNotThrow(() => encodeDocumentPayload(coded, { id: "a", depth: L - 1 })); + assert.throws(() => encodeDocumentPayload(coded, { id: "a", depth: L }), CultCachePayloadDepthError); assert.throws(() => decodeDocumentPayload(coded, documentPayloadFromBytes(arrays(L + 1))), CultCachePayloadDepthError); });