Skip to content

Commit 12ed44f

Browse files
committed
test(plugins): assert error propagation in on_*_error fallback tests
The three on_*_error "fallback to runner" tests placed their only assertion inside an `except` block with no guard, so they passed even when no error was raised, the exact regression they exist to catch. The model-callback variant only constructed InMemoryRunner (which never runs the agent), so it could never raise and was fully vacuous. Rewrite them to fail on a no-raise regression, matching existing repo conventions: - test_async/live_on_tool_error_fallback_to_runner: wrap the call in `pytest.raises(ClientError)` and assert the raised error. - test_on_model_error_callback_fallback_to_runner: run the agent and assert the unhandled model error surfaces as a terminal error event (error_code == 'ClientError'), mirroring the error-event assertions in test_base_llm_flow.py. No production code changes.
1 parent e6df097 commit 12ed44f

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

tests/unittests/flows/llm_flows/test_plugin_model_callbacks.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,18 +171,20 @@ def test_on_model_error_callback_with_plugin(mock_plugin):
171171

172172

173173
def test_on_model_error_callback_fallback_to_runner(mock_plugin):
174-
"""Tests that the model error is not handled and falls back to raise from runner."""
174+
"""Tests that the model error is not handled and surfaces from the runner."""
175175
mock_model = testing_utils.MockModel.create(error=mock_error, responses=[])
176176
mock_plugin.enable_on_model_error_callback = False
177177
agent = Agent(
178178
name='root_agent',
179179
model=mock_model,
180180
)
181181

182-
try:
183-
testing_utils.InMemoryRunner(agent, plugins=[mock_plugin])
184-
except Exception as e:
185-
assert e == mock_error
182+
runner = testing_utils.InMemoryRunner(agent, plugins=[mock_plugin])
183+
184+
events = runner.run('test')
185+
error_events = [e for e in events if e.error_code]
186+
assert len(error_events) == 1
187+
assert error_events[0].error_code == 'ClientError'
186188

187189

188190
if __name__ == '__main__':

tests/unittests/flows/llm_flows/test_plugin_tool_callbacks.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,9 @@ async def test_async_on_tool_error_fallback_to_runner(
180180
):
181181
mock_plugin.enable_on_tool_error_callback = False
182182

183-
try:
183+
with pytest.raises(ClientError) as exc_info:
184184
await invoke_tool_with_plugin(mock_error_tool, mock_plugin)
185-
except Exception as e:
186-
assert e == mock_error
185+
assert exc_info.value == mock_error
187186

188187

189188
async def invoke_tool_with_plugin_live(
@@ -258,10 +257,9 @@ async def test_live_on_tool_error_fallback_to_runner(
258257
):
259258
mock_plugin.enable_on_tool_error_callback = False
260259

261-
try:
260+
with pytest.raises(ClientError) as exc_info:
262261
await invoke_tool_with_plugin_live(mock_error_tool, mock_plugin)
263-
except Exception as e:
264-
assert e == mock_error
262+
assert exc_info.value == mock_error
265263

266264

267265
@pytest.mark.asyncio

0 commit comments

Comments
 (0)