From d213397b1de70afe21d3d962e29f2ae4e5257010 Mon Sep 17 00:00:00 2001 From: Shakker Date: Fri, 8 May 2026 19:38:09 +0100 Subject: [PATCH] test: tighten channel secret contract assertions --- .../channel-contract-api.external.test.ts | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/secrets/channel-contract-api.external.test.ts b/src/secrets/channel-contract-api.external.test.ts index 1f58fe08091..ffe48c21bfc 100644 --- a/src/secrets/channel-contract-api.external.test.ts +++ b/src/secrets/channel-contract-api.external.test.ts @@ -33,6 +33,18 @@ vi.mock("../plugins/hardlink-policy.js", () => ({ import { loadChannelSecretContractApi } from "./channel-contract-api.js"; +type ChannelSecretContractApi = NonNullable>; + +function requireChannelSecretContractApi( + api: ReturnType, +): ChannelSecretContractApi { + expect(api).toBeDefined(); + if (!api) { + throw new Error("expected channel secret contract API"); + } + return api; +} + function channelSecretContractModuleSource(channelId: string) { return ` module.exports = { @@ -102,14 +114,15 @@ describe("external channel secret contract api", () => { loadablePluginOrigins: new Map([["discord", "global"]]), }); - expect(api?.secretTargetRegistryEntries).toEqual( + const contractApi = requireChannelSecretContractApi(api); + expect(contractApi.secretTargetRegistryEntries).toEqual( expect.arrayContaining([ expect.objectContaining({ id: "channels.discord.token", }), ]), ); - expect(api?.collectRuntimeConfigAssignments).toBeTypeOf("function"); + expect(contractApi.collectRuntimeConfigAssignments).toBeTypeOf("function"); }); it("loads dist/ secret-contract-api sidecars for compiled npm-published external channel plugins", () => { @@ -138,14 +151,15 @@ describe("external channel secret contract api", () => { loadablePluginOrigins: new Map([["discord", "global"]]), }); - expect(api?.secretTargetRegistryEntries).toEqual( + const contractApi = requireChannelSecretContractApi(api); + expect(contractApi.secretTargetRegistryEntries).toEqual( expect.arrayContaining([ expect.objectContaining({ id: "channels.discord.token", }), ]), ); - expect(api?.collectRuntimeConfigAssignments).toBeTypeOf("function"); + expect(contractApi.collectRuntimeConfigAssignments).toBeTypeOf("function"); }); it.runIf(process.platform !== "win32")( @@ -185,7 +199,8 @@ describe("external channel secret contract api", () => { rootDir, env, }); - expect(api?.secretTargetRegistryEntries).toEqual( + const contractApi = requireChannelSecretContractApi(api); + expect(contractApi.secretTargetRegistryEntries).toEqual( expect.arrayContaining([ expect.objectContaining({ id: "channels.discord.token",