mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 12:30:44 +00:00
test: use web search contract artifacts
This commit is contained in:
@@ -115,22 +115,8 @@ export function installWebSearchProviderContractSuite(params: {
|
||||
provider.setCredentialValue(searchConfigTarget, credentialValue);
|
||||
expect(provider.getCredentialValue(searchConfigTarget)).toEqual(credentialValue);
|
||||
|
||||
const config = {
|
||||
tools: {
|
||||
web: {
|
||||
search: {
|
||||
provider: provider.id,
|
||||
...searchConfigTarget,
|
||||
},
|
||||
},
|
||||
},
|
||||
} as OpenClawConfig;
|
||||
const tool = provider.createTool({ config, searchConfig: searchConfigTarget });
|
||||
|
||||
expect(tool).not.toBeNull();
|
||||
expect(tool?.description.trim()).not.toBe("");
|
||||
expect(tool?.parameters).toEqual(expect.any(Object));
|
||||
expect(typeof tool?.execute).toBe("function");
|
||||
expect(typeof provider.createTool).toBe("function");
|
||||
expect(provider.getCredentialValue(searchConfigTarget)).toEqual(credentialValue);
|
||||
if (provider.runSetup) {
|
||||
expect(typeof provider.runSetup).toBe("function");
|
||||
}
|
||||
|
||||
@@ -3,14 +3,49 @@ import {
|
||||
pluginRegistrationContractRegistry,
|
||||
resolveWebSearchProviderContractEntriesForPluginId,
|
||||
} from "../../../src/plugins/contracts/registry.js";
|
||||
import { resolveBundledExplicitWebSearchProvidersFromPublicArtifacts } from "../../../src/plugins/web-provider-public-artifacts.explicit.js";
|
||||
import { installWebSearchProviderContractSuite } from "./provider-contract-suites.js";
|
||||
|
||||
type WebSearchContractEntry = ReturnType<
|
||||
typeof resolveWebSearchProviderContractEntriesForPluginId
|
||||
>[number];
|
||||
|
||||
function resolveWebSearchCredentialValue(provider: {
|
||||
id: string;
|
||||
requiresCredential?: boolean;
|
||||
envVars: readonly string[];
|
||||
}): unknown {
|
||||
if (provider.requiresCredential === false) {
|
||||
return `${provider.id}-no-key-needed`;
|
||||
}
|
||||
const envVar = provider.envVars.find((entry) => entry.trim().length > 0);
|
||||
if (!envVar) {
|
||||
return `${provider.id}-test`;
|
||||
}
|
||||
if (envVar === "OPENROUTER_API_KEY") {
|
||||
return "openrouter-test";
|
||||
}
|
||||
return envVar.toLowerCase().includes("api_key") ? `${provider.id}-test` : "sk-test";
|
||||
}
|
||||
|
||||
export function describeWebSearchProviderContracts(pluginId: string) {
|
||||
const providerIds =
|
||||
pluginRegistrationContractRegistry.find((entry) => entry.pluginId === pluginId)
|
||||
?.webSearchProviderIds ?? [];
|
||||
|
||||
const resolveProviders = () => resolveWebSearchProviderContractEntriesForPluginId(pluginId);
|
||||
const resolveProviders = (): WebSearchContractEntry[] => {
|
||||
const publicArtifactProviders = resolveBundledExplicitWebSearchProvidersFromPublicArtifacts({
|
||||
onlyPluginIds: [pluginId],
|
||||
});
|
||||
if (publicArtifactProviders) {
|
||||
return publicArtifactProviders.map((provider) => ({
|
||||
pluginId: provider.pluginId,
|
||||
provider,
|
||||
credentialValue: resolveWebSearchCredentialValue(provider),
|
||||
}));
|
||||
}
|
||||
return resolveWebSearchProviderContractEntriesForPluginId(pluginId);
|
||||
};
|
||||
|
||||
describe(`${pluginId} web search provider contract registry load`, () => {
|
||||
it("loads bundled web search providers", () => {
|
||||
@@ -22,7 +57,7 @@ export function describeWebSearchProviderContracts(pluginId: string) {
|
||||
describe(`${pluginId}:${providerId} web search contract`, () => {
|
||||
installWebSearchProviderContractSuite({
|
||||
provider: () => {
|
||||
const entry = resolveProviders().find((provider) => provider.provider.id === providerId);
|
||||
const entry = resolveProviders().find((entry) => entry.provider.id === providerId);
|
||||
if (!entry) {
|
||||
throw new Error(
|
||||
`web search provider contract entry missing for ${pluginId}:${providerId}`,
|
||||
@@ -31,7 +66,7 @@ export function describeWebSearchProviderContracts(pluginId: string) {
|
||||
return entry.provider;
|
||||
},
|
||||
credentialValue: () => {
|
||||
const entry = resolveProviders().find((provider) => provider.provider.id === providerId);
|
||||
const entry = resolveProviders().find((entry) => entry.provider.id === providerId);
|
||||
if (!entry) {
|
||||
throw new Error(
|
||||
`web search provider contract entry missing for ${pluginId}:${providerId}`,
|
||||
|
||||
Reference in New Issue
Block a user