From 3867d9e8b91cb1b604576d159cf15a4835ca5311 Mon Sep 17 00:00:00 2001 From: Storm Date: Fri, 30 Jan 2026 15:54:16 +0100 Subject: [PATCH] test: fixed 1 test, removed 2 redundant tests ref: N25B-393 --- .../test_ri_communication_agent.py | 35 ------------------- .../user_interrupt/test_user_interrupt.py | 30 +++++++++------- 2 files changed, 17 insertions(+), 48 deletions(-) diff --git a/test/unit/agents/communication/test_ri_communication_agent.py b/test/unit/agents/communication/test_ri_communication_agent.py index a678907..8a5e5ef 100644 --- a/test/unit/agents/communication/test_ri_communication_agent.py +++ b/test/unit/agents/communication/test_ri_communication_agent.py @@ -396,38 +396,3 @@ async def test_negotiate_req_socket_none_causes_retry(zmq_context): result = await agent._negotiate_connection(max_retries=1) assert result is False - - -@pytest.mark.asyncio -async def test_handle_message_pause_command(zmq_context): - """Test handle_message with a valid PauseCommand.""" - agent = RICommunicationAgent("ri_comm") - agent._req_socket = AsyncMock() - agent.logger = MagicMock() - - agent._req_socket.recv_json.return_value = {"status": "ok"} - - pause_cmd = PauseCommand(data=True) - msg = InternalMessage(to="ri_comm", sender="user_int", body=pause_cmd.model_dump_json()) - - await agent.handle_message(msg) - - agent._req_socket.send_json.assert_awaited_once() - args = agent._req_socket.send_json.await_args[0][0] - assert args["endpoint"] == RIEndpoint.PAUSE.value - assert args["data"] is True - - -@pytest.mark.asyncio -async def test_handle_message_invalid_pause_command(zmq_context): - """Test handle_message with invalid JSON.""" - agent = RICommunicationAgent("ri_comm") - agent._req_socket = AsyncMock() - agent.logger = MagicMock() - - msg = InternalMessage(to="ri_comm", sender="user_int", body="invalid json") - - await agent.handle_message(msg) - - agent.logger.warning.assert_called_with("Incorrect message format for PauseCommand.") - agent._req_socket.send_json.assert_not_called() diff --git a/test/unit/agents/user_interrupt/test_user_interrupt.py b/test/unit/agents/user_interrupt/test_user_interrupt.py index c41d79e..d125a0b 100644 --- a/test/unit/agents/user_interrupt/test_user_interrupt.py +++ b/test/unit/agents/user_interrupt/test_user_interrupt.py @@ -299,26 +299,30 @@ async def test_send_experiment_control(agent): @pytest.mark.asyncio async def test_send_pause_command(agent): + # --- Test PAUSE --- await agent._send_pause_command("true") - # Sends to RI and VAD - assert agent.send.await_count == 2 - msgs = [call.args[0] for call in agent.send.call_args_list] - ri_msg = next(m for m in msgs if m.to == settings.agent_settings.ri_communication_name) - assert json.loads(ri_msg.body)["endpoint"] == "" # PAUSE endpoint - assert json.loads(ri_msg.body)["data"] is True + # Should send exactly 1 message + assert agent.send.await_count == 1 + + # Extract the message object from the mock call + # call_args[0] are positional args, and [0] is the first arg (the message) + msg = agent.send.call_args[0][0] - vad_msg = next(m for m in msgs if m.to == settings.agent_settings.vad_name) - assert vad_msg.body == "PAUSE" + # Verify Body + assert msg.body == "PAUSE" + # --- Test RESUME --- agent.send.reset_mock() await agent._send_pause_command("false") - assert agent.send.await_count == 2 - vad_msg = next( - m for m in agent.send.call_args_list if m.args[0].to == settings.agent_settings.vad_name - ).args[0] - assert vad_msg.body == "RESUME" + # Should send exactly 1 message + assert agent.send.await_count == 1 + + msg = agent.send.call_args[0][0] + + # Verify Body + assert msg.body == "RESUME" @pytest.mark.asyncio async def test_setup(agent):