FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(tests): repair test_streaming_model so all 28 tests run and pass by smoreinis · Pull Request #334 · scaleapi/scale-agentex-python · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
CodeInterpreterTool,
ImageGenerationTool,
)
from agents.computer import Computer
from agents.model_settings import Reasoning # type: ignore[attr-defined]
from openai.types.responses import (
ResponseCompletedEvent,
Expand All @@ -47,6 +48,34 @@ def sample_task_id():
return f"task_{uuid.uuid4().hex[:8]}"


@pytest.fixture
def _streaming_context_vars(sample_task_id):
"""Populate the streaming ContextVars that ContextInterceptor sets from
request headers in real Temporal flows. TemporalStreamingModel.get_response()
validates that all three are set before doing any work, so any test that
calls get_response() must request this fixture.

Named with a leading underscore so tests can request it purely for its
setup/teardown side effects without ruff flagging it as an unused argument
(ARG002). The yielded value is the task_id set on the ContextVar, available
for tests that need to assert against it.
"""
from agentex.lib.core.temporal.plugins.openai_agents.interceptors.context_interceptor import (
streaming_task_id,
streaming_trace_id,
streaming_parent_span_id,
)
task_token = streaming_task_id.set(sample_task_id)
trace_token = streaming_trace_id.set("test-trace-id")
span_token = streaming_parent_span_id.set("test-parent-span-id")
try:
yield sample_task_id
finally:
streaming_task_id.reset(task_token)
streaming_trace_id.reset(trace_token)
streaming_parent_span_id.reset(span_token)


@pytest.fixture
def mock_streaming_context():
"""Mock streaming context for testing"""
Expand Down Expand Up @@ -115,8 +144,13 @@ def sample_file_search_tool():

@pytest.fixture
def sample_computer_tool():
"""Sample ComputerTool for testing"""
computer = MagicMock()
"""Sample ComputerTool for testing.

Production validates ``isinstance(computer, (Computer, AsyncComputer))`` for
Responses API serialization, so the mock must be ``spec``-bound to
``Computer`` for the isinstance check to pass.
"""
computer = MagicMock(spec=Computer)
computer.environment = "desktop"
computer.dimensions = [1920, 1080]
return ComputerTool(computer=computer)
Expand Down
Loading
Loading

Back | FazBrowse Home | New Git URL