Skip to content

Commit 8e26b73

Browse files
committed
Merge remote-tracking branch 'origin/main' into perf/streaming-coalesce
2 parents 0258aa5 + 7e5e69c commit 8e26b73

2 files changed

Lines changed: 115 additions & 55 deletions

File tree

src/agentex/lib/core/temporal/plugins/openai_agents/tests/conftest.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
CodeInterpreterTool,
2222
ImageGenerationTool,
2323
)
24+
from agents.computer import Computer
2425
from agents.model_settings import Reasoning # type: ignore[attr-defined]
2526
from openai.types.responses import (
2627
ResponseCompletedEvent,
@@ -47,6 +48,34 @@ def sample_task_id():
4748
return f"task_{uuid.uuid4().hex[:8]}"
4849

4950

51+
@pytest.fixture
52+
def _streaming_context_vars(sample_task_id):
53+
"""Populate the streaming ContextVars that ContextInterceptor sets from
54+
request headers in real Temporal flows. TemporalStreamingModel.get_response()
55+
validates that all three are set before doing any work, so any test that
56+
calls get_response() must request this fixture.
57+
58+
Named with a leading underscore so tests can request it purely for its
59+
setup/teardown side effects without ruff flagging it as an unused argument
60+
(ARG002). The yielded value is the task_id set on the ContextVar, available
61+
for tests that need to assert against it.
62+
"""
63+
from agentex.lib.core.temporal.plugins.openai_agents.interceptors.context_interceptor import (
64+
streaming_task_id,
65+
streaming_trace_id,
66+
streaming_parent_span_id,
67+
)
68+
task_token = streaming_task_id.set(sample_task_id)
69+
trace_token = streaming_trace_id.set("test-trace-id")
70+
span_token = streaming_parent_span_id.set("test-parent-span-id")
71+
try:
72+
yield sample_task_id
73+
finally:
74+
streaming_task_id.reset(task_token)
75+
streaming_trace_id.reset(trace_token)
76+
streaming_parent_span_id.reset(span_token)
77+
78+
5079
@pytest.fixture
5180
def mock_streaming_context():
5281
"""Mock streaming context for testing"""
@@ -115,8 +144,13 @@ def sample_file_search_tool():
115144

116145
@pytest.fixture
117146
def sample_computer_tool():
118-
"""Sample ComputerTool for testing"""
119-
computer = MagicMock()
147+
"""Sample ComputerTool for testing.
148+
149+
Production validates ``isinstance(computer, (Computer, AsyncComputer))`` for
150+
Responses API serialization, so the mock must be ``spec``-bound to
151+
``Computer`` for the isinstance check to pass.
152+
"""
153+
computer = MagicMock(spec=Computer)
120154
computer.environment = "desktop"
121155
computer.dimensions = [1920, 1080]
122156
return ComputerTool(computer=computer)

0 commit comments

Comments
 (0)