fix(calendar): TZID Europe/Berlin for timed events/tasks, resolve real resource href on delete/update, fix _report_tasks XML; sync deployed servers (owamail, openwearables, ghostfolio), docs and tests

This commit is contained in:
Stefan Lohmaier committed 2026-10-01 04:29:57 +02:00
1 parent 7c01e7be53
commit 75185ef2ba
41 files changed
+8834 -324

No files matched your search

+219 -97
View File
@@ -13,6 +13,7 @@ Run: /opt/mcp-servers/venv/bin/python -m pytest /opt/mcp-servers/tests/test_all.
import json
import hashlib
import base64
import re
import secrets
import time
@@ -59,11 +60,11 @@ def get_token_pkce(port):
return r2.json()["access_token"]
def mcp_call(port, token, method, params=None):
def mcp_call(port, token, method, params=None, timeout=60):
r = httpx.post(f"http://127.0.0.1:{port}/mcp",
json={"jsonrpc": "2.0", "id": 1, "method": method, "params": params or {}},
headers={"Authorization": f"Bearer {token}", "Accept": "application/json, text/event-stream"},
timeout=60)
timeout=timeout)
assert r.status_code == 200, f"MCP {r.status_code}: {r.text[:200]}"
for line in r.text.split("\n"):
if line.startswith("data: "):
@@ -71,8 +72,8 @@ def mcp_call(port, token, method, params=None):
return None
def tool_call(port, token, tool_name, arguments=None):
result = mcp_call(port, token, "tools/call", {"name": tool_name, "arguments": arguments or {}})
def tool_call(port, token, tool_name, arguments=None, timeout=60):
result = mcp_call(port, token, "tools/call", {"name": tool_name, "arguments": arguments or {}}, timeout=timeout)
assert result and "error" not in result, f"Error: {result}"
content = result["result"]["content"]
assert len(content) > 0
@@ -229,125 +230,203 @@ class TestMail:
# ============================================================
# Calendar Tests (CRUD on calendar-test)
# Calendar Tests (CRUD on calendar-test + calendar-test-second)
# Baikal mcptest-Backend. Nur MCP-Methoden, kein direkter DAV-Zugriff.
# Selbstreinigend: alle erzeugten Events/Tasks werden am Ende geloescht.
# ============================================================
import re as _re
def _extract_uids(text):
"""Alle UIDs (uuid-Format) aus einem MCP-Textauszug extrahieren."""
return _re.findall(r"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}", text)
class TestCalendar:
PORT = SERVERS["calendar"]
TEST_CAL = "calendar-test"
CAL1 = "calendar-test"
CAL2 = "calendar-test-second"
def test_list_calendars(self):
def test_list_calendars_both(self):
"""Beide Test-Kalender muessen sichtbar sein (klares Fehlerbild, wenn Backend fehlt)."""
text = tool_call(self.PORT, get_token(self.PORT), "list_calendars")
assert "calendar-test" in text or "MCP Test" in text
missing = [c for c in (self.CAL1, self.CAL2) if c not in text]
assert not missing, (
f"mcptest-Backend unvollstaendig: Kalender {missing} nicht in list_calendars. "
f"Pruefe Baikal (baikal.slohmaier.de, User mcptest) und config.json.")
def test_list_task_lists(self):
def test_list_task_lists_contains(self):
"""calendar-test ist auch Task-Liste (VEVENT+VTODO)."""
text = tool_call(self.PORT, get_token(self.PORT), "list_task_lists")
assert len(text) > 0
assert self.CAL1 in text or self.CAL2 in text, f"Keine Task-Liste sichtbar: {text[:200]}"
def test_create_and_find_event(self):
def test_create_update_delete_event_full_fields(self):
token = get_token(self.PORT)
tag = f"mcptest-{int(time.time())}"
# Create
result = tool_call(self.PORT, token, "create_event", {
"calendar": self.TEST_CAL,
"title": f"Test Event {tag}",
"start": "2026-12-25T10:00",
"end": "2026-12-25T11:00",
"location": "Testort",
"description": "Automatischer Test",
})
assert "erstellt" in result.lower() or "created" in result.lower(), f"Create failed: {result}"
tag = f"McpFeldtest-{int(time.time())}"
created = []
try:
r = tool_call(self.PORT, token, "create_event", {
"calendar": self.CAL1, "title": tag,
"start": "2026-12-25T10:00", "end": "2026-12-25T11:00",
"location": "Marienplatz 1, Muenchen", "description": "Export Test Beschreibung",
"travel_minutes": 30, "travel_mode": "driving",
"travel_advisory": True, "reminder_minutes": 15,
})
assert "erstellt" in r.lower() or "created" in r.lower(), f"create_event failed: {r}"
found = tool_call(self.PORT, token, "search_events",
{"query": tag, "date_from": "2026-12-01", "date_to": "2026-12-31"})
assert tag in found, f"Event nach Create nicht auffindbar: {found[:300]}"
uids = _extract_uids(found)
assert uids, f"Keine UID im Create-Ergebnis: {found[:300]}"
uid = uids[0]
created.append((self.CAL1, uid))
# Search
found = tool_call(self.PORT, token, "search_events", {"query": tag})
assert tag in found, f"Event not found after create: {found[:200]}"
tag2 = f"{tag}-GEANDERT"
r = tool_call(self.PORT, token, "update_event", {
"calendar": self.CAL1, "uid": uid, "title": tag2,
"start": "2026-12-26T14:30", "end": "2026-12-26T15:30",
"location": "Hauptbahnhof Muenchen", "description": "Neue Beschreibung nach Update",
"travel_minutes": 45, "travel_mode": "transit",
"travel_advisory": True, "reminder_minutes": 30,
})
assert "aktualisiert" in r.lower() or "updated" in r.lower(), f"update_event failed: {r}"
found2 = tool_call(self.PORT, token, "search_events",
{"query": tag2, "date_from": "2026-12-01", "date_to": "2027-01-31"})
assert tag2 in found2, f"Event nach Update nicht auffindbar: {found2[:300]}"
assert "Hauptbahnhof" in found2, f"Ort nach Update fehlt: {found2[:300]}"
assert "Verkehrsmittel" in found2, f"travel_mode nach Update nicht angezeigt: {found2[:300]}"
finally:
for cal, uid in created:
try:
tool_call(self.PORT, token, "delete_event", {"calendar": cal, "uid": uid})
except Exception:
pass
def test_create_and_find_task(self):
def test_event_timezone_tzid(self):
"""Timed events muessen mit TZID (Europe/Berlin) gespeichert werden, nicht floating.
Regression 2026-09-30: floating DTSTART wurde von Baikal als UTC gelesen (+2h)."""
token = get_token(self.PORT)
tag = f"mcptask-{int(time.time())}"
result = tool_call(self.PORT, token, "create_task", {
"task_list": self.TEST_CAL,
"title": f"Test Task {tag}",
"due": "2026-12-31",
"priority": 5,
})
assert "erstellt" in result.lower() or "created" in result.lower(), f"Create failed: {result}"
tag = f"McpTz-{int(time.time())}"
created = []
try:
r = tool_call(self.PORT, token, "create_event", {
"calendar": self.CAL1, "title": tag,
"start": "2026-12-25T17:30", "end": "2026-12-25T19:15",
})
assert "erstellt" in r.lower() or "created" in r.lower(), f"create_event failed: {r}"
found = tool_call(self.PORT, token, "search_events",
{"query": tag, "date_from": "2026-12-01", "date_to": "2026-12-31"})
uids = _extract_uids(found)
assert uids, f"Keine UID: {found[:300]}"
created.append((self.CAL1, uids[0]))
assert re.search(r"T17:30:00[+-]0[12]:00", found), (
f"Event ohne Berlin-Offset (floating?) gespeichert: {found[:300]}")
finally:
for cal, uid in created:
try:
tool_call(self.PORT, token, "delete_event", {"calendar": cal, "uid": uid})
except Exception:
pass
tasks = tool_call(self.PORT, token, "get_tasks", {"task_list": self.TEST_CAL, "include_completed": True})
assert tag in tasks, f"Task not found: {tasks[:200]}"
def test_create_event_second_calendar(self):
"""Event in zweitem Kalender anlegen (Wechsel/Mehrfach-Test)."""
token = get_token(self.PORT)
tag = f"McpZweiter-{int(time.time())}"
created = []
try:
r = tool_call(self.PORT, token, "create_event", {
"calendar": self.CAL2, "title": tag,
"start": "2027-01-15T09:00", "end": "2027-01-15T10:00",
"location": "Marienplatz", "description": "Zweiter Kalender Test",
})
assert "erstellt" in r.lower() or "created" in r.lower(), f"create_event(second) failed: {r}"
found = tool_call(self.PORT, token, "search_events",
{"query": tag, "date_from": "2027-01-01", "date_to": "2027-02-01"})
uids = _extract_uids(found)
assert uids, f"Event in zweitem Kalender nicht auffindbar: {found[:300]}"
created.append((self.CAL2, uids[0]))
finally:
for cal, uid in created:
try:
tool_call(self.PORT, token, "delete_event", {"calendar": cal, "uid": uid})
except Exception:
pass
def test_get_events_date_range(self):
text = tool_call(self.PORT, get_token(self.PORT), "get_events", {
"calendar": "calendar-test", "date_from": "2026-06-01", "date_to": "2026-06-30",
})
assert "Wann:" in text or "Keine Termine" in text
def test_create_update_delete_task(self):
"""Aufgabe in calendar-test (VTODO) anlegen, aendern, loeschen."""
token = get_token(self.PORT)
tag = f"McpAufgabe-{int(time.time())}"
created = []
try:
r = tool_call(self.PORT, token, "create_task", {
"task_list": self.CAL1, "title": tag, "due": "2026-12-31", "priority": 5, "description": "Testbeschreibung",
})
assert "erstellt" in r.lower() or "created" in r.lower(), f"create_task failed: {r}"
tasks = tool_call(self.PORT, token, "get_tasks", {"task_list": self.CAL1, "include_completed": True})
assert tag in tasks, f"Task nach Create nicht auffindbar: {tasks[:300]}"
uids = _extract_uids(tasks)
assert uids, f"Keine UID bei Task: {tasks[:300]}"
uid = uids[0]
created.append(uid)
tag2 = f"{tag}-GEANDERT"
r = tool_call(self.PORT, token, "update_task", {
"task_list": self.CAL1, "uid": uid, "title": tag2, "due": "2026-12-30", "priority": 8, "description": "Update Notiz",
})
assert "aktualisiert" in r.lower() or "updated" in r.lower(), f"update_task failed: {r}"
tasks2 = tool_call(self.PORT, token, "get_tasks", {"task_list": self.CAL1, "include_completed": True})
assert tag2 in tasks2, f"Task nach Update nicht auffindbar: {tasks2[:300]}"
assert "Update Notiz" in tasks2, f"Task-Beschreibung nach Update fehlt: {tasks2[:300]}"
finally:
for uid in created:
try:
tool_call(self.PORT, token, "delete_task", {"task_list": self.CAL1, "uid": uid})
except Exception:
pass
# ============================================================
# Contacts Tests (CRUD on contacts-test)
# ============================================================
class TestContacts:
PORT = SERVERS["contacts"]
def test_search_real_contacts(self):
def test_search_contacts_read(self):
"""Read-only Smoke auf das Adressbuch (leer ok)."""
text = tool_call(self.PORT, get_token(self.PORT), "search_contacts", {"query": "Mustermann", "limit": 3})
assert "Mustermann" in text
assert isinstance(text, str), f"search_contacts Kaputt: {text}"
def test_search_empty(self):
text = tool_call(self.PORT, get_token(self.PORT), "search_contacts", {"query": "xyzzy_nobody_99"})
assert "Keine Kontakte" in text
def test_create_search_contact(self):
def test_create_update_delete_contact(self):
token = get_token(self.PORT)
tag = f"McpTest-{int(time.time())}"
result = tool_call(self.PORT, token, "create_contact", {
"name": f"{tag} Mustermann",
"email": f"{tag.lower()}@example.com",
"phone": "+49 170 0000000",
"organization": "MCP Tests GmbH",
"note": "Automatisch erstellt",
})
assert "erstellt" in result.lower() or "created" in result.lower(), f"Create failed: {result}"
tag = f"McpKontakt-{int(time.time())}"
created = []
try:
r = tool_call(self.PORT, token, "create_contact", {
"name": f"{tag} Mustermann", "email": "max@example.com",
"phone": "+49 170 0000000", "organization": "MCP Tests GmbH", "note": "Automatisch erstellt",
})
assert "erstellt" in r.lower() or "created" in r.lower(), f"create_contact failed: {r}"
found = tool_call(self.PORT, token, "search_contacts", {"query": tag, "limit": 5})
assert tag in found, f"Kontakt nach Create nicht auffindbar: {found[:300]}"
uids = _extract_uids(found)
assert uids, f"Keine UID bei Kontakt: {found[:300]}"
uid = uids[0]
created.append(uid)
found = tool_call(self.PORT, token, "search_contacts", {"query": tag})
assert tag in found, f"Contact not found: {found[:200]}"
tag2 = f"{tag}-GEANDERT"
r = tool_call(self.PORT, token, "update_contact", {
"uid": uid, "name": f"{tag2} Mustermann", "email": "neu@example.org",
"phone": "+49 171 999999", "organization": "Andere Firma", "note": "Update-Notiz",
})
assert "aktualisiert" in r.lower() or "updated" in r.lower(), f"update_contact failed: {r}"
found2 = tool_call(self.PORT, token, "search_contacts", {"query": tag2, "limit": 5})
assert tag2 in found2, f"Kontakt nach Update nicht auffindbar: {found2[:300]}"
assert "Andere Firma" in found2, f"Organisation nach Update fehlt: {found2[:300]}"
finally:
for uid in created:
try:
tool_call(self.PORT, token, "delete_contact", {"uid": uid})
except Exception:
pass
def test_get_contact_details(self):
token = get_token(self.PORT)
search = tool_call(self.PORT, token, "search_contacts", {"query": "Mustermann", "limit": 1})
if "Keine" in search:
pytest.skip("No contacts")
uid = [l for l in search.split("\n") if "UID:" in l][0].split("UID: ")[1].strip()
# get_contact returns list content, first element is text
result = mcp_call(self.PORT, token, "tools/call", {"name": "get_contact", "arguments": {"uid": uid}})
text = result["result"]["content"][0]["text"]
assert "Mustermann" in text
assert "UID:" in text
def test_set_and_read_photo(self):
# Foto setzen + zuruecklesen (get_contact liefert dann ImageContent)
token = get_token(self.PORT)
tag = f"PhotoTest{int(time.time())}"
tool_call(self.PORT, token, "create_contact", {"name": f"{tag} Bildmann", "email": f"{tag.lower()}@example.com"})
search = tool_call(self.PORT, token, "search_contacts", {"query": tag, "limit": 1})
uid = [l for l in search.split("\n") if "UID:" in l][0].split("UID:")[1].strip()
# 1x1 PNG
png_b64 = ("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwC"
"AAAAC0lEQVR42mNk+M8AAAMCAYAAAS+ZkAAAAABJRU5ErkJggg==")
res = tool_call(self.PORT, token, "set_contact_photo",
{"uid": uid, "image_base64": png_b64, "image_type": "png"})
assert "esetzt" in res.lower() or "set" in res.lower()
content = mcp_call(self.PORT, token, "tools/call",
{"name": "get_contact", "arguments": {"uid": uid}})["result"]["content"]
imgs = [c for c in content if c.get("type") == "image"]
assert imgs, f"Kein Bild in get_contact: {[c.get('type') for c in content]}"
assert imgs[0].get("mimeType", "").startswith("image/")
# ============================================================
# Files Tests (CRUD on /mcp-tests/)
# ============================================================
class TestFiles:
PORT = SERVERS["files"]
@@ -497,6 +576,49 @@ class TestNotes:
result = tool_call(self.PORT, token, "delete_note", {"note_id": note_id, "permanent": True})
assert "ENDGUELTIG" in result, f"Delete failed: {result}"
def test_attachment_crud(self):
"""Anhang-Zyklus: add -> list -> read -> update (Inhalt+Props) -> delete (inkl. Link-Cleanup)."""
token = get_token(self.PORT)
tag = f"mcptest-att-{int(time.time())}"
result = tool_call(self.PORT, token, "create_note", {
"notebook": self.TEST_NOTEBOOK, "title": f"Att {tag}", "body": "anfang",
})
assert "erstellt" in result.lower(), f"Create failed: {result}"
note_id = result.split("id: ")[1].rstrip(")").strip()
content = base64.b64encode(f"Hallo {tag}\n".encode()).decode()
res = tool_call(self.PORT, token, "add_attachment", {
"note_id": note_id, "filename": f"{tag}.txt", "content_base64": content,
})
assert "hinzugefuegt" in res.lower(), f"Add failed: {res}"
rid = res.split("resource id: ")[1].split(",")[0].strip()
listing = tool_call(self.PORT, token, "list_note_resources", {"note_id": note_id})
assert rid in listing and f"{tag}.txt" in listing, f"Listing mismatch: {listing}"
body = tool_call(self.PORT, token, "read_note", {"note_id": note_id})
assert f":/{rid}" in body, f"Link missing in body: {body}"
text = tool_call(self.PORT, token, "read_resource", {"resource_id": rid})
assert tag in text, f"Content mismatch: {text}"
new_content = base64.b64encode(f"Neu {tag}\n".encode()).decode()
upd = tool_call(self.PORT, token, "update_attachment", {
"resource_id": rid, "content_base64": new_content, "title": f"{tag}-neu.txt",
})
assert "ersetzt" in upd.lower(), f"Content update failed: {upd}"
text = tool_call(self.PORT, token, "read_resource", {"resource_id": rid})
assert f"Neu {tag}" in text, f"Content update not applied: {text}"
upd2 = tool_call(self.PORT, token, "update_attachment", {"resource_id": rid, "mime": "text/plain"})
assert "aktualisiert" in upd2.lower(), f"Props update failed: {upd2}"
dele = tool_call(self.PORT, token, "delete_attachment", {"resource_id": rid, "note_id": note_id})
assert "geloescht" in dele.lower(), f"Delete failed: {dele}"
assert f":/{rid}" not in tool_call(self.PORT, token, "read_note", {"note_id": note_id})
tool_call(self.PORT, token, "delete_note", {"note_id": note_id, "permanent": True})
# ============================================================
# File Type Tests (read_file auf vorbereiteten /testdata-Dateien)