Refactor into package, add 6 new tools, add 96 tests

Split the monolithic syncthing_mcp.py into a proper src/syncthing_mcp/
package with focused modules: client, models, registry, server, and
tool submodules (system, folders, devices, config, instances).

New tools: browse_folder, file_info, folder_need (file-level queries),
override_folder, revert_folder (conflict resolution), check_upgrade
(system management). Bumps tool count from 30 to 36.

Adds comprehensive test suite (96 tests) using pytest + respx for
HTTP mocking, covering client methods, registry logic, model validation,
and all tool functions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Piers Dawson-DamerandClaude Opus 4.6 committed 2026-02-15 10:13:37 +11:00
1 parent 5b54c09cd5
commit 3a33d34bd1
26 files changed
+3398 -1897

No files matched your search

+142
View File
@@ -0,0 +1,142 @@
"""Tests for system tools (status, health, errors, log, restart, upgrade)."""
import json
import pytest
import respx
from httpx import Response
from syncthing_mcp.models import EmptyInput
from syncthing_mcp.registry import reload_instances
from tests.conftest import (
BASE_URL,
DEVICE_ID_LOCAL,
FOLDER_ID,
make_completion,
make_config,
make_connections,
make_db_status,
make_system_status,
make_version,
)
@pytest.fixture(autouse=True)
def _setup(single_instance_env):
reload_instances()
yield
reload_instances()
class TestSystemStatus:
async def test_returns_status(self, mock_api):
from syncthing_mcp.tools.system import syncthing_system_status
result = json.loads(await syncthing_system_status(EmptyInput()))
assert result["myID"] == DEVICE_ID_LOCAL
assert result["deviceName"] == "local-dev"
assert result["version"] == "v1.28.0"
assert result["instance"] == "default"
class TestSystemErrors:
async def test_no_errors(self, mock_api):
from syncthing_mcp.tools.system import syncthing_system_errors
result = json.loads(await syncthing_system_errors(EmptyInput()))
assert result["errorCount"] == 0
async def test_with_errors(self, mock_api):
from syncthing_mcp.tools.system import syncthing_system_errors
mock_api.get("/rest/system/error").respond(
json={"errors": [{"when": "2025-01-01", "message": "disk full"}]}
)
result = json.loads(await syncthing_system_errors(EmptyInput()))
assert result["errorCount"] == 1
class TestClearErrors:
async def test_clear(self, mock_api):
from syncthing_mcp.tools.system import syncthing_clear_errors
mock_api.post("/rest/system/error/clear").respond(status_code=200, content=b"")
result = json.loads(await syncthing_clear_errors(EmptyInput()))
assert result["status"] == "cleared"
class TestSystemLog:
async def test_returns_log(self, mock_api):
from syncthing_mcp.tools.system import syncthing_system_log
result = json.loads(await syncthing_system_log(EmptyInput()))
assert result["messageCount"] == 0
class TestRecentChanges:
async def test_returns_events(self, mock_api):
from syncthing_mcp.tools.system import syncthing_recent_changes
mock_api.get("/rest/events").respond(json=[
{"id": 1, "type": "LocalChangeDetected", "data": {"path": "file.txt"}}
])
result = json.loads(await syncthing_recent_changes(EmptyInput()))
assert result["eventCount"] == 1
class TestRestartRequired:
async def test_not_required(self, mock_api):
from syncthing_mcp.tools.system import syncthing_restart_required
result = json.loads(await syncthing_restart_required(EmptyInput()))
assert result["restartRequired"] is False
class TestRestart:
async def test_restart(self, mock_api):
from syncthing_mcp.tools.system import syncthing_restart
mock_api.post("/rest/system/restart").respond(status_code=200, content=b"")
result = json.loads(await syncthing_restart(EmptyInput()))
assert result["status"] == "restart_initiated"
class TestCheckUpgrade:
async def test_upgrade_available(self, mock_api):
from syncthing_mcp.tools.system import syncthing_check_upgrade
mock_api.get("/rest/system/upgrade").respond(json={
"latest": "v1.29.0", "newer": True, "majorNewer": False
})
result = json.loads(await syncthing_check_upgrade(EmptyInput()))
assert result["newer"] is True
assert result["latest"] == "v1.29.0"
assert result["running"] == "v1.28.0"
async def test_upgrade_disabled(self, mock_api):
from syncthing_mcp.tools.system import syncthing_check_upgrade
mock_api.get("/rest/system/upgrade").respond(status_code=501)
result = json.loads(await syncthing_check_upgrade(EmptyInput()))
assert "not available" in result["message"]
class TestHealthSummary:
async def test_all_good(self, mock_api):
from syncthing_mcp.tools.system import syncthing_health_summary
mock_api.get("/rest/db/status").respond(json=make_db_status())
result = json.loads(await syncthing_health_summary(EmptyInput()))
assert result["status"] == "good"
assert result["summary"]["foldersIdle"] == 1
async def test_error_state(self, mock_api):
from syncthing_mcp.tools.system import syncthing_health_summary
mock_api.get("/rest/system/error").respond(
json={"errors": [{"when": "now", "message": "bad"}]}
)
mock_api.get("/rest/db/status").respond(json=make_db_status())
result = json.loads(await syncthing_health_summary(EmptyInput()))
assert result["status"] == "error"
assert any("system error" in a for a in result["alerts"])