From 12ed44fb837b3755d5fb3987b4257f5a42f1a60c Mon Sep 17 00:00:00 2001 From: Anas Khan <83116240+anxkhn@users.noreply.github.com> Date: Sat, 4 Jul 2026 14:06:20 +0530 Subject: [PATCH] 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. --- .../flows/llm_flows/test_plugin_model_callbacks.py | 12 +++++++----- .../flows/llm_flows/test_plugin_tool_callbacks.py | 10 ++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/unittests/flows/llm_flows/test_plugin_model_callbacks.py b/tests/unittests/flows/llm_flows/test_plugin_model_callbacks.py index f2f7e35b054..43474ad3531 100644 --- a/tests/unittests/flows/llm_flows/test_plugin_model_callbacks.py +++ b/tests/unittests/flows/llm_flows/test_plugin_model_callbacks.py @@ -171,7 +171,7 @@ def test_on_model_error_callback_with_plugin(mock_plugin): def test_on_model_error_callback_fallback_to_runner(mock_plugin): - """Tests that the model error is not handled and falls back to raise from runner.""" + """Tests that the model error is not handled and surfaces from the runner.""" mock_model = testing_utils.MockModel.create(error=mock_error, responses=[]) mock_plugin.enable_on_model_error_callback = False agent = Agent( @@ -179,10 +179,12 @@ def test_on_model_error_callback_fallback_to_runner(mock_plugin): model=mock_model, ) - try: - testing_utils.InMemoryRunner(agent, plugins=[mock_plugin]) - except Exception as e: - assert e == mock_error + runner = testing_utils.InMemoryRunner(agent, plugins=[mock_plugin]) + + events = runner.run('test') + error_events = [e for e in events if e.error_code] + assert len(error_events) == 1 + assert error_events[0].error_code == 'ClientError' if __name__ == '__main__': diff --git a/tests/unittests/flows/llm_flows/test_plugin_tool_callbacks.py b/tests/unittests/flows/llm_flows/test_plugin_tool_callbacks.py index 3c39e2844b8..ff18c38abaa 100644 --- a/tests/unittests/flows/llm_flows/test_plugin_tool_callbacks.py +++ b/tests/unittests/flows/llm_flows/test_plugin_tool_callbacks.py @@ -180,10 +180,9 @@ async def test_async_on_tool_error_fallback_to_runner( ): mock_plugin.enable_on_tool_error_callback = False - try: + with pytest.raises(ClientError) as exc_info: await invoke_tool_with_plugin(mock_error_tool, mock_plugin) - except Exception as e: - assert e == mock_error + assert exc_info.value == mock_error async def invoke_tool_with_plugin_live( @@ -258,10 +257,9 @@ async def test_live_on_tool_error_fallback_to_runner( ): mock_plugin.enable_on_tool_error_callback = False - try: + with pytest.raises(ClientError) as exc_info: await invoke_tool_with_plugin_live(mock_error_tool, mock_plugin) - except Exception as e: - assert e == mock_error + assert exc_info.value == mock_error @pytest.mark.asyncio