test(openai-agents): Replace mocks with httpx types for streamed responses#5580
test(openai-agents): Replace mocks with httpx types for streamed responses#5580alexander-alderman-webb wants to merge 7 commits intomasterfrom
httpx types for streamed responses#5580Conversation
Codecov Results 📊✅ 11 passed | Total: 11 | Pass Rate: 100% | Execution Time: 1m 41s All tests are passing successfully. ✅ Patch coverage is 100.00%. Project has 15081 uncovered lines. Generated by Codecov Action |
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. Bug Fixes 🐛
Documentation 📚
Internal Changes 🔧Openai Agents
🤖 This preview updates automatically when you update the PR. |
| ] | ||
| ) | ||
| ), | ||
| ) |
There was a problem hiding this comment.
Async generator passed to wrong httpx.Response parameter
High Severity
The httpx.Response constructor's content parameter expects bytes, but the code passes an async generator (async_iterator(sse_chunks(...))) to it. For streaming content, the correct parameter is stream, which accepts an AsyncByteStream (async generators satisfy this via __aiter__). The openai-python test pattern that this PR claims to follow actually uses stream=MockStream(body), not content=. Passing a non-bytes object to content will cause the tests to fail — either immediately at construction time with a TypeError, or at read time when httpx tries to treat the async generator as bytes.
Additional Locations (1)
httpx types for streamed responses
| assert ai_client_span2["data"]["gen_ai.usage.total_tokens"] == 25 | ||
|
|
||
|
|
||
| def sse_chunks(events): |
There was a problem hiding this comment.
Nit: I'm assuming sse = "server-side events"? For easier readability, could we expand the name of this function?
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Autofix Details
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Unused imports added to test file
- Removed the four unused imports from the test module to eliminate dead dependencies and keep imports accurate.
Or push these changes by commenting:
@cursor push 8b145826b2
Preview (8b145826b2)
diff --git a/tests/integrations/openai_agents/test_openai_agents.py b/tests/integrations/openai_agents/test_openai_agents.py
--- a/tests/integrations/openai_agents/test_openai_agents.py
+++ b/tests/integrations/openai_agents/test_openai_agents.py
@@ -15,7 +15,7 @@
from sentry_sdk.integrations.openai_agents.utils import _set_input_data, safe_serialize
from sentry_sdk.utils import parse_version
-from openai import AsyncOpenAI, AsyncStream
+from openai import AsyncOpenAI
from agents.models.openai_responses import OpenAIResponsesModel
from unittest import mock
@@ -44,16 +44,12 @@
ResponseCompletedEvent,
Response,
ResponseUsage,
- ResponseStreamEvent,
)
from openai.types.responses.response_usage import (
InputTokensDetails,
OutputTokensDetails,
)
-from openai._response import AsyncAPIResponse
-from openai._models import FinalRequestOptions
-
test_run_config = agents.RunConfig(tracing_disabled=True)
EXAMPLE_RESPONSE = Response(There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.



Description
Replace mocks with
openaitypes to avoid test failures when library internals change.Move
async_iterator()toconftest.pyIssues
Reminders
tox -e linters.feat:,fix:,ref:,meta:)