test(mcp): pin PROXY_BASE_URL off in MCP OAuth tests

get_request_base_url resolves PROXY_BASE_URL ahead of request.base_url, and
import litellm loads a .env from any parent directory of the checkout, so a
developer with that var set (git worktrees under <repo>/.claude/worktrees/
inherit the main checkout's .env this way) had the mocked request origins
silently ignored and these tests failed on unmodified code.
This commit is contained in:
Yuneng Jiang 2026-07-26 00:19:18 -07:00
parent 24123269cc
commit 87679b2e5b
No known key found for this signature in database
2 changed files with 20 additions and 0 deletions

View file

@ -20,3 +20,15 @@ def _hermetic_server_root_path():
finally:
if saved is not None:
os.environ["SERVER_ROOT_PATH"] = saved
@pytest.fixture(autouse=True)
def _hermetic_proxy_base_url(monkeypatch):
"""Isolate MCP discovery tests from a developer's ``PROXY_BASE_URL``.
``get_request_base_url`` resolves that env var ahead of the request's own base URL, and
``import litellm`` loads a ``.env`` from any parent directory of the checkout, so a set value
silently overrides the origins these tests drive through the request. Clearing it here pins
the request-derived origin; a test that exercises the env override sets the value itself.
"""
monkeypatch.delenv("PROXY_BASE_URL", raising=False)

View file

@ -1556,6 +1556,14 @@ class TestTeamScopedMCPServerAccess:
class TestTemporaryMCPSessionEndpoints:
@pytest.fixture(autouse=True)
def unset_proxy_base_url(self, monkeypatch):
"""``get_request_base_url`` resolves ``PROXY_BASE_URL`` ahead of ``request.base_url``, so a
developer with that env var set (a ``.env`` in any parent directory of the checkout is
enough, since ``import litellm`` runs dotenv) would otherwise silently bypass the mocked
``request.base_url`` these tests assert on."""
monkeypatch.delenv("PROXY_BASE_URL", raising=False)
def test_inherit_credentials_from_existing_server(self):
payload = NewMCPServerRequest(
server_id="server-123",