claude-code-sdk-python/tests
Lina Tawfik 404c50bce0
Fix FastAPI SSE streaming compatibility (fixes #4)
Remove anyio.create_task_group() from receive_messages() to fix the
RuntimeError "Attempted to exit cancel scope in a different task than
it was entered in" when using the SDK with FastAPI's SSE streaming.

The issue occurred because FastAPI can move async generators between
different asyncio tasks during the streaming lifecycle, which conflicts
with anyio's cancel scope tracking.

Changes:
- Remove task group usage from receive_messages()
- Read stderr sequentially after stdout completes
- Add test to ensure no task groups are used
- Fix existing test expectation for buffer overflow

This is a minimal fix that maintains compatibility while solving the
core issue. The trade-off is that stderr is read after stdout instead
of concurrently, but this is unlikely to cause issues in practice.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-01 00:04:50 -07:00
..
conftest.py Initial Python SDK import 2025-06-12 00:16:19 -07:00
test_client.py Fix tests to match updated ResultMessage type 2025-06-17 16:51:28 -07:00
test_errors.py Initial Python SDK import 2025-06-12 00:16:19 -07:00
test_fastapi_streaming_compatibility.py Fix FastAPI SSE streaming compatibility (fixes #4) 2025-07-01 00:04:50 -07:00
test_integration.py Fix tests to match updated ResultMessage type 2025-06-17 16:51:28 -07:00
test_subprocess_buffering.py Fix FastAPI SSE streaming compatibility (fixes #4) 2025-07-01 00:04:50 -07:00
test_transport.py Fix code formatting for CI 2025-06-12 00:20:28 -07:00
test_types.py Fix tests to match updated ResultMessage type 2025-06-17 16:51:28 -07:00