2026-02-11 11:50:36 +01:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
from nanobot.agent.tools.message import MessageTool
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
|
|
|
async def test_message_tool_returns_error_when_no_target_context() -> None:
|
|
|
|
|
tool = MessageTool()
|
|
|
|
|
result = await tool.execute(content="test")
|
|
|
|
|
assert result == "Error: No target channel/chat specified"
|
2026-04-23 04:32:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
"bad",
|
|
|
|
|
[
|
|
|
|
|
"not a list",
|
|
|
|
|
[["ok"], "row-not-a-list"],
|
|
|
|
|
[["ok", 42]],
|
|
|
|
|
[[None]],
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
async def test_message_tool_rejects_malformed_buttons(bad) -> None:
|
|
|
|
|
"""``buttons`` must be ``list[list[str]]``; the tool validates the shape
|
|
|
|
|
up front so a malformed LLM payload errors visibly instead of slipping
|
|
|
|
|
into the channel layer where Telegram would silently reject the frame."""
|
|
|
|
|
tool = MessageTool()
|
|
|
|
|
result = await tool.execute(
|
|
|
|
|
content="hi", channel="telegram", chat_id="1", buttons=bad,
|
|
|
|
|
)
|
|
|
|
|
assert result == "Error: buttons must be a list of list of strings"
|