@@ -671,14 +671,15 @@ def test_schedule_update_loop_running_uses_run_coroutine_threadsafe(
671671 loop .close ()
672672
673673
674- @pytest .mark .asyncio
675- async def test_terminal_tool_lifecycle_stream_then_action_then_observation ():
674+ def test_terminal_tool_lifecycle_stream_then_action_then_observation (
675+ mock_connection , event_loop
676+ ):
676677 """
677678 Lifecycle:
678679 1) on_token streams partial TerminalAction -> emits
679680 ToolCallStart(in_progress) then ToolCallProgress(in_progress)
680681 2) unstreamed ActionEvent arrives (same tool_call_id) -> may emit
681- another ToolCallStart (in_progress)
682+ ToolCallProgress (in_progress) to update title with summary
682683 3) unstreamed ObservationEvent arrives (same tool_call_id) -> emits
683684 ToolCallProgress(completed)
684685
@@ -687,12 +688,10 @@ async def test_terminal_tool_lifecycle_stream_then_action_then_observation():
687688 tool_call (in_progress) -> tool_call_update (in_progress) ->
688689 tool_call_update (completed)
689690 """
690- conn = AsyncMock ()
691- loop = asyncio .get_running_loop ()
692691 subscriber = TokenBasedEventSubscriber (
693692 session_id = "test-session" ,
694- conn = conn ,
695- loop = loop ,
693+ conn = mock_connection ,
694+ loop = event_loop ,
696695 )
697696
698697 tool_call_id = "call-123"
@@ -714,9 +713,10 @@ async def test_terminal_tool_lifecycle_stream_then_action_then_observation():
714713 arguments = 'and":"ls"}' ,
715714 )
716715
717- # with patch.object(loop, "is_running", return_value=False):
718- subscriber .on_token (_chunk (tool_calls = [tc1 ]))
719- subscriber .on_token (_chunk (tool_calls = [tc2 ]))
716+ # Patch is_running to False so updates are executed synchronously
717+ with patch .object (event_loop , "is_running" , return_value = False ):
718+ subscriber .on_token (_chunk (tool_calls = [tc1 ]))
719+ subscriber .on_token (_chunk (tool_calls = [tc2 ]))
720720
721721 # -----------------------
722722 # 2) Final ActionEvent arrives (same tool_call_id)
@@ -742,7 +742,8 @@ async def test_terminal_tool_lifecycle_stream_then_action_then_observation():
742742 llm_response_id = "llm-1" ,
743743 tool_call = message_tool_call ,
744744 )
745- await subscriber .unstreamed_event_handler (action_event )
745+ with patch .object (event_loop , "is_running" , return_value = False ):
746+ event_loop .run_until_complete (subscriber .unstreamed_event_handler (action_event ))
746747
747748 # -----------------------
748749 # 3) ObservationEvent arrives (same tool_call_id)
@@ -761,14 +762,15 @@ async def test_terminal_tool_lifecycle_stream_then_action_then_observation():
761762 action_id = action_id , # REQUIRED linkage
762763 )
763764
764- await subscriber .unstreamed_event_handler (obs_event )
765+ with patch .object (event_loop , "is_running" , return_value = False ):
766+ event_loop .run_until_complete (subscriber .unstreamed_event_handler (obs_event ))
765767
766768 # -----------------------
767769 # Assert: status progression
768770 # -----------------------
769771 # Gather ONLY the updates related to our tool_call_id.
770772 updates = []
771- for call in conn .session_update .call_args_list :
773+ for call in mock_connection .session_update .call_args_list :
772774 update = call .kwargs ["update" ]
773775 # Filter only tool-call updates for this tool_call_id
774776 if getattr (update , "tool_call_id" , None ) == tool_call_id :
@@ -777,17 +779,18 @@ async def test_terminal_tool_lifecycle_stream_then_action_then_observation():
777779 assert updates , "Expected at least one ACP update for tool_call_id"
778780
779781 # We want to see:
780- # - at least one ToolCallStart with status in_progress
781- # - at least one ToolCallProgress with status in_progress
782+ # - at least one ToolCallStart with status in_progress (from streaming)
783+ # - at least one ToolCallProgress with status in_progress (from streaming or
784+ # ActionEvent updating the title with summary)
782785 # - final ToolCallProgress with status completed
783786 starts = [u for u in updates if isinstance (u , ToolCallStart )]
784787 progresses = [u for u in updates if isinstance (u , ToolCallProgress )]
785788
786789 assert any (isinstance (s , ToolCallStart ) for s in starts ), (
787- "Expected a ToolCallStart from streaming and/or ActionEvent "
790+ "Expected a ToolCallStart from streaming"
788791 )
789792 assert any (isinstance (p , ToolCallProgress ) for p in progresses ), (
790- "Expected at least one ToolCallProgress during streaming"
793+ "Expected at least one ToolCallProgress during streaming or from ActionEvent "
791794 )
792795
793796 # The last tool-call-related update should be completion.
0 commit comments