refactor(search): remove the Gemini search backend
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>
This commit is contained in:
@@ -1,139 +0,0 @@
|
||||
"""Behaviour tests for the Gemini CLI (OAuth login) real-time search backend.
|
||||
|
||||
These verify the observable contract of ``gemini_cli_search``:
|
||||
- a fenced answer when the CLI returns a JSON ``response``,
|
||||
- fail-open (``None``) when the CLI is missing, times out, errors, or returns
|
||||
empty/garbage output,
|
||||
- the child process never inherits ``GEMINI_API_KEY`` / ``GOOGLE_API_KEY`` so
|
||||
the CLI uses the account OAuth login rather than API-key auth.
|
||||
"""
|
||||
|
||||
import subprocess
|
||||
import types
|
||||
|
||||
import jarvis.tools.builtin.realtime_search as rs
|
||||
|
||||
|
||||
def _fake_proc(stdout: str) -> types.SimpleNamespace:
|
||||
return types.SimpleNamespace(stdout=stdout, stderr="", returncode=0)
|
||||
|
||||
|
||||
def test_returns_fenced_answer_on_success(monkeypatch):
|
||||
monkeypatch.setattr(rs, "_gemini_bin", lambda: "/usr/bin/gemini")
|
||||
monkeypatch.setattr(
|
||||
rs.subprocess,
|
||||
"run",
|
||||
lambda *a, **k: _fake_proc('{"response": "Seoul is sunny, 21C.", "stats": {}}'),
|
||||
)
|
||||
|
||||
out = rs.gemini_cli_search("weather in Seoul")
|
||||
|
||||
assert out is not None
|
||||
assert "Seoul is sunny, 21C." in out
|
||||
assert "UNTRUSTED WEB EXTRACT" in out # untrusted-data fence preserved
|
||||
|
||||
|
||||
def test_none_when_cli_not_installed(monkeypatch):
|
||||
monkeypatch.setattr(rs, "_gemini_bin", lambda: None)
|
||||
# subprocess.run must not even be reached
|
||||
monkeypatch.setattr(rs.subprocess, "run", lambda *a, **k: (_ for _ in ()).throw(AssertionError("should not run")))
|
||||
|
||||
assert rs.gemini_cli_search("anything") is None
|
||||
|
||||
|
||||
def test_none_on_empty_query(monkeypatch):
|
||||
monkeypatch.setattr(rs, "_gemini_bin", lambda: "/usr/bin/gemini")
|
||||
assert rs.gemini_cli_search("") is None
|
||||
|
||||
|
||||
def test_none_on_empty_response(monkeypatch):
|
||||
monkeypatch.setattr(rs, "_gemini_bin", lambda: "/usr/bin/gemini")
|
||||
monkeypatch.setattr(rs.subprocess, "run", lambda *a, **k: _fake_proc('{"response": "", "stats": {}}'))
|
||||
assert rs.gemini_cli_search("q") is None
|
||||
|
||||
|
||||
def test_none_on_garbage_output(monkeypatch):
|
||||
monkeypatch.setattr(rs, "_gemini_bin", lambda: "/usr/bin/gemini")
|
||||
monkeypatch.setattr(rs.subprocess, "run", lambda *a, **k: _fake_proc("not json at all"))
|
||||
assert rs.gemini_cli_search("q") is None
|
||||
|
||||
|
||||
def test_none_on_timeout(monkeypatch):
|
||||
monkeypatch.setattr(rs, "_gemini_bin", lambda: "/usr/bin/gemini")
|
||||
|
||||
def _boom(*a, **k):
|
||||
raise subprocess.TimeoutExpired(cmd="gemini", timeout=30)
|
||||
|
||||
monkeypatch.setattr(rs.subprocess, "run", _boom)
|
||||
assert rs.gemini_cli_search("q") is None
|
||||
|
||||
|
||||
def test_api_key_stripped_from_child_env(monkeypatch):
|
||||
monkeypatch.setattr(rs, "_gemini_bin", lambda: "/usr/bin/gemini")
|
||||
monkeypatch.setenv("GEMINI_API_KEY", "AIza-secret")
|
||||
monkeypatch.setenv("GOOGLE_API_KEY", "another-secret")
|
||||
captured = {}
|
||||
|
||||
def _capture(*a, **k):
|
||||
captured["env"] = k.get("env", {})
|
||||
captured["cmd"] = a[0] if a else k.get("args")
|
||||
return _fake_proc('{"response": "ok"}')
|
||||
|
||||
monkeypatch.setattr(rs.subprocess, "run", _capture)
|
||||
rs.gemini_cli_search("q")
|
||||
|
||||
assert "GEMINI_API_KEY" not in captured["env"]
|
||||
assert "GOOGLE_API_KEY" not in captured["env"]
|
||||
# Google-account (OAuth) auth method is selected explicitly so a missing
|
||||
# login fails fast non-interactively instead of erroring on "no auth method".
|
||||
assert captured["env"].get("GOOGLE_GENAI_USE_GCA") == "true"
|
||||
# invoked headless with JSON output
|
||||
assert "-p" in captured["cmd"] and "-o" in captured["cmd"] and "json" in captured["cmd"]
|
||||
# never auto-approve all tools: a search query must not be able to trigger
|
||||
# write/shell tool execution.
|
||||
assert "yolo" not in captured["cmd"]
|
||||
assert "--yolo" not in captured["cmd"]
|
||||
|
||||
|
||||
def test_oauth_ready_reflects_creds_file(monkeypatch, tmp_path):
|
||||
"""``gemini_oauth_ready`` is the seeded-login signal: false until the CLI's
|
||||
``~/.gemini/oauth_creds.json`` exists, true once it does."""
|
||||
monkeypatch.setenv("HOME", str(tmp_path))
|
||||
assert rs.gemini_oauth_ready() is False
|
||||
gdir = tmp_path / ".gemini"
|
||||
gdir.mkdir()
|
||||
(gdir / "oauth_creds.json").write_text("{}")
|
||||
assert rs.gemini_oauth_ready() is True
|
||||
assert rs.gemini_oauth_dir() == gdir
|
||||
|
||||
|
||||
def test_hint_logged_once_when_oauth_not_seeded(monkeypatch):
|
||||
"""When OAuth is selected but no login is seeded, the path still attempts the
|
||||
CLI (behaviour unchanged) but logs a single actionable hint so the silent
|
||||
DDG/Brave fallback is diagnosable."""
|
||||
monkeypatch.setattr(rs, "_gemini_bin", lambda: "/usr/bin/gemini")
|
||||
monkeypatch.setattr(rs, "gemini_oauth_ready", lambda: False)
|
||||
monkeypatch.setattr(rs.subprocess, "run", lambda *a, **k: _fake_proc('{"response": "ok"}'))
|
||||
logs: list[str] = []
|
||||
monkeypatch.setattr(rs, "debug_log", lambda msg, *a, **k: logs.append(msg))
|
||||
monkeypatch.setattr(rs, "_oauth_hint_shown", False)
|
||||
|
||||
assert rs.gemini_cli_search("q") is not None # still attempts, behaviour unchanged
|
||||
rs.gemini_cli_search("q again") # second call must not re-log
|
||||
|
||||
hints = [m for m in logs if "no Gemini login" in m]
|
||||
assert len(hints) == 1
|
||||
|
||||
|
||||
def test_no_hint_when_oauth_seeded(monkeypatch):
|
||||
"""A seeded login produces no fallback hint."""
|
||||
monkeypatch.setattr(rs, "_gemini_bin", lambda: "/usr/bin/gemini")
|
||||
monkeypatch.setattr(rs, "gemini_oauth_ready", lambda: True)
|
||||
monkeypatch.setattr(rs.subprocess, "run", lambda *a, **k: _fake_proc('{"response": "ok"}'))
|
||||
logs: list[str] = []
|
||||
monkeypatch.setattr(rs, "debug_log", lambda msg, *a, **k: logs.append(msg))
|
||||
monkeypatch.setattr(rs, "_oauth_hint_shown", False)
|
||||
|
||||
rs.gemini_cli_search("q")
|
||||
|
||||
assert not [m for m in logs if "no Gemini login" in m]
|
||||
@@ -11,7 +11,7 @@ Routing contract (docs/stream_browser_modes.md, web_search.spec.md):
|
||||
True False Exa
|
||||
False True/None Exa (broadcast disabled, never Chrome)
|
||||
|
||||
Gemini only runs when Exa found nothing, and the CLI only with a Google login.
|
||||
When Exa finds nothing the chain goes on to Brave (opt-in) and Wikipedia.
|
||||
"""
|
||||
|
||||
from types import SimpleNamespace
|
||||
@@ -30,10 +30,7 @@ def _ctx(stream_browser, broadcasting):
|
||||
cfg = SimpleNamespace(
|
||||
web_search_enabled=True,
|
||||
stream_browser=stream_browser,
|
||||
gemini_auth="oauth",
|
||||
gemini_api_key="",
|
||||
gemini_model="gemini-2.0-flash",
|
||||
wikipedia_fallback_enabled=False,
|
||||
wikipedia_fallback_enabled=True,
|
||||
)
|
||||
return ToolContext(
|
||||
db=None,
|
||||
@@ -59,11 +56,8 @@ def backends(monkeypatch):
|
||||
return result() if callable(result) else result
|
||||
return call
|
||||
|
||||
state = SimpleNamespace(exa=EXA_HIT, login=True, ran=ran)
|
||||
state = SimpleNamespace(exa=EXA_HIT, ran=ran)
|
||||
monkeypatch.setattr(rs, "browser_search", fake("browser", "BROWSER_RESULT"))
|
||||
monkeypatch.setattr(rs, "gemini_cli_search", fake("gemini", "GEMINI_RESULT"))
|
||||
monkeypatch.setattr(rs, "gemini_search", fake("gemini", "GEMINI_RESULT"))
|
||||
monkeypatch.setattr(rs, "gemini_oauth_ready", lambda: state.login)
|
||||
monkeypatch.setattr(ws, "_exa_search", fake("exa", lambda: state.exa))
|
||||
monkeypatch.setattr(ws, "_wikipedia_summary", fake("wikipedia", None))
|
||||
return state
|
||||
@@ -73,8 +67,6 @@ 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 res.reply_text == "GEMINI_RESULT":
|
||||
return "gemini"
|
||||
if "EXA_TEXT" in res.reply_text:
|
||||
return "exa"
|
||||
return "fallthrough"
|
||||
@@ -110,23 +102,16 @@ def test_browser_failure_while_live_falls_through_to_exa(backends, monkeypatch):
|
||||
assert _route(True, True) == "exa"
|
||||
|
||||
|
||||
def test_exa_results_mean_gemini_never_runs(backends):
|
||||
def test_exa_results_stop_the_chain(backends):
|
||||
assert _route(False, None) == "exa"
|
||||
assert "gemini" not in backends.ran
|
||||
assert backends.ran == ["exa"]
|
||||
|
||||
|
||||
def test_exa_empty_with_login_uses_gemini_cli(backends):
|
||||
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) == "gemini"
|
||||
assert backends.ran == ["exa", "gemini"]
|
||||
|
||||
|
||||
def test_exa_empty_without_login_never_starts_gemini_cli(backends):
|
||||
# No Google login: the CLI would only fail, so it is not started at all.
|
||||
backends.exa = []
|
||||
backends.login = False
|
||||
assert _route(False, None) == "fallthrough"
|
||||
assert "gemini" not in backends.ran
|
||||
assert backends.ran == ["exa", "wikipedia"]
|
||||
|
||||
|
||||
def test_a_query_given_as_query_instead_of_search_query_still_searches(backends, monkeypatch):
|
||||
|
||||
@@ -11,7 +11,6 @@ from src.jarvis.tools.base import ToolContext
|
||||
from src.jarvis.tools.types import ToolExecutionResult
|
||||
|
||||
WS = "src.jarvis.tools.builtin.web_search"
|
||||
RS = "src.jarvis.tools.builtin.realtime_search"
|
||||
|
||||
|
||||
def _cfg(**overrides):
|
||||
@@ -20,8 +19,6 @@ def _cfg(**overrides):
|
||||
cfg.web_search_enabled = True
|
||||
cfg.voice_debug = False
|
||||
cfg.stream_browser = False
|
||||
cfg.gemini_auth = "api_key"
|
||||
cfg.gemini_api_key = ""
|
||||
cfg.brave_search_api_key = ""
|
||||
cfg.wikipedia_fallback_enabled = False
|
||||
cfg.mcps = {}
|
||||
@@ -95,11 +92,10 @@ class TestWebSearchTool:
|
||||
assert "disabled" in result.reply_text.lower()
|
||||
|
||||
@patch(f"{WS}._wikipedia_summary")
|
||||
@patch(f"{RS}.gemini_search")
|
||||
def test_exa_results_are_fenced_with_links_and_stop_the_chain(self, mock_gemini, mock_wiki):
|
||||
def test_exa_results_are_fenced_with_links_and_stop_the_chain(self, mock_wiki):
|
||||
"""Exa's page text lands inside the fence, its links follow it, and no
|
||||
later provider is consulted."""
|
||||
self.context.cfg = _cfg(gemini_api_key="key", wikipedia_fallback_enabled=True)
|
||||
self.context.cfg = _cfg(wikipedia_fallback_enabled=True)
|
||||
self.exa.return_value = [
|
||||
("Possessor (film)", "https://exa1.test/possessor",
|
||||
"Possessor is a 2020 film directed by Brandon Cronenberg."),
|
||||
@@ -115,7 +111,6 @@ class TestWebSearchTool:
|
||||
assert begin < text.index("Brandon Cronenberg") < end
|
||||
assert text.index("https://exa1.test/possessor") > end
|
||||
assert "https://exa2.test/review" in text
|
||||
mock_gemini.assert_not_called()
|
||||
mock_wiki.assert_not_called()
|
||||
|
||||
def test_envelope_directs_extraction_when_content_found(self):
|
||||
|
||||
Reference in New Issue
Block a user