mirror of
https://github.com/jmagar/unraid-mcp.git
synced 2026-03-02 00:04:45 -08:00
**Project Configuration:** - Enhance pyproject.toml with comprehensive metadata, keywords, and classifiers - Add LICENSE file (MIT) for proper open-source distribution - Add PUBLISHING.md with comprehensive publishing guidelines - Update .gitignore to exclude tool artifacts (.cache, .pytest_cache, .ruff_cache, .ty_cache) - Ignore documentation working directories (.docs, .full-review, docs/plans, docs/sessions) **Documentation:** - Add extensive Unraid API research documentation - API source code analysis and resolver mapping - Competitive analysis and feature gap assessment - Release notes analysis (7.0.0, 7.1.0, 7.2.0) - Connect platform overview and remote access documentation - Document known API patterns, limitations, and edge cases **Testing & Code Quality:** - Expand test coverage across all tool modules - Add destructive action confirmation tests - Improve test assertions and error case validation - Refine type annotations for better static analysis **Tool Improvements:** - Enhance error handling consistency across all tools - Improve type safety with explicit type annotations - Refine GraphQL query construction patterns - Better handling of optional parameters and edge cases This commit prepares the project for v0.2.0 release with improved metadata, comprehensive documentation, and enhanced code quality. Co-authored-by: Claude <noreply@anthropic.com>
104 lines
4.2 KiB
Python
104 lines
4.2 KiB
Python
"""Tests for unraid_array tool."""
|
|
|
|
from unittest.mock import AsyncMock, patch
|
|
|
|
import pytest
|
|
from conftest import make_tool_fn
|
|
|
|
from unraid_mcp.core.exceptions import ToolError
|
|
|
|
|
|
@pytest.fixture
|
|
def _mock_graphql() -> AsyncMock:
|
|
with patch("unraid_mcp.tools.array.make_graphql_request", new_callable=AsyncMock) as mock:
|
|
yield mock
|
|
|
|
|
|
def _make_tool():
|
|
return make_tool_fn("unraid_mcp.tools.array", "register_array_tool", "unraid_array")
|
|
|
|
|
|
class TestArrayValidation:
|
|
async def test_destructive_action_requires_confirm(self, _mock_graphql: AsyncMock) -> None:
|
|
tool_fn = _make_tool()
|
|
for action in ("start", "stop", "shutdown", "reboot"):
|
|
with pytest.raises(ToolError, match="destructive"):
|
|
await tool_fn(action=action)
|
|
|
|
async def test_disk_action_requires_disk_id(self, _mock_graphql: AsyncMock) -> None:
|
|
tool_fn = _make_tool()
|
|
for action in ("mount_disk", "unmount_disk", "clear_stats"):
|
|
with pytest.raises(ToolError, match="disk_id"):
|
|
await tool_fn(action=action)
|
|
|
|
|
|
class TestArrayActions:
|
|
async def test_start_array(self, _mock_graphql: AsyncMock) -> None:
|
|
_mock_graphql.return_value = {"setState": {"state": "STARTED"}}
|
|
tool_fn = _make_tool()
|
|
result = await tool_fn(action="start", confirm=True)
|
|
assert result["success"] is True
|
|
assert result["action"] == "start"
|
|
_mock_graphql.assert_called_once()
|
|
|
|
async def test_parity_start_with_correct(self, _mock_graphql: AsyncMock) -> None:
|
|
_mock_graphql.return_value = {"parityCheck": {"start": True}}
|
|
tool_fn = _make_tool()
|
|
result = await tool_fn(action="parity_start", correct=True)
|
|
assert result["success"] is True
|
|
call_args = _mock_graphql.call_args
|
|
assert call_args[0][1] == {"correct": True}
|
|
|
|
async def test_parity_history(self, _mock_graphql: AsyncMock) -> None:
|
|
_mock_graphql.return_value = {"array": {"parityCheckStatus": {"progress": 50}}}
|
|
tool_fn = _make_tool()
|
|
result = await tool_fn(action="parity_history")
|
|
assert result["success"] is True
|
|
|
|
async def test_mount_disk(self, _mock_graphql: AsyncMock) -> None:
|
|
_mock_graphql.return_value = {"mountArrayDisk": True}
|
|
tool_fn = _make_tool()
|
|
result = await tool_fn(action="mount_disk", disk_id="disk:1")
|
|
assert result["success"] is True
|
|
call_args = _mock_graphql.call_args
|
|
assert call_args[0][1] == {"id": "disk:1"}
|
|
|
|
async def test_shutdown(self, _mock_graphql: AsyncMock) -> None:
|
|
_mock_graphql.return_value = {"shutdown": True}
|
|
tool_fn = _make_tool()
|
|
result = await tool_fn(action="shutdown", confirm=True)
|
|
assert result["success"] is True
|
|
assert result["action"] == "shutdown"
|
|
|
|
async def test_stop_array(self, _mock_graphql: AsyncMock) -> None:
|
|
_mock_graphql.return_value = {"setState": {"state": "STOPPED"}}
|
|
tool_fn = _make_tool()
|
|
result = await tool_fn(action="stop", confirm=True)
|
|
assert result["success"] is True
|
|
assert result["action"] == "stop"
|
|
|
|
async def test_reboot(self, _mock_graphql: AsyncMock) -> None:
|
|
_mock_graphql.return_value = {"reboot": True}
|
|
tool_fn = _make_tool()
|
|
result = await tool_fn(action="reboot", confirm=True)
|
|
assert result["success"] is True
|
|
assert result["action"] == "reboot"
|
|
|
|
async def test_parity_pause(self, _mock_graphql: AsyncMock) -> None:
|
|
_mock_graphql.return_value = {"parityCheck": {"pause": True}}
|
|
tool_fn = _make_tool()
|
|
result = await tool_fn(action="parity_pause")
|
|
assert result["success"] is True
|
|
|
|
async def test_unmount_disk(self, _mock_graphql: AsyncMock) -> None:
|
|
_mock_graphql.return_value = {"unmountArrayDisk": True}
|
|
tool_fn = _make_tool()
|
|
result = await tool_fn(action="unmount_disk", disk_id="disk:1")
|
|
assert result["success"] is True
|
|
|
|
async def test_generic_exception_wraps(self, _mock_graphql: AsyncMock) -> None:
|
|
_mock_graphql.side_effect = RuntimeError("disk error")
|
|
tool_fn = _make_tool()
|
|
with pytest.raises(ToolError, match="disk error"):
|
|
await tool_fn(action="parity_history")
|