mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-30 22:09:49 +02:00
Tests: lazy-load web search contract registries
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
pluginRegistrationContractRegistry,
|
||||
providerContractLoadError,
|
||||
providerContractPluginIds,
|
||||
resolveWebSearchProviderContractEntriesForPluginId,
|
||||
speechProviderContractRegistry,
|
||||
} from "./registry.js";
|
||||
import { uniqueSortedStrings } from "./testkit.js";
|
||||
@@ -104,4 +105,16 @@ describe("plugin contract registry", () => {
|
||||
),
|
||||
).toEqual(bundledWebSearchPluginIds);
|
||||
});
|
||||
|
||||
it(
|
||||
"loads bundled web search providers for each shared-resolver plugin",
|
||||
{ timeout: REGISTRY_CONTRACT_TIMEOUT_MS },
|
||||
() => {
|
||||
for (const pluginId of resolveBundledWebSearchPluginIds({})) {
|
||||
expect(resolveWebSearchProviderContractEntriesForPluginId(pluginId).length).toBeGreaterThan(
|
||||
0,
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
@@ -77,6 +77,10 @@ function uniqueStrings(values: readonly string[]): string[] {
|
||||
let providerContractRegistryCache: ProviderContractEntry[] | null = null;
|
||||
let providerContractRegistryByPluginIdCache: Map<string, ProviderContractEntry[]> | null = null;
|
||||
let webSearchProviderContractRegistryCache: WebSearchProviderContractEntry[] | null = null;
|
||||
let webSearchProviderContractRegistryByPluginIdCache: Map<
|
||||
string,
|
||||
WebSearchProviderContractEntry[]
|
||||
> | null = null;
|
||||
let speechProviderContractRegistryCache: SpeechProviderContractEntry[] | null = null;
|
||||
let mediaUnderstandingProviderContractRegistryCache:
|
||||
| MediaUnderstandingProviderContractEntry[]
|
||||
@@ -188,6 +192,34 @@ function loadWebSearchProviderContractRegistry(): WebSearchProviderContractEntry
|
||||
return webSearchProviderContractRegistryCache;
|
||||
}
|
||||
|
||||
export function resolveWebSearchProviderContractEntriesForPluginId(
|
||||
pluginId: string,
|
||||
): WebSearchProviderContractEntry[] {
|
||||
if (webSearchProviderContractRegistryCache) {
|
||||
return webSearchProviderContractRegistryCache.filter((entry) => entry.pluginId === pluginId);
|
||||
}
|
||||
|
||||
const cache =
|
||||
webSearchProviderContractRegistryByPluginIdCache ??
|
||||
new Map<string, WebSearchProviderContractEntry[]>();
|
||||
webSearchProviderContractRegistryByPluginIdCache = cache;
|
||||
const cached = cache.get(pluginId);
|
||||
if (cached) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
const entries = loadBundledCapabilityRuntimeRegistry({
|
||||
pluginIds: [pluginId],
|
||||
pluginSdkResolution: "dist",
|
||||
}).webSearchProviders.map((entry) => ({
|
||||
pluginId: entry.pluginId,
|
||||
provider: entry.provider,
|
||||
credentialValue: resolveWebSearchCredentialValue(entry.provider),
|
||||
}));
|
||||
cache.set(pluginId, entries);
|
||||
return entries;
|
||||
}
|
||||
|
||||
function loadSpeechProviderContractRegistry(): SpeechProviderContractEntry[] {
|
||||
if (!speechProviderContractRegistryCache) {
|
||||
speechProviderContractRegistryCache = process.env.VITEST
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
pluginRegistrationContractRegistry,
|
||||
webSearchProviderContractRegistry,
|
||||
resolveWebSearchProviderContractEntriesForPluginId,
|
||||
} from "../../../src/plugins/contracts/registry.js";
|
||||
import { installWebSearchProviderContractSuite } from "../../../src/plugins/contracts/suites.js";
|
||||
|
||||
@@ -10,8 +10,7 @@ export function describeWebSearchProviderContracts(pluginId: string) {
|
||||
pluginRegistrationContractRegistry.find((entry) => entry.pluginId === pluginId)
|
||||
?.webSearchProviderIds ?? [];
|
||||
|
||||
const resolveProviders = () =>
|
||||
webSearchProviderContractRegistry.filter((entry) => entry.pluginId === pluginId);
|
||||
const resolveProviders = () => resolveWebSearchProviderContractEntriesForPluginId(pluginId);
|
||||
|
||||
describe(`${pluginId} web search provider contract registry load`, () => {
|
||||
it("loads bundled web search providers", () => {
|
||||
|
||||
Reference in New Issue
Block a user