mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-29 01:31:41 +00:00
✨ feat(web): expose search result limit
This commit is contained in:
parent
4e5ebf07ea
commit
4462b349b2
2 changed files with 64 additions and 3 deletions
|
|
@ -448,6 +448,54 @@ class TestParallelClientConfig:
|
|||
assert client1 is client2
|
||||
|
||||
|
||||
class TestWebSearchSchema:
|
||||
"""Test suite for web_search tool schema and handler wiring."""
|
||||
|
||||
def test_schema_exposes_optional_limit(self):
|
||||
import tools.web_tools
|
||||
|
||||
limit_schema = tools.web_tools.WEB_SEARCH_SCHEMA["parameters"]["properties"]["limit"]
|
||||
|
||||
assert limit_schema["type"] == "integer"
|
||||
assert limit_schema["minimum"] == 1
|
||||
assert limit_schema["maximum"] == 100
|
||||
assert limit_schema["default"] == 5
|
||||
assert "limit" not in tools.web_tools.WEB_SEARCH_SCHEMA["parameters"]["required"]
|
||||
|
||||
def test_registered_handler_passes_limit(self):
|
||||
import tools.web_tools
|
||||
|
||||
entry = tools.web_tools.registry.get_entry("web_search")
|
||||
with patch("tools.web_tools.web_search_tool", return_value='{"success": true}') as mock_search:
|
||||
result = entry.handler({"query": "site:example.com docs", "limit": 12})
|
||||
|
||||
assert result == '{"success": true}'
|
||||
mock_search.assert_called_once_with("site:example.com docs", limit=12)
|
||||
|
||||
def test_registered_handler_defaults_limit_to_five(self):
|
||||
import tools.web_tools
|
||||
|
||||
entry = tools.web_tools.registry.get_entry("web_search")
|
||||
with patch("tools.web_tools.web_search_tool", return_value='{"success": true}') as mock_search:
|
||||
result = entry.handler({"query": "docs"})
|
||||
|
||||
assert result == '{"success": true}'
|
||||
mock_search.assert_called_once_with("docs", limit=5)
|
||||
|
||||
def test_web_search_clamps_limit_before_backend_call(self):
|
||||
import tools.web_tools
|
||||
|
||||
with patch("tools.web_tools._get_backend", return_value="parallel"), \
|
||||
patch("tools.web_tools._parallel_search", return_value={"success": True, "data": {"web": []}}) as mock_search, \
|
||||
patch("tools.interrupt.is_interrupted", return_value=False), \
|
||||
patch.object(tools.web_tools._debug, "log_call"), \
|
||||
patch.object(tools.web_tools._debug, "save"):
|
||||
result = json.loads(tools.web_tools.web_search_tool("docs", limit=500))
|
||||
|
||||
assert result == {"success": True, "data": {"web": []}}
|
||||
mock_search.assert_called_once_with("docs", 100)
|
||||
|
||||
|
||||
class TestWebSearchErrorHandling:
|
||||
"""Test suite for web_search_tool() error responses."""
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue