From f218c9e8f37c7a2e3e7f8b79652d50c1d1543f51 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Fri, 2 Oct 2026 23:28:53 +0200 Subject: [PATCH] Tests: pin the authority record shape checks and the dangling-link message Mutation survivors of the authority reader (record count, schema id, type) and of the reader's dangling-link error text each get a test that fails when the rule breaks. Co-Authored-By: Claude Sonnet 5.5 --- packages/cultcache-ts/test/cult-cache.test.ts | 5 ++- .../test/idunn-runtime-authority.test.ts | 34 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/packages/cultcache-ts/test/cult-cache.test.ts b/packages/cultcache-ts/test/cult-cache.test.ts index 34120fce..9890814a 100644 --- a/packages/cultcache-ts/test/cult-cache.test.ts +++ b/packages/cultcache-ts/test/cult-cache.test.ts @@ -2143,7 +2143,10 @@ test("SingleFileMessagePackBackingStore refuses a dangling symlink at its path a await symlink(join(volume, "store.cc"), file); const store = new SingleFileMessagePackBackingStore(file); const envelope = { key: "k", type: "t", payload: Uint8Array.of(0x90), storedAt: "2026-09-30T00:00:00Z" }; - await assert.rejects(() => store.pullAll(), (error: NodeJS.ErrnoException) => error.code === "ENOENT"); + await assert.rejects( + () => store.pullAll(), + (error: NodeJS.ErrnoException) => error.code === "ENOENT" && error.message.includes("symbolic link") && error.message.includes(file), + ); await assert.rejects(() => store.push(envelope), (error: NodeJS.ErrnoException) => error.code === "ENOENT"); await assert.rejects(() => store.pushAll([envelope], { soft: true }), (error: NodeJS.ErrnoException) => error.code === "ENOENT"); assert.ok((await lstat(file)).isSymbolicLink()); diff --git a/packages/cultnet-ts/test/idunn-runtime-authority.test.ts b/packages/cultnet-ts/test/idunn-runtime-authority.test.ts index c2e79894..fdd72320 100644 --- a/packages/cultnet-ts/test/idunn-runtime-authority.test.ts +++ b/packages/cultnet-ts/test/idunn-runtime-authority.test.ts @@ -181,6 +181,40 @@ for (const file of ["expected.cc", "activation.cc"]) { }); } +// What an authority file may hold once the one reader has accepted it: exactly one record, under the schema +// id and the type the loader asked for. Each case edits the Rust-written store and changes one thing. +function withStore(change: (store: unknown[][]) => void): (bytes: Buffer) => Buffer { + return (bytes) => { + const store = decode(bytes) as unknown[][]; + change(store); + return Buffer.from(encode(store)); + }; +} + +test("an authority file holding two records is refused", (context) => { + const bundle = bundleWith(context, "web", "expected.cc", withStore((store) => { + const second = [...(store[2]![0] as unknown[])]; + second[0] = "second"; + store[2]!.push(second); + })); + assert.throws(() => openAuthority(context, "web", { bundle }), /must contain exactly one record/); +}); + +test("an authority file whose one record is under another schema id is refused", (context) => { + const bundle = bundleWith(context, "web", "expected.cc", () => fixtureFile("web", "activation.cc")); + assert.throws( + () => openAuthority(context, "web", { bundle }), + (error: Error) => /must contain exactly one .+ record/.test(error.message) && !error.message.includes("unexpected CultCache type"), + ); +}); + +test("an authority record whose catalog names another type is refused, naming that type", (context) => { + const bundle = bundleWith(context, "web", "expected.cc", withStore((store) => { + (store[1]![0] as unknown[])[1] = "idunn.other_type"; + })); + assert.throws(() => openAuthority(context, "web", { bundle }), /unexpected CultCache type idunn.other_type/); +}); + function presenceSlot(document: { payload: Uint8Array }, slot: number): unknown { return (decode(document.payload) as unknown[])[slot]; }