diff --git a/tests/integration/_support/mcp.py b/tests/integration/_support/mcp.py index e6ae70f27e9..2d88a77a037 100644 --- a/tests/integration/_support/mcp.py +++ b/tests/integration/_support/mcp.py @@ -58,7 +58,16 @@ class McpPeer: def registration(self) -> dict[str, object]: if self.transport == "stdio": - return {"transport": "stdio", "command": self.command, "args": list(self.args)} + return { + "transport": "stdio", + "command": self.command, + "args": list(self.args), + **( + {"env": {"COVERAGE_PROCESS_CONFIG": os.environ["COVERAGE_PROCESS_CONFIG"]}} + if os.environ.get("COVERAGE_PROCESS_CONFIG") + else {} + ), + } if self.spec_path is not None: return {"transport": "http", "url": self.url, "spec_path": str(self.spec_path)} return {"transport": self.transport, "url": self.url} diff --git a/tests/unit/integration_support/test_conformance.py b/tests/unit/integration_support/test_conformance.py index 9471adee8dd..aaa8bfa07b1 100644 --- a/tests/unit/integration_support/test_conformance.py +++ b/tests/unit/integration_support/test_conformance.py @@ -52,6 +52,26 @@ async def test_negotiation_records_preserve_the_peer_call_contract(monkeypatch: assert records[0]["negotiation"] == {"requested": "2025-03-26", "returned": "2025-03-26"} +@pytest.mark.parametrize("covered", (False, True)) +def test_stdio_registration_forwards_only_explicit_coverage( + tmp_path: Path, monkeypatch: pytest.MonkeyPatch, covered: bool +) -> None: + monkeypatch.syspath_prepend(str(Path(__file__).resolve().parents[2])) + from integration._support.mcp import stdio_peer + + monkeypatch.delenv("COVERAGE_PROCESS_CONFIG", raising=False) + monkeypatch.setenv("OPENAI_API_KEY", "must-not-reach-peer") + if covered: + monkeypatch.setenv("COVERAGE_PROCESS_CONFIG", "coverage-config") + with stdio_peer(tmp_path) as peer: + assert peer.registration() == { + "transport": "stdio", + "command": peer.command, + "args": list(peer.args), + **({"env": {"COVERAGE_PROCESS_CONFIG": "coverage-config"}} if covered else {}), + } + + @pytest.mark.parametrize("file_backed", (False, True)) def test_peer_drain_preserves_received_requests( tmp_path: Path, file_backed: bool, monkeypatch: pytest.MonkeyPatch