"""Tests for the MCP server."""
import pytest
from unittest.mock import patch, AsyncMock
from xcsift_mcp import __version__
class TestVersion:
"""Tests for version."""
def test_version_is_set(self):
"""Should have a version string."""
assert __version__ is not None
assert isinstance(__version__, str)
assert "0.1.0" in __version__
class TestAppContext:
"""Tests for application context."""
@pytest.mark.asyncio
async def test_lifespan_provides_xcsift_path(self):
"""Should provide xcsift path in lifespan context."""
from xcsift_mcp.server import app_lifespan, AppContext
# Mock ensure_xcsift
with patch(
"xcsift_mcp.server.ensure_xcsift",
new_callable=AsyncMock,
return_value="/usr/local/bin/xcsift",
):
# Create a mock FastMCP server
mock_server = AsyncMock()
async with app_lifespan(mock_server) as ctx:
assert isinstance(ctx, AppContext)
assert ctx.xcsift_path == "/usr/local/bin/xcsift"
@pytest.mark.asyncio
async def test_lifespan_raises_on_missing_xcsift(self):
"""Should raise error if xcsift cannot be found."""
from xcsift_mcp.server import app_lifespan
from xcsift_mcp.xcsift_installer import XcsiftNotFoundError
with patch(
"xcsift_mcp.server.ensure_xcsift",
new_callable=AsyncMock,
side_effect=XcsiftNotFoundError("xcsift not found"),
):
mock_server = AsyncMock()
with pytest.raises(XcsiftNotFoundError):
async with app_lifespan(mock_server):
pass
class TestMCPServer:
"""Tests for MCP server configuration."""
def test_server_has_name(self):
"""Should have server name set."""
from xcsift_mcp.server import mcp
assert mcp.name == "xcsift"
def test_server_has_instructions(self):
"""Should have instructions set."""
from xcsift_mcp.server import mcp
assert mcp.instructions is not None
assert "xcsift" in mcp.instructions.lower()