From c2559b80fa82380d89ce46f3a90afd84c070d9ef Mon Sep 17 00:00:00 2001 From: Teknium Date: Fri, 17 Apr 2026 06:56:57 -0700 Subject: [PATCH] fix(tests): pass base_url explicitly in AIAgent constructor calls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tests that construct AIAgent(api_key=..., ...) without base_url were relying on provider-resolver fallback state from other tests in the same xdist worker. When matrix-split distributed them to different shards, the resolver found no env vars and no config and raised 'No LLM provider configured'. Fix: add base_url='https://openrouter.ai/api/v1' to every AIAgent construction that passes api_key. AIAgent.__init__ with both args set takes the direct-construction path (line 960 in run_agent.py) and skips resolver fallback entirely, making these tests self-contained. 7 files, 16 call sites updated via AST-based fixup. One call site (test_none_base_url_passed_as_none) left alone — that test's intent is to verify base_url=None behavior, so adding base_url defeats the test. Validation: - tests/run_agent/ full run: 760 passed, 0 failed (was 1 failure under the AST script's over-application, now clean) - Matrix shard 3 local run: 3083 passed, 0 failed, 1m44s --- .../run_agent/test_1630_context_overflow_loop.py | 1 + tests/run_agent/test_413_compression.py | 1 + tests/run_agent/test_fallback_model.py | 1 + .../run_agent/test_plugin_context_engine_init.py | 2 ++ tests/run_agent/test_provider_fallback.py | 1 + tests/run_agent/test_run_agent.py | 15 ++++++++++++++- tests/run_agent/test_token_persistence_non_cli.py | 1 + 7 files changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/run_agent/test_1630_context_overflow_loop.py b/tests/run_agent/test_1630_context_overflow_loop.py index c33aaa9670..f69b01241b 100644 --- a/tests/run_agent/test_1630_context_overflow_loop.py +++ b/tests/run_agent/test_1630_context_overflow_loop.py @@ -32,6 +32,7 @@ class TestGeneric400Heuristic: from run_agent import AIAgent a = AIAgent( api_key="test-key-12345", + base_url="https://openrouter.ai/api/v1", quiet_mode=True, skip_context_files=True, skip_memory=True, diff --git a/tests/run_agent/test_413_compression.py b/tests/run_agent/test_413_compression.py index 1d6f6cebb8..e8835c6412 100644 --- a/tests/run_agent/test_413_compression.py +++ b/tests/run_agent/test_413_compression.py @@ -69,6 +69,7 @@ def agent(): ): a = AIAgent( api_key="test-key-1234567890", + base_url="https://openrouter.ai/api/v1", quiet_mode=True, skip_context_files=True, skip_memory=True, diff --git a/tests/run_agent/test_fallback_model.py b/tests/run_agent/test_fallback_model.py index ac693caf01..6491bd686d 100644 --- a/tests/run_agent/test_fallback_model.py +++ b/tests/run_agent/test_fallback_model.py @@ -36,6 +36,7 @@ def _make_agent(fallback_model=None): ): agent = AIAgent( api_key="test-key", + base_url="https://openrouter.ai/api/v1", quiet_mode=True, skip_context_files=True, skip_memory=True, diff --git a/tests/run_agent/test_plugin_context_engine_init.py b/tests/run_agent/test_plugin_context_engine_init.py index 7583d9e753..60e8988908 100644 --- a/tests/run_agent/test_plugin_context_engine_init.py +++ b/tests/run_agent/test_plugin_context_engine_init.py @@ -45,6 +45,7 @@ def test_plugin_engine_gets_context_length_on_init(): agent = AIAgent( api_key="test-key-1234567890", + base_url="https://openrouter.ai/api/v1", quiet_mode=True, skip_context_files=True, skip_memory=True, @@ -75,6 +76,7 @@ def test_plugin_engine_update_model_args(): agent = AIAgent( model="openrouter/auto", api_key="test-key-1234567890", + base_url="https://openrouter.ai/api/v1", quiet_mode=True, skip_context_files=True, skip_memory=True, diff --git a/tests/run_agent/test_provider_fallback.py b/tests/run_agent/test_provider_fallback.py index 2bb2109552..e441bfd33b 100644 --- a/tests/run_agent/test_provider_fallback.py +++ b/tests/run_agent/test_provider_fallback.py @@ -19,6 +19,7 @@ def _make_agent(fallback_model=None): ): agent = AIAgent( api_key="test-key", + base_url="https://openrouter.ai/api/v1", quiet_mode=True, skip_context_files=True, skip_memory=True, diff --git a/tests/run_agent/test_run_agent.py b/tests/run_agent/test_run_agent.py index 46eec2cf71..86f95580f0 100644 --- a/tests/run_agent/test_run_agent.py +++ b/tests/run_agent/test_run_agent.py @@ -55,6 +55,7 @@ def agent(): ): a = AIAgent( api_key="test-key-1234567890", + base_url="https://openrouter.ai/api/v1", quiet_mode=True, skip_context_files=True, skip_memory=True, @@ -76,6 +77,7 @@ def agent_with_memory_tool(): ): a = AIAgent( api_key="test-k...7890", + base_url="https://openrouter.ai/api/v1", quiet_mode=True, skip_context_files=True, skip_memory=True, @@ -112,12 +114,14 @@ def test_aiagent_reuses_existing_errors_log_handler(): ): AIAgent( api_key="test-k...7890", + base_url="https://openrouter.ai/api/v1", quiet_mode=True, skip_context_files=True, skip_memory=True, ) AIAgent( api_key="test-k...7890", + base_url="https://openrouter.ai/api/v1", quiet_mode=True, skip_context_files=True, skip_memory=True, @@ -491,6 +495,7 @@ class TestInit: ): a = AIAgent( api_key="test-key-1234567890", + base_url="https://openrouter.ai/api/v1", model="openai/gpt-4o", quiet_mode=True, skip_context_files=True, @@ -542,6 +547,7 @@ class TestInit: ): a = AIAgent( api_key="test-key-1234567890", + base_url="https://openrouter.ai/api/v1", quiet_mode=True, skip_context_files=True, skip_memory=True, @@ -557,6 +563,7 @@ class TestInit: ): a = AIAgent( api_key="test-key-1234567890", + base_url="https://openrouter.ai/api/v1", quiet_mode=True, skip_context_files=True, skip_memory=True, @@ -694,6 +701,7 @@ class TestBuildSystemPrompt: ): agent = AIAgent( api_key="test-k...7890", + base_url="https://openrouter.ai/api/v1", quiet_mode=True, skip_context_files=True, skip_memory=True, @@ -726,6 +734,7 @@ class TestToolUseEnforcementConfig: a = AIAgent( model=model, api_key="test-key-1234567890", + base_url="https://openrouter.ai/api/v1", quiet_mode=True, skip_context_files=True, skip_memory=True, @@ -822,6 +831,7 @@ class TestToolUseEnforcementConfig: ): a = AIAgent( api_key="test-key-1234567890", + base_url="https://openrouter.ai/api/v1", quiet_mode=True, skip_context_files=True, skip_memory=True, @@ -3433,7 +3443,7 @@ class TestAnthropicBaseUrlPassthrough: ): mock_build.return_value = MagicMock() a = AIAgent( - api_key="sk-ant-api03-test1234567890", + api_key="sk-ant...7890", api_mode="anthropic_messages", quiet_mode=True, skip_context_files=True, @@ -3457,6 +3467,7 @@ class TestAnthropicCredentialRefresh: mock_build.side_effect = [old_client, new_client] agent = AIAgent( api_key="sk-ant-oat01-stale-token", + base_url="https://openrouter.ai/api/v1", api_mode="anthropic_messages", quiet_mode=True, skip_context_files=True, @@ -3487,6 +3498,7 @@ class TestAnthropicCredentialRefresh: ): agent = AIAgent( api_key="sk-ant-oat01-same-token", + base_url="https://openrouter.ai/api/v1", api_mode="anthropic_messages", quiet_mode=True, skip_context_files=True, @@ -3514,6 +3526,7 @@ class TestAnthropicCredentialRefresh: ): agent = AIAgent( api_key="sk-ant-oat01-current-token", + base_url="https://openrouter.ai/api/v1", api_mode="anthropic_messages", quiet_mode=True, skip_context_files=True, diff --git a/tests/run_agent/test_token_persistence_non_cli.py b/tests/run_agent/test_token_persistence_non_cli.py index d25cf07ab8..044d8abb3b 100644 --- a/tests/run_agent/test_token_persistence_non_cli.py +++ b/tests/run_agent/test_token_persistence_non_cli.py @@ -22,6 +22,7 @@ def _make_agent(session_db, *, platform: str): ): agent = AIAgent( api_key="test-key", + base_url="https://openrouter.ai/api/v1", quiet_mode=True, skip_context_files=True, skip_memory=True,