From 0b8a3aa6468d838e80e7c915da8dc0722139124d Mon Sep 17 00:00:00 2001 From: Chris Coutinho Date: Fri, 1 Aug 2025 09:29:15 +0200 Subject: [PATCH] Prepare calendar before running tests --- .github/workflows/test.yml | 11 +++++-- .../post-installation/install-calendar-app.sh | 30 +++++++++++++++++++ nextcloud_mcp_server/client/calendar.py | 22 +++++++++++--- 3 files changed, 57 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ce6a532..b3395c0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -89,12 +89,19 @@ jobs: attempt=$((attempt + 1)) if [ $attempt -ge $max_attempts ]; then echo "Calendar app not ready after $max_attempts attempts." + # Debug output + echo "Final calendar check response:" + curl -u admin:admin -v -X PROPFIND http://localhost:8080/remote.php/dav/calendars/admin exit 1 fi - echo "Calendar app attempt $attempt/$max_attempts: Not ready, sleeping for 3 seconds..." - sleep 3 + echo "Calendar app attempt $attempt/$max_attempts: Not ready, sleeping for 5 seconds..." + sleep 5 done echo "Calendar app is ready." + + # Additional verification - wait longer for CalDAV to be fully ready + echo "Waiting additional 10 seconds for CalDAV service to stabilize..." + sleep 10 echo "All required apps are installed and ready!" diff --git a/app-hooks/post-installation/install-calendar-app.sh b/app-hooks/post-installation/install-calendar-app.sh index 88cc244..e0c9d66 100755 --- a/app-hooks/post-installation/install-calendar-app.sh +++ b/app-hooks/post-installation/install-calendar-app.sh @@ -1,3 +1,33 @@ #!/bin/bash +set -e # Exit on any error + +echo "Installing and configuring Calendar app..." + +# Enable calendar app php /var/www/html/occ app:enable calendar + +# Wait for calendar app to be fully initialized +echo "Waiting for calendar app to initialize..." +sleep 10 + +# Ensure maintenance mode is off before calendar operations +php /var/www/html/occ maintenance:mode --off + +# Create a default calendar for the admin user (may already exist, ignore errors) +echo "Creating default calendar..." +php /var/www/html/occ dav:create-calendar admin personal "Personal" "Default personal calendar" || true + +# Sync DAV system to ensure proper initialization +echo "Syncing DAV system..." +php /var/www/html/occ dav:sync-system-addressbook + +# Repair calendar app to ensure proper setup +echo "Repairing calendar app..." +php /var/www/html/occ maintenance:repair --include-expensive + +# Final wait to ensure CalDAV service is fully ready +echo "Final CalDAV initialization wait..." +sleep 10 + +echo "Calendar app installation complete!" diff --git a/nextcloud_mcp_server/client/calendar.py b/nextcloud_mcp_server/client/calendar.py index f75278e..b75e5a9 100644 --- a/nextcloud_mcp_server/client/calendar.py +++ b/nextcloud_mcp_server/client/calendar.py @@ -1,5 +1,6 @@ """CalDAV client for NextCloud calendar operations.""" +import asyncio import xml.etree.ElementTree as ET import datetime as dt from typing import Dict, Any, List, Optional, Tuple @@ -45,10 +46,23 @@ class CalendarClient(BaseNextcloudClient): "Accept": "application/xml", } - response = await self._client.request( - "PROPFIND", caldav_path, content=propfind_body, headers=headers - ) - response.raise_for_status() + # Retry logic for CalDAV initialization issues + max_retries = 3 + for attempt in range(max_retries): + try: + response = await self._client.request( + "PROPFIND", caldav_path, content=propfind_body, headers=headers + ) + response.raise_for_status() + break + except HTTPStatusError as e: + if e.response.status_code == 401 and attempt < max_retries - 1: + logger.warning( + f"CalDAV auth failed (attempt {attempt + 1}/{max_retries}), retrying in 2s..." + ) + await asyncio.sleep(2) + continue + raise # Parse XML response root = ET.fromstring(response.content)