@@ -130,7 +130,7 @@ class TestBackendSelection:
130130 setups.
131131 """
132132
133- _ENV_KEYS = ("PARALLEL_API_KEY" , "FIRECRAWL_API_KEY" , "FIRECRAWL_API_URL" )
133+ _ENV_KEYS = ("PARALLEL_API_KEY" , "FIRECRAWL_API_KEY" , "FIRECRAWL_API_URL" , "TAVILY_API_KEY" )
134134
135135 def setup_method (self ):
136136 for key in self ._ENV_KEYS :
@@ -155,12 +155,31 @@ def test_config_firecrawl(self):
155155 patch .dict (os .environ , {"PARALLEL_API_KEY" : "test-key" }):
156156 assert _get_backend () == "firecrawl"
157157
158+ def test_config_tavily (self ):
159+ """web.backend=tavily in config → 'tavily' regardless of other keys."""
160+ from tools .web_tools import _get_backend
161+ with patch ("tools.web_tools._load_web_config" , return_value = {"backend" : "tavily" }):
162+ assert _get_backend () == "tavily"
163+
164+ def test_config_tavily_overrides_env_keys (self ):
165+ """web.backend=tavily in config → 'tavily' even if Firecrawl key set."""
166+ from tools .web_tools import _get_backend
167+ with patch ("tools.web_tools._load_web_config" , return_value = {"backend" : "tavily" }), \
168+ patch .dict (os .environ , {"FIRECRAWL_API_KEY" : "fc-test" }):
169+ assert _get_backend () == "tavily"
170+
158171 def test_config_case_insensitive (self ):
159172 """web.backend=Parallel (mixed case) → 'parallel'."""
160173 from tools .web_tools import _get_backend
161174 with patch ("tools.web_tools._load_web_config" , return_value = {"backend" : "Parallel" }):
162175 assert _get_backend () == "parallel"
163176
177+ def test_config_tavily_case_insensitive (self ):
178+ """web.backend=Tavily (mixed case) → 'tavily'."""
179+ from tools .web_tools import _get_backend
180+ with patch ("tools.web_tools._load_web_config" , return_value = {"backend" : "Tavily" }):
181+ assert _get_backend () == "tavily"
182+
164183 # ── Fallback (no web.backend in config) ───────────────────────────
165184
166185 def test_fallback_parallel_only_key (self ):
@@ -170,6 +189,28 @@ def test_fallback_parallel_only_key(self):
170189 patch .dict (os .environ , {"PARALLEL_API_KEY" : "test-key" }):
171190 assert _get_backend () == "parallel"
172191
192+ def test_fallback_tavily_only_key (self ):
193+ """Only TAVILY_API_KEY set → 'tavily'."""
194+ from tools .web_tools import _get_backend
195+ with patch ("tools.web_tools._load_web_config" , return_value = {}), \
196+ patch .dict (os .environ , {"TAVILY_API_KEY" : "tvly-test" }):
197+ assert _get_backend () == "tavily"
198+
199+ def test_fallback_tavily_with_firecrawl_prefers_firecrawl (self ):
200+ """Tavily + Firecrawl keys, no config → 'firecrawl' (backward compat)."""
201+ from tools .web_tools import _get_backend
202+ with patch ("tools.web_tools._load_web_config" , return_value = {}), \
203+ patch .dict (os .environ , {"TAVILY_API_KEY" : "tvly-test" , "FIRECRAWL_API_KEY" : "fc-test" }):
204+ assert _get_backend () == "firecrawl"
205+
206+ def test_fallback_tavily_with_parallel_prefers_parallel (self ):
207+ """Tavily + Parallel keys, no config → 'parallel' (Parallel takes priority over Tavily)."""
208+ from tools .web_tools import _get_backend
209+ with patch ("tools.web_tools._load_web_config" , return_value = {}), \
210+ patch .dict (os .environ , {"TAVILY_API_KEY" : "tvly-test" , "PARALLEL_API_KEY" : "par-test" }):
211+ # Parallel + no Firecrawl → parallel
212+ assert _get_backend () == "parallel"
213+
173214 def test_fallback_both_keys_defaults_to_firecrawl (self ):
174215 """Both keys set, no config → 'firecrawl' (backward compat)."""
175216 from tools .web_tools import _get_backend
@@ -193,7 +234,7 @@ def test_fallback_no_keys_defaults_to_firecrawl(self):
193234 def test_invalid_config_falls_through_to_fallback (self ):
194235 """web.backend=invalid → ignored, uses key-based fallback."""
195236 from tools .web_tools import _get_backend
196- with patch ("tools.web_tools._load_web_config" , return_value = {"backend" : "tavily " }), \
237+ with patch ("tools.web_tools._load_web_config" , return_value = {"backend" : "nonexistent " }), \
197238 patch .dict (os .environ , {"PARALLEL_API_KEY" : "test-key" }):
198239 assert _get_backend () == "parallel"
199240
@@ -238,7 +279,7 @@ def test_singleton_returns_same_instance(self):
238279class TestCheckWebApiKey :
239280 """Test suite for check_web_api_key() unified availability check."""
240281
241- _ENV_KEYS = ("PARALLEL_API_KEY" , "FIRECRAWL_API_KEY" , "FIRECRAWL_API_URL" )
282+ _ENV_KEYS = ("PARALLEL_API_KEY" , "FIRECRAWL_API_KEY" , "FIRECRAWL_API_URL" , "TAVILY_API_KEY" )
242283
243284 def setup_method (self ):
244285 for key in self ._ENV_KEYS :
@@ -263,6 +304,11 @@ def test_firecrawl_url_only(self):
263304 from tools .web_tools import check_web_api_key
264305 assert check_web_api_key () is True
265306
307+ def test_tavily_key_only (self ):
308+ with patch .dict (os .environ , {"TAVILY_API_KEY" : "tvly-test" }):
309+ from tools .web_tools import check_web_api_key
310+ assert check_web_api_key () is True
311+
266312 def test_no_keys_returns_false (self ):
267313 from tools .web_tools import check_web_api_key
268314 assert check_web_api_key () is False
@@ -274,3 +320,12 @@ def test_both_keys_returns_true(self):
274320 }):
275321 from tools .web_tools import check_web_api_key
276322 assert check_web_api_key () is True
323+
324+ def test_all_three_keys_returns_true (self ):
325+ with patch .dict (os .environ , {
326+ "PARALLEL_API_KEY" : "test-key" ,
327+ "FIRECRAWL_API_KEY" : "fc-test" ,
328+ "TAVILY_API_KEY" : "tvly-test" ,
329+ }):
330+ from tools .web_tools import check_web_api_key
331+ assert check_web_api_key () is True
0 commit comments