Commit 7e5e69c
authored
fix(tests): repair test_streaming_model so all 28 tests run and pass (#334)
Four pre-existing bugs left this entire test file unrunnable on main (4
failures + 24 errors); fixing them here so the suite actually exercises
TemporalStreamingModel and protects against regressions.
Bug 1 (24 errors): `conftest.py` defines fixture `mock_adk_streaming` (no
underscore) but every test in TestStreamingModelSettings and
TestStreamingModelTools requested it as `_mock_adk_streaming`, so pytest
failed to resolve the fixture before the body ever ran. The fixture is
``autouse=True`` and the param value was never used in any test body, so
the parameter was vestigial — replaced with `_streaming_context_vars`,
which provides the ContextVar setup these tests now actually need.
Bug 2 (4 failures): `TemporalStreamingModel.get_response()` reads
`task_id`, `trace_id`, and `parent_span_id` from ContextVars populated
by `ContextInterceptor` from request headers in real Temporal flows.
Tests had been passing `task_id=...` as a kwarg, which is silently
swallowed by `**kwargs` and ignored, so all three ContextVars stayed at
their defaults and the validation at the top of `get_response` raised
before any work happened. New `_streaming_context_vars` fixture in
conftest sets all three vars (and resets them on teardown), simulating
what `ContextInterceptor` does in production.
Bug 3 (test_computer_tool): A recent commit narrowed `ComputerTool`
serialization to require an actual `Computer`/`AsyncComputer` instance,
but `sample_computer_tool` still built a bare `MagicMock`. Switched to
`MagicMock(spec=Computer)` so the production isinstance check passes.
Bug 4 (3 streaming-context tests): The 3 tests in TestStreamingModelBasics
that assert on `streaming_task_message_context` calls built event
sequences with raw `MagicMock(type="...")`. Production dispatches via
`isinstance(event, ResponseOutputItemAddedEvent)` etc., which `MagicMock`
without `spec` never satisfies, so dispatch was silently skipped and
the assertions failed. Switched to `MagicMock(spec=...)` for each event
type — passes isinstance without triggering pydantic validation on the
event's required fields. Also fixed `test_task_id_threading` which had
been asserting against a hardcoded `task_id="test_task_12345"` that was
never actually threaded anywhere (the kwarg was ignored, just like in
Bug 2); it now asserts against the value yielded by the fixture, which
is the value production reads from the ContextVar.
After all four fixes: 28/28 pass, ruff clean, pyright clean.1 parent e1effb5 commit 7e5e69c
2 files changed
Lines changed: 115 additions & 55 deletions
File tree
- src/agentex/lib/core/temporal/plugins/openai_agents/tests
Lines changed: 36 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
50 | 79 | | |
51 | 80 | | |
52 | 81 | | |
| |||
115 | 144 | | |
116 | 145 | | |
117 | 146 | | |
118 | | - | |
119 | | - | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
120 | 154 | | |
121 | 155 | | |
122 | 156 | | |
| |||
0 commit comments