From 6523dce30cc5497771ee32b1eca1fc49d144916c Mon Sep 17 00:00:00 2001 From: majdyz Date: Fri, 10 Apr 2026 23:53:52 +0700 Subject: [PATCH] fix(backend/orchestrator): use AsyncMock for charge_node_usage in test charge_node_usage is async and is directly awaited; using MagicMock caused a TypeError that was silently swallowed by the outer except Exception block, meaning the billing assertion passed for the wrong reason (mock called but await failed, so no billing actually ran). --- .../backend/backend/blocks/test/test_orchestrator.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/autogpt_platform/backend/backend/blocks/test/test_orchestrator.py b/autogpt_platform/backend/backend/blocks/test/test_orchestrator.py index c92ba3c702..2eb27012dc 100644 --- a/autogpt_platform/backend/backend/blocks/test/test_orchestrator.py +++ b/autogpt_platform/backend/backend/blocks/test/test_orchestrator.py @@ -923,10 +923,10 @@ async def test_orchestrator_agent_mode(): return_value=mock_node_stats ) # Mock charge_node_usage (called after successful tool execution). - # Returns (cost, remaining_balance). Synchronous because it's called - # via asyncio.to_thread. Use a non-zero cost so the merge_stats - # branch is actually exercised, and assert it's called below. - mock_execution_processor.charge_node_usage = MagicMock(return_value=(10, 990)) + # Returns (cost, remaining_balance). Must be AsyncMock because it is + # an async method and is directly awaited in _execute_single_tool_with_manager. + # Use a non-zero cost so the merge_stats branch is exercised. + mock_execution_processor.charge_node_usage = AsyncMock(return_value=(10, 990)) # Mock the get_execution_outputs_by_node_exec_id method mock_db_client.get_execution_outputs_by_node_exec_id.return_value = {