fix(web-search): split runtime provider resolution

This commit is contained in:
Vincent Koc
2026-03-20 00:01:31 -07:00
parent 397b0d85f5
commit e56dde815e
12 changed files with 394 additions and 320 deletions

View File

@@ -1,7 +1,8 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type { OpenClawConfig } from "../config/config.js";
import type { PluginWebSearchProviderEntry } from "../plugins/types.js";
import * as webSearchProviders from "../plugins/web-search-providers.js";
import * as bundledWebSearchProviders from "../plugins/web-search-providers.js";
import * as runtimeWebSearchProviders from "../plugins/web-search-providers.runtime.js";
import * as secretResolve from "./resolve.js";
import { createResolverContext } from "./runtime-shared.js";
import { resolveRuntimeWebTools } from "./runtime-web-tools.js";
@@ -18,6 +19,9 @@ const { resolveBundledPluginWebSearchProvidersMock } = vi.hoisted(() => ({
vi.mock("../plugins/web-search-providers.js", () => ({
resolveBundledPluginWebSearchProviders: resolveBundledPluginWebSearchProvidersMock,
}));
vi.mock("../plugins/web-search-providers.runtime.js", () => ({
resolvePluginWebSearchProviders: resolvePluginWebSearchProvidersMock,
}));
@@ -181,8 +185,8 @@ function expectInactiveFirecrawlSecretRef(params: {
describe("runtime web tools resolution", () => {
beforeEach(() => {
vi.mocked(webSearchProviders.resolvePluginWebSearchProviders).mockClear();
vi.mocked(webSearchProviders.resolveBundledPluginWebSearchProviders).mockClear();
vi.mocked(bundledWebSearchProviders.resolveBundledPluginWebSearchProviders).mockClear();
vi.mocked(runtimeWebSearchProviders.resolvePluginWebSearchProviders).mockClear();
});
afterEach(() => {
@@ -190,7 +194,7 @@ describe("runtime web tools resolution", () => {
});
it("skips loading web search providers when search config is absent", async () => {
const providerSpy = vi.mocked(webSearchProviders.resolvePluginWebSearchProviders);
const providerSpy = vi.mocked(runtimeWebSearchProviders.resolvePluginWebSearchProviders);
const { metadata } = await runRuntimeWebTools({
config: asConfig({
@@ -538,8 +542,8 @@ describe("runtime web tools resolution", () => {
});
it("uses bundled provider resolution for configured bundled providers", async () => {
const bundledSpy = vi.mocked(webSearchProviders.resolveBundledPluginWebSearchProviders);
const genericSpy = vi.mocked(webSearchProviders.resolvePluginWebSearchProviders);
const bundledSpy = vi.mocked(bundledWebSearchProviders.resolveBundledPluginWebSearchProviders);
const genericSpy = vi.mocked(runtimeWebSearchProviders.resolvePluginWebSearchProviders);
const { metadata } = await runRuntimeWebTools({
config: asConfig({