Harden private search fallback and freshness handling
This commit is contained in:
@@ -39,6 +39,23 @@ class WebSearchMcpTests(unittest.TestCase):
|
||||
self.assertEqual(results, [])
|
||||
wikipedia.assert_not_called()
|
||||
|
||||
def test_empty_fresh_search_relaxes_once_and_marks_result(self) -> None:
|
||||
hit = {"title": "Current page", "url": "https://example.com/current"}
|
||||
with mock.patch.object(
|
||||
WEB,
|
||||
"general_discovery",
|
||||
side_effect=[([], []), ([hit], [])],
|
||||
) as discovery:
|
||||
result = WEB.web_search({
|
||||
"query": "current test release",
|
||||
"freshness": "week",
|
||||
"max_results": 3,
|
||||
})
|
||||
self.assertTrue(result["task_complete"])
|
||||
self.assertFalse(result["freshness_applied"])
|
||||
self.assertIn("unfiltered", result["backend_warning"])
|
||||
self.assertEqual(discovery.call_count, 2)
|
||||
|
||||
def test_related_search_budget_is_enforced(self) -> None:
|
||||
with mock.patch.object(WEB, "SEARCH_BUDGET_MAX_RELATED_CALLS", 2):
|
||||
self.assertTrue(WEB.consume_search_budget("latest Proper People video")[0])
|
||||
|
||||
@@ -20,3 +20,13 @@ server:
|
||||
outgoing:
|
||||
request_timeout: 8.0
|
||||
max_request_timeout: 15.0
|
||||
|
||||
# Several default general-purpose engines aggressively block datacenter IPs.
|
||||
# Bing is disabled in SearXNG's upstream defaults but works reliably from the
|
||||
# Athena egress path. Explicitly enabling it gives the private metasearch a
|
||||
# useful primary engine while the others remain independent fallbacks.
|
||||
engines:
|
||||
- name: bing
|
||||
engine: bing
|
||||
shortcut: bi
|
||||
disabled: false
|
||||
|
||||
@@ -1614,6 +1614,7 @@ def web_search(arguments: dict[str, Any]) -> dict[str, Any]:
|
||||
)
|
||||
results: list[dict[str, Any]] = []
|
||||
backend_warning = None
|
||||
freshness_applied = freshness == "any"
|
||||
if backend in {"github", "huggingface"}:
|
||||
try:
|
||||
results.extend(specialized_search(backend, query, limit))
|
||||
@@ -1626,6 +1627,14 @@ def web_search(arguments: dict[str, Any]) -> dict[str, Any]:
|
||||
results.extend(parse_search_xml(payload, limit))
|
||||
else:
|
||||
discovered, discovery_warnings = general_discovery(scoped_query, limit, freshness)
|
||||
freshness_applied = freshness == "any" or bool(discovered)
|
||||
if not discovered and freshness != "any":
|
||||
discovered, relaxed_warnings = general_discovery(scoped_query, limit, "any")
|
||||
discovery_warnings.extend(relaxed_warnings)
|
||||
if discovered:
|
||||
discovery_warnings.append(
|
||||
f"No results survived freshness={freshness}; returned unfiltered discovery results. Verify publication dates before claiming recency."
|
||||
)
|
||||
results.extend(discovered)
|
||||
if discovery_warnings:
|
||||
backend_warning = "; ".join(discovery_warnings)
|
||||
@@ -1636,6 +1645,7 @@ def web_search(arguments: dict[str, Any]) -> dict[str, Any]:
|
||||
"query": query,
|
||||
"backend_used": backend,
|
||||
"freshness": freshness,
|
||||
"freshness_applied": freshness_applied,
|
||||
"domain_filters": {"include": includes, "exclude": excludes},
|
||||
"result_semantics": (
|
||||
"api_verified evidence comes from the named primary API. preview_unverified is "
|
||||
|
||||
Reference in New Issue
Block a user