The blade had no write gate and no confirm parameter anywhere — every mutating tool (override, revert, restart, accept-device, replace-stignore, …) fired ungated, unlike every sibling blade. This brings syncthing up to the class baseline: - All 13 mutating tools now require SYNCTHING_WRITE_ENABLED=true (models.require_write, env read at call time) and refuse with a clear message when the gate is off. - Destructive/disruptive operations additionally require confirm=true: syncthing_override_folder, syncthing_revert_folder, syncthing_restart, syncthing_accept_device, syncthing_accept_folder, syncthing_set_ignores. Refusals explain what the operation would do. These six are now annotated destructiveHint: true. - New ConfirmWriteParams / ConfirmFolderWriteParams models; confirm field added to AcceptDeviceInput, AcceptFolderInput, SetIgnoresInput. - Server-level FastMCP instructions document the gate + confirm contract; README, SKILL.md, and stallari-plugin.yaml (setup field + env entry) updated to match. - Regression suite tests/test_write_gate.py: gated-off refusal (all 13, unset + non-"true" value), gated-on-without-confirm refusal (all 6 destructive), gated-on-with-confirm proceeds (mocked), and non-destructive-needs-no-confirm. Existing write-tool tests updated to enable the gate + pass confirm. 201 tests green. Version 0.8.0 → 0.9.0 (behaviour-affecting safety gate). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
150 lines
5.1 KiB
Python
150 lines
5.1 KiB
Python
"""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 ConfirmWriteParams, 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,
|
|
split_meta,
|
|
)
|
|
|
|
|
|
@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()))
|
|
# Concise mode truncates device ID to 8 chars
|
|
assert result["myID"] == DEVICE_ID_LOCAL[:8]
|
|
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["count"] == 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["count"] == 1
|
|
|
|
|
|
class TestClearErrors:
|
|
async def test_clear(self, mock_api, write_enabled_env):
|
|
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["count"] == 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"}}
|
|
])
|
|
payload, meta = split_meta(await syncthing_recent_changes(EmptyInput()))
|
|
result = json.loads(payload)
|
|
assert result["count"] == 1
|
|
assert meta["matched_total"] == 1
|
|
assert meta["returned"] == 1
|
|
assert meta["filtered_by"] == []
|
|
assert meta["redactions"] == []
|
|
|
|
|
|
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, write_enabled_env):
|
|
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(ConfirmWriteParams(confirm=True)))
|
|
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 result["upgradeCheck"] == "unavailable"
|
|
|
|
|
|
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"]["idle"] == 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"])
|