Wartung: Labels, leere Zeitstempel, Versionierung aus als Zustand, parallele Konfliktsuche

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Mikei386andClaude Opus 5.5 committed 2026-11-23 12:50:03 +01:00
1 parent b678f1da1c
commit f40ae55671
2 files changed
+37 -8

No files matched your search

+26 -6
View File
@@ -1,8 +1,11 @@
"""Maintenance tools: sync conflicts, archived file versions, folder statistics."""
import asyncio
import re
from typing import Any
import httpx
from syncthing_mcp.formatters import fmt, format_bytes, truncate
from syncthing_mcp.models import (
FindConflictsInput,
@@ -75,14 +78,19 @@ async def syncthing_find_conflicts(params: FindConflictsInput) -> str:
try:
client = get_instance(params.instance)
if params.folder_id:
folders = [{"id": params.folder_id, "label": params.folder_id}]
folders = [await client._get(f"/rest/config/folders/{params.folder_id}")]
else:
folders = await client._get("/rest/config/folders")
limiter = asyncio.Semaphore(3)
async def scan(folder_id: str) -> list[dict[str, Any]]:
async with limiter:
return find_conflicts(await client._get("/rest/db/browse", params={"folder": folder_id}))
found_per_folder = await asyncio.gather(*(scan(folder["id"]) for folder in folders))
result = []
total = 0
for folder in folders:
tree = await client._get("/rest/db/browse", params={"folder": folder["id"]})
found = find_conflicts(tree)
for folder, found in zip(folders, found_per_folder):
total += len(found)
if found:
result.append({
@@ -120,7 +128,19 @@ async def syncthing_list_versions(params: ListVersionsInput) -> str:
folder). Use with syncthing_restore_version. READ ONLY."""
try:
client = get_instance(params.instance)
versions = await client._get("/rest/folder/versions", params={"folder": params.folder_id})
try:
versions = await client._get("/rest/folder/versions", params={"folder": params.folder_id})
except httpx.HTTPStatusError as exc:
if "no versioner" not in exc.response.text:
raise
return fmt({
"instance": client.name,
"folder": params.folder_id,
"versioning": "off",
"files_with_versions": 0,
"files": [],
"hint": "File versioning is disabled for this folder; enable it in Syncthing to keep old versions.",
}, concise=params.concise)
files = sorted(
(path, items) for path, items in (versions or {}).items()
if path.startswith(params.path_prefix)
@@ -228,7 +248,7 @@ async def syncthing_folder_stats(params: FolderStatsInput) -> str:
"label": labels.get(folder_id, folder_id),
"last_scan": entry.get("lastScan"),
"last_file": last.get("filename") or None,
"last_file_at": last.get("at"),
"last_file_at": last.get("at") if last.get("filename") else None,
"last_file_deleted": bool(last.get("deleted")),
})
if params.folder_id and not rows:
+11 -2
View File
@@ -33,9 +33,11 @@ class TestFindConflicts:
async def test_finds_nested_conflicts_newest_first(self, mock_api):
from syncthing_mcp.tools.maintenance import syncthing_find_conflicts
mock_api.get(f"/rest/config/folders/{FOLDER_ID}").respond(json={"id": FOLDER_ID, "label": "Docs"})
mock_api.get("/rest/db/browse").respond(json=TREE)
result = json.loads(await syncthing_find_conflicts(FindConflictsInput(folder_id=FOLDER_ID)))
assert result["total_conflicts"] == 2
assert result["folders"][0]["label"] == "Docs"
items = result["folders"][0]["items"]
assert items[0]["conflict_file"] == "notes.sync-conflict-20261120-080000-CCCCCCC"
assert items[0]["original_file"] == "notes"
@@ -97,10 +99,17 @@ class TestVersions:
folder_id=FOLDER_ID, file="other.txt", version_time="2026-10-01T00:00:00Z", confirm=True)))
assert result["details"] == {"other.txt": "permission denied"}
async def test_versioning_disabled_is_a_tool_error(self, mock_api):
async def test_versioning_off_is_a_normal_result(self, mock_api):
from syncthing_mcp.tools.maintenance import syncthing_list_versions
mock_api.get("/rest/folder/versions").respond(status_code=500, text="no versioner configured")
mock_api.get("/rest/folder/versions").respond(status_code=500, text="folder has no versioner")
result = json.loads(await syncthing_list_versions(ListVersionsInput(folder_id=FOLDER_ID)))
assert result["versioning"] == "off"
async def test_other_version_errors_are_tool_errors(self, mock_api):
from syncthing_mcp.tools.maintenance import syncthing_list_versions
mock_api.get("/rest/folder/versions").respond(status_code=500, text="no such folder")
with pytest.raises(ToolError, match="500"):
await syncthing_list_versions(ListVersionsInput(folder_id=FOLDER_ID))