11"""Tests for StreamableHTTPSessionManager."""
22
33import json
4+ import logging
45from typing import Any
56from unittest .mock import AsyncMock , patch
67
@@ -269,7 +270,7 @@ async def mock_receive():
269270
270271
271272@pytest .mark .anyio
272- async def test_unknown_session_id_returns_404 ():
273+ async def test_unknown_session_id_returns_404 (caplog : pytest . LogCaptureFixture ):
273274 """Test that requests with unknown session IDs return HTTP 404 per MCP spec."""
274275 app = Server ("test-unknown-session" )
275276 manager = StreamableHTTPSessionManager (app = app )
@@ -299,7 +300,8 @@ async def mock_send(message: Message):
299300 async def mock_receive ():
300301 return {"type" : "http.request" , "body" : b"{}" , "more_body" : False } # pragma: no cover
301302
302- await manager .handle_request (scope , mock_receive , mock_send )
303+ with caplog .at_level (logging .INFO ):
304+ await manager .handle_request (scope , mock_receive , mock_send )
303305
304306 # Find the response start message
305307 response_start = next (
@@ -315,6 +317,7 @@ async def mock_receive():
315317 assert error_data ["id" ] is None
316318 assert error_data ["error" ]["code" ] == INVALID_REQUEST
317319 assert error_data ["error" ]["message" ] == "Session not found"
320+ assert "Rejected request with unknown or expired session ID: non-existent-session-id" in caplog .text
318321
319322
320323@pytest .mark .anyio
0 commit comments