test: share provider allowlist fallback setup

This commit is contained in:
Peter Steinberger
2026-04-20 22:19:44 +01:00
parent f197ca503a
commit df3374d11d
3 changed files with 41 additions and 49 deletions

View File

@@ -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,
});

View File

@@ -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({

View File

@@ -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 };
}