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

推荐订阅源

Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 三生石上(FineUI控件)
雷峰网
雷峰网
WordPress大学
WordPress大学
S
SegmentFault 最新的问题
博客园 - 叶小钗
The Cloudflare Blog
T
Tailwind CSS Blog
Hugging Face - Blog
Hugging Face - Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
月光博客
月光博客
小众软件
小众软件
罗磊的独立博客
酷 壳 – CoolShell
酷 壳 – CoolShell
大猫的无限游戏
大猫的无限游戏
阮一峰的网络日志
阮一峰的网络日志
V
V2EX
美团技术团队
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 聂微东
量子位
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
宝玉的分享
宝玉的分享

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(searxng): retry empty category searches · openclaw/op...
steipete · 2026-05-02 · via Recent Commits to openclaw:main

@@ -1,6 +1,32 @@

11

import type { LookupFn } from "openclaw/plugin-sdk/ssrf-runtime";

2-

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

3-

import { __testing } from "./searxng-client.js";

2+

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

3+4+

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

5+

calls: [] as Array<{ url: string; timeoutSeconds: number; init: RequestInit }>,

6+

responses: [] as Response[],

7+

}));

8+9+

vi.mock("openclaw/plugin-sdk/provider-web-search", async (importOriginal) => {

10+

const actual = await importOriginal<typeof import("openclaw/plugin-sdk/provider-web-search")>();

11+

const runEndpoint = async (

12+

params: { url: string; timeoutSeconds: number; init: RequestInit },

13+

run: (response: Response) => Promise<unknown>,

14+

) => {

15+

endpointMockState.calls.push(params);

16+

const response = endpointMockState.responses.shift();

17+

if (!response) {

18+

throw new Error("Missing mocked SearXNG response.");

19+

}

20+

return await run(response);

21+

};

22+

return {

23+

...actual,

24+

withSelfHostedWebSearchEndpoint: vi.fn(runEndpoint),

25+

withTrustedWebSearchEndpoint: vi.fn(runEndpoint),

26+

};

27+

});

28+29+

import { __testing, runSearxngSearch } from "./searxng-client.js";

430531

function createLookupFn(addresses: Array<{ address: string; family: number }>): LookupFn {

632

return vi.fn(async (_hostname: string, options?: unknown) => {

@@ -12,6 +38,12 @@ function createLookupFn(addresses: Array<{ address: string; family: number }>):

1238

}

13391440

describe("searxng client", () => {

41+

beforeEach(() => {

42+

endpointMockState.calls = [];

43+

endpointMockState.responses = [];

44+

__testing.SEARXNG_SEARCH_CACHE.clear();

45+

});

46+1547

it("preserves a configured base-path prefix when building the search URL", () => {

1648

expect(

1749

__testing.buildSearxngSearchUrl({

@@ -39,6 +71,72 @@ describe("searxng client", () => {

3971

).toEqual([{ title: "One", url: "https://example.com/1", content: "A" }]);

4072

});

417374+

it("retries an empty category search with general results", async () => {

75+

endpointMockState.responses.push(

76+

new Response(JSON.stringify({ results: [] }), { status: 200 }),

77+

new Response(

78+

JSON.stringify({

79+

results: [

80+

{

81+

title: "Beijing hourly weather",

82+

url: "https://example.com/weather",

83+

content: "Hourly forecast",

84+

},

85+

],

86+

}),

87+

{ status: 200 },

88+

),

89+

);

90+91+

const result = await runSearxngSearch({

92+

baseUrl: "http://127.0.0.1:8888",

93+

query: "beijing hourly weather",

94+

categories: "weather",

95+

count: 5,

96+

});

97+98+

expect(endpointMockState.calls).toHaveLength(2);

99+

expect(new URL(endpointMockState.calls[0].url).searchParams.get("categories")).toBe("weather");

100+

expect(new URL(endpointMockState.calls[1].url).searchParams.get("categories")).toBe("general");

101+

expect(result).toMatchObject({

102+

provider: "searxng",

103+

count: 1,

104+

results: [

105+

expect.objectContaining({

106+

url: "https://example.com/weather",

107+

}),

108+

],

109+

});

110+

});

111+112+

it("does not retry empty general category searches", async () => {

113+

endpointMockState.responses.push(

114+

new Response(JSON.stringify({ results: [] }), { status: 200 }),

115+

);

116+117+

const result = await runSearxngSearch({

118+

baseUrl: "http://127.0.0.1:8888",

119+

query: "openclaw",

120+

categories: "general",

121+

count: 5,

122+

});

123+124+

expect(endpointMockState.calls).toHaveLength(1);

125+

expect(result).toMatchObject({

126+

provider: "searxng",

127+

count: 0,

128+

results: [],

129+

});

130+

});

131+132+

it("detects category searches that should retry with general", () => {

133+

expect(__testing.shouldRetryEmptyCategorySearchWithGeneral("weather")).toBe(true);

134+

expect(__testing.shouldRetryEmptyCategorySearchWithGeneral("weather,news")).toBe(true);

135+

expect(__testing.shouldRetryEmptyCategorySearchWithGeneral("general")).toBe(false);

136+

expect(__testing.shouldRetryEmptyCategorySearchWithGeneral("general,news")).toBe(false);

137+

expect(__testing.shouldRetryEmptyCategorySearchWithGeneral(undefined)).toBe(false);

138+

});

139+42140

it("preserves img_src from image search results", () => {

43141

expect(

44142

__testing.parseSearxngResponseText(