From df3374d11d62d76bc22c370685b0181d74277218 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 20 Apr 2026 22:19:44 +0100 Subject: [PATCH] test: share provider allowlist fallback setup --- .../provider-registry.allowlist.test.ts | 30 +++-------------- .../provider-registry.allowlist.test.ts | 28 +++------------- ...rovider-registry-allowlist.test-helpers.ts | 32 +++++++++++++++++++ 3 files changed, 41 insertions(+), 49 deletions(-) diff --git a/src/image-generation/provider-registry.allowlist.test.ts b/src/image-generation/provider-registry.allowlist.test.ts index e4a34b4d5ce..2466f39137b 100644 --- a/src/image-generation/provider-registry.allowlist.test.ts +++ b/src/image-generation/provider-registry.allowlist.test.ts @@ -1,9 +1,9 @@ import { beforeAll, describe, expect, it } from "vitest"; import type { OpenClawConfig } from "../config/config.js"; import { - createEmptyProviderRegistryAllowlistFallbackRegistry, getProviderRegistryAllowlistMocks, installProviderRegistryAllowlistMockDefaults, + primeBundledProviderAllowlistFallback, } from "../test-utils/provider-registry-allowlist.test-helpers.js"; let getImageGenerationProvider: typeof import("./provider-registry.js").getImageGenerationProvider; @@ -18,32 +18,12 @@ describe("image-generation provider registry allowlist fallback", () => { }); it("adds bundled capability plugin ids to plugins.allow before fallback registry load", () => { - const cfg = { plugins: { allow: ["custom-plugin"] } } as OpenClawConfig; - const compatConfig = { - plugins: { - allow: ["custom-plugin", "openai"], - entries: { openai: { enabled: true } }, - }, - }; - - mocks.loadPluginManifestRegistry.mockReturnValue({ - plugins: [ - { - id: "openai", - origin: "bundled", - contracts: { imageGenerationProviders: ["openai"] }, - }, - ] as never, - diagnostics: [], + const { cfg, compatConfig } = primeBundledProviderAllowlistFallback({ + contractKey: "imageGenerationProviders", }); - mocks.withBundledPluginEnablementCompat.mockReturnValue(compatConfig); - mocks.withBundledPluginVitestCompat.mockReturnValue(compatConfig); - mocks.resolveRuntimePluginRegistry.mockImplementation(() => - createEmptyProviderRegistryAllowlistFallbackRegistry(), - ); - expect(listImageGenerationProviders(cfg)).toEqual([]); - expect(getImageGenerationProvider("openai", cfg)).toBeUndefined(); + expect(listImageGenerationProviders(cfg as OpenClawConfig)).toEqual([]); + expect(getImageGenerationProvider("openai", cfg as OpenClawConfig)).toBeUndefined(); expect(mocks.resolveRuntimePluginRegistry).toHaveBeenCalledWith({ config: compatConfig, }); diff --git a/src/media-understanding/provider-registry.allowlist.test.ts b/src/media-understanding/provider-registry.allowlist.test.ts index 5b259198168..ca315b0bbad 100644 --- a/src/media-understanding/provider-registry.allowlist.test.ts +++ b/src/media-understanding/provider-registry.allowlist.test.ts @@ -1,9 +1,9 @@ import { beforeAll, describe, expect, it } from "vitest"; import type { OpenClawConfig } from "../config/types.js"; import { - createEmptyProviderRegistryAllowlistFallbackRegistry, getProviderRegistryAllowlistMocks, installProviderRegistryAllowlistMockDefaults, + primeBundledProviderAllowlistFallback, } from "../test-utils/provider-registry-allowlist.test-helpers.js"; let buildMediaUnderstandingRegistry: typeof import("./provider-registry.js").buildMediaUnderstandingRegistry; @@ -18,31 +18,11 @@ describe("media-understanding provider registry allowlist fallback", () => { }); it("adds bundled capability plugin ids to plugins.allow before fallback registry load", () => { - const cfg = { plugins: { allow: ["custom-plugin"] } } as OpenClawConfig; - const compatConfig = { - plugins: { - allow: ["custom-plugin", "openai"], - entries: { openai: { enabled: true } }, - }, - }; - - mocks.loadPluginManifestRegistry.mockReturnValue({ - plugins: [ - { - id: "openai", - origin: "bundled", - contracts: { mediaUnderstandingProviders: ["openai"] }, - }, - ] as never, - diagnostics: [], + const { cfg, compatConfig } = primeBundledProviderAllowlistFallback({ + contractKey: "mediaUnderstandingProviders", }); - mocks.withBundledPluginEnablementCompat.mockReturnValue(compatConfig); - mocks.withBundledPluginVitestCompat.mockReturnValue(compatConfig); - mocks.resolveRuntimePluginRegistry.mockImplementation(() => - createEmptyProviderRegistryAllowlistFallbackRegistry(), - ); - const registry = buildMediaUnderstandingRegistry(undefined, cfg); + const registry = buildMediaUnderstandingRegistry(undefined, cfg as OpenClawConfig); expect(getMediaUnderstandingProvider("openai", registry)).toBeUndefined(); expect(mocks.resolveRuntimePluginRegistry).toHaveBeenCalledWith({ diff --git a/src/test-utils/provider-registry-allowlist.test-helpers.ts b/src/test-utils/provider-registry-allowlist.test-helpers.ts index 23e021e07be..5e535d89e67 100644 --- a/src/test-utils/provider-registry-allowlist.test-helpers.ts +++ b/src/test-utils/provider-registry-allowlist.test-helpers.ts @@ -57,3 +57,35 @@ export function installProviderRegistryAllowlistMockDefaults(): void { ); }); } + +export function primeBundledProviderAllowlistFallback(params: { + contractKey: "imageGenerationProviders" | "mediaUnderstandingProviders"; + providerId?: string; +}) { + const providerId = params.providerId ?? "openai"; + const cfg = { plugins: { allow: ["custom-plugin"] } }; + const compatConfig = { + plugins: { + allow: ["custom-plugin", providerId], + entries: { [providerId]: { enabled: true } }, + }, + }; + + providerRegistryAllowlistMocks.loadPluginManifestRegistry.mockReturnValue({ + plugins: [ + { + id: providerId, + origin: "bundled", + contracts: { [params.contractKey]: [providerId] }, + }, + ] as never, + diagnostics: [], + }); + providerRegistryAllowlistMocks.withBundledPluginEnablementCompat.mockReturnValue(compatConfig); + providerRegistryAllowlistMocks.withBundledPluginVitestCompat.mockReturnValue(compatConfig); + providerRegistryAllowlistMocks.resolveRuntimePluginRegistry.mockImplementation(() => + createEmptyProviderRegistryAllowlistFallbackRegistry(), + ); + + return { cfg, compatConfig, providerId }; +}