summaryrefslogtreecommitdiff
path: root/tests/test_tools.py
diff options
context:
space:
mode:
authortanaka takashi <isazaka@gmail.com>2026-10-20 02:03:54 +0900
committertanaka takashi <isazaka@gmail.com>2026-10-20 02:03:54 +0900
commit4e9c66ee25ed77858985765382f41d0cf22ea588 (patch)
treefcde86704f98035e8dbae8814c07b0cb07d19bdb /tests/test_tools.py
parentfbda00608e52eef6a0e7b01ce831b1e6c3666909 (diff)
Improve web search region selection and normalize provider resultsHEADmain
Update ddgs to 9.16.0 and keep backend="auto" while preserving the LLM-facing query/max_results inputs and title/href/body result schema. Implementation: - Add OLLAMA_WEB_SEARCH_REGION with auto/us-en/jp-jp values, normalized configuration input, and a clear startup error for unsupported values. - In auto mode, detect kana after NFKC normalization and exclusion of URLs and site:/filetype: tokens. Select jp-jp for kana and us-en otherwise, without modifying the original query or sharing per-call region state. - Preserve href/url and body/snippet fallbacks and normalize None values. - Reject malformed HTTP(S) URLs without DNS lookups or extra requests. - Unwrap known Yahoo redirect URLs before excluding Bing aclick ads. - Represent missing and URL-only titles as empty strings rather than inventing titles from snippets. Preserve remaining provider order and allow fewer results after filtering, without additional searches. - Preserve provider exception propagation and identify ddgs in error logs. Coverage and documentation: - Add 72 regression cases for configuration, region routing, concurrency, public schemas, title/URL/ad boundaries, limits, and search_and_fetch continuation. Update existing provider mocks and log assertions. - Document the region environment setting and result semantics in both READMEs and tools-schema.md; update the changelog. - Keep only a short backend availability caveat in tools-schema.md and remove the temporary backend comparison, design, and validation docs. Validation: - pytest: 222 passed; ruff check . and mypy src/ passed. - uv lock --check and git diff --check passed. - Initial live acceptance: 56 searches plus 3 registry smoke checks; default-region auto succeeded 8/18 times and real ad filtering removed two ads. Stable relevance/title quality targets remain unmet because provider acquisition is unreliable. - Follow-up backend study: 234 comparative searches plus 3 Yahoo response diagnostics. Yahoo led individual backends at 9/18; restricted multi- backend combinations did not outperform the contemporaneous auto control. Authentication, access restrictions, temporary upstream failures, and Yahoo HTML/parser mismatches were observed. Do not claim search reliability is fixed or add backend configuration, custom retries, ranking changes, or challenge bypasses. Running app processes were not restarted; restart is needed to load the changes.
Diffstat (limited to 'tests/test_tools.py')
-rw-r--r--tests/test_tools.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/tests/test_tools.py b/tests/test_tools.py
index 6ba537b..487ce98 100644
--- a/tests/test_tools.py
+++ b/tests/test_tools.py
@@ -103,7 +103,9 @@ def test_web_search_mocked():
def __exit__(self, *a):
return None
- def text(self, q, max_results=5):
+ def text(self, q, max_results=5, *, region, backend):
+ assert region == "us-en"
+ assert backend == "auto"
return fake
monkey = MagicMock()
@@ -126,7 +128,7 @@ def test_web_search_returns_empty_list_for_no_provider_results() -> None:
def __exit__(self, *args):
return None
- def text(self, query, max_results=5):
+ def text(self, query, max_results=5, *, region, backend):
return []
with patch.object(search_mod, "DDGS", EmptyDDGS):
@@ -145,7 +147,7 @@ def test_web_search_logs_and_propagates_provider_errors(
def __exit__(self, *args):
return None
- def text(self, query, max_results=5):
+ def text(self, query, max_results=5, *, region, backend):
raise RuntimeError("403 Forbidden")
with (
@@ -155,7 +157,7 @@ def test_web_search_logs_and_propagates_provider_errors(
with pytest.raises(RuntimeError, match="403 Forbidden"):
search_mod.web_search("private search terms")
- assert "DuckDuckGo web search failed" in caplog.text
+ assert "ddgs web search failed" in caplog.text
assert "private search terms" not in caplog.text
registry = ToolRegistry()