Skip to content

Commit dbddc8b

Browse files
test(streamable-http): make resumption guard test pyright-safe and deterministic
1 parent e814535 commit dbddc8b

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

tests/shared/test_streamable_http.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,27 +1809,26 @@ def test_streamable_http_transport_includes_seeded_session_id_header():
18091809
assert headers["mcp-session-id"] == "resume-session-id"
18101810

18111811

1812-
@pytest.mark.anyio
1813-
async def test_streamable_http_client_resumption_starts_get_stream_once(monkeypatch: pytest.MonkeyPatch):
1812+
def test_streamable_http_client_resumption_starts_get_stream_once(monkeypatch: pytest.MonkeyPatch):
18141813
start_count = 0
18151814

18161815
async def fake_handle_get_stream(
1817-
self: StreamableHTTPTransport,
1818-
client: httpx.AsyncClient,
1819-
read_stream_writer: anyio.abc.ObjectSendStream[SessionMessage | Exception],
1816+
self: StreamableHTTPTransport, # noqa: ARG001
1817+
client: httpx.AsyncClient, # noqa: ARG001
1818+
read_stream_writer: Any, # noqa: ARG001
18201819
) -> None:
18211820
nonlocal start_count
18221821
start_count += 1
18231822
await anyio.sleep(0)
18241823

18251824
async def fake_post_writer(
1826-
self: StreamableHTTPTransport,
1827-
client: httpx.AsyncClient,
1828-
write_stream_reader: anyio.abc.ObjectReceiveStream[SessionMessage],
1829-
read_stream_writer: anyio.abc.ObjectSendStream[SessionMessage | Exception],
1830-
write_stream: anyio.abc.ObjectSendStream[SessionMessage],
1831-
start_get_stream: Any,
1832-
tg: anyio.abc.TaskGroup,
1825+
self: StreamableHTTPTransport, # noqa: ARG001
1826+
client: httpx.AsyncClient, # noqa: ARG001
1827+
write_stream_reader: Any, # noqa: ARG001
1828+
read_stream_writer: Any, # noqa: ARG001
1829+
write_stream: Any, # noqa: ARG001
1830+
start_get_stream: Any, # noqa: ARG001
1831+
tg: Any, # noqa: ARG001
18331832
) -> None:
18341833
# Call twice; the second call should hit the early return guard.
18351834
start_get_stream()
@@ -1839,12 +1838,15 @@ async def fake_post_writer(
18391838
monkeypatch.setattr(StreamableHTTPTransport, "handle_get_stream", fake_handle_get_stream)
18401839
monkeypatch.setattr(StreamableHTTPTransport, "post_writer", fake_post_writer)
18411840

1842-
async with streamable_http_client(
1843-
"http://localhost:8000/mcp",
1844-
session_id="resume-session-id",
1845-
terminate_on_close=False,
1846-
):
1847-
await anyio.sleep(0)
1841+
async def exercise_client() -> None:
1842+
async with streamable_http_client(
1843+
"http://localhost:8000/mcp",
1844+
session_id="resume-session-id",
1845+
terminate_on_close=False,
1846+
):
1847+
await anyio.sleep(0)
1848+
1849+
anyio.run(exercise_client)
18481850

18491851
assert start_count == 1
18501852

0 commit comments

Comments
 (0)