Skip to content

Commit 049b403

Browse files
Add coverage pragmas for SSE polling reconnection code
The SSE polling reconnection code paths run in a subprocess during testing, making them difficult to cover with the main test process's coverage instrumentation. Add pragma comments to exclude these from coverage requirements: - Client _attempt_sse_reconnection method and call site - Server StreamableHTTPSessionManager.close_sse_stream method - Test callback branch for empty data handling Github-Issue:#1654
1 parent 9390ef9 commit 049b403

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

src/mcp/client/streamable_http.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,12 +415,12 @@ async def _handle_sse_response(
415415
await ctx.read_stream_writer.send(e)
416416

417417
# Auto-reconnect if stream ended without completion and we have priming event
418-
if not is_complete and has_priming_event and last_event_id:
418+
if not is_complete and has_priming_event and last_event_id: # pragma: no cover
419419
await self._attempt_sse_reconnection(ctx, last_event_id, attempt)
420420

421421
return has_priming_event, last_event_id
422422

423-
async def _attempt_sse_reconnection(
423+
async def _attempt_sse_reconnection( # pragma: no cover
424424
self,
425425
ctx: RequestContext,
426426
last_event_id: str,

src/mcp/server/streamable_http_manager.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,9 @@ async def run_server(*, task_status: TaskStatus[None] = anyio.TASK_STATUS_IGNORE
281281
)
282282
await response(scope, receive, send)
283283

284-
async def close_sse_stream(self, session_id: str, request_id: str | int) -> bool:
284+
async def close_sse_stream( # pragma: no cover
285+
self, session_id: str, request_id: str | int
286+
) -> bool:
285287
"""Close an SSE stream for a specific request, triggering client reconnection.
286288
287289
Use this to implement polling behavior during long-running operations.

tests/shared/test_streamable_http.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1907,9 +1907,8 @@ async def test_streamablehttp_client_auto_reconnection(event_server: tuple[Simpl
19071907

19081908
async def logging_callback(params: types.LoggingMessageNotificationParams) -> None:
19091909
"""Called when a log message notification is received from the server."""
1910-
data = params.data
1911-
if data:
1912-
notifications_received.append(str(data))
1910+
if params.data: # pragma: no branch
1911+
notifications_received.append(str(params.data))
19131912

19141913
# Configure client with reconnection options (fast delays for testing)
19151914
reconnection_options = StreamableHTTPReconnectionOptions(

0 commit comments

Comments
 (0)