Files
syncthing-blade-mcp/tests/test_tools_config.py
T
PiersandClaude Fable 5 bf50002e8b AUD-04-02 — add write gate + confirm discipline (DD-385 Phase W)
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>
2026-06-11 23:20:48 +10:00

167 lines
5.6 KiB
Python

"""Tests for config mutation tools (pending, accept/reject, ignores)."""
import json
import pytest
from syncthing_mcp.models import (
AcceptDeviceInput,
AcceptFolderInput,
DeviceInput,
EmptyInput,
FolderInput,
RejectFolderInput,
SetDefaultIgnoresInput,
SetIgnoresInput,
)
from syncthing_mcp.registry import reload_instances
from tests.conftest import (
BASE_URL,
DEVICE_ID_LOCAL,
DEVICE_ID_REMOTE,
DEVICE_ID_REMOTE2,
FOLDER_ID,
make_system_status,
)
@pytest.fixture(autouse=True)
def _setup(single_instance_env):
reload_instances()
yield
reload_instances()
class TestPendingDevices:
async def test_empty(self, mock_api):
from syncthing_mcp.tools.config import syncthing_pending_devices
result = json.loads(await syncthing_pending_devices(EmptyInput()))
assert result["pendingDevices"] == {}
class TestPendingFolders:
async def test_empty(self, mock_api):
from syncthing_mcp.tools.config import syncthing_pending_folders
result = json.loads(await syncthing_pending_folders(EmptyInput()))
assert result["pendingFolders"] == {}
class TestAcceptDevice:
async def test_accept(self, mock_api, write_enabled_env):
from syncthing_mcp.tools.config import syncthing_accept_device
mock_api.get("/rest/cluster/pending/devices").respond(json={
DEVICE_ID_REMOTE2: {"name": "new-device", "address": "10.0.0.5"}
})
mock_api.get("/rest/config/defaults/device").respond(json={
"addresses": ["dynamic"],
})
mock_api.post("/rest/config/devices").respond(status_code=200, content=b"")
result = json.loads(await syncthing_accept_device(
AcceptDeviceInput(device_id=DEVICE_ID_REMOTE2, confirm=True)
))
assert result["status"] == "accepted"
assert result["name"] == "new-device"
class TestRejectDevice:
async def test_reject(self, mock_api, write_enabled_env):
from syncthing_mcp.tools.config import syncthing_reject_device
mock_api.delete("/rest/cluster/pending/devices").respond(status_code=200, content=b"")
result = json.loads(await syncthing_reject_device(
DeviceInput(device_id=DEVICE_ID_REMOTE2)
))
assert result["status"] == "rejected"
class TestAcceptFolder:
async def test_accept(self, mock_api, write_enabled_env):
from syncthing_mcp.tools.config import syncthing_accept_folder
mock_api.get("/rest/cluster/pending/folders").respond(json={
"new-folder": {
"offeredBy": {
DEVICE_ID_REMOTE: {"label": "Shared Docs"},
}
}
})
mock_api.get("/rest/config/defaults/folder").respond(json={
"path": "/home/user/Sync",
"type": "sendreceive",
})
mock_api.post("/rest/config/folders").respond(status_code=200, content=b"")
result = json.loads(await syncthing_accept_folder(
AcceptFolderInput(folder_id="new-folder", confirm=True)
))
assert result["status"] == "accepted"
assert result["label"] == "Shared Docs"
async def test_not_pending(self, mock_api, write_enabled_env):
from syncthing_mcp.tools.config import syncthing_accept_folder
result = json.loads(await syncthing_accept_folder(
AcceptFolderInput(folder_id="nonexistent", confirm=True)
))
assert "error" in result
class TestRejectFolder:
async def test_reject(self, mock_api, write_enabled_env):
from syncthing_mcp.tools.config import syncthing_reject_folder
mock_api.delete("/rest/cluster/pending/folders").respond(status_code=200, content=b"")
result = json.loads(await syncthing_reject_folder(
RejectFolderInput(folder_id="some-folder")
))
assert result["status"] == "rejected"
class TestGetIgnores:
async def test_get(self, mock_api):
from syncthing_mcp.tools.config import syncthing_get_ignores
mock_api.get("/rest/db/ignores").respond(json={
"ignore": ["*.tmp", ".DS_Store"],
"expanded": ["*.tmp", ".DS_Store"],
})
result = json.loads(await syncthing_get_ignores(FolderInput(folder_id=FOLDER_ID)))
assert len(result["patterns"]) == 2
class TestSetIgnores:
async def test_set(self, mock_api, write_enabled_env):
from syncthing_mcp.tools.config import syncthing_set_ignores
mock_api.post("/rest/db/ignores").respond(status_code=200, content=b"")
result = json.loads(await syncthing_set_ignores(
SetIgnoresInput(folder_id=FOLDER_ID, patterns=["*.log", "node_modules"], confirm=True)
))
assert result["status"] == "updated"
assert result["count"] == 2
class TestGetDefaultIgnores:
async def test_get(self, mock_api):
from syncthing_mcp.tools.config import syncthing_get_default_ignores
mock_api.get("/rest/config/defaults/ignores").respond(json={"lines": [".DS_Store"]})
result = json.loads(await syncthing_get_default_ignores(EmptyInput()))
assert result["lines"] == [".DS_Store"]
class TestSetDefaultIgnores:
async def test_set(self, mock_api, write_enabled_env):
from syncthing_mcp.tools.config import syncthing_set_default_ignores
mock_api.put("/rest/config/defaults/ignores").respond(
json={"lines": ["Thumbs.db"]},
headers={"content-type": "application/json"},
)
result = json.loads(await syncthing_set_default_ignores(
SetDefaultIgnoresInput(lines=["Thumbs.db"])
))
assert result["status"] == "updated"