diff --git a/src/commands/channel-test-registry.ts b/src/commands/channel-test-registry.ts index 1b0d10602b8..ccbfebad7df 100644 --- a/src/commands/channel-test-registry.ts +++ b/src/commands/channel-test-registry.ts @@ -13,6 +13,15 @@ let nostrPluginCache: ChannelPlugin | undefined; let tlonPluginCache: ChannelPlugin | undefined; let whatsappPluginCache: ChannelPlugin | undefined; +const testPluginOverrides = new Map ChannelPlugin>([ + ["googlechat", getGooglechatPlugin], + ["matrix", getMatrixPlugin], + ["msteams", getMSTeamsPlugin], + ["nostr", getNostrPlugin], + ["tlon", getTlonPlugin], + ["whatsapp", getWhatsAppPlugin], +]); + function getGooglechatPlugin(): ChannelPlugin { if (!googlechatPluginCache) { ({ googlechatPlugin: googlechatPluginCache } = loadBundledPluginTestApiSync<{ @@ -76,24 +85,44 @@ function getWhatsAppPlugin(): ChannelPlugin { return whatsappPluginCache; } -export function setDefaultChannelPluginRegistryForTests(): void { - getSetMatrixRuntime()({ - state: { - resolveStateDir: (_env, homeDir) => (homeDir ?? (() => "/tmp"))(), - }, - } as Parameters>[0]); - const channels = [ - ...listBundledChannelPlugins(), - getMatrixPlugin(), - getMSTeamsPlugin(), - getNostrPlugin(), - getTlonPlugin(), - getGooglechatPlugin(), - getWhatsAppPlugin(), - ].map((plugin) => ({ +function resolveChannelPluginsForTests(onlyPluginIds?: readonly string[]): ChannelPlugin[] { + const scopedIds = onlyPluginIds ? new Set(onlyPluginIds) : null; + const selectedPlugins = new Map(); + + for (const plugin of listBundledChannelPlugins()) { + if (scopedIds && !scopedIds.has(plugin.id)) { + continue; + } + selectedPlugins.set(plugin.id, plugin); + } + + for (const [pluginId, loadPlugin] of testPluginOverrides) { + if (scopedIds && !scopedIds.has(pluginId)) { + continue; + } + selectedPlugins.set(pluginId, loadPlugin()); + } + + return [...selectedPlugins.values()]; +} + +export function setChannelPluginRegistryForTests(onlyPluginIds?: readonly string[]): void { + if (!onlyPluginIds || onlyPluginIds.includes("matrix")) { + getSetMatrixRuntime()({ + state: { + resolveStateDir: (_env, homeDir) => (homeDir ?? (() => "/tmp"))(), + }, + } as Parameters>[0]); + } + + const channels = resolveChannelPluginsForTests(onlyPluginIds).map((plugin) => ({ pluginId: plugin.id, plugin, source: "test" as const, })) as unknown as Parameters[0]; setActivePluginRegistry(createTestRegistry(channels)); } + +export function setDefaultChannelPluginRegistryForTests(): void { + setChannelPluginRegistryForTests(); +} diff --git a/test/helpers/channels/session-binding-registry-backed-contract.ts b/test/helpers/channels/session-binding-registry-backed-contract.ts index e32878e2547..1952479b862 100644 --- a/test/helpers/channels/session-binding-registry-backed-contract.ts +++ b/test/helpers/channels/session-binding-registry-backed-contract.ts @@ -1,7 +1,8 @@ import { afterEach, beforeEach, describe } from "vitest"; +import { sessionBindingContractChannelIds } from "../../../src/channels/plugins/contracts/manifest.js"; import { sessionBindingContractRegistry } from "../../../src/channels/plugins/contracts/registry-session-binding.js"; import { installSessionBindingContractSuite } from "../../../src/channels/plugins/contracts/suites.js"; -import { setDefaultChannelPluginRegistryForTests } from "../../../src/commands/channel-test-registry.js"; +import { setChannelPluginRegistryForTests } from "../../../src/commands/channel-test-registry.js"; import { clearRuntimeConfigSnapshot, setRuntimeConfigSnapshot, @@ -82,7 +83,8 @@ export function describeSessionBindingRegistryBackedContract(id: string) { // Opt those specific plugins in so the activation boundary behaves like real runtime usage. setRuntimeConfigSnapshot(runtimeConfig); } - setDefaultChannelPluginRegistryForTests(); + // These suites only exercise the session-binding channels, so keep the seeded registry narrow. + setChannelPluginRegistryForTests(sessionBindingContractChannelIds); sessionBindingTesting.resetSessionBindingAdaptersForTests(); getDiscordThreadBindingTesting().resetThreadBindingsForTests(); (await getFeishuThreadBindingTesting()).resetFeishuThreadBindingsForTests();