"""Tests for firmware MCP tools.

Tests tool registration, confirm gate for destructive operations,
and response format. Uses async mcp.list_tools() following the same
pattern as test_mcp_server.py.
"""

import inspect

from lc29h.mcp_server import firmware_update, mcp


class TestFirmwareToolRegistration:
    """Verify firmware tools are registered with the MCP server."""

    async def test_firmware_info_registered(self):
        """firmware_info tool should be registered."""
        tool_names = [t.name for t in await mcp.list_tools()]
        assert "firmware_info" in tool_names

    async def test_firmware_backup_registered(self):
        """firmware_backup tool should be registered."""
        tool_names = [t.name for t in await mcp.list_tools()]
        assert "firmware_backup" in tool_names

    async def test_firmware_update_registered(self):
        """firmware_update tool should be registered."""
        tool_names = [t.name for t in await mcp.list_tools()]
        assert "firmware_update" in tool_names

    async def test_firmware_verify_registered(self):
        """firmware_verify tool should be registered."""
        tool_names = [t.name for t in await mcp.list_tools()]
        assert "firmware_verify" in tool_names


class TestFirmwareToolCount:
    """Verify the total number of MCP tools hasn't changed unexpectedly."""

    async def test_tool_count(self):
        """Should have at least the 4 firmware tools + existing tools."""
        tools = await mcp.list_tools()
        # Existing: ~20 tools + 4 firmware tools = 24+
        assert len(tools) >= 24


class TestFirmwareUpdateConfirmGate:
    """The firmware_update tool MUST require confirm=True."""

    def test_tool_has_confirm_param(self):
        """firmware_update should have a 'confirm' parameter."""
        sig = inspect.signature(firmware_update)
        param_names = list(sig.parameters.keys())
        assert "confirm" in param_names
