Skip to content

Your lightweight open-source personal agent.

test(web): cover Kagi search provider

Xubin Renb959ae6d8965
diff --git a/tests/tools/test_web_search_tool.py b/tests/tools/test_web_search_tool.py
index e33dd7e6c..790d8adcd 100644
--- a/tests/tools/test_web_search_tool.py
+++ b/tests/tools/test_web_search_tool.py
@@ -120,6 +120,27 @@ async def test_jina_search(monkeypatch):
assert "https://jina.ai" in result
+async def test_kagi_search(monkeypatch):
+ async def mock_get(self, url, **kw):
+ assert "kagi.com/api/v0/search" in url
+ assert kw["headers"]["Authorization"] == "Bot kagi-key"
+ assert kw["params"] == {"q": "test", "limit": 2}
+ return _response(json={
+ "data": [
+ {"t": 0, "title": "Kagi Result", "url": "https://kagi.com", "snippet": "Premium search"},
+ {"t": 1, "list": ["ignored related search"]},
+ ]
+ })
+
+ monkeypatch.setattr(httpx.AsyncClient, "get", mock_get)
+ tool = _tool(provider="kagi", api_key="kagi-key")
+ result = await tool.execute(query="test", count=2)
+ assert "Kagi Result" in result
+ assert "https://kagi.com" in result
+ assert "ignored related search" not in result
+
+
@pytest.mark.asyncio
async def test_unknown_provider():
tool = _tool(provider="unknown")
@@ -189,6 +210,23 @@ async def test_jina_422_falls_back_to_duckduckgo(monkeypatch):
assert "DuckDuckGo fallback" in result
+async def test_kagi_fallback_to_duckduckgo_when_no_key(monkeypatch):
+ class MockDDGS:
+ def __init__(self, **kw):
+ pass
+
+ def text(self, query, max_results=5):
+ return [{"title": "Fallback", "href": "https://ddg.example", "body": "DuckDuckGo fallback"}]
+
+ monkeypatch.setattr("ddgs.DDGS", MockDDGS)
+ monkeypatch.delenv("KAGI_API_KEY", raising=False)
+
+ tool = _tool(provider="kagi", api_key="")
+ result = await tool.execute(query="test")
+ assert "Fallback" in result
+
+
@pytest.mark.asyncio
async def test_jina_search_uses_path_encoded_query(monkeypatch):
calls = {}