mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 15:18:09 +08:00
test: mock web provider fast-path artifacts
This commit is contained in:
@@ -6,6 +6,55 @@ const { loadPluginManifestRegistryMock } = vi.hoisted(() => ({
|
||||
}),
|
||||
}));
|
||||
|
||||
const { loadBundledPluginPublicArtifactModuleSyncMock } = vi.hoisted(() => {
|
||||
const providerBase = {
|
||||
label: "Fixture",
|
||||
hint: "fixture",
|
||||
envVars: ["FIXTURE_API_KEY"],
|
||||
placeholder: "fixture",
|
||||
signupUrl: "https://example.com",
|
||||
credentialPath: "plugins.entries.fixture.config.apiKey",
|
||||
getCredentialValue: () => undefined,
|
||||
setCredentialValue: () => ({}),
|
||||
};
|
||||
return {
|
||||
loadBundledPluginPublicArtifactModuleSyncMock: vi.fn(
|
||||
({ dirName, artifactBasename }: { dirName: string; artifactBasename: string }) => {
|
||||
if (dirName === "brave" && artifactBasename === "web-search-contract-api.js") {
|
||||
return {
|
||||
createBraveWebSearchProvider: () => ({
|
||||
...providerBase,
|
||||
id: "brave",
|
||||
createTool: () => null,
|
||||
}),
|
||||
};
|
||||
}
|
||||
if (dirName === "google" && artifactBasename === "web-search-provider.js") {
|
||||
return {
|
||||
createGeminiWebSearchProvider: () => ({
|
||||
...providerBase,
|
||||
id: "gemini",
|
||||
createTool: () => ({ description: "fixture", parameters: {} }),
|
||||
}),
|
||||
};
|
||||
}
|
||||
if (dirName === "firecrawl" && artifactBasename === "web-fetch-contract-api.js") {
|
||||
return {
|
||||
createFirecrawlWebFetchProvider: () => ({
|
||||
...providerBase,
|
||||
id: "firecrawl",
|
||||
createTool: () => null,
|
||||
}),
|
||||
};
|
||||
}
|
||||
throw new Error(
|
||||
`Unable to resolve bundled plugin public surface ${dirName}/${artifactBasename}`,
|
||||
);
|
||||
},
|
||||
),
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("./manifest-registry.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("./manifest-registry.js")>();
|
||||
return {
|
||||
@@ -14,6 +63,14 @@ vi.mock("./manifest-registry.js", async (importOriginal) => {
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("./public-surface-loader.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("./public-surface-loader.js")>();
|
||||
return {
|
||||
...actual,
|
||||
loadBundledPluginPublicArtifactModuleSync: loadBundledPluginPublicArtifactModuleSyncMock,
|
||||
};
|
||||
});
|
||||
|
||||
import { resolveBundledExplicitRuntimeWebSearchProvidersFromPublicArtifacts as resolveExplicitRuntimeWebSearchProviders } from "./web-provider-public-artifacts.explicit.js";
|
||||
import {
|
||||
resolveBundledWebFetchProvidersFromPublicArtifacts,
|
||||
@@ -23,6 +80,7 @@ import {
|
||||
describe("web provider public artifacts explicit fast path", () => {
|
||||
beforeEach(() => {
|
||||
loadPluginManifestRegistryMock.mockClear();
|
||||
loadBundledPluginPublicArtifactModuleSyncMock.mockClear();
|
||||
});
|
||||
|
||||
it("resolves bundled web search providers by explicit plugin id without manifest scans", () => {
|
||||
@@ -33,6 +91,10 @@ describe("web provider public artifacts explicit fast path", () => {
|
||||
|
||||
expect(provider?.pluginId).toBe("brave");
|
||||
expect(provider?.createTool({ config: {} as never })).toBeNull();
|
||||
expect(loadBundledPluginPublicArtifactModuleSyncMock).toHaveBeenCalledWith({
|
||||
dirName: "brave",
|
||||
artifactBasename: "web-search-contract-api.js",
|
||||
});
|
||||
expect(loadPluginManifestRegistryMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -43,6 +105,10 @@ describe("web provider public artifacts explicit fast path", () => {
|
||||
|
||||
expect(provider?.pluginId).toBe("google");
|
||||
expect(provider?.createTool({ config: {} as never })).not.toBeNull();
|
||||
expect(loadBundledPluginPublicArtifactModuleSyncMock).toHaveBeenCalledWith({
|
||||
dirName: "google",
|
||||
artifactBasename: "web-search-provider.js",
|
||||
});
|
||||
expect(loadPluginManifestRegistryMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -54,6 +120,10 @@ describe("web provider public artifacts explicit fast path", () => {
|
||||
|
||||
expect(provider?.pluginId).toBe("firecrawl");
|
||||
expect(provider?.createTool({ config: {} as never })).toBeNull();
|
||||
expect(loadBundledPluginPublicArtifactModuleSyncMock).toHaveBeenCalledWith({
|
||||
dirName: "firecrawl",
|
||||
artifactBasename: "web-fetch-contract-api.js",
|
||||
});
|
||||
expect(loadPluginManifestRegistryMock).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user