This commit is contained in:
Vito Botta 2026-04-25 03:32:51 +03:00 committed by GitHub
commit 9a6620d499
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 125 additions and 8 deletions

View file

@ -354,6 +354,27 @@ class TestBackendSelection:
patch.dict(os.environ, {"TAVILY_API_KEY": "tvly-test"}):
assert _get_backend() == "tavily"
def test_fallback_brave_only_key(self):
"""Only BRAVE_API_KEY set → 'brave'."""
from tools.web_tools import _get_backend
with patch("tools.web_tools._load_web_config", return_value={}), \
patch.dict(os.environ, {"BRAVE_API_KEY": "brave-test"}):
assert _get_backend() == "brave"
def test_fallback_exa_takes_priority_over_brave(self):
"""Exa should win over Brave in the fallback path (Brave is last priority)."""
from tools.web_tools import _get_backend
with patch("tools.web_tools._load_web_config", return_value={}), \
patch.dict(os.environ, {"BRAVE_API_KEY": "brave-test", "EXA_API_KEY": "exa-test"}):
assert _get_backend() == "exa"
def test_fallback_tavily_takes_priority_over_brave(self):
"""Tavily should win over Brave in the fallback path."""
from tools.web_tools import _get_backend
with patch("tools.web_tools._load_web_config", return_value={}), \
patch.dict(os.environ, {"TAVILY_API_KEY": "tvly-test", "BRAVE_API_KEY": "brave-test"}):
assert _get_backend() == "tavily"
def test_fallback_tavily_with_firecrawl_prefers_firecrawl(self):
"""Tavily + Firecrawl keys, no config → 'firecrawl' (backward compat)."""
from tools.web_tools import _get_backend
@ -386,7 +407,8 @@ class TestBackendSelection:
def test_fallback_no_keys_defaults_to_firecrawl(self):
"""No keys, no config → 'firecrawl' (will fail at client init)."""
from tools.web_tools import _get_backend
with patch("tools.web_tools._load_web_config", return_value={}):
with patch("tools.web_tools._load_web_config", return_value={}), \
patch.dict(os.environ, {"BRAVE_API_KEY": ""}, clear=False):
assert _get_backend() == "firecrawl"
def test_invalid_config_falls_through_to_fallback(self):