2026-06-03 05:30:19 +01:00
|
|
|
import asyncio
|
|
|
|
|
|
|
|
|
|
import services.search.service as svc_mod
|
|
|
|
|
from services.search.service import SearchService
|
|
|
|
|
|
|
|
|
|
def test_search_skips_non_dict_results(monkeypatch):
|
|
|
|
|
# comprehensive_web_search aggregates external provider + cache results;
|
|
|
|
|
# a malformed row (string/None) made the old loop call r.get and crash,
|
|
|
|
|
# losing the whole search.
|
2026-06-04 21:19:51 +08:00
|
|
|
def fake_search(query, max_pages=10, return_sources=False):
|
|
|
|
|
results = [
|
|
|
|
|
{"url": "https://a.com", "title": "A"},
|
2026-06-03 05:30:19 +01:00
|
|
|
"junk-row",
|
|
|
|
|
None,
|
2026-06-04 21:19:51 +08:00
|
|
|
{"url": "https://b.com", "title": "B"},
|
2026-06-03 05:30:19 +01:00
|
|
|
]
|
2026-06-04 21:19:51 +08:00
|
|
|
return ("", results)
|
2026-06-03 05:30:19 +01:00
|
|
|
|
|
|
|
|
monkeypatch.setattr(svc_mod, "comprehensive_web_search", fake_search)
|
|
|
|
|
svc = SearchService()
|
|
|
|
|
res = asyncio.run(svc.search("anything"))
|
|
|
|
|
assert [r.url for r in res.results] == ["https://a.com", "https://b.com"]
|
|
|
|
|
assert res.total == 2
|