mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-10 16:51:13 +00:00
test: isolate bundled plugin coverage from unit
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { AuthProfileStore } from "../agents/auth-profiles.js";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import type { PluginWebSearchProviderEntry } from "../plugins/types.js";
|
||||
import type {
|
||||
PluginWebFetchProviderEntry,
|
||||
PluginWebSearchProviderEntry,
|
||||
} from "../plugins/types.js";
|
||||
import { getPath, setPathCreateStrict } from "./path-utils.js";
|
||||
import { canonicalizeSecretTargetCoverageId } from "./target-registry-test-helpers.js";
|
||||
import { listSecretTargetRegistryEntries } from "./target-registry.js";
|
||||
@@ -13,6 +16,11 @@ const { resolveBundledPluginWebSearchProvidersMock, resolvePluginWebSearchProvid
|
||||
resolveBundledPluginWebSearchProvidersMock: vi.fn(() => buildTestWebSearchProviders()),
|
||||
resolvePluginWebSearchProvidersMock: vi.fn(() => buildTestWebSearchProviders()),
|
||||
}));
|
||||
const { resolveBundledPluginWebFetchProvidersMock, resolvePluginWebFetchProvidersMock } =
|
||||
vi.hoisted(() => ({
|
||||
resolveBundledPluginWebFetchProvidersMock: vi.fn(() => buildTestWebFetchProviders()),
|
||||
resolvePluginWebFetchProvidersMock: vi.fn(() => buildTestWebFetchProviders()),
|
||||
}));
|
||||
|
||||
let clearSecretsRuntimeSnapshot: typeof import("./runtime.js").clearSecretsRuntimeSnapshot;
|
||||
let prepareSecretsRuntimeSnapshot: typeof import("./runtime.js").prepareSecretsRuntimeSnapshot;
|
||||
@@ -25,6 +33,14 @@ vi.mock("../plugins/web-search-providers.runtime.js", () => ({
|
||||
resolvePluginWebSearchProviders: resolvePluginWebSearchProvidersMock,
|
||||
}));
|
||||
|
||||
vi.mock("../plugins/web-fetch-providers.js", () => ({
|
||||
resolveBundledPluginWebFetchProviders: resolveBundledPluginWebFetchProvidersMock,
|
||||
}));
|
||||
|
||||
vi.mock("../plugins/web-fetch-providers.runtime.js", () => ({
|
||||
resolvePluginWebFetchProviders: resolvePluginWebFetchProvidersMock,
|
||||
}));
|
||||
|
||||
function createTestProvider(params: {
|
||||
id: "brave" | "gemini" | "grok" | "kimi" | "perplexity" | "firecrawl" | "tavily";
|
||||
pluginId: string;
|
||||
@@ -90,6 +106,42 @@ function buildTestWebSearchProviders(): PluginWebSearchProviderEntry[] {
|
||||
];
|
||||
}
|
||||
|
||||
function buildTestWebFetchProviders(): PluginWebFetchProviderEntry[] {
|
||||
return [
|
||||
{
|
||||
pluginId: "firecrawl",
|
||||
id: "firecrawl",
|
||||
label: "firecrawl",
|
||||
hint: "firecrawl test provider",
|
||||
envVars: ["FIRECRAWL_API_KEY"],
|
||||
placeholder: "fc-...",
|
||||
signupUrl: "https://example.com/firecrawl",
|
||||
autoDetectOrder: 50,
|
||||
credentialPath: "plugins.entries.firecrawl.config.webFetch.apiKey",
|
||||
inactiveSecretPaths: ["plugins.entries.firecrawl.config.webFetch.apiKey"],
|
||||
getCredentialValue: (fetchConfig) => fetchConfig?.apiKey,
|
||||
setCredentialValue: (fetchConfigTarget, value) => {
|
||||
fetchConfigTarget.apiKey = value;
|
||||
},
|
||||
getConfiguredCredentialValue: (config) => {
|
||||
const entryConfig = config?.plugins?.entries?.firecrawl?.config;
|
||||
return entryConfig && typeof entryConfig === "object"
|
||||
? (entryConfig as { webFetch?: { apiKey?: unknown } }).webFetch?.apiKey
|
||||
: undefined;
|
||||
},
|
||||
setConfiguredCredentialValue: (configTarget, value) => {
|
||||
const plugins = (configTarget.plugins ??= {}) as { entries?: Record<string, unknown> };
|
||||
const entries = (plugins.entries ??= {});
|
||||
const entry = (entries.firecrawl ??= {}) as { config?: Record<string, unknown> };
|
||||
const config = (entry.config ??= {});
|
||||
const webFetch = (config.webFetch ??= {}) as { apiKey?: unknown };
|
||||
webFetch.apiKey = value;
|
||||
},
|
||||
createTool: () => null,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
function toConcretePathSegments(pathPattern: string): string[] {
|
||||
const segments = pathPattern.split(".").filter(Boolean);
|
||||
const out: string[] = [];
|
||||
@@ -250,6 +302,8 @@ describe("secrets runtime target coverage", () => {
|
||||
clearSecretsRuntimeSnapshot();
|
||||
resolveBundledPluginWebSearchProvidersMock.mockReset();
|
||||
resolvePluginWebSearchProvidersMock.mockReset();
|
||||
resolveBundledPluginWebFetchProvidersMock.mockReset();
|
||||
resolvePluginWebFetchProvidersMock.mockReset();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
Reference in New Issue
Block a user