mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 10:50:44 +00:00
test: share provider allowlist fallback setup
This commit is contained in:
@@ -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,
|
||||
});
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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 };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user