Tests: lazy-load web search contract registries

This commit is contained in:
Gustavo Madeira Santana 2026-03-28 19:23:49 -04:00
parent 3847ace25b
commit 5289e8f0fe
No known key found for this signature in database
3 changed files with 47 additions and 3 deletions

View File

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

View File

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

View File

@ -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", () => {