67 lines
2.1 KiB
Python
67 lines
2.1 KiB
Python
import pytest
|
|
from beaver_gateway.mcp.types import McpServer
|
|
from beaver_gateway.mcp.wrap import build_python_tool_server
|
|
from fastmcp import Client
|
|
from fastmcp.exceptions import ToolError
|
|
|
|
from mcps.vibegram import Vibegram, _cards, _event, _work
|
|
|
|
|
|
def test_events_render_and_unknown_kinds_are_skipped():
|
|
msg = _event(
|
|
{
|
|
"id": 61,
|
|
"nick": "claude-neighbour",
|
|
"kind": "message",
|
|
"payload": {"body": "@beaver-test привет"},
|
|
"createdAt": "2026-08-30T10:00:00.000Z",
|
|
}
|
|
)
|
|
assert (
|
|
msg is not None
|
|
and msg.line() == "[08-30 10:00] claude-neighbour: @beaver-test привет"
|
|
)
|
|
assert _event({"id": 1, "kind": "tree", "payload": {}}) is None
|
|
|
|
|
|
def test_mentioned_and_cards():
|
|
v = Vibegram(hub="http://127.0.0.1:9", token="t", nick="beaver-test")
|
|
ev = _event(
|
|
{
|
|
"id": 2,
|
|
"nick": "x",
|
|
"kind": "message",
|
|
"payload": {"body": "эй @Beaver-Test"},
|
|
}
|
|
)
|
|
assert ev is not None and v.mentioned([ev])
|
|
text = _cards(
|
|
[
|
|
{
|
|
"nick": "beaver-test",
|
|
"status": "online",
|
|
"skills": [],
|
|
"focus": {"holding": ["a.md"]},
|
|
}
|
|
],
|
|
"beaver-test",
|
|
)
|
|
assert "(это ты)" in text and "держит: a.md" in text
|
|
assert "плана в комнате пока нет" in _work(
|
|
{"free": [], "taken": [], "busy": [], "cards": [], "planRevision": 0}, "me"
|
|
)
|
|
|
|
|
|
async def test_tool_schema_lists_actions_and_needs_text_for_send():
|
|
tool = Vibegram(hub="http://127.0.0.1:9", token="t", nick="beaver-test")
|
|
server = build_python_tool_server(
|
|
McpServer.python_tool(name="vibegram", tools=[tool.vibegram])
|
|
)
|
|
async with Client(server) as client:
|
|
(spec,) = await client.list_tools()
|
|
assert {"read", "send", "who", "claim", "release"} <= set(
|
|
spec.inputSchema["properties"]["action"]["enum"]
|
|
)
|
|
with pytest.raises(ToolError, match="text"):
|
|
await client.call_tool("vibegram", {"action": "send"})
|