import pytest from pydantic import BaseModel from backend.tools.mcp.server import mcp, TOOLS class TestToolRegistration: """ Check that all tools from TOOLS are registered in MCP and available. """ @pytest.mark.asyncio async def test_all_tools_registered(self) -> None: tools = await mcp.list_tools() registered = {t.name for t in tools} expected = {tool["name"] for tool in TOOLS} assert expected == registered @pytest.mark.asyncio @pytest.mark.parametrize("tool", TOOLS, ids=[t["name"] for t in TOOLS]) async def test_each_tool_is_registered(self, tool) -> None: tools = await mcp.list_tools() registered = {t.name for t in tools} assert tool["name"] in registered class TestToolsConfig: """ Check that the tools have the correct structure, without duplicates, with Pydantic schema and correct 'remove_keys'. """ def test_all_tools_have_required_keys(self) -> None: for tool in TOOLS: assert "name" in tool assert "route" in tool assert "schema" in tool @pytest.mark.parametrize("param", ["name", "route"]) def test_no_duplicate(self, param) -> None: params = [tool[param] for tool in TOOLS] assert len(params) == len(set(params)) @pytest.mark.parametrize("tool", TOOLS, ids=[t["name"] for t in TOOLS]) def test_schema_is_pydantic(self, tool) -> None: assert issubclass(tool["schema"], BaseModel) def test_court_id_removes_foto(self) -> None: tool = next(t for t in TOOLS if t["name"] == "court_id") assert tool["remove_keys"] == ["foto"] def test_judge_search_removes_sudca_map_list(self) -> None: tool = next(t for t in TOOLS if t["name"] == "judge_search") assert tool["remove_keys"] == ["sudcaMapList"]