feat: apply new agent naming standards

Expanding abbreviations to remove ambiguity, simplifying agent names to reduce repetition.

ref: N25B-257
This commit is contained in:
Twirre Meulenbelt
2025-11-19 15:56:09 +01:00
parent f4dbca5b94
commit efe49c219c
39 changed files with 218 additions and 222 deletions

View File

@@ -4,13 +4,13 @@ from unittest.mock import AsyncMock, MagicMock, patch
import pytest
import zmq
from control_backend.agents.act_agents.act_speech_agent import ActSpeechAgent
from control_backend.agents.actuation.robot_speech_agent import RobotSpeechAgent
@pytest.fixture
def zmq_context(mocker):
mock_context = mocker.patch(
"control_backend.agents.act_agents.act_speech_agent.zmq.Context.instance"
"control_backend.agents.actuation.robot_speech_agent.zmq.Context.instance"
)
mock_context.return_value = MagicMock()
return mock_context
@@ -21,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 = ActSpeechAgent("test@server", "password", address="tcp://localhost:5555", bind=True)
settings = mocker.patch("control_backend.agents.act_agents.act_speech_agent.settings")
agent = RobotSpeechAgent("test@server", "password", address="tcp://localhost:5555", bind=True)
settings = mocker.patch("control_backend.agents.actuation.robot_speech_agent.settings")
settings.zmq_settings.internal_sub_address = "tcp://internal:1234"
await agent.setup()
@@ -40,8 +40,8 @@ async def test_setup_connect(zmq_context, mocker):
"""Test setup with bind=False"""
fake_socket = zmq_context.return_value.socket.return_value
agent = ActSpeechAgent("test@server", "password", address="tcp://localhost:5555", bind=False)
settings = mocker.patch("control_backend.agents.act_agents.act_speech_agent.settings")
agent = RobotSpeechAgent("test@server", "password", address="tcp://localhost:5555", bind=False)
settings = mocker.patch("control_backend.agents.actuation.robot_speech_agent.settings")
settings.zmq_settings.internal_sub_address = "tcp://internal:1234"
await agent.setup()
@@ -59,7 +59,7 @@ async def test_send_commands_behaviour_valid_message():
)
fake_socket.send_json = AsyncMock()
agent = ActSpeechAgent("test@server", "password")
agent = RobotSpeechAgent("test@server", "password")
agent.subsocket = fake_socket
agent.pubsocket = fake_socket
@@ -67,7 +67,7 @@ async def test_send_commands_behaviour_valid_message():
behaviour.agent = agent
with patch(
"control_backend.agents.act_agents.act_speech_agent.SpeechCommand"
"control_backend.agents.actuation.robot_speech_agent.SpeechCommand"
) as MockSpeechCommand:
mock_message = MagicMock()
MockSpeechCommand.model_validate.return_value = mock_message
@@ -85,7 +85,7 @@ async def test_send_commands_behaviour_invalid_message():
fake_socket.recv_multipart = AsyncMock(return_value=(b"command", b"{invalid_json}"))
fake_socket.send_json = AsyncMock()
agent = ActSpeechAgent("test@server", "password")
agent = RobotSpeechAgent("test@server", "password")
agent.subsocket = fake_socket
agent.pubsocket = fake_socket

View File

@@ -3,11 +3,11 @@ from unittest.mock import ANY, AsyncMock, MagicMock, patch
import pytest
from control_backend.agents.com_agents.com_ri_agent import ComRIAgent
from control_backend.agents.communication.ri_communication_agent import RICommunicationAgent
def act_agent_path():
return "control_backend.agents.com_agents.com_ri_agent.ActSpeechAgent"
def speech_agent_path():
return "control_backend.agents.communication.ri_communication_agent.RobotSpeechAgent"
def fake_json_correct_negototiate_1():
@@ -91,7 +91,7 @@ def fake_json_invalid_id_negototiate():
@pytest.fixture
def zmq_context(mocker):
mock_context = mocker.patch(
"control_backend.agents.com_agents.com_ri_agent.zmq.Context.instance"
"control_backend.agents.communication.ri_communication_agent.zmq.Context.instance"
)
mock_context.return_value = MagicMock()
return mock_context
@@ -109,12 +109,17 @@ async def test_setup_creates_socket_and_negotiate_1(zmq_context):
fake_socket.send_multipart = AsyncMock()
# Mock ActSpeechAgent agent startup
with patch(act_agent_path(), autospec=True) as MockCommandAgent:
with patch(speech_agent_path(), autospec=True) as MockCommandAgent:
fake_agent_instance = MockCommandAgent.return_value
fake_agent_instance.start = AsyncMock()
# --- Act ---
agent = ComRIAgent("test@server", "password", address="tcp://localhost:5555", bind=False)
agent = RICommunicationAgent(
"test@server",
"password",
address="tcp://localhost:5555",
bind=False,
)
await agent.setup()
# --- Assert ---
@@ -144,12 +149,17 @@ async def test_setup_creates_socket_and_negotiate_2(zmq_context):
fake_socket.send_multipart = AsyncMock()
# Mock ActSpeechAgent agent startup
with patch(act_agent_path(), autospec=True) as MockCommandAgent:
with patch(speech_agent_path(), autospec=True) as MockCommandAgent:
fake_agent_instance = MockCommandAgent.return_value
fake_agent_instance.start = AsyncMock()
# --- Act ---
agent = ComRIAgent("test@server", "password", address="tcp://localhost:5555", bind=False)
agent = RICommunicationAgent(
"test@server",
"password",
address="tcp://localhost:5555",
bind=False,
)
await agent.setup()
# --- Assert ---
@@ -182,12 +192,17 @@ async def test_setup_creates_socket_and_negotiate_3(zmq_context):
# 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(act_agent_path(), autospec=True) as MockCommandAgent:
with patch(speech_agent_path(), autospec=True) as MockCommandAgent:
fake_agent_instance = MockCommandAgent.return_value
fake_agent_instance.start = AsyncMock()
# --- Act ---
agent = ComRIAgent("test@server", "password", address="tcp://localhost:5555", bind=False)
agent = RICommunicationAgent(
"test@server",
"password",
address="tcp://localhost:5555",
bind=False,
)
await agent.setup(max_retries=1)
# --- Assert ---
@@ -213,11 +228,16 @@ async def test_setup_creates_socket_and_negotiate_4(zmq_context):
fake_socket.send_multipart = AsyncMock()
# Mock ActSpeechAgent agent startup
with patch(act_agent_path(), autospec=True) as MockCommandAgent:
with patch(speech_agent_path(), autospec=True) as MockCommandAgent:
fake_agent_instance = MockCommandAgent.return_value
fake_agent_instance.start = AsyncMock()
# --- Act ---
agent = ComRIAgent("test@server", "password", address="tcp://localhost:5555", bind=True)
agent = RICommunicationAgent(
"test@server",
"password",
address="tcp://localhost:5555",
bind=True,
)
await agent.setup()
# --- Assert ---
@@ -247,11 +267,16 @@ async def test_setup_creates_socket_and_negotiate_5(zmq_context):
fake_socket.send_multipart = AsyncMock()
# Mock ActSpeechAgent agent startup
with patch(act_agent_path(), autospec=True) as MockCommandAgent:
with patch(speech_agent_path(), autospec=True) as MockCommandAgent:
fake_agent_instance = MockCommandAgent.return_value
fake_agent_instance.start = AsyncMock()
# --- Act ---
agent = ComRIAgent("test@server", "password", address="tcp://localhost:5555", bind=False)
agent = RICommunicationAgent(
"test@server",
"password",
address="tcp://localhost:5555",
bind=False,
)
await agent.setup()
# --- Assert ---
@@ -281,11 +306,16 @@ async def test_setup_creates_socket_and_negotiate_6(zmq_context):
fake_socket.send_multipart = AsyncMock()
# Mock ActSpeechAgent agent startup
with patch(act_agent_path(), autospec=True) as MockCommandAgent:
with patch(speech_agent_path(), autospec=True) as MockCommandAgent:
fake_agent_instance = MockCommandAgent.return_value
fake_agent_instance.start = AsyncMock()
# --- Act ---
agent = ComRIAgent("test@server", "password", address="tcp://localhost:5555", bind=False)
agent = RICommunicationAgent(
"test@server",
"password",
address="tcp://localhost:5555",
bind=False,
)
await agent.setup()
# --- Assert ---
@@ -318,13 +348,18 @@ async def test_setup_creates_socket_and_negotiate_7(zmq_context):
# 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(act_agent_path(), autospec=True) as MockCommandAgent:
with patch(speech_agent_path(), autospec=True) as MockCommandAgent:
fake_agent_instance = MockCommandAgent.return_value
fake_agent_instance.start = AsyncMock()
# --- Act ---
agent = ComRIAgent("test@server", "password", address="tcp://localhost:5555", bind=False)
agent = RICommunicationAgent(
"test@server",
"password",
address="tcp://localhost:5555",
bind=False,
)
await agent.setup(max_retries=1)
# --- Assert ---
@@ -346,13 +381,18 @@ async def test_setup_creates_socket_and_negotiate_timeout(zmq_context):
fake_socket.recv_json = AsyncMock(side_effect=asyncio.TimeoutError)
fake_socket.send_multipart = AsyncMock()
with patch(act_agent_path(), autospec=True) as MockCommandAgent:
with patch(speech_agent_path(), autospec=True) as MockCommandAgent:
fake_agent_instance = MockCommandAgent.return_value
fake_agent_instance.start = AsyncMock()
# --- Act ---
agent = ComRIAgent("test@server", "password", address="tcp://localhost:5555", bind=False)
agent = RICommunicationAgent(
"test@server",
"password",
address="tcp://localhost:5555",
bind=False,
)
await agent.setup(max_retries=1)
# --- Assert ---
@@ -372,7 +412,7 @@ async def test_listen_behaviour_ping_correct():
fake_socket.recv_json = AsyncMock(return_value={"endpoint": "ping", "data": {}})
fake_socket.send_multipart = AsyncMock()
agent = ComRIAgent("test@server", "password")
agent = RICommunicationAgent("test@server", "password")
agent._req_socket = fake_socket
agent.connected = True
@@ -405,7 +445,7 @@ async def test_listen_behaviour_ping_wrong_endpoint():
)
fake_pub_socket = AsyncMock()
agent = ComRIAgent("test@server", "password", fake_pub_socket)
agent = RICommunicationAgent("test@server", "password", fake_pub_socket)
agent._req_socket = fake_socket
agent.connected = True
@@ -428,7 +468,7 @@ async def test_listen_behaviour_timeout(zmq_context):
fake_socket.recv_json = AsyncMock(side_effect=asyncio.TimeoutError)
fake_socket.send_multipart = AsyncMock()
agent = ComRIAgent("test@server", "password")
agent = RICommunicationAgent("test@server", "password")
agent._req_socket = fake_socket
agent.connected = True
@@ -456,7 +496,7 @@ async def test_listen_behaviour_ping_no_endpoint():
}
)
agent = ComRIAgent("test@server", "password")
agent = RICommunicationAgent("test@server", "password")
agent._req_socket = fake_socket
agent.connected = True
@@ -477,7 +517,12 @@ async def test_setup_unexpected_exception(zmq_context):
fake_socket.recv_json = AsyncMock(side_effect=Exception("boom!"))
fake_socket.send_multipart = AsyncMock()
agent = ComRIAgent("test@server", "password", address="tcp://localhost:5555", bind=False)
agent = RICommunicationAgent(
"test@server",
"password",
address="tcp://localhost:5555",
bind=False,
)
await agent.setup(max_retries=1)
@@ -500,11 +545,16 @@ async def test_setup_unpacking_exception(zmq_context):
fake_socket.recv_json = AsyncMock(return_value=malformed_data)
# Patch ActSpeechAgent so it won't actually start
with patch(act_agent_path(), autospec=True) as MockCommandAgent:
with patch(speech_agent_path(), autospec=True) as MockCommandAgent:
fake_agent_instance = MockCommandAgent.return_value
fake_agent_instance.start = AsyncMock()
agent = ComRIAgent("test@server", "password", address="tcp://localhost:5555", bind=False)
agent = RICommunicationAgent(
"test@server",
"password",
address="tcp://localhost:5555",
bind=False,
)
# --- Act & Assert ---

View File

@@ -5,27 +5,25 @@ import pytest
import zmq
from spade.agent import Agent
from control_backend.agents.per_agents.per_vad_agent import PerVADAgent
from control_backend.agents.perception.vad_agent import VADAgent
@pytest.fixture
def zmq_context(mocker):
mock_context = mocker.patch(
"control_backend.agents.per_agents.per_vad_agent.azmq.Context.instance"
)
mock_context = mocker.patch("control_backend.agents.perception.vad_agent.azmq.Context.instance")
mock_context.return_value = MagicMock()
return mock_context
@pytest.fixture
def streaming(mocker):
return mocker.patch("control_backend.agents.per_agents.per_vad_agent.Streaming")
return mocker.patch("control_backend.agents.perception.vad_agent.StreamingBehaviour")
@pytest.fixture
def per_transcription_agent(mocker):
return mocker.patch(
"control_backend.agents.per_agents.per_vad_agent.PerTranscriptionAgent", autospec=True
"control_backend.agents.perception.vad_agent.TranscriptionAgent", autospec=True
)
@@ -33,9 +31,9 @@ def per_transcription_agent(mocker):
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 PerTranscriptionAgent without loading real models.
sockets, and starts the TranscriptionAgent without loading real models.
"""
per_vad_agent = PerVADAgent("tcp://localhost:12345", False)
per_vad_agent = VADAgent("tcp://localhost:12345", False)
per_vad_agent.add_behaviour = MagicMock()
await per_vad_agent.setup()
@@ -54,7 +52,7 @@ 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.
"""
per_vad_agent = PerVADAgent(f"tcp://{'*' if do_bind else 'localhost'}:12345", do_bind)
per_vad_agent = VADAgent(f"tcp://{'*' if do_bind else 'localhost'}:12345", do_bind)
per_vad_agent._connect_audio_in_socket()
@@ -78,7 +76,7 @@ def test_out_socket_creation(zmq_context):
"""
Test that the VAD agent creates an audio output socket correctly.
"""
per_vad_agent = PerVADAgent("tcp://localhost:12345", False)
per_vad_agent = VADAgent("tcp://localhost:12345", False)
per_vad_agent._connect_audio_out_socket()
@@ -97,7 +95,7 @@ async def test_out_socket_creation_failure(zmq_context):
zmq_context.return_value.socket.return_value.bind_to_random_port.side_effect = (
zmq.ZMQBindError
)
per_vad_agent = PerVADAgent("tcp://localhost:12345", False)
per_vad_agent = VADAgent("tcp://localhost:12345", False)
await per_vad_agent.setup()
@@ -110,7 +108,7 @@ async def test_stop(zmq_context, per_transcription_agent):
"""
Test that when the VAD agent is stopped, the sockets are closed correctly.
"""
per_vad_agent = PerVADAgent("tcp://localhost:12345", False)
per_vad_agent = VADAgent("tcp://localhost:12345", False)
zmq_context.return_value.socket.return_value.bind_to_random_port.return_value = random.randint(
1000,
10000,

View File

@@ -5,7 +5,7 @@ import pytest
import soundfile as sf
import zmq
from control_backend.agents.per_agents.per_vad_agent import Streaming
from control_backend.agents.perception.vad_agent import StreamingBehaviour
def get_audio_chunks() -> list[bytes]:
@@ -42,14 +42,12 @@ 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.per_agents.per_vad_agent.zmq.Poller"
)
mock_poller: MagicMock = mocker.patch("control_backend.agents.perception.vad_agent.zmq.Poller")
mock_poller.return_value.poll.return_value = [(audio_in_socket, zmq.POLLIN)]
audio_out_socket = AsyncMock()
vad_streamer = Streaming(audio_in_socket, audio_out_socket)
vad_streamer = StreamingBehaviour(audio_in_socket, audio_out_socket)
vad_streamer._ready = True
vad_streamer.agent = MagicMock()
for _ in audio_chunks: