mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 07:40:44 +00:00
test: use web fetch contract artifacts
This commit is contained in:
@@ -164,21 +164,6 @@ export function installWebFetchProviderContractSuite(params: {
|
||||
expect(applied.plugins?.entries?.[params.pluginId]?.enabled).toBe(true);
|
||||
}
|
||||
|
||||
const config = {
|
||||
tools: {
|
||||
web: {
|
||||
fetch: {
|
||||
provider: provider.id,
|
||||
...fetchConfigTarget,
|
||||
},
|
||||
},
|
||||
},
|
||||
} as OpenClawConfig;
|
||||
const tool = provider.createTool({ config, fetchConfig: fetchConfigTarget });
|
||||
|
||||
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");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3,14 +3,39 @@ import {
|
||||
pluginRegistrationContractRegistry,
|
||||
resolveWebFetchProviderContractEntriesForPluginId,
|
||||
} from "../../../src/plugins/contracts/registry.js";
|
||||
import type { WebFetchProviderPlugin } from "../../../src/plugins/types.js";
|
||||
import { resolveBundledExplicitWebFetchProvidersFromPublicArtifacts } from "../../../src/plugins/web-provider-public-artifacts.explicit.js";
|
||||
import { installWebFetchProviderContractSuite } from "./provider-contract-suites.js";
|
||||
|
||||
function resolveWebFetchCredentialValue(provider: WebFetchProviderPlugin): 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`;
|
||||
}
|
||||
return envVar.toLowerCase().includes("api_key") ? `${provider.id}-test` : "sk-test";
|
||||
}
|
||||
|
||||
export function describeWebFetchProviderContracts(pluginId: string) {
|
||||
const providerIds =
|
||||
pluginRegistrationContractRegistry.find((entry) => entry.pluginId === pluginId)
|
||||
?.webFetchProviderIds ?? [];
|
||||
|
||||
const resolveProviders = () => resolveWebFetchProviderContractEntriesForPluginId(pluginId);
|
||||
const resolveProviders = () => {
|
||||
const publicArtifactProviders = resolveBundledExplicitWebFetchProvidersFromPublicArtifacts({
|
||||
onlyPluginIds: [pluginId],
|
||||
});
|
||||
if (publicArtifactProviders) {
|
||||
return publicArtifactProviders.map((provider) => ({
|
||||
pluginId: provider.pluginId,
|
||||
provider,
|
||||
credentialValue: resolveWebFetchCredentialValue(provider),
|
||||
}));
|
||||
}
|
||||
return resolveWebFetchProviderContractEntriesForPluginId(pluginId);
|
||||
};
|
||||
|
||||
describe(`${pluginId} web fetch provider contract registry load`, () => {
|
||||
it("loads bundled web fetch providers", () => {
|
||||
|
||||
Reference in New Issue
Block a user