refactor: rename all agents and improve structure pt1
ref: N25B-257
This commit is contained in:
@@ -5,43 +5,47 @@ import pytest
|
||||
import zmq
|
||||
from spade.agent import Agent
|
||||
|
||||
from control_backend.agents.vad_agent import VADAgent
|
||||
from control_backend.agents.per_agents.per_vad_agent import PerVADAgent
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def zmq_context(mocker):
|
||||
mock_context = mocker.patch("control_backend.agents.vad_agent.azmq.Context.instance")
|
||||
mock_context = mocker.patch(
|
||||
"control_backend.agents.per_agents.per_vad_agent.azmq.Context.instance"
|
||||
)
|
||||
mock_context.return_value = MagicMock()
|
||||
return mock_context
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def streaming(mocker):
|
||||
return mocker.patch("control_backend.agents.vad_agent.Streaming")
|
||||
return mocker.patch("control_backend.agents.per_agents.per_vad_agent.Streaming")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def transcription_agent(mocker):
|
||||
return mocker.patch("control_backend.agents.vad_agent.TranscriptionAgent", autospec=True)
|
||||
def per_transcription_agent(mocker):
|
||||
return mocker.patch(
|
||||
"control_backend.agents.per_agents.per_vad_agent.PerTranscriptionAgent", autospec=True
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_normal_setup(streaming, transcription_agent):
|
||||
async def test_normal_setup(streaming, per_transcription_agent):
|
||||
"""
|
||||
Test that during normal setup, the VAD agent creates a Streaming behavior and creates audio
|
||||
sockets, and starts the TranscriptionAgent without loading real models.
|
||||
sockets, and starts the PerTranscriptionAgent without loading real models.
|
||||
"""
|
||||
vad_agent = VADAgent("tcp://localhost:12345", False)
|
||||
vad_agent.add_behaviour = MagicMock()
|
||||
per_vad_agent = PerVADAgent("tcp://localhost:12345", False)
|
||||
per_vad_agent.add_behaviour = MagicMock()
|
||||
|
||||
await vad_agent.setup()
|
||||
await per_vad_agent.setup()
|
||||
|
||||
streaming.assert_called_once()
|
||||
vad_agent.add_behaviour.assert_called_once_with(streaming.return_value)
|
||||
transcription_agent.assert_called_once()
|
||||
transcription_agent.return_value.start.assert_called_once()
|
||||
assert vad_agent.audio_in_socket is not None
|
||||
assert vad_agent.audio_out_socket is not None
|
||||
per_vad_agent.add_behaviour.assert_called_once_with(streaming.return_value)
|
||||
per_transcription_agent.assert_called_once()
|
||||
per_transcription_agent.return_value.start.assert_called_once()
|
||||
assert per_vad_agent.audio_in_socket is not None
|
||||
assert per_vad_agent.audio_out_socket is not None
|
||||
|
||||
|
||||
@pytest.mark.parametrize("do_bind", [True, False])
|
||||
@@ -50,11 +54,11 @@ def test_in_socket_creation(zmq_context, do_bind: bool):
|
||||
Test that the VAD agent creates an audio input socket, differentiating between binding and
|
||||
connecting.
|
||||
"""
|
||||
vad_agent = VADAgent(f"tcp://{'*' if do_bind else 'localhost'}:12345", do_bind)
|
||||
per_vad_agent = PerVADAgent(f"tcp://{'*' if do_bind else 'localhost'}:12345", do_bind)
|
||||
|
||||
vad_agent._connect_audio_in_socket()
|
||||
per_vad_agent._connect_audio_in_socket()
|
||||
|
||||
assert vad_agent.audio_in_socket is not None
|
||||
assert per_vad_agent.audio_in_socket is not None
|
||||
|
||||
zmq_context.return_value.socket.assert_called_once_with(zmq.SUB)
|
||||
zmq_context.return_value.socket.return_value.setsockopt_string.assert_called_once_with(
|
||||
@@ -74,11 +78,11 @@ def test_out_socket_creation(zmq_context):
|
||||
"""
|
||||
Test that the VAD agent creates an audio output socket correctly.
|
||||
"""
|
||||
vad_agent = VADAgent("tcp://localhost:12345", False)
|
||||
per_vad_agent = PerVADAgent("tcp://localhost:12345", False)
|
||||
|
||||
vad_agent._connect_audio_out_socket()
|
||||
per_vad_agent._connect_audio_out_socket()
|
||||
|
||||
assert vad_agent.audio_out_socket is not None
|
||||
assert per_vad_agent.audio_out_socket is not None
|
||||
|
||||
zmq_context.return_value.socket.assert_called_once_with(zmq.PUB)
|
||||
zmq_context.return_value.socket.return_value.bind_to_random_port.assert_called_once()
|
||||
@@ -93,28 +97,28 @@ async def test_out_socket_creation_failure(zmq_context):
|
||||
zmq_context.return_value.socket.return_value.bind_to_random_port.side_effect = (
|
||||
zmq.ZMQBindError
|
||||
)
|
||||
vad_agent = VADAgent("tcp://localhost:12345", False)
|
||||
per_vad_agent = PerVADAgent("tcp://localhost:12345", False)
|
||||
|
||||
await vad_agent.setup()
|
||||
await per_vad_agent.setup()
|
||||
|
||||
assert vad_agent.audio_out_socket is None
|
||||
assert per_vad_agent.audio_out_socket is None
|
||||
mock_super_stop.assert_called_once()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_stop(zmq_context, transcription_agent):
|
||||
async def test_stop(zmq_context, per_transcription_agent):
|
||||
"""
|
||||
Test that when the VAD agent is stopped, the sockets are closed correctly.
|
||||
"""
|
||||
vad_agent = VADAgent("tcp://localhost:12345", False)
|
||||
per_vad_agent = PerVADAgent("tcp://localhost:12345", False)
|
||||
zmq_context.return_value.socket.return_value.bind_to_random_port.return_value = random.randint(
|
||||
1000,
|
||||
10000,
|
||||
)
|
||||
|
||||
await vad_agent.setup()
|
||||
await vad_agent.stop()
|
||||
await per_vad_agent.setup()
|
||||
await per_vad_agent.stop()
|
||||
|
||||
assert zmq_context.return_value.socket.return_value.close.call_count == 2
|
||||
assert vad_agent.audio_in_socket is None
|
||||
assert vad_agent.audio_out_socket is None
|
||||
assert per_vad_agent.audio_in_socket is None
|
||||
assert per_vad_agent.audio_out_socket is None
|
||||
@@ -5,7 +5,7 @@ import pytest
|
||||
import soundfile as sf
|
||||
import zmq
|
||||
|
||||
from control_backend.agents.vad_agent import Streaming
|
||||
from control_backend.agents.per_agents.per_vad_agent import Streaming
|
||||
|
||||
|
||||
def get_audio_chunks() -> list[bytes]:
|
||||
@@ -42,7 +42,9 @@ async def test_real_audio(mocker):
|
||||
audio_in_socket = AsyncMock()
|
||||
audio_in_socket.recv.side_effect = audio_chunks
|
||||
|
||||
mock_poller: MagicMock = mocker.patch("control_backend.agents.vad_agent.zmq.Poller")
|
||||
mock_poller: MagicMock = mocker.patch(
|
||||
"control_backend.agents.per_agents.per_vad_agent.zmq.Poller"
|
||||
)
|
||||
mock_poller.return_value.poll.return_value = [(audio_in_socket, zmq.POLLIN)]
|
||||
|
||||
audio_out_socket = AsyncMock()
|
||||
@@ -4,12 +4,14 @@ from unittest.mock import AsyncMock, MagicMock, patch
|
||||
import pytest
|
||||
import zmq
|
||||
|
||||
from control_backend.agents.ri_command_agent import RICommandAgent
|
||||
from control_backend.agents.act_agents.act_speech_agent import ActSpeechAgent
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def zmq_context(mocker):
|
||||
mock_context = mocker.patch("control_backend.agents.vad_agent.azmq.Context.instance")
|
||||
mock_context = mocker.patch(
|
||||
"control_backend.agents.act_agents.act_speech_agent.zmq.Context.instance"
|
||||
)
|
||||
mock_context.return_value = MagicMock()
|
||||
return mock_context
|
||||
|
||||
@@ -19,8 +21,8 @@ async def test_setup_bind(zmq_context, mocker):
|
||||
"""Test setup with bind=True"""
|
||||
fake_socket = zmq_context.return_value.socket.return_value
|
||||
|
||||
agent = RICommandAgent("test@server", "password", address="tcp://localhost:5555", bind=True)
|
||||
settings = mocker.patch("control_backend.agents.ri_command_agent.settings")
|
||||
agent = ActSpeechAgent("test@server", "password", address="tcp://localhost:5555", bind=True)
|
||||
settings = mocker.patch("control_backend.agents.act_agents.act_speech_agent.settings")
|
||||
settings.zmq_settings.internal_sub_address = "tcp://internal:1234"
|
||||
|
||||
await agent.setup()
|
||||
@@ -40,8 +42,8 @@ async def test_setup_connect(zmq_context, mocker):
|
||||
"""Test setup with bind=False"""
|
||||
fake_socket = zmq_context.return_value.socket.return_value
|
||||
|
||||
agent = RICommandAgent("test@server", "password", address="tcp://localhost:5555", bind=False)
|
||||
settings = mocker.patch("control_backend.agents.ri_command_agent.settings")
|
||||
agent = ActSpeechAgent("test@server", "password", address="tcp://localhost:5555", bind=False)
|
||||
settings = mocker.patch("control_backend.agents.act_agents.act_speech_agent.settings")
|
||||
settings.zmq_settings.internal_sub_address = "tcp://internal:1234"
|
||||
|
||||
await agent.setup()
|
||||
@@ -60,14 +62,16 @@ async def test_send_commands_behaviour_valid_message():
|
||||
)
|
||||
fake_socket.send_json = AsyncMock()
|
||||
|
||||
agent = RICommandAgent("test@server", "password")
|
||||
agent = ActSpeechAgent("test@server", "password")
|
||||
agent.subsocket = fake_socket
|
||||
agent.pubsocket = fake_socket
|
||||
|
||||
behaviour = agent.SendCommandsBehaviour()
|
||||
behaviour.agent = agent
|
||||
|
||||
with patch("control_backend.agents.ri_command_agent.SpeechCommand") as MockSpeechCommand:
|
||||
with patch(
|
||||
"control_backend.agents.act_agents.act_speech_agent.SpeechCommand"
|
||||
) as MockSpeechCommand:
|
||||
mock_message = MagicMock()
|
||||
MockSpeechCommand.model_validate.return_value = mock_message
|
||||
|
||||
@@ -84,16 +88,14 @@ async def test_send_commands_behaviour_invalid_message(caplog):
|
||||
fake_socket.recv_multipart = AsyncMock(return_value=(b"command", b"{invalid_json}"))
|
||||
fake_socket.send_json = AsyncMock()
|
||||
|
||||
agent = RICommandAgent("test@server", "password")
|
||||
agent = ActSpeechAgent("test@server", "password")
|
||||
agent.subsocket = fake_socket
|
||||
agent.pubsocket = fake_socket
|
||||
|
||||
behaviour = agent.SendCommandsBehaviour()
|
||||
behaviour.agent = agent
|
||||
|
||||
with caplog.at_level("ERROR"):
|
||||
await behaviour.run()
|
||||
await behaviour.run()
|
||||
|
||||
fake_socket.recv_multipart.assert_awaited()
|
||||
fake_socket.send_json.assert_not_awaited()
|
||||
assert "Error processing message" in caplog.text
|
||||
@@ -3,7 +3,11 @@ from unittest.mock import ANY, AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from control_backend.agents.ri_communication_agent import RICommunicationAgent
|
||||
from control_backend.agents.com_agents.com_ri_agent import ComRIAgent
|
||||
|
||||
|
||||
def act_agent_path():
|
||||
return "control_backend.agents.com_agents.com_ri_agent.ActSpeechAgent"
|
||||
|
||||
|
||||
def fake_json_correct_negototiate_1():
|
||||
@@ -86,7 +90,9 @@ def fake_json_invalid_id_negototiate():
|
||||
|
||||
@pytest.fixture
|
||||
def zmq_context(mocker):
|
||||
mock_context = mocker.patch("control_backend.agents.vad_agent.azmq.Context.instance")
|
||||
mock_context = mocker.patch(
|
||||
"control_backend.agents.com_agents.com_ri_agent.zmq.Context.instance"
|
||||
)
|
||||
mock_context.return_value = MagicMock()
|
||||
return mock_context
|
||||
|
||||
@@ -101,17 +107,13 @@ async def test_setup_creates_socket_and_negotiate_1(zmq_context):
|
||||
fake_socket.send_json = AsyncMock()
|
||||
fake_socket.recv_json = fake_json_correct_negototiate_1()
|
||||
|
||||
# Mock RICommandAgent agent startup
|
||||
with patch(
|
||||
"control_backend.agents.ri_communication_agent.RICommandAgent", autospec=True
|
||||
) as MockCommandAgent:
|
||||
# Mock ActSpeechAgent agent startup
|
||||
with patch(act_agent_path(), autospec=True) as MockCommandAgent:
|
||||
fake_agent_instance = MockCommandAgent.return_value
|
||||
fake_agent_instance.start = AsyncMock()
|
||||
|
||||
# --- Act ---
|
||||
agent = RICommunicationAgent(
|
||||
"test@server", "password", address="tcp://localhost:5555", bind=False
|
||||
)
|
||||
agent = ComRIAgent("test@server", "password", address="tcp://localhost:5555", bind=False)
|
||||
await agent.setup()
|
||||
|
||||
# --- Assert ---
|
||||
@@ -139,17 +141,13 @@ async def test_setup_creates_socket_and_negotiate_2(zmq_context):
|
||||
fake_socket.send_json = AsyncMock()
|
||||
fake_socket.recv_json = fake_json_correct_negototiate_2()
|
||||
|
||||
# Mock RICommandAgent agent startup
|
||||
with patch(
|
||||
"control_backend.agents.ri_communication_agent.RICommandAgent", autospec=True
|
||||
) as MockCommandAgent:
|
||||
# Mock ActSpeechAgent agent startup
|
||||
with patch(act_agent_path(), autospec=True) as MockCommandAgent:
|
||||
fake_agent_instance = MockCommandAgent.return_value
|
||||
fake_agent_instance.start = AsyncMock()
|
||||
|
||||
# --- Act ---
|
||||
agent = RICommunicationAgent(
|
||||
"test@server", "password", address="tcp://localhost:5555", bind=False
|
||||
)
|
||||
agent = ComRIAgent("test@server", "password", address="tcp://localhost:5555", bind=False)
|
||||
await agent.setup()
|
||||
|
||||
# --- Assert ---
|
||||
@@ -177,19 +175,17 @@ async def test_setup_creates_socket_and_negotiate_3(zmq_context, caplog):
|
||||
fake_socket.send_json = AsyncMock()
|
||||
fake_socket.recv_json = fake_json_wrong_negototiate_1()
|
||||
|
||||
# Mock RICommandAgent agent startup
|
||||
# Mock ActSpeechAgent agent startup
|
||||
|
||||
# We are sending wrong negotiation info to the communication agent,
|
||||
# so we should retry and expect a better response, within a limited time.
|
||||
with patch(
|
||||
"control_backend.agents.ri_communication_agent.RICommandAgent", autospec=True
|
||||
) as MockCommandAgent:
|
||||
with patch(act_agent_path(), autospec=True) as MockCommandAgent:
|
||||
fake_agent_instance = MockCommandAgent.return_value
|
||||
fake_agent_instance.start = AsyncMock()
|
||||
|
||||
# --- Act ---
|
||||
with caplog.at_level("ERROR"):
|
||||
agent = RICommunicationAgent(
|
||||
agent = ComRIAgent(
|
||||
"test@server", "password", address="tcp://localhost:5555", bind=False
|
||||
)
|
||||
await agent.setup(max_retries=1)
|
||||
@@ -200,7 +196,7 @@ async def test_setup_creates_socket_and_negotiate_3(zmq_context, caplog):
|
||||
|
||||
# Since it failed, there should not be any command agent.
|
||||
fake_agent_instance.start.assert_not_awaited()
|
||||
assert "Failed to set up RICommunicationAgent" in caplog.text
|
||||
assert "Failed to set up ComRIAgent" in caplog.text
|
||||
|
||||
# Ensure the agent did not attach a ListenBehaviour
|
||||
assert not any(isinstance(b, agent.ListenBehaviour) for b in agent.behaviours)
|
||||
@@ -216,17 +212,13 @@ async def test_setup_creates_socket_and_negotiate_4(zmq_context):
|
||||
fake_socket.send_json = AsyncMock()
|
||||
fake_socket.recv_json = fake_json_correct_negototiate_3()
|
||||
|
||||
# Mock RICommandAgent agent startup
|
||||
with patch(
|
||||
"control_backend.agents.ri_communication_agent.RICommandAgent", autospec=True
|
||||
) as MockCommandAgent:
|
||||
# Mock ActSpeechAgent agent startup
|
||||
with patch(act_agent_path(), autospec=True) as MockCommandAgent:
|
||||
fake_agent_instance = MockCommandAgent.return_value
|
||||
fake_agent_instance.start = AsyncMock()
|
||||
|
||||
# --- Act ---
|
||||
agent = RICommunicationAgent(
|
||||
"test@server", "password", address="tcp://localhost:5555", bind=True
|
||||
)
|
||||
agent = ComRIAgent("test@server", "password", address="tcp://localhost:5555", bind=True)
|
||||
await agent.setup()
|
||||
|
||||
# --- Assert ---
|
||||
@@ -254,17 +246,13 @@ async def test_setup_creates_socket_and_negotiate_5(zmq_context):
|
||||
fake_socket.send_json = AsyncMock()
|
||||
fake_socket.recv_json = fake_json_correct_negototiate_4()
|
||||
|
||||
# Mock RICommandAgent agent startup
|
||||
with patch(
|
||||
"control_backend.agents.ri_communication_agent.RICommandAgent", autospec=True
|
||||
) as MockCommandAgent:
|
||||
# Mock ActSpeechAgent agent startup
|
||||
with patch(act_agent_path(), autospec=True) as MockCommandAgent:
|
||||
fake_agent_instance = MockCommandAgent.return_value
|
||||
fake_agent_instance.start = AsyncMock()
|
||||
|
||||
# --- Act ---
|
||||
agent = RICommunicationAgent(
|
||||
"test@server", "password", address="tcp://localhost:5555", bind=False
|
||||
)
|
||||
agent = ComRIAgent("test@server", "password", address="tcp://localhost:5555", bind=False)
|
||||
await agent.setup()
|
||||
|
||||
# --- Assert ---
|
||||
@@ -292,17 +280,13 @@ async def test_setup_creates_socket_and_negotiate_6(zmq_context):
|
||||
fake_socket.send_json = AsyncMock()
|
||||
fake_socket.recv_json = fake_json_correct_negototiate_5()
|
||||
|
||||
# Mock RICommandAgent agent startup
|
||||
with patch(
|
||||
"control_backend.agents.ri_communication_agent.RICommandAgent", autospec=True
|
||||
) as MockCommandAgent:
|
||||
# Mock ActSpeechAgent agent startup
|
||||
with patch(act_agent_path(), autospec=True) as MockCommandAgent:
|
||||
fake_agent_instance = MockCommandAgent.return_value
|
||||
fake_agent_instance.start = AsyncMock()
|
||||
|
||||
# --- Act ---
|
||||
agent = RICommunicationAgent(
|
||||
"test@server", "password", address="tcp://localhost:5555", bind=False
|
||||
)
|
||||
agent = ComRIAgent("test@server", "password", address="tcp://localhost:5555", bind=False)
|
||||
await agent.setup()
|
||||
|
||||
# --- Assert ---
|
||||
@@ -330,19 +314,17 @@ async def test_setup_creates_socket_and_negotiate_7(zmq_context, caplog):
|
||||
fake_socket.send_json = AsyncMock()
|
||||
fake_socket.recv_json = fake_json_invalid_id_negototiate()
|
||||
|
||||
# Mock RICommandAgent agent startup
|
||||
# Mock ActSpeechAgent agent startup
|
||||
|
||||
# We are sending wrong negotiation info to the communication agent,
|
||||
# so we should retry and expect a better response, within a limited time.
|
||||
with patch(
|
||||
"control_backend.agents.ri_communication_agent.RICommandAgent", autospec=True
|
||||
) as MockCommandAgent:
|
||||
with patch(act_agent_path(), autospec=True) as MockCommandAgent:
|
||||
fake_agent_instance = MockCommandAgent.return_value
|
||||
fake_agent_instance.start = AsyncMock()
|
||||
|
||||
# --- Act ---
|
||||
with caplog.at_level("WARNING"):
|
||||
agent = RICommunicationAgent(
|
||||
agent = ComRIAgent(
|
||||
"test@server", "password", address="tcp://localhost:5555", bind=False
|
||||
)
|
||||
await agent.setup(max_retries=1)
|
||||
@@ -366,15 +348,13 @@ async def test_setup_creates_socket_and_negotiate_timeout(zmq_context, caplog):
|
||||
fake_socket.send_json = AsyncMock()
|
||||
fake_socket.recv_json = AsyncMock(side_effect=asyncio.TimeoutError)
|
||||
|
||||
with patch(
|
||||
"control_backend.agents.ri_communication_agent.RICommandAgent", autospec=True
|
||||
) as MockCommandAgent:
|
||||
with patch(act_agent_path(), autospec=True) as MockCommandAgent:
|
||||
fake_agent_instance = MockCommandAgent.return_value
|
||||
fake_agent_instance.start = AsyncMock()
|
||||
|
||||
# --- Act ---
|
||||
with caplog.at_level("WARNING"):
|
||||
agent = RICommunicationAgent(
|
||||
agent = ComRIAgent(
|
||||
"test@server", "password", address="tcp://localhost:5555", bind=False
|
||||
)
|
||||
await agent.setup(max_retries=1)
|
||||
@@ -397,7 +377,7 @@ async def test_listen_behaviour_ping_correct(caplog):
|
||||
fake_socket.recv_json = AsyncMock(return_value={"endpoint": "ping", "data": {}})
|
||||
|
||||
# TODO: Integration test between actual server and password needed for spade agents
|
||||
agent = RICommunicationAgent("test@server", "password")
|
||||
agent = ComRIAgent("test@server", "password")
|
||||
agent.req_socket = fake_socket
|
||||
|
||||
behaviour = agent.ListenBehaviour()
|
||||
@@ -431,7 +411,7 @@ async def test_listen_behaviour_ping_wrong_endpoint(caplog):
|
||||
}
|
||||
)
|
||||
|
||||
agent = RICommunicationAgent("test@server", "password")
|
||||
agent = ComRIAgent("test@server", "password")
|
||||
agent.req_socket = fake_socket
|
||||
|
||||
behaviour = agent.ListenBehaviour()
|
||||
@@ -453,7 +433,7 @@ async def test_listen_behaviour_timeout(zmq_context, caplog):
|
||||
# recv_json will never resolve, simulate timeout
|
||||
fake_socket.recv_json = AsyncMock(side_effect=asyncio.TimeoutError)
|
||||
|
||||
agent = RICommunicationAgent("test@server", "password")
|
||||
agent = ComRIAgent("test@server", "password")
|
||||
agent.req_socket = fake_socket
|
||||
|
||||
behaviour = agent.ListenBehaviour()
|
||||
@@ -480,7 +460,7 @@ async def test_listen_behaviour_ping_no_endpoint(caplog):
|
||||
}
|
||||
)
|
||||
|
||||
agent = RICommunicationAgent("test@server", "password")
|
||||
agent = ComRIAgent("test@server", "password")
|
||||
agent.req_socket = fake_socket
|
||||
|
||||
behaviour = agent.ListenBehaviour()
|
||||
@@ -502,9 +482,7 @@ async def test_setup_unexpected_exception(zmq_context, caplog):
|
||||
# Simulate unexpected exception during recv_json()
|
||||
fake_socket.recv_json = AsyncMock(side_effect=Exception("boom!"))
|
||||
|
||||
agent = RICommunicationAgent(
|
||||
"test@server", "password", address="tcp://localhost:5555", bind=False
|
||||
)
|
||||
agent = ComRIAgent("test@server", "password", address="tcp://localhost:5555", bind=False)
|
||||
|
||||
with caplog.at_level("ERROR"):
|
||||
await agent.setup(max_retries=1)
|
||||
@@ -526,16 +504,12 @@ async def test_setup_unpacking_exception(zmq_context, caplog):
|
||||
} # missing 'port' and 'bind'
|
||||
fake_socket.recv_json = AsyncMock(return_value=malformed_data)
|
||||
|
||||
# Patch RICommandAgent so it won't actually start
|
||||
with patch(
|
||||
"control_backend.agents.ri_communication_agent.RICommandAgent", autospec=True
|
||||
) as MockCommandAgent:
|
||||
# Patch ActSpeechAgent so it won't actually start
|
||||
with patch(act_agent_path(), autospec=True) as MockCommandAgent:
|
||||
fake_agent_instance = MockCommandAgent.return_value
|
||||
fake_agent_instance.start = AsyncMock()
|
||||
|
||||
agent = RICommunicationAgent(
|
||||
"test@server", "password", address="tcp://localhost:5555", bind=False
|
||||
)
|
||||
agent = ComRIAgent("test@server", "password", address="tcp://localhost:5555", bind=False)
|
||||
|
||||
# --- Act & Assert ---
|
||||
with caplog.at_level("ERROR"):
|
||||
@@ -4,10 +4,10 @@ from unittest.mock import AsyncMock, MagicMock, call
|
||||
|
||||
import pytest
|
||||
|
||||
from control_backend.agents.bdi.behaviours.belief_setter import BeliefSetterBehaviour
|
||||
from control_backend.agents.bdi_agents.behaviours.belief_setter import BeliefSetterBehaviour
|
||||
|
||||
# Define a constant for the collector agent name to use in tests
|
||||
COLLECTOR_AGENT_NAME = "belief_collector"
|
||||
COLLECTOR_AGENT_NAME = "bel_collector_agent"
|
||||
COLLECTOR_AGENT_JID = f"{COLLECTOR_AGENT_NAME}@test"
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ def belief_setter(mock_agent, mocker):
|
||||
"""Fixture to create an instance of BeliefSetterBehaviour with a mocked agent."""
|
||||
# Patch the settings to use a predictable agent name
|
||||
mocker.patch(
|
||||
"control_backend.agents.bdi.behaviours.belief_setter.settings.agent_settings.belief_collector_agent_name",
|
||||
"control_backend.agents.bdi_agents.behaviours.belief_setter.settings.agent_settings.bel_collector_agent_name",
|
||||
COLLECTOR_AGENT_NAME,
|
||||
)
|
||||
|
||||
@@ -62,7 +62,7 @@ async def test_run_message_received(belief_setter, mocker):
|
||||
belief_setter._process_message.assert_called_once_with(msg)
|
||||
|
||||
|
||||
def test_process_message_from_belief_collector(belief_setter, mocker):
|
||||
def test_process_message_from_bel_collector_agent(belief_setter, mocker):
|
||||
"""
|
||||
Test processing a message from the correct belief collector agent.
|
||||
"""
|
||||
|
||||
@@ -3,7 +3,7 @@ from unittest.mock import AsyncMock, MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
from control_backend.agents.belief_collector.behaviours.continuous_collect import (
|
||||
from control_backend.agents.bel_agents.bel_collector_agent.behaviours.continuous_collect import (
|
||||
ContinuousBeliefCollector,
|
||||
)
|
||||
|
||||
@@ -20,7 +20,7 @@ def create_mock_message(sender_node: str, body: str) -> MagicMock:
|
||||
def mock_agent(mocker):
|
||||
"""Fixture to create a mock Agent."""
|
||||
agent = MagicMock()
|
||||
agent.jid = "belief_collector_agent@test"
|
||||
agent.jid = "bel_collector_agent@test"
|
||||
return agent
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ async def test_routes_to_handle_belief_text_by_type(continuous_collector, mocker
|
||||
@pytest.mark.asyncio
|
||||
async def test_routes_to_handle_belief_text_by_sender(continuous_collector, mocker):
|
||||
msg = create_mock_message(
|
||||
"belief_text_agent_mock", json.dumps({"beliefs": {"user_said": [["hi"]]}})
|
||||
"bel_text_agent_mock", json.dumps({"beliefs": {"user_said": [["hi"]]}})
|
||||
)
|
||||
spy = mocker.patch.object(continuous_collector, "_handle_belief_text", new=AsyncMock())
|
||||
await continuous_collector._process_message(msg)
|
||||
@@ -87,7 +87,7 @@ async def test_routes_to_handle_emo_text(continuous_collector, mocker):
|
||||
async def test_belief_text_happy_path_sends(continuous_collector, mocker):
|
||||
payload = {"type": "belief_extraction_text", "beliefs": {"user_said": ["hello test", "No"]}}
|
||||
continuous_collector.send = AsyncMock()
|
||||
await continuous_collector._handle_belief_text(payload, "belief_text_agent_mock")
|
||||
await continuous_collector._handle_belief_text(payload, "bel_text_agent_mock")
|
||||
|
||||
# make sure we attempted a send
|
||||
continuous_collector.send.assert_awaited_once()
|
||||
|
||||
@@ -4,7 +4,9 @@ from unittest.mock import AsyncMock, MagicMock, patch
|
||||
import pytest
|
||||
from spade.message import Message
|
||||
|
||||
from control_backend.agents.bdi.behaviours.text_belief_extractor import BeliefFromText
|
||||
from control_backend.agents.bel_agents.bel_text_extract_agent.behaviours.text_belief_extractor import ( # noqa: E501, We can't shorten this import.
|
||||
BeliefFromText,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -15,15 +17,16 @@ def mock_settings():
|
||||
"""
|
||||
# Create a mock object that mimics the nested structure
|
||||
settings_mock = MagicMock()
|
||||
settings_mock.agent_settings.transcription_agent_name = "transcriber"
|
||||
settings_mock.agent_settings.belief_collector_agent_name = "collector"
|
||||
settings_mock.agent_settings.per_transcription_agent_name = "transcriber"
|
||||
settings_mock.agent_settings.bel_collector_agent_name = "collector"
|
||||
settings_mock.agent_settings.host = "fake.host"
|
||||
|
||||
# Use patch to replace the settings object during the test
|
||||
# Adjust 'control_backend.behaviours.belief_from_text.settings' to where
|
||||
# your behaviour file imports it from.
|
||||
with patch(
|
||||
"control_backend.agents.bdi.behaviours.text_belief_extractor.settings", settings_mock
|
||||
"control_backend.agents.bel_agents.bel_text_extract_agent.behaviours.text_belief_extractor.settings",
|
||||
settings_mock,
|
||||
):
|
||||
yield settings_mock
|
||||
|
||||
@@ -100,7 +103,7 @@ async def test_run_message_from_transcriber_demo(behavior, mock_settings, monkey
|
||||
# Arrange: Create a mock message from the transcriber
|
||||
transcription_text = "hello world"
|
||||
mock_msg = create_mock_message(
|
||||
mock_settings.agent_settings.transcription_agent_name, transcription_text, None
|
||||
mock_settings.agent_settings.per_transcription_agent_name, transcription_text, None
|
||||
)
|
||||
behavior.receive.return_value = mock_msg
|
||||
|
||||
@@ -119,7 +122,7 @@ async def test_run_message_from_transcriber_demo(behavior, mock_settings, monkey
|
||||
|
||||
assert (
|
||||
sent_msg.to
|
||||
== mock_settings.agent_settings.belief_collector_agent_name
|
||||
== mock_settings.agent_settings.bel_collector_agent_name
|
||||
+ "@"
|
||||
+ mock_settings.agent_settings.host
|
||||
)
|
||||
@@ -159,7 +162,7 @@ async def test_process_transcription_success(behavior, mock_settings):
|
||||
# 2. Inspect the sent message
|
||||
sent_msg: Message = behavior.send.call_args[0][0]
|
||||
expected_to = (
|
||||
mock_settings.agent_settings.belief_collector_agent_name
|
||||
mock_settings.agent_settings.bel_collector_agent_name
|
||||
+ "@"
|
||||
+ mock_settings.agent_settings.host
|
||||
)
|
||||
|
||||
@@ -3,7 +3,7 @@ from unittest.mock import AsyncMock, MagicMock
|
||||
import pytest
|
||||
import zmq
|
||||
|
||||
from control_backend.agents.vad_agent import SocketPoller
|
||||
from control_backend.agents.per_agents.per_vad_agent import SocketPoller
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -16,7 +16,9 @@ async def test_socket_poller_with_data(socket, mocker):
|
||||
socket_data = b"test"
|
||||
socket.recv.return_value = socket_data
|
||||
|
||||
mock_poller: MagicMock = mocker.patch("control_backend.agents.vad_agent.zmq.Poller")
|
||||
mock_poller: MagicMock = mocker.patch(
|
||||
"control_backend.agents.per_agents.per_vad_agent.zmq.Poller"
|
||||
)
|
||||
mock_poller.return_value.poll.return_value = [(socket, zmq.POLLIN)]
|
||||
|
||||
poller = SocketPoller(socket)
|
||||
@@ -35,7 +37,9 @@ async def test_socket_poller_with_data(socket, mocker):
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_socket_poller_no_data(socket, mocker):
|
||||
mock_poller: MagicMock = mocker.patch("control_backend.agents.vad_agent.zmq.Poller")
|
||||
mock_poller: MagicMock = mocker.patch(
|
||||
"control_backend.agents.per_agents.per_vad_agent.zmq.Poller"
|
||||
)
|
||||
mock_poller.return_value.poll.return_value = []
|
||||
|
||||
poller = SocketPoller(socket)
|
||||
|
||||
@@ -3,7 +3,7 @@ from unittest.mock import AsyncMock, MagicMock
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from control_backend.agents.vad_agent import Streaming
|
||||
from control_backend.agents.per_agents.per_vad_agent import Streaming
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -20,7 +20,7 @@ def audio_out_socket():
|
||||
def mock_agent(mocker):
|
||||
"""Fixture to create a mock BDIAgent."""
|
||||
agent = MagicMock()
|
||||
agent.jid = "vad_agent@test"
|
||||
agent.jid = "per_vad_agent@test"
|
||||
return agent
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import numpy as np
|
||||
|
||||
from control_backend.agents.transcription.speech_recognizer import (
|
||||
from control_backend.agents.per_agents.per_transcription_agent.speech_recognizer import (
|
||||
OpenAIWhisperSpeechRecognizer,
|
||||
SpeechRecognizer,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user