Skip to content

Commit a0e96ea

Browse files
author
skyvanguard
committed
fix: use lax no cover for non-deterministic coverage paths
These validation functions and exception handlers have coverage that varies between parallel test runs. Using 'lax no cover' correctly excludes them from coverage measurement without triggering strict-no-cover violations when they happen to be covered. Github-Issue:#1648
1 parent f176d67 commit a0e96ea

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/mcp/server/streamable_http.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -806,14 +806,14 @@ async def _handle_unsupported_request(self, request: Request, send: Send) -> Non
806806
)
807807
await response(request.scope, request.receive, send)
808808

809-
async def _validate_request_headers(self, request: Request, send: Send) -> bool:
809+
async def _validate_request_headers(self, request: Request, send: Send) -> bool: # pragma: lax no cover
810810
if not await self._validate_session(request, send):
811811
return False
812812
if not await self._validate_protocol_version(request, send):
813813
return False
814814
return True
815815

816-
async def _validate_session(self, request: Request, send: Send) -> bool:
816+
async def _validate_session(self, request: Request, send: Send) -> bool: # pragma: lax no cover
817817
"""Validate the session ID in the request."""
818818
if not self.mcp_session_id:
819819
# If we're not using session IDs, return True
@@ -842,7 +842,7 @@ async def _validate_session(self, request: Request, send: Send) -> bool:
842842

843843
return True
844844

845-
async def _validate_protocol_version(self, request: Request, send: Send) -> bool:
845+
async def _validate_protocol_version(self, request: Request, send: Send) -> bool: # pragma: lax no cover
846846
"""Validate the protocol version header in the request."""
847847
# Get the protocol version from the request headers
848848
protocol_version = request.headers.get(MCP_PROTOCOL_VERSION_HEADER)

src/mcp/server/streamable_http_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ async def run_stateless_server(*, task_status: TaskStatus[None] = anyio.TASK_STA
182182
self.app.create_initialization_options(),
183183
stateless=True,
184184
)
185-
except Exception:
185+
except Exception: # pragma: lax no cover
186186
logger.exception("Stateless session crashed")
187187

188188
# Assert task group is not None for type checking

0 commit comments

Comments
 (0)