惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

罗磊的独立博客
L
LangChain Blog
aimingoo的专栏
aimingoo的专栏
IT之家
IT之家
B
Blog
博客园_首页
博客园 - 司徒正美
有赞技术团队
有赞技术团队
博客园 - 聂微东
I
InfoQ
美团技术团队
GbyAI
GbyAI
阮一峰的网络日志
阮一峰的网络日志
H
Help Net Security
大猫的无限游戏
大猫的无限游戏
MyScale Blog
MyScale Blog
WordPress大学
WordPress大学
The GitHub Blog
The GitHub Blog
A
About on SuperTechFans
人人都是产品经理
人人都是产品经理
Microsoft Azure Blog
Microsoft Azure Blog
Engineering at Meta
Engineering at Meta
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The Cloudflare Blog

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(web-search): keep first-class web_search runtime prov...
joeykrug · 2026-05-04 · via Recent Commits to openclaw:main

@@ -0,0 +1,165 @@

1+

import { beforeEach, describe, expect, it, vi } from "vitest";

2+3+

const mocks = vi.hoisted(() => ({

4+

runWebSearch: vi.fn(),

5+

resolveManifestContractOwnerPluginId: vi.fn(),

6+

getActiveRuntimeWebToolsMetadata: vi.fn(),

7+

getActiveSecretsRuntimeSnapshot: vi.fn(),

8+

}));

9+10+

vi.mock("../../web-search/runtime.js", () => ({

11+

resolveWebSearchProviderId: vi.fn(() => "mock"),

12+

runWebSearch: mocks.runWebSearch,

13+

}));

14+15+

vi.mock("../../plugins/plugin-registry.js", () => ({

16+

resolveManifestContractOwnerPluginId: mocks.resolveManifestContractOwnerPluginId,

17+

}));

18+19+

vi.mock("../../secrets/runtime-web-tools-state.js", () => ({

20+

getActiveRuntimeWebToolsMetadata: mocks.getActiveRuntimeWebToolsMetadata,

21+

}));

22+23+

vi.mock("../../secrets/runtime.js", () => ({

24+

getActiveSecretsRuntimeSnapshot: mocks.getActiveSecretsRuntimeSnapshot,

25+

}));

26+27+

describe("web_search late-bound runtime fallback", () => {

28+

beforeEach(() => {

29+

mocks.runWebSearch.mockReset();

30+

mocks.runWebSearch.mockResolvedValue({

31+

provider: "brave",

32+

result: { ok: true },

33+

});

34+

mocks.resolveManifestContractOwnerPluginId.mockReset();

35+

mocks.resolveManifestContractOwnerPluginId.mockReturnValue(undefined);

36+

mocks.getActiveRuntimeWebToolsMetadata.mockReset();

37+

mocks.getActiveRuntimeWebToolsMetadata.mockReturnValue(null);

38+

mocks.getActiveSecretsRuntimeSnapshot.mockReset();

39+

mocks.getActiveSecretsRuntimeSnapshot.mockReturnValue(null);

40+

});

41+42+

it("falls back to options.runtimeWebSearch when active runtime web tools metadata is absent", async () => {

43+

const { createWebSearchTool } = await import("./web-search.js");

44+

const tool = createWebSearchTool({

45+

config: {},

46+

lateBindRuntimeConfig: true,

47+

runtimeWebSearch: {

48+

selectedProvider: "brave",

49+

providerConfigured: "brave",

50+

providerSource: "plugin",

51+

diagnostics: [],

52+

},

53+

});

54+55+

await tool?.execute("call-search", { query: "openclaw" }, undefined);

56+57+

expect(mocks.runWebSearch).toHaveBeenCalledWith(

58+

expect.objectContaining({

59+

runtimeWebSearch: expect.objectContaining({ selectedProvider: "brave" }),

60+

}),

61+

);

62+

});

63+64+

it("falls back to options.config when getActiveSecretsRuntimeSnapshot is null", async () => {

65+

const { createWebSearchTool } = await import("./web-search.js");

66+

const fallbackConfig = {

67+

tools: { web: { search: { provider: "brave" } } },

68+

};

69+

const tool = createWebSearchTool({

70+

config: fallbackConfig,

71+

lateBindRuntimeConfig: true,

72+

});

73+74+

await tool?.execute("call-search", { query: "openclaw" }, undefined);

75+76+

expect(mocks.runWebSearch).toHaveBeenCalledWith(

77+

expect.objectContaining({

78+

config: fallbackConfig,

79+

}),

80+

);

81+

});

82+83+

it("uses configured provider id from config when no runtime selection is present", async () => {

84+

const { createWebSearchTool } = await import("./web-search.js");

85+

const config = {

86+

tools: { web: { search: { provider: "Brave" } } },

87+

};

88+

const tool = createWebSearchTool({

89+

config,

90+

lateBindRuntimeConfig: true,

91+

});

92+93+

await tool?.execute("call-search", { query: "openclaw" }, undefined);

94+95+

expect(mocks.resolveManifestContractOwnerPluginId).toHaveBeenCalledWith(

96+

expect.objectContaining({ value: "brave" }),

97+

);

98+

expect(mocks.runWebSearch).toHaveBeenCalledWith(

99+

expect.objectContaining({ preferRuntimeProviders: true }),

100+

);

101+

});

102+103+

it("does not prefer runtime providers when no provider id is selected anywhere", async () => {

104+

const { createWebSearchTool } = await import("./web-search.js");

105+

const tool = createWebSearchTool({

106+

config: {},

107+

lateBindRuntimeConfig: true,

108+

});

109+110+

await tool?.execute("call-search", { query: "openclaw" }, undefined);

111+112+

expect(mocks.resolveManifestContractOwnerPluginId).not.toHaveBeenCalled();

113+

expect(mocks.runWebSearch).toHaveBeenCalledWith(

114+

expect.objectContaining({ preferRuntimeProviders: false }),

115+

);

116+

});

117+118+

it("does not prefer runtime providers when the configured provider is a bundled manifest owner", async () => {

119+

mocks.resolveManifestContractOwnerPluginId.mockReturnValue("openclaw-bundled-brave");

120+

const { createWebSearchTool } = await import("./web-search.js");

121+

const config = {

122+

tools: { web: { search: { provider: "brave" } } },

123+

};

124+

const tool = createWebSearchTool({

125+

config,

126+

lateBindRuntimeConfig: true,

127+

});

128+129+

await tool?.execute("call-search", { query: "openclaw" }, undefined);

130+131+

expect(mocks.runWebSearch).toHaveBeenCalledWith(

132+

expect.objectContaining({ preferRuntimeProviders: false }),

133+

);

134+

});

135+136+

it("prefers active runtime metadata over options.runtimeWebSearch when present", async () => {

137+

mocks.getActiveRuntimeWebToolsMetadata.mockReturnValue({

138+

search: {

139+

selectedProvider: "perplexity",

140+

providerConfigured: "perplexity",

141+

providerSource: "plugin",

142+

diagnostics: [],

143+

},

144+

});

145+

const { createWebSearchTool } = await import("./web-search.js");

146+

const tool = createWebSearchTool({

147+

config: {},

148+

lateBindRuntimeConfig: true,

149+

runtimeWebSearch: {

150+

selectedProvider: "brave",

151+

providerConfigured: "brave",

152+

providerSource: "plugin",

153+

diagnostics: [],

154+

},

155+

});

156+157+

await tool?.execute("call-search", { query: "openclaw" }, undefined);

158+159+

expect(mocks.runWebSearch).toHaveBeenCalledWith(

160+

expect.objectContaining({

161+

runtimeWebSearch: expect.objectContaining({ selectedProvider: "perplexity" }),

162+

}),

163+

);

164+

});

165+

});