test: move extension-owned coverage out of core

This commit is contained in:
Peter Steinberger
2026-04-03 10:55:47 +01:00
parent 2bfbddb81f
commit 64755c52f2
8 changed files with 410 additions and 197 deletions

View File

@@ -1,6 +1,14 @@
import fs from "node:fs";
import { afterEach, describe, expect, it, vi } from "vitest";
import { validateJsonSchemaValue } from "../../../src/plugins/schema-validator.js";
import { __testing, createBraveWebSearchProvider } from "./brave-web-search-provider.js";
const braveManifest = JSON.parse(
fs.readFileSync(new URL("../openclaw.plugin.json", import.meta.url), "utf-8"),
) as {
configSchema?: Record<string, unknown>;
};
describe("brave web search provider", () => {
const priorFetch = global.fetch;
@@ -58,6 +66,51 @@ describe("brave web search provider", () => {
expect(__testing.resolveBraveMode({ mode: "llm-context" })).toBe("llm-context");
});
it("accepts llm-context in the Brave plugin config schema", () => {
if (!braveManifest.configSchema) {
throw new Error("Expected Brave manifest config schema");
}
const result = validateJsonSchemaValue({
schema: braveManifest.configSchema,
cacheKey: "test:brave-config-schema",
value: {
webSearch: {
mode: "llm-context",
},
},
});
expect(result.ok).toBe(true);
});
it("rejects invalid Brave mode values in the plugin config schema", () => {
if (!braveManifest.configSchema) {
throw new Error("Expected Brave manifest config schema");
}
const result = validateJsonSchemaValue({
schema: braveManifest.configSchema,
cacheKey: "test:brave-config-schema",
value: {
webSearch: {
mode: "invalid-mode",
},
},
});
expect(result.ok).toBe(false);
if (result.ok) {
return;
}
expect(result.errors).toContainEqual(
expect.objectContaining({
path: "webSearch.mode",
allowedValues: ["web", "llm-context"],
}),
);
});
it("maps llm-context results into wrapped source entries", () => {
expect(
__testing.mapBraveLlmContextResults({

View File

@@ -0,0 +1,35 @@
import { describe, expect, it } from "vitest";
import type { OpenClawConfig } from "../../src/config/config.js";
import { withEnv } from "../../test/helpers/plugins/env.js";
import { __testing, createGeminiWebSearchProvider } from "./src/gemini-web-search-provider.js";
describe("google web search provider", () => {
it("falls back to GEMINI_API_KEY from the environment", () => {
withEnv({ GEMINI_API_KEY: "AIza-env-test" }, () => {
expect(__testing.resolveGeminiApiKey()).toBe("AIza-env-test");
});
});
it("prefers configured api keys over env fallbacks", () => {
withEnv({ GEMINI_API_KEY: "AIza-env-test" }, () => {
expect(__testing.resolveGeminiApiKey({ apiKey: "AIza-configured-test" })).toBe(
"AIza-configured-test",
);
});
});
it("stores configured credentials at the canonical plugin config path", () => {
const provider = createGeminiWebSearchProvider();
const config = {} as OpenClawConfig;
provider.setConfiguredCredentialValue?.(config, "AIza-plugin-test");
expect(provider.credentialPath).toBe("plugins.entries.google.config.webSearch.apiKey");
expect(provider.getConfiguredCredentialValue?.(config)).toBe("AIza-plugin-test");
});
it("defaults the Gemini web search model and trims explicit overrides", () => {
expect(__testing.resolveGeminiModel()).toBe("gemini-2.5-flash");
expect(__testing.resolveGeminiModel({ model: " gemini-2.5-pro " })).toBe("gemini-2.5-pro");
});
});