test: dedupe web search provider fixtures

This commit is contained in:
Peter Steinberger
2026-03-26 15:25:23 +00:00
parent df04ca7da3
commit 9bc3d33b53

View File

@@ -5,118 +5,72 @@ vi.mock("../runtime.js", () => ({
defaultRuntime: { log: vi.fn(), error: vi.fn() },
}));
vi.mock("../plugins/web-search-providers.js", () => {
const getScoped = (key: string) => (search?: Record<string, unknown>) =>
(search?.[key] as { apiKey?: unknown } | undefined)?.apiKey;
const getConfigured = (pluginId: string) => (config?: Record<string, unknown>) =>
const getScopedWebSearchCredential = (key: string) => (search?: Record<string, unknown>) =>
(search?.[key] as { apiKey?: unknown } | undefined)?.apiKey;
const getConfiguredPluginWebSearchCredential =
(pluginId: string) => (config?: Record<string, unknown>) =>
(
config?.plugins as
| { entries?: Record<string, { config?: { webSearch?: { apiKey?: unknown } } }> }
| undefined
)?.entries?.[pluginId]?.config?.webSearch?.apiKey;
const mockWebSearchProviders = [
{
id: "brave",
envVars: ["BRAVE_API_KEY"],
credentialPath: "plugins.entries.brave.config.webSearch.apiKey",
getCredentialValue: (search?: Record<string, unknown>) => search?.apiKey,
getConfiguredCredentialValue: getConfiguredPluginWebSearchCredential("brave"),
},
{
id: "firecrawl",
envVars: ["FIRECRAWL_API_KEY"],
credentialPath: "plugins.entries.firecrawl.config.webSearch.apiKey",
getCredentialValue: getScopedWebSearchCredential("firecrawl"),
getConfiguredCredentialValue: getConfiguredPluginWebSearchCredential("firecrawl"),
},
{
id: "gemini",
envVars: ["GEMINI_API_KEY"],
credentialPath: "plugins.entries.google.config.webSearch.apiKey",
getCredentialValue: getScopedWebSearchCredential("gemini"),
getConfiguredCredentialValue: getConfiguredPluginWebSearchCredential("google"),
},
{
id: "grok",
envVars: ["XAI_API_KEY"],
credentialPath: "plugins.entries.xai.config.webSearch.apiKey",
getCredentialValue: getScopedWebSearchCredential("grok"),
getConfiguredCredentialValue: getConfiguredPluginWebSearchCredential("xai"),
},
{
id: "kimi",
envVars: ["KIMI_API_KEY", "MOONSHOT_API_KEY"],
credentialPath: "plugins.entries.moonshot.config.webSearch.apiKey",
getCredentialValue: getScopedWebSearchCredential("kimi"),
getConfiguredCredentialValue: getConfiguredPluginWebSearchCredential("moonshot"),
},
{
id: "perplexity",
envVars: ["PERPLEXITY_API_KEY", "OPENROUTER_API_KEY"],
credentialPath: "plugins.entries.perplexity.config.webSearch.apiKey",
getCredentialValue: getScopedWebSearchCredential("perplexity"),
getConfiguredCredentialValue: getConfiguredPluginWebSearchCredential("perplexity"),
},
{
id: "tavily",
envVars: ["TAVILY_API_KEY"],
credentialPath: "plugins.entries.tavily.config.webSearch.apiKey",
getCredentialValue: getScopedWebSearchCredential("tavily"),
getConfiguredCredentialValue: getConfiguredPluginWebSearchCredential("tavily"),
},
] as const;
vi.mock("../plugins/web-search-providers.js", () => {
return {
resolveBundledPluginWebSearchProviders: () => [
{
id: "brave",
envVars: ["BRAVE_API_KEY"],
credentialPath: "plugins.entries.brave.config.webSearch.apiKey",
getCredentialValue: (search?: Record<string, unknown>) => search?.apiKey,
getConfiguredCredentialValue: getConfigured("brave"),
},
{
id: "firecrawl",
envVars: ["FIRECRAWL_API_KEY"],
credentialPath: "plugins.entries.firecrawl.config.webSearch.apiKey",
getCredentialValue: getScoped("firecrawl"),
getConfiguredCredentialValue: getConfigured("firecrawl"),
},
{
id: "gemini",
envVars: ["GEMINI_API_KEY"],
credentialPath: "plugins.entries.google.config.webSearch.apiKey",
getCredentialValue: getScoped("gemini"),
getConfiguredCredentialValue: getConfigured("google"),
},
{
id: "grok",
envVars: ["XAI_API_KEY"],
credentialPath: "plugins.entries.xai.config.webSearch.apiKey",
getCredentialValue: getScoped("grok"),
getConfiguredCredentialValue: getConfigured("xai"),
},
{
id: "kimi",
envVars: ["KIMI_API_KEY", "MOONSHOT_API_KEY"],
credentialPath: "plugins.entries.moonshot.config.webSearch.apiKey",
getCredentialValue: getScoped("kimi"),
getConfiguredCredentialValue: getConfigured("moonshot"),
},
{
id: "perplexity",
envVars: ["PERPLEXITY_API_KEY", "OPENROUTER_API_KEY"],
credentialPath: "plugins.entries.perplexity.config.webSearch.apiKey",
getCredentialValue: getScoped("perplexity"),
getConfiguredCredentialValue: getConfigured("perplexity"),
},
{
id: "tavily",
envVars: ["TAVILY_API_KEY"],
credentialPath: "plugins.entries.tavily.config.webSearch.apiKey",
getCredentialValue: getScoped("tavily"),
getConfiguredCredentialValue: getConfigured("tavily"),
},
],
resolvePluginWebSearchProviders: () => [
{
id: "brave",
envVars: ["BRAVE_API_KEY"],
credentialPath: "plugins.entries.brave.config.webSearch.apiKey",
getCredentialValue: (search?: Record<string, unknown>) => search?.apiKey,
getConfiguredCredentialValue: getConfigured("brave"),
},
{
id: "firecrawl",
envVars: ["FIRECRAWL_API_KEY"],
credentialPath: "plugins.entries.firecrawl.config.webSearch.apiKey",
getCredentialValue: getScoped("firecrawl"),
getConfiguredCredentialValue: getConfigured("firecrawl"),
},
{
id: "gemini",
envVars: ["GEMINI_API_KEY"],
credentialPath: "plugins.entries.google.config.webSearch.apiKey",
getCredentialValue: getScoped("gemini"),
getConfiguredCredentialValue: getConfigured("google"),
},
{
id: "grok",
envVars: ["XAI_API_KEY"],
credentialPath: "plugins.entries.xai.config.webSearch.apiKey",
getCredentialValue: getScoped("grok"),
getConfiguredCredentialValue: getConfigured("xai"),
},
{
id: "kimi",
envVars: ["KIMI_API_KEY", "MOONSHOT_API_KEY"],
credentialPath: "plugins.entries.moonshot.config.webSearch.apiKey",
getCredentialValue: getScoped("kimi"),
getConfiguredCredentialValue: getConfigured("moonshot"),
},
{
id: "perplexity",
envVars: ["PERPLEXITY_API_KEY", "OPENROUTER_API_KEY"],
credentialPath: "plugins.entries.perplexity.config.webSearch.apiKey",
getCredentialValue: getScoped("perplexity"),
getConfiguredCredentialValue: getConfigured("perplexity"),
},
{
id: "tavily",
envVars: ["TAVILY_API_KEY"],
credentialPath: "plugins.entries.tavily.config.webSearch.apiKey",
getCredentialValue: getScoped("tavily"),
getConfiguredCredentialValue: getConfigured("tavily"),
},
],
resolveBundledPluginWebSearchProviders: () => mockWebSearchProviders,
resolvePluginWebSearchProviders: () => mockWebSearchProviders,
};
});