Skip to content

Commit 361bb9d

Browse files
committed
backport: coverage — recognize 'lax no cover'; pragma harness scaffolding + 3.11 dead-zone lines
- pyproject: add 'pragma: lax no cover' to exclude_lines (matches main) - _connect.py: Protocol stub body, verifier-gate no-branch, SSE return-Response no-cover - _harness.py: resource_server_url gate no-branch - test_initialize/test_wire: tg.cancel_scope.cancel() lax-no-cover (cpython#106749, 3.11 only) - test_sse: nested-async-with no-branch (3.11 arc) All harness scaffolding; no port bugs. Local ./scripts/test → 100.00%.
1 parent 1f981e5 commit 361bb9d

6 files changed

Lines changed: 10 additions & 8 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ ignore_errors = true
213213
precision = 2
214214
exclude_lines = [
215215
"pragma: no cover",
216+
"pragma: lax no cover",
216217
"if TYPE_CHECKING:",
217218
"@overload",
218219
"raise NotImplementedError",

tests/interaction/_connect.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def __call__(
103103
logging_callback: LoggingFnT | None = None,
104104
message_handler: MessageHandlerFnT | None = None,
105105
client_info: Implementation | None = None,
106-
) -> AbstractAsyncContextManager[ClientSession]: ...
106+
) -> AbstractAsyncContextManager[ClientSession]: ... # pragma: no cover
107107

108108

109109
@asynccontextmanager
@@ -188,7 +188,7 @@ def build_streamable_http_app(
188188

189189
if auth is not None:
190190
required_scopes = auth.required_scopes or []
191-
if verifier is not None:
191+
if verifier is not None: # pragma: no branch — every auth-bearing caller supplies a provider/verifier
192192
middleware = [
193193
Middleware(AuthenticationMiddleware, backend=BearerAuthBackend(verifier)),
194194
Middleware(AuthContextMiddleware),
@@ -437,7 +437,8 @@ def build_sse_app(server: Server[Any] | FastMCP) -> tuple[Starlette, SseServerTr
437437
async def handle_sse(request: Request) -> Response:
438438
async with sse.connect_sse(request.scope, request.receive, request._send) as (read, write): # type: ignore[reportPrivateUsage]
439439
await lowlevel.run(read, write, lowlevel.create_initialization_options())
440-
return Response()
440+
# under StreamingASGITransport the request is cancelled on close, so run() never returns
441+
return Response() # pragma: no cover
441442

442443
app = Starlette(
443444
routes=[

tests/interaction/auth/_harness.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ async def connect_with_oauth(
477477
else:
478478
routes.append(Route("/mcp", endpoint=asgi))
479479

480-
if settings.resource_server_url:
480+
if settings.resource_server_url: # pragma: no branch — auth_settings() always sets this
481481
routes.extend(
482482
create_protected_resource_routes(
483483
resource_url=settings.resource_server_url,

tests/interaction/lowlevel/test_initialize.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ async def _initialize(server: Server[Any]) -> InitializeResult:
7070
async with ClientSession(client_read, client_write) as session:
7171
with anyio.fail_after(5):
7272
initialize_result = await session.initialize()
73-
tg.cancel_scope.cancel()
73+
tg.cancel_scope.cancel() # pragma: lax no cover — python/cpython#106749 (3.11 tracer dead-zone)
7474
return initialize_result
7575

7676

@@ -88,7 +88,7 @@ async def _bare_session(server: Server[Any]) -> AsyncIterator[ClientSession]:
8888
tg.start_soon(lambda: server.run(server_read, server_write, server.create_initialization_options()))
8989
async with ClientSession(client_read, client_write) as session:
9090
yield session
91-
tg.cancel_scope.cancel()
91+
tg.cancel_scope.cancel() # pragma: lax no cover — python/cpython#106749 (3.11 tracer dead-zone)
9292

9393

9494
@requirement("lifecycle:initialize:basic")

tests/interaction/lowlevel/test_wire.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ async def _record(
8383
await client.initialize()
8484
yield client, recording
8585
finally:
86-
tg.cancel_scope.cancel()
86+
tg.cancel_scope.cancel() # pragma: lax no cover — python/cpython#106749 (3.11 tracer dead-zone)
8787

8888

8989
@requirement("protocol:request-id:unique")

tests/interaction/transports/test_sse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def httpx_client_factory(
5454
async with sse_client(
5555
f"{BASE_URL}/sse", httpx_client_factory=httpx_client_factory, on_session_created=captured_session_id.append
5656
) as (read, write):
57-
async with ClientSession(read, write) as client:
57+
async with ClientSession(read, write) as client: # pragma: no branch
5858
await client.initialize()
5959
assert len(captured_session_id) == 1
6060
assert UUID(hex=captured_session_id[0]) in sse._read_stream_writers

0 commit comments

Comments
 (0)