默认 general 类别在 Docker 任务容器里要 20.0 秒才回 (wikipedia/wikidata/brave/duckduckgo/google 引擎全超时, 只有 bing+360search 回),撞 MCP 默认 20 秒超时;随后 DuckDuckGo 经代理也超时,整条链失败。代理本身无问题 (Tinyproxy 白名单早已放行 searx 与 duckduckgo)。 修法:_provider_searxng 默认 engines=bing,360search, SEARXNG_ENGINES 可覆盖、空值恢复旧行为;worker 搜索 env 透传补 SEARXNG_ENGINES。容器实测:钉住后 0.26 秒 回 3 条(首条北京天气),auto 链 0.15 秒成功;旧 20.0 秒。 测试:新增 test_websearch_searxng 3 项,MCP/worker 共 21 项全过。生产未部署。
53 lines
1.7 KiB
Python
53 lines
1.7 KiB
Python
"""SearXNG provider: engines are pinned, not left to the default
|
|
general category (2026-10-30: default took 20s in a Docker task,
|
|
pinned bing,360search took 0.47s via the same egress proxy)."""
|
|
|
|
import json
|
|
import os
|
|
import sys
|
|
import unittest
|
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", ".."))
|
|
from cloud.websearch import _provider_searxng # noqa: E402
|
|
|
|
|
|
class _FakeHttp:
|
|
def __init__(self):
|
|
self.urls = []
|
|
|
|
def get(self, url, headers=None):
|
|
self.urls.append(url)
|
|
body = json.dumps({"results": [
|
|
{"title": "Beijing weather", "url": "https://example.test/w",
|
|
"content": "sunny"}]}).encode("utf-8")
|
|
return 200, body, "application/json"
|
|
|
|
|
|
class TestSearXNGEngines(unittest.TestCase):
|
|
def test_default_pins_bing_360search(self):
|
|
http = _FakeHttp()
|
|
results, _ = _provider_searxng(
|
|
"Beijing weather", 3, {"SEARXNG_URL": "http://searx.test"},
|
|
http)
|
|
self.assertEqual(len(results), 1)
|
|
self.assertIn("engines=bing%2C360search", http.urls[0])
|
|
|
|
def test_env_overrides_pin(self):
|
|
http = _FakeHttp()
|
|
_provider_searxng(
|
|
"q", 3, {"SEARXNG_URL": "http://searx.test",
|
|
"SEARXNG_ENGINES": "bing"}, http)
|
|
self.assertIn("engines=bing", http.urls[0])
|
|
self.assertNotIn("360search", http.urls[0])
|
|
|
|
def test_empty_env_restores_unpinned(self):
|
|
http = _FakeHttp()
|
|
_provider_searxng(
|
|
"q", 3, {"SEARXNG_URL": "http://searx.test",
|
|
"SEARXNG_ENGINES": ""}, http)
|
|
self.assertNotIn("engines=", http.urls[0])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|