2121 CodeInterpreterTool ,
2222 ImageGenerationTool ,
2323)
24+ from agents .computer import Computer
2425from agents .model_settings import Reasoning # type: ignore[attr-defined]
2526from 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
5180def mock_streaming_context ():
5281 """Mock streaming context for testing"""
@@ -115,8 +144,13 @@ def sample_file_search_tool():
115144
116145@pytest .fixture
117146def 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