chore(test): fix stale web search audit coverage

This commit is contained in:
Vignesh Natarajan
2026-03-28 17:17:42 -07:00
parent 3d69ad8308
commit c3a0304f63
2 changed files with 57 additions and 35 deletions

View File

@@ -1,5 +1,7 @@
import { describe, expect, it } from "vitest";
import type { OpenClawConfig } from "../config/config.js";
import { BUNDLED_WEB_SEARCH_PLUGIN_IDS } from "./bundled-web-search-ids.js";
import { hasBundledWebSearchCredential } from "./bundled-web-search-registry.js";
import {
listBundledWebSearchProviders,
resolveBundledWebSearchPluginIds,
@@ -50,3 +52,53 @@ describe("bundled web search metadata", () => {
expectBundledWebSearchAlignment({ actual, expected });
});
});
describe("hasBundledWebSearchCredential", () => {
const baseCfg = {
agents: { defaults: { model: { primary: "ollama/mistral-8b" } } },
browser: { enabled: false },
tools: { web: { fetch: { enabled: false } } },
} satisfies OpenClawConfig;
it.each([
{
name: "detects google plugin web search credentials",
config: {
...baseCfg,
plugins: {
entries: {
google: { enabled: true, config: { webSearch: { apiKey: "AIza-test" } } },
},
},
} satisfies OpenClawConfig,
env: {},
},
{
name: "detects gemini env credentials",
config: baseCfg,
env: { GEMINI_API_KEY: "AIza-test" },
},
{
name: "detects xai env credentials",
config: baseCfg,
env: { XAI_API_KEY: "xai-test" },
},
{
name: "detects kimi env credentials",
config: baseCfg,
env: { KIMI_API_KEY: "sk-kimi-test" },
},
{
name: "detects moonshot env credentials",
config: baseCfg,
env: { MOONSHOT_API_KEY: "sk-moonshot-test" },
},
{
name: "detects openrouter env credentials through bundled web search providers",
config: baseCfg,
env: { OPENROUTER_API_KEY: "sk-or-v1-test" },
},
] as const)("$name", ({ config, env }) => {
expect(hasBundledWebSearchCredential({ config, env })).toBe(true);
});
});

View File

@@ -58,42 +58,10 @@ describe("collectSmallModelRiskFindings", () => {
it.each([
{
name: "gemini plugin config",
cfg: {
...baseCfg,
plugins: {
entries: {
google: { enabled: true, config: { webSearch: { apiKey: "AIza-test" } } },
},
},
} satisfies OpenClawConfig,
name: "small model without sandbox all stays critical even when browser/web tools are off",
cfg: baseCfg,
env: {},
},
{
name: "gemini env key",
cfg: baseCfg,
env: { GEMINI_API_KEY: "AIza-test" },
},
{
name: "grok env key",
cfg: baseCfg,
env: { XAI_API_KEY: "xai-test" },
},
{
name: "kimi env key",
cfg: baseCfg,
env: { KIMI_API_KEY: "sk-kimi-test" },
},
{
name: "moonshot env key",
cfg: baseCfg,
env: { MOONSHOT_API_KEY: "sk-moonshot-test" },
},
{
name: "openrouter env fallback",
cfg: baseCfg,
env: { OPENROUTER_API_KEY: "sk-or-v1-test" },
},
])("$name", ({ cfg, env }) => {
const [finding] = collectSmallModelRiskFindings({
cfg,
@@ -102,6 +70,8 @@ describe("collectSmallModelRiskFindings", () => {
expect(finding?.checkId).toBe("models.small_params");
expect(finding?.severity).toBe("critical");
expect(finding?.detail).toContain("web_search");
expect(finding?.detail).toContain("ollama/mistral-8b");
expect(finding?.detail).toContain("web=[off]");
expect(finding?.detail).toContain("No web/browser tools detected");
});
});