The user asked to drop it: nobody had the Gemini CLI login or a key set up, and Exa then Wikipedia cover the voice use. webSearch is now live Chrome, Exa, Brave (opt-in), Wikipedia. Removes the CLI/REST backends, the GEMINI_* settings, the Docker login mount and checks, and updates the specs and docs/llm_contexts.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
124 lines
4.1 KiB
Python
124 lines
4.1 KiB
Python
"""Behaviour tests for webSearch provider routing.
|
|
|
|
Routing contract (docs/stream_browser_modes.md, web_search.spec.md):
|
|
- master flag cfg.stream_browser (env STREAM_BROWSER) = broadcast capability
|
|
- context.broadcasting = live screen-share state for the turn (set by the bot)
|
|
|
|
master live(ctx) -> backend
|
|
------- --------- -------
|
|
True True on-screen Chrome (browser_search)
|
|
True None Chrome (no signal -> fall back to master)
|
|
True False Exa
|
|
False True/None Exa (broadcast disabled, never Chrome)
|
|
|
|
When Exa finds nothing the chain goes on to Brave (opt-in) and Wikipedia.
|
|
"""
|
|
|
|
from types import SimpleNamespace
|
|
|
|
import pytest
|
|
|
|
import jarvis.tools.builtin.realtime_search as rs
|
|
import jarvis.tools.builtin.web_search as ws
|
|
from jarvis.tools.base import ToolContext
|
|
from jarvis.tools.builtin.web_search import WebSearchTool
|
|
|
|
EXA_HIT = [("Seoul weather", "https://exa.test/seoul", "EXA_TEXT sunny, 21C")]
|
|
|
|
|
|
def _ctx(stream_browser, broadcasting):
|
|
cfg = SimpleNamespace(
|
|
web_search_enabled=True,
|
|
stream_browser=stream_browser,
|
|
wikipedia_fallback_enabled=True,
|
|
)
|
|
return ToolContext(
|
|
db=None,
|
|
cfg=cfg,
|
|
system_prompt="",
|
|
original_prompt="",
|
|
redacted_text="",
|
|
max_retries=0,
|
|
user_print=lambda *a, **k: None,
|
|
language=None,
|
|
broadcasting=broadcasting,
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def backends(monkeypatch):
|
|
"""Fake every backend; returns the list of backends that ran, in order."""
|
|
ran = []
|
|
|
|
def fake(name, result):
|
|
def call(*a, **k):
|
|
ran.append(name)
|
|
return result() if callable(result) else result
|
|
return call
|
|
|
|
state = SimpleNamespace(exa=EXA_HIT, ran=ran)
|
|
monkeypatch.setattr(rs, "browser_search", fake("browser", "BROWSER_RESULT"))
|
|
monkeypatch.setattr(ws, "_exa_search", fake("exa", lambda: state.exa))
|
|
monkeypatch.setattr(ws, "_wikipedia_summary", fake("wikipedia", None))
|
|
return state
|
|
|
|
|
|
def _route(stream_browser, broadcasting, query="현재 서울 날씨"):
|
|
res = WebSearchTool().run({"search_query": query}, _ctx(stream_browser, broadcasting))
|
|
if res.reply_text == "BROWSER_RESULT":
|
|
return "browser"
|
|
if "EXA_TEXT" in res.reply_text:
|
|
return "exa"
|
|
return "fallthrough"
|
|
|
|
|
|
def test_master_on_live_on_uses_browser(backends):
|
|
assert _route(True, True) == "browser"
|
|
assert backends.ran == ["browser"]
|
|
|
|
|
|
def test_master_on_live_off_uses_exa(backends):
|
|
assert _route(True, False) == "exa"
|
|
assert "browser" not in backends.ran
|
|
|
|
|
|
def test_master_on_no_signal_defaults_to_browser(backends):
|
|
# None = no live signal (evals / text entry / older bot) -> behave as master
|
|
assert _route(True, None) == "browser"
|
|
|
|
|
|
def test_master_off_never_uses_browser_even_if_live(backends):
|
|
# STREAM_BROWSER=false disables broadcast entirely.
|
|
assert _route(False, True) == "exa"
|
|
assert "browser" not in backends.ran
|
|
|
|
|
|
def test_master_off_no_signal_uses_exa(backends):
|
|
assert _route(False, None) == "exa"
|
|
|
|
|
|
def test_browser_failure_while_live_falls_through_to_exa(backends, monkeypatch):
|
|
monkeypatch.setattr(rs, "browser_search", lambda *a, **k: None)
|
|
assert _route(True, True) == "exa"
|
|
|
|
|
|
def test_exa_results_stop_the_chain(backends):
|
|
assert _route(False, None) == "exa"
|
|
assert backends.ran == ["exa"]
|
|
|
|
|
|
def test_exa_empty_goes_straight_to_wikipedia(backends):
|
|
# No Brave key: after Exa the only provider left is Wikipedia.
|
|
backends.exa = []
|
|
assert _route(False, None) == "fallthrough"
|
|
assert backends.ran == ["exa", "wikipedia"]
|
|
|
|
|
|
def test_a_query_given_as_query_instead_of_search_query_still_searches(backends, monkeypatch):
|
|
# Live 2026-11-16: the planner wrote "webSearch query='...'" and the model passed `query`;
|
|
# both searches failed with "Please provide a search query".
|
|
seen = []
|
|
monkeypatch.setattr(ws, "_exa_search", lambda q, *a, **k: seen.append(q) or EXA_HIT)
|
|
res = WebSearchTool().run({"query": "안강 산책 코스"}, _ctx(False, None))
|
|
assert "EXA_TEXT" in res.reply_text and seen == ["안강 산책 코스"]
|