test: fix tests after changing schema and
ref: N25B-299
This commit is contained in:
@@ -7,7 +7,7 @@ import pytest
|
||||
from control_backend.agents.bdi.bdi_core_agent.bdi_core_agent import BDICoreAgent
|
||||
from control_backend.core.agent_system import InternalMessage
|
||||
from control_backend.core.config import settings
|
||||
from control_backend.schemas.belief_message import BeliefMessage
|
||||
from control_backend.schemas.belief_message import Belief, BeliefMessage
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -45,7 +45,7 @@ async def test_setup_no_asl(mock_agentspeak_env, agent):
|
||||
@pytest.mark.asyncio
|
||||
async def test_handle_belief_collector_message(agent, mock_settings):
|
||||
"""Test that incoming beliefs are added to the BDI agent"""
|
||||
beliefs = {"user_said": ["Hello"]}
|
||||
beliefs = [Belief(name="user_said", arguments=["Hello"])]
|
||||
msg = InternalMessage(
|
||||
to="bdi_agent",
|
||||
sender=mock_settings.agent_settings.bdi_belief_collector_name,
|
||||
@@ -116,11 +116,11 @@ async def test_custom_actions(agent):
|
||||
|
||||
# Invoke action
|
||||
mock_term = MagicMock()
|
||||
mock_term.args = ["Hello"]
|
||||
mock_term.args = ["Hello", "Norm", "Goal"]
|
||||
mock_intention = MagicMock()
|
||||
|
||||
# Run generator
|
||||
gen = action_fn(agent, mock_term, mock_intention)
|
||||
next(gen) # Execute
|
||||
|
||||
agent._send_to_llm.assert_called_with("Hello")
|
||||
agent._send_to_llm.assert_called_with("Hello", "Norm", "Goal")
|
||||
|
||||
@@ -8,6 +8,7 @@ from control_backend.agents.bdi import (
|
||||
)
|
||||
from control_backend.core.agent_system import InternalMessage
|
||||
from control_backend.core.config import settings
|
||||
from control_backend.schemas.belief_message import Belief
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -57,10 +58,11 @@ async def test_handle_message_bad_json(agent, mocker):
|
||||
async def test_handle_belief_text_sends_when_beliefs_exist(agent, mocker):
|
||||
payload = {"type": "belief_extraction_text", "beliefs": {"user_said": ["hello"]}}
|
||||
spy = mocker.patch.object(agent, "_send_beliefs_to_bdi", new_callable=AsyncMock)
|
||||
expected = [Belief(name="user_said", arguments=["hello"])]
|
||||
|
||||
await agent._handle_belief_text(payload, "origin")
|
||||
|
||||
spy.assert_awaited_once_with(payload["beliefs"], origin="origin")
|
||||
spy.assert_awaited_once_with(expected, origin="origin")
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -76,7 +78,7 @@ async def test_handle_belief_text_no_send_when_empty(agent, mocker):
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_beliefs_to_bdi(agent):
|
||||
agent.send = AsyncMock()
|
||||
beliefs = {"user_said": ["hello", "world"]}
|
||||
beliefs = [Belief(name="user_said", arguments=["hello", "world"])]
|
||||
|
||||
await agent._send_beliefs_to_bdi(beliefs, origin="origin")
|
||||
|
||||
@@ -84,4 +86,4 @@ async def test_send_beliefs_to_bdi(agent):
|
||||
sent: InternalMessage = agent.send.call_args.args[0]
|
||||
assert sent.to == settings.agent_settings.bdi_core_name
|
||||
assert sent.thread == "beliefs"
|
||||
assert json.loads(sent.body)["beliefs"] == beliefs
|
||||
assert json.loads(sent.body)["beliefs"] == [belief.model_dump() for belief in beliefs]
|
||||
|
||||
@@ -7,6 +7,7 @@ import pytest
|
||||
|
||||
from control_backend.agents.llm.llm_agent import LLMAgent, LLMInstructions
|
||||
from control_backend.core.agent_system import InternalMessage
|
||||
from control_backend.schemas.llm_prompt_message import LLMPromptMessage
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -49,8 +50,11 @@ async def test_llm_processing_success(mock_httpx_client, mock_settings):
|
||||
agent.send = AsyncMock() # Mock the send method to verify replies
|
||||
|
||||
# Simulate receiving a message from BDI
|
||||
prompt = LLMPromptMessage(text="Hi", norms=[], goals=[])
|
||||
msg = InternalMessage(
|
||||
to="llm_agent", sender=mock_settings.agent_settings.bdi_core_name, body="Hi"
|
||||
to="llm_agent",
|
||||
sender=mock_settings.agent_settings.bdi_core_name,
|
||||
body=prompt.model_dump_json(),
|
||||
)
|
||||
|
||||
await agent.handle_message(msg)
|
||||
@@ -68,7 +72,12 @@ async def test_llm_processing_success(mock_httpx_client, mock_settings):
|
||||
async def test_llm_processing_errors(mock_httpx_client, mock_settings):
|
||||
agent = LLMAgent("llm_agent")
|
||||
agent.send = AsyncMock()
|
||||
msg = InternalMessage(to="llm", sender=mock_settings.agent_settings.bdi_core_name, body="Hi")
|
||||
prompt = LLMPromptMessage(text="Hi", norms=[], goals=[])
|
||||
msg = InternalMessage(
|
||||
to="llm",
|
||||
sender=mock_settings.agent_settings.bdi_core_name,
|
||||
body=prompt.model_dump_json(),
|
||||
)
|
||||
|
||||
# HTTP Error
|
||||
mock_httpx_client.stream = MagicMock(side_effect=httpx.HTTPError("Fail"))
|
||||
@@ -103,8 +112,11 @@ async def test_llm_json_error(mock_httpx_client, mock_settings):
|
||||
agent.send = AsyncMock()
|
||||
|
||||
with patch.object(agent.logger, "error") as log:
|
||||
prompt = LLMPromptMessage(text="Hi", norms=[], goals=[])
|
||||
msg = InternalMessage(
|
||||
to="llm", sender=mock_settings.agent_settings.bdi_core_name, body="Hi"
|
||||
to="llm",
|
||||
sender=mock_settings.agent_settings.bdi_core_name,
|
||||
body=prompt.model_dump_json(),
|
||||
)
|
||||
await agent.handle_message(msg)
|
||||
log.assert_called() # Should log JSONDecodeError
|
||||
@@ -112,10 +124,10 @@ async def test_llm_json_error(mock_httpx_client, mock_settings):
|
||||
|
||||
def test_llm_instructions():
|
||||
# Full custom
|
||||
instr = LLMInstructions(norms="N", goals="G")
|
||||
instr = LLMInstructions(norms=["N1", "N2"], goals=["G1", "G2"])
|
||||
text = instr.build_developer_instruction()
|
||||
assert "Norms to follow:\nN" in text
|
||||
assert "Goals to reach:\nG" in text
|
||||
assert "Norms to follow:\n- N1\n- N2" in text
|
||||
assert "Goals to reach:\n- G1\n- G2" in text
|
||||
|
||||
# Defaults
|
||||
instr_def = LLMInstructions()
|
||||
|
||||
Reference in New Issue
Block a user