Skip to content

Your lightweight open-source personal agent.

test: add regression test for DuckDuckGo asyncio.wait_for timeout guard

Xubin Ren4b4d8b506dcc
diff --git a/tests/tools/test_web_search_tool.py b/tests/tools/test_web_search_tool.py
index 2c6826dea..e33dd7e6c 100644
--- a/tests/tools/test_web_search_tool.py
+++ b/tests/tools/test_web_search_tool.py
@@ -1,5 +1,7 @@
"""Tests for multi-provider web search."""
+import asyncio
+
import httpx
import pytest
@@ -205,3 +207,25 @@ async def test_jina_search_uses_path_encoded_query(monkeypatch):
assert calls["params"] in (None, {})
+async def test_duckduckgo_timeout_returns_error(monkeypatch):
+ """asyncio.wait_for guard should fire when DDG search hangs."""
+ import threading
+ gate = threading.Event()
+
+ class HangingDDGS:
+ def __init__(self, **kw):
+ pass
+
+ def text(self, query, max_results=5):
+ gate.wait(timeout=10)
+ return []
+
+ monkeypatch.setattr("ddgs.DDGS", HangingDDGS)
+ tool = _tool(provider="duckduckgo")
+ tool.config.timeout = 0.2
+ result = await tool.execute(query="test")
+ gate.set()
+ assert "Error" in result
+
+