Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b9a30bc02b
|
||
|
|
7508880485
|
||
|
|
1bad6949f0
|
No files matched your search
@@ -1,56 +0,0 @@
|
|||||||
name: CI Shared Jobs
|
|
||||||
|
|
||||||
on:
|
|
||||||
workflow_call:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
hadolint:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
|
|
||||||
- uses: hadolint/hadolint-action@06be81baf89a55ffd0e24b8f04a4185738dd3387 # v3.5.0
|
|
||||||
with:
|
|
||||||
dockerfile: pkg/Dockerfile
|
|
||||||
failure-threshold: warning
|
|
||||||
|
|
||||||
build-test:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4
|
|
||||||
- name: Build (cached)
|
|
||||||
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
file: pkg/Dockerfile
|
|
||||||
push: false
|
|
||||||
load: true
|
|
||||||
tags: ci-image:${{ github.sha }}
|
|
||||||
cache-from: type=gha
|
|
||||||
cache-to: type=gha,mode=max
|
|
||||||
- name: Smoke test (compile sanity)
|
|
||||||
run: docker run --rm --name mcp-ics-smoke-$(hostname) ci-image:${{ github.sha }} python -m compileall -q src/
|
|
||||||
|
|
||||||
pytest:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4
|
|
||||||
- name: Build (cached)
|
|
||||||
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
file: pkg/Dockerfile
|
|
||||||
push: false
|
|
||||||
load: true
|
|
||||||
tags: ci-image:${{ github.sha }}
|
|
||||||
cache-from: type=gha
|
|
||||||
cache-to: type=gha,mode=max
|
|
||||||
- name: Unit tests (pytest, in-image env with prod requirements)
|
|
||||||
run: >
|
|
||||||
docker run --rm ci-image:${{ github.sha }}
|
|
||||||
sh -c "pip install pytest --quiet && python -m pytest tests/ -q"
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
name: Nightly Rebuild
|
|
||||||
on:
|
|
||||||
schedule:
|
|
||||||
- cron: '0 0 * * *'
|
|
||||||
jobs:
|
|
||||||
ci:
|
|
||||||
uses: ./.gitea/workflows/_ci-common.yaml
|
|
||||||
secrets: inherit
|
|
||||||
build-push:
|
|
||||||
needs: [ci]
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4
|
|
||||||
- name: Login to Docker Hub
|
|
||||||
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4
|
|
||||||
with:
|
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
||||||
- id: get-latest-tag
|
|
||||||
name: Get latest tag
|
|
||||||
run: |
|
|
||||||
TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
|
|
||||||
echo "tag=$TAG" >> $GITHUB_OUTPUT
|
|
||||||
- id: meta
|
|
||||||
name: Docker metadata
|
|
||||||
uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6
|
|
||||||
with:
|
|
||||||
images: jcabillot/mcp-ics
|
|
||||||
tags: |
|
|
||||||
type=raw,value=${{ steps.get-latest-tag.outputs.tag }}-latest,enable=${{ steps.get-latest-tag.outputs.tag != '' }}
|
|
||||||
- name: Build and push
|
|
||||||
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
file: pkg/Dockerfile
|
|
||||||
push: true
|
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
|
||||||
pull: true
|
|
||||||
cache-from: type=gha
|
|
||||||
cache-to: type=gha,mode=max
|
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
name: Docker Build and Push
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches: [main]
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
schedule:
|
||||||
|
- cron: '0 0 * * *'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v6
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v4
|
||||||
|
|
||||||
|
- name: Login to Docker Hub
|
||||||
|
if: github.event_name != 'pull_request'
|
||||||
|
uses: docker/login-action@v4
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Docker metadata
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@v6
|
||||||
|
with:
|
||||||
|
images: jcabillot/mcp-caldav
|
||||||
|
tags: |
|
||||||
|
#type=ref,event=branch
|
||||||
|
#type=ref,event=pr
|
||||||
|
#type=sha
|
||||||
|
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
|
||||||
|
|
||||||
|
- name: Build and push
|
||||||
|
uses: docker/build-push-action@v7
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: pkg/Dockerfile
|
||||||
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
pull: true
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
name: Lint
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
branches: [main]
|
|
||||||
paths:
|
|
||||||
- 'pkg/Dockerfile'
|
|
||||||
- 'Dockerfile'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
hadolint:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Run hadolint
|
|
||||||
uses: hadolint/hadolint-action@06be81baf89a55ffd0e24b8f04a4185738dd3387 # v3.5.0
|
|
||||||
with:
|
|
||||||
dockerfile: pkg/Dockerfile
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
name: Main Release
|
|
||||||
on:
|
|
||||||
workflow_dispatch:
|
|
||||||
push:
|
|
||||||
branches: [main]
|
|
||||||
jobs:
|
|
||||||
ci:
|
|
||||||
uses: ./.gitea/workflows/_ci-common.yaml
|
|
||||||
secrets: inherit
|
|
||||||
build:
|
|
||||||
needs: [ci]
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4
|
|
||||||
- name: Build (cached)
|
|
||||||
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
file: pkg/Dockerfile
|
|
||||||
push: false
|
|
||||||
load: true
|
|
||||||
tags: jcabillot/mcp-ics:${{ github.sha }}
|
|
||||||
cache-from: type=gha
|
|
||||||
cache-to: type=gha,mode=max
|
|
||||||
tag:
|
|
||||||
needs: [build]
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
- name: Configure git auth
|
|
||||||
run: |
|
|
||||||
git remote set-url origin "https://x-access-token:${{ secrets.SA_TOKEN_ACTION_PUSH_TAGS }}@scm.cabillot.eu/perso/mcp-ics.git"
|
|
||||||
- name: Bump version and push tag
|
|
||||||
uses: anothrNick/github-tag-action@4ed44965e0db8dab2b466a16da04aec3cc312fd8 # v1.75.0
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.SA_TOKEN_ACTION_PUSH_TAGS }}
|
|
||||||
DEFAULT_BUMP: patch
|
|
||||||
RELEASE_BRANCHES: main
|
|
||||||
WITH_V: true
|
|
||||||
GIT_API_TAGGING: false
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
name: PR Checks
|
|
||||||
on:
|
|
||||||
workflow_dispatch:
|
|
||||||
pull_request:
|
|
||||||
branches: [main]
|
|
||||||
concurrency:
|
|
||||||
group: pr-${{ github.ref }}
|
|
||||||
cancel-in-progress: true
|
|
||||||
jobs:
|
|
||||||
ci:
|
|
||||||
uses: ./.gitea/workflows/_ci-common.yaml
|
|
||||||
secrets: inherit
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
name: Renovate
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
renovate:
|
|
||||||
uses: perso/gitea-pipelines/.gitea/workflows/renovate.yaml@main
|
|
||||||
secrets: inherit
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
name: Tag Release
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
tags: ['*']
|
|
||||||
jobs:
|
|
||||||
ci:
|
|
||||||
uses: ./.gitea/workflows/_ci-common.yaml
|
|
||||||
secrets: inherit
|
|
||||||
build-push:
|
|
||||||
needs: [ci]
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4
|
|
||||||
- name: Login to Docker Hub
|
|
||||||
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4
|
|
||||||
with:
|
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
||||||
- id: meta
|
|
||||||
name: Docker metadata
|
|
||||||
uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6
|
|
||||||
with:
|
|
||||||
images: jcabillot/mcp-ics
|
|
||||||
tags: |
|
|
||||||
type=ref,event=tag
|
|
||||||
type=ref,event=tag,suffix=-latest
|
|
||||||
- name: Build and push
|
|
||||||
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
file: pkg/Dockerfile
|
|
||||||
push: true
|
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
|
||||||
pull: true
|
|
||||||
cache-from: type=gha
|
|
||||||
cache-to: type=gha,mode=max
|
|
||||||
Vendored
+38
@@ -0,0 +1,38 @@
|
|||||||
|
pipeline {
|
||||||
|
environment {
|
||||||
|
registry = 'https://registry.hub.docker.com'
|
||||||
|
registryCredential = 'dockerhub_jcabillot'
|
||||||
|
dockerImage = 'jcabillot/mcp-caldav'
|
||||||
|
}
|
||||||
|
|
||||||
|
agent any
|
||||||
|
|
||||||
|
triggers {
|
||||||
|
cron('@midnight')
|
||||||
|
}
|
||||||
|
|
||||||
|
stages {
|
||||||
|
stage('Clone repository') {
|
||||||
|
steps{
|
||||||
|
checkout scm
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Build image') {
|
||||||
|
steps{
|
||||||
|
sh 'docker build --force-rm=true --no-cache=true --pull -t ${dockerImage} -f pkg/Dockerfile .'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Deploy Image') {
|
||||||
|
steps{
|
||||||
|
script {
|
||||||
|
withCredentials([usernamePassword(credentialsId: 'dockerhub_jcabillot', usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) {
|
||||||
|
sh 'docker login --username ${DOCKER_USER} --password ${DOCKER_PASS}'
|
||||||
|
sh 'docker push ${dockerImage}'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,8 +16,5 @@ RUN --mount=type=cache,target=/root/.cache/pip pip install -r requirements.txt
|
|||||||
# Copy the source code
|
# Copy the source code
|
||||||
COPY src/ ./src/
|
COPY src/ ./src/
|
||||||
|
|
||||||
# Copy tests (used by CI; harmless in production)
|
|
||||||
COPY tests/ ./tests/
|
|
||||||
|
|
||||||
# Command to run the MCP server
|
# Command to run the MCP server
|
||||||
CMD ["python", "src/server.py"]
|
CMD ["python", "src/server.py"]
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
[pytest]
|
|
||||||
testpaths = tests
|
|
||||||
addopts = -q
|
|
||||||
+2
-1
@@ -1,7 +1,8 @@
|
|||||||
|
mcp>=1,<2
|
||||||
fastmcp>=3,<4
|
fastmcp>=3,<4
|
||||||
python-dotenv>=1,<2
|
python-dotenv>=1,<2
|
||||||
uvicorn>=0.34,<1
|
uvicorn>=0.34,<1
|
||||||
starlette>=1.2,<2
|
starlette>=0.46,<1
|
||||||
icalendar>=7,<8
|
icalendar>=7,<8
|
||||||
recurring-ical-events>=3,<4
|
recurring-ical-events>=3,<4
|
||||||
python-dateutil>=2,<3
|
python-dateutil>=2,<3
|
||||||
+6
-8
@@ -35,15 +35,13 @@ CALDAV_DATA_PATH = os.environ.get("CALDAV_DATA_PATH", "")
|
|||||||
EXCLUDE_PATTERN = os.environ.get("EXCLUDE_PATTERN", "")
|
EXCLUDE_PATTERN = os.environ.get("EXCLUDE_PATTERN", "")
|
||||||
BIRTHDAY_PATTERN = os.environ.get("BIRTHDAY_PATTERN", r"^Anniversaire|^Anniv")
|
BIRTHDAY_PATTERN = os.environ.get("BIRTHDAY_PATTERN", r"^Anniversaire|^Anniv")
|
||||||
|
|
||||||
|
if not CALDAV_DATA_PATH:
|
||||||
|
raise ValueError("CALDAV_DATA_PATH environment variable is required.")
|
||||||
|
|
||||||
def _validate_startup_config(caldav_data_path: str = CALDAV_DATA_PATH) -> None:
|
logger.info("Starting MCP CalDAV server with data path: %s", CALDAV_DATA_PATH)
|
||||||
"""Validates required startup configuration, raising on missing values."""
|
if EXCLUDE_PATTERN:
|
||||||
if not caldav_data_path:
|
logger.info("Exclude pattern: %s", EXCLUDE_PATTERN)
|
||||||
raise ValueError("CALDAV_DATA_PATH environment variable is required.")
|
logger.info("Birthday pattern: %s", BIRTHDAY_PATTERN)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__" or os.environ.get("MCP_ICS_VALIDATE_ON_IMPORT") == "1":
|
|
||||||
_validate_startup_config()
|
|
||||||
|
|
||||||
# Compile patterns once at startup
|
# Compile patterns once at startup
|
||||||
_exclude_re: Optional[re.Pattern] = None
|
_exclude_re: Optional[re.Pattern] = None
|
||||||
|
|||||||
@@ -1,149 +0,0 @@
|
|||||||
"""Shared fixtures: a fake Radicale data tree on disk + pre-imported server module."""
|
|
||||||
|
|
||||||
import json
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import textwrap
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
REPO_ROOT = Path(__file__).resolve().parent.parent
|
|
||||||
sys.path.insert(0, str(REPO_ROOT / "src"))
|
|
||||||
|
|
||||||
|
|
||||||
def _write(path: Path, content: str) -> Path:
|
|
||||||
path.parent.mkdir(parents=True, exist_ok=True)
|
|
||||||
path.write_text(content, encoding="utf-8")
|
|
||||||
return path
|
|
||||||
|
|
||||||
|
|
||||||
def _cal_props(displayname: str = "", description: str = "") -> str:
|
|
||||||
props = {"tag": "VCALENDAR"}
|
|
||||||
if displayname:
|
|
||||||
props["D:displayname"] = displayname
|
|
||||||
if description:
|
|
||||||
props["C:calendar-description"] = description
|
|
||||||
return json.dumps(props)
|
|
||||||
|
|
||||||
|
|
||||||
ICS_HEADER = "BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:-//mcp-ics-test//EN\n"
|
|
||||||
ICS_FOOTER = "END:VCALENDAR\n"
|
|
||||||
|
|
||||||
|
|
||||||
def _ics(body: str) -> str:
|
|
||||||
return ICS_HEADER + body + ICS_FOOTER
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="module")
|
|
||||||
def radicale_tree(tmp_path_factory) -> Path:
|
|
||||||
"""A minimal Radicale collection-root layout covering edge cases."""
|
|
||||||
root = tmp_path_factory.mktemp("radicale")
|
|
||||||
cr = root / "collections" / "collection-root"
|
|
||||||
|
|
||||||
# user 'manuel', regular calendar
|
|
||||||
cal = cr / "manuel" / "perso"
|
|
||||||
_write(cal / ".Radicale.props", _cal_props("Perso manuel", "Agenda perso"))
|
|
||||||
_write(
|
|
||||||
cal / "abc.ics",
|
|
||||||
ICS_HEADER
|
|
||||||
+ (
|
|
||||||
"BEGIN:VEVENT\n"
|
|
||||||
"UID:evt-1@test\n"
|
|
||||||
"DTSTAMP:20260101T000000Z\n"
|
|
||||||
"DTSTART:20260315T090000\n"
|
|
||||||
"DTEND:20260315T100000\n"
|
|
||||||
"SUMMARY:Réunion équipe\n"
|
|
||||||
"LOCATION:Bureau\n"
|
|
||||||
"DESCRIPTION:Point hebdo\n"
|
|
||||||
"END:VEVENT\n"
|
|
||||||
)
|
|
||||||
+ ICS_FOOTER,
|
|
||||||
)
|
|
||||||
# recurring weekly event (10 occurrences)
|
|
||||||
_write(
|
|
||||||
cal / "recurring.ics",
|
|
||||||
ICS_HEADER
|
|
||||||
+ (
|
|
||||||
"BEGIN:VEVENT\n"
|
|
||||||
"UID:evt-rrule@test\n"
|
|
||||||
"DTSTAMP:20260101T000000Z\n"
|
|
||||||
"DTSTART:20260302T070000\n"
|
|
||||||
"DTEND:20260302T080000\n"
|
|
||||||
"RRULE:FREQ=WEEKLY;COUNT=10\n"
|
|
||||||
"SUMMARY:Présence matinale\n"
|
|
||||||
"END:VEVENT\n"
|
|
||||||
)
|
|
||||||
+ ICS_FOOTER,
|
|
||||||
)
|
|
||||||
# birthday (filtered by default via BIRTHDAY_PATTERN) + excluded summary
|
|
||||||
_write(
|
|
||||||
cal / "special.ics",
|
|
||||||
ICS_HEADER
|
|
||||||
+ (
|
|
||||||
"BEGIN:VEVENT\n"
|
|
||||||
"UID:birth-1@test\n"
|
|
||||||
"DTSTAMP:20260101T000000Z\n"
|
|
||||||
"DTSTART;VALUE=DATE:20260410\n"
|
|
||||||
"SUMMARY:Anniversaire Marc\n"
|
|
||||||
"END:VEVENT\n"
|
|
||||||
"BEGIN:VEVENT\n"
|
|
||||||
"UID:trash-1@test\n"
|
|
||||||
"DTSTAMP:20260101T000000Z\n"
|
|
||||||
"DTSTART:20260316T180000\n"
|
|
||||||
"SUMMARY:Poubelle verte\n"
|
|
||||||
"END:VEVENT\n"
|
|
||||||
)
|
|
||||||
+ ICS_FOOTER,
|
|
||||||
)
|
|
||||||
# VTODO on a second calendar
|
|
||||||
cal2 = cr / "manuel" / "taches"
|
|
||||||
_write(cal2 / ".Radicale.props", _cal_props("Tâches"))
|
|
||||||
_write(
|
|
||||||
cal2 / "todo.ics",
|
|
||||||
ICS_HEADER
|
|
||||||
+ (
|
|
||||||
"BEGIN:VTODO\n"
|
|
||||||
"UID:todo-1@test\n"
|
|
||||||
"DTSTAMP:20260101T000000Z\n"
|
|
||||||
"DUE:20260320T170000\n"
|
|
||||||
"STATUS:NEEDS-ACTION\n"
|
|
||||||
"SUMMARY:Ranger le garage\n"
|
|
||||||
"END:VTODO\n"
|
|
||||||
)
|
|
||||||
+ ICS_FOOTER,
|
|
||||||
)
|
|
||||||
# user 'robert' with a family calendar
|
|
||||||
cal3 = cr / "robert" / "famille"
|
|
||||||
_write(cal3 / ".Radicale.props", _cal_props("Famille"))
|
|
||||||
_write(cal3 / "x.ics", ICS_HEADER + ICS_FOOTER) # empty calendar
|
|
||||||
|
|
||||||
# VADDRESSBOOK (contacts) must be ignored
|
|
||||||
_write(cr / "robert" / "contacts" / ".Radicale.props", '{"tag": "VADDRESSBOOK"}')
|
|
||||||
# hidden dirs ignored
|
|
||||||
(cr / ".stfolder").mkdir(parents=True)
|
|
||||||
_write(cr / ".stfolder" / "x" / ".Radicale.props", '{"tag": "VCALENDAR"}')
|
|
||||||
(cr / "manuel" / ".trash").mkdir(parents=True)
|
|
||||||
_write(cr / "manuel" / ".trash" / "y.ics", ICS_HEADER + ICS_FOOTER)
|
|
||||||
# corrupt props must be skipped with a warning
|
|
||||||
_write(cr / "manuel" / "broken" / ".Radicale.props", "{not json")
|
|
||||||
_write(cr / "manuel" / "broken" / "z.ics", ICS_HEADER + ICS_FOOTER)
|
|
||||||
return root
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="module")
|
|
||||||
def server(radicale_tree):
|
|
||||||
"""Import the server module once per module with the fixture tree as data path."""
|
|
||||||
os.environ["CALDAV_DATA_PATH"] = str(radicale_tree)
|
|
||||||
os.environ["EXCLUDE_PATTERN"] = "^Poubelle"
|
|
||||||
os.environ["BIRTHDAY_PATTERN"] = "^Anniversaire|^Anniv"
|
|
||||||
import server # noqa: E402
|
|
||||||
|
|
||||||
return server
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
|
||||||
def server_mod(server, monkeypatch, radicale_tree):
|
|
||||||
"""Reset mutable module state around each test."""
|
|
||||||
monkeypatch.setattr(server, "CALDAV_DATA_PATH", str(radicale_tree))
|
|
||||||
return server
|
|
||||||
@@ -1,313 +0,0 @@
|
|||||||
"""Unit tests for mcp-ics server (pure functions, no server, no Docker)."""
|
|
||||||
|
|
||||||
import calendar as calmod
|
|
||||||
import logging
|
|
||||||
from datetime import date, datetime
|
|
||||||
|
|
||||||
import icalendar
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
import conftest # noqa: F401 (sys.path setup)
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------- discover_calendars
|
|
||||||
|
|
||||||
def test_discover_finds_calendars_with_names(server_mod, radicale_tree):
|
|
||||||
cals = server_mod.discover_calendars(str(radicale_tree))
|
|
||||||
by_path = {c["path"]: c for c in cals}
|
|
||||||
assert len(cals) == 3 # perso, taches, famille
|
|
||||||
assert by_path[str(radicale_tree / "collections/collection-root/manuel/perso")][
|
|
||||||
"name"
|
|
||||||
] == "Perso manuel"
|
|
||||||
assert by_path[str(radicale_tree / "collections/collection-root/manuel/taches")][
|
|
||||||
"name"
|
|
||||||
] == "Tâches"
|
|
||||||
assert by_path[str(radicale_tree / "collections/collection-root/robert/famille")][
|
|
||||||
"user"
|
|
||||||
] == "robert"
|
|
||||||
|
|
||||||
|
|
||||||
def test_discover_skips_vaddressbook_hidden_and_broken(server_mod, radicale_tree):
|
|
||||||
cals = server_mod.discover_calendars(str(radicale_tree))
|
|
||||||
paths = " ".join(c["path"] for c in cals)
|
|
||||||
assert "contacts" not in paths
|
|
||||||
assert ".stfolder" not in paths
|
|
||||||
assert ".trash" not in paths
|
|
||||||
assert "broken" not in paths
|
|
||||||
|
|
||||||
|
|
||||||
def test_discover_missing_collection_root(server, tmp_path):
|
|
||||||
assert server.discover_calendars(str(tmp_path / "nowhere")) == []
|
|
||||||
|
|
||||||
|
|
||||||
def test_discover_empty_path(server):
|
|
||||||
assert server.discover_calendars("") == []
|
|
||||||
|
|
||||||
|
|
||||||
def test_discover_defaults_displayname_to_dirname(server_mod, radicale_tree):
|
|
||||||
# taches cal has no explicit name in tree? it does: "Tâches". famille: "Famille".
|
|
||||||
# Build one WITHOUT displayname.
|
|
||||||
import json
|
|
||||||
|
|
||||||
cal = radicale_tree / "collections/collection-root/manuel/noname"
|
|
||||||
cal.mkdir(parents=True, exist_ok=True)
|
|
||||||
(cal / ".Radicale.props").write_text(json.dumps({"tag": "VCALENDAR"}))
|
|
||||||
try:
|
|
||||||
cals = server_mod.discover_calendars(str(radicale_tree))
|
|
||||||
noname = [c for c in cals if c["path"].endswith("noname")][0]
|
|
||||||
assert noname["name"] == "noname"
|
|
||||||
finally:
|
|
||||||
(cal / ".Radicale.props").unlink()
|
|
||||||
cal.rmdir()
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------- parse_ics_files
|
|
||||||
|
|
||||||
def test_parse_ics_files_reads_component(server_mod, radicale_tree):
|
|
||||||
path = radicale_tree / "collections/collection-root/manuel/perso"
|
|
||||||
cals = server_mod.parse_ics_files(str(path))
|
|
||||||
assert len(cals) == 3
|
|
||||||
types = {sub.name for cal in cals for sub in cal.subcomponents}
|
|
||||||
assert "VEVENT" in types
|
|
||||||
|
|
||||||
|
|
||||||
def test_parse_ics_files_skips_unparseable(server_mod, radicale_tree):
|
|
||||||
import json
|
|
||||||
|
|
||||||
cal = radicale_tree / "collections/collection-root/manuel/badics"
|
|
||||||
cal.mkdir(parents=True, exist_ok=True)
|
|
||||||
(cal / ".Radicale.props").write_text(json.dumps({"tag": "VCALENDAR"}))
|
|
||||||
(cal / "x.ics").write_bytes(b"NOT AN ICS FILE \xff\xfe at all")
|
|
||||||
cals = server_mod.parse_ics_files(str(cal))
|
|
||||||
assert cals == []
|
|
||||||
|
|
||||||
|
|
||||||
def test_parse_ics_files_empty_dir(server_mod, radicale_tree):
|
|
||||||
assert server_mod.parse_ics_files(str(radicale_tree / "does/not/exist")) == []
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------- component_to_dt
|
|
||||||
|
|
||||||
def test_component_to_dt_datetime_passthrough(server_mod):
|
|
||||||
dt = datetime(2026, 3, 15, 9, 0)
|
|
||||||
prop = icalendar.prop.vDatetime(dt)
|
|
||||||
assert server_mod.component_to_dt(prop) == dt
|
|
||||||
|
|
||||||
|
|
||||||
def test_component_to_dt_date_becomes_midnight(server_mod):
|
|
||||||
d = date(2026, 4, 10)
|
|
||||||
prop = icalendar.prop.vDate(d)
|
|
||||||
assert server_mod.component_to_dt(prop) == datetime(2026, 4, 10, 0, 0)
|
|
||||||
|
|
||||||
|
|
||||||
def test_component_to_dt_none(server_mod):
|
|
||||||
assert server_mod.component_to_dt(None) is None
|
|
||||||
assert server_mod.component_to_dt("not-a-date") is None
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------- format_dt
|
|
||||||
|
|
||||||
def test_format_dt(server_mod):
|
|
||||||
assert server_mod.format_dt(None) is None
|
|
||||||
d = date(2026, 4, 10)
|
|
||||||
assert server_mod.format_dt(d) == "2026-04-10"
|
|
||||||
dt = datetime(2026, 3, 15, 9, 0)
|
|
||||||
assert server_mod.format_dt(dt) == dt.isoformat()
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------- format_component (filters)
|
|
||||||
|
|
||||||
def _ven_event(summary, uid="x@test", dtstart=None):
|
|
||||||
if dtstart is None:
|
|
||||||
dtstart = datetime(2026, 3, 15, 9, 0)
|
|
||||||
ev = icalendar.cal.Event()
|
|
||||||
ev.add("uid", uid)
|
|
||||||
ev.add("dtstamp", datetime(2026, 1, 1, tzinfo=__import__("datetime").timezone.utc))
|
|
||||||
ev.add("dtstart", dtstart)
|
|
||||||
ev.add("summary", summary)
|
|
||||||
return ev
|
|
||||||
|
|
||||||
|
|
||||||
class TestFilters:
|
|
||||||
def test_exclude_pattern_hides_poubelle(self, server_mod):
|
|
||||||
comp = _ven_event("Poubelle verte")
|
|
||||||
assert server_mod.format_component(comp, "Perso") is None
|
|
||||||
|
|
||||||
def test_birthdays_excluded_by_default(self, server_mod):
|
|
||||||
comp = _ven_event("Anniversaire Marc", dtstart=date(2026, 4, 10))
|
|
||||||
assert server_mod.format_component(comp, "Perso") is None
|
|
||||||
|
|
||||||
def test_birthdays_included_on_demand(self, server_mod):
|
|
||||||
comp = _ven_event("Anniversaire Marc", dtstart=date(2026, 4, 10))
|
|
||||||
out = server_mod.format_component(comp, "Perso", include_birthdays=True)
|
|
||||||
assert out is not None
|
|
||||||
assert out["summary"] == "Anniversaire Marc"
|
|
||||||
|
|
||||||
def test_normal_event_passes_birthday_filter(self, server_mod):
|
|
||||||
comp = _ven_event("Réunion équipe")
|
|
||||||
assert server_mod.format_component(comp, "Perso") is not None
|
|
||||||
|
|
||||||
|
|
||||||
class TestOutput:
|
|
||||||
def test_event_shape(self, server_mod, radicale_tree):
|
|
||||||
cal_path = str(radicale_tree / "collections/collection-root/manuel/perso")
|
|
||||||
found = None
|
|
||||||
for cal in server_mod.parse_ics_files(cal_path):
|
|
||||||
for c in cal.subcomponents:
|
|
||||||
if str(c.get("UID", "")) == "evt-1@test":
|
|
||||||
found = c
|
|
||||||
out = server_mod.format_component(found, "Perso manuel")
|
|
||||||
assert out["type"] == "event"
|
|
||||||
assert out["summary"] == "Réunion équipe"
|
|
||||||
assert out["start"] == "2026-03-15T09:00:00"
|
|
||||||
assert out["end"] == "2026-03-15T10:00:00"
|
|
||||||
assert out["calendar"] == "Perso manuel"
|
|
||||||
assert out["uid"] == "evt-1@test"
|
|
||||||
assert out["location"] == "Bureau"
|
|
||||||
assert out["description"] == "Point hebdo"
|
|
||||||
assert "due" not in out
|
|
||||||
assert "status" not in out
|
|
||||||
|
|
||||||
def test_todo_shape(self, server_mod, radicale_tree):
|
|
||||||
cal_path = str(radicale_tree / "collections/collection-root/manuel/taches")
|
|
||||||
cal = server_mod.parse_ics_files(cal_path)[0]
|
|
||||||
todo = [c for c in cal.subcomponents if c.name == "VTODO"][0]
|
|
||||||
out = server_mod.format_component(todo, "Tâches")
|
|
||||||
assert out["type"] == "todo"
|
|
||||||
assert out["due"] == "2026-03-20T17:00:00"
|
|
||||||
assert out["status"] == "NEEDS-ACTION"
|
|
||||||
assert "end" not in out
|
|
||||||
|
|
||||||
def test_optional_fields_absent_when_empty(self, server_mod):
|
|
||||||
comp = _ven_event("Sans extras")
|
|
||||||
out = server_mod.format_component(comp, "C")
|
|
||||||
assert "location" not in out
|
|
||||||
assert "description" not in out
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------- get_events_in_range
|
|
||||||
|
|
||||||
class TestGetEventsInRange:
|
|
||||||
def test_range_aggregates_and_sorts(self, server_mod):
|
|
||||||
items = server_mod.get_events_in_range(
|
|
||||||
datetime(2026, 3, 15), datetime(2026, 3, 21)
|
|
||||||
)
|
|
||||||
summaries = [i["summary"] for i in items]
|
|
||||||
assert "Réunion équipe" in summaries
|
|
||||||
assert "Ranger le garage" in summaries # DUE 03-20 lands inside the window
|
|
||||||
# chronological order
|
|
||||||
starts = [i.get("start") or i.get("due") or "" for i in items]
|
|
||||||
assert starts == sorted(starts)
|
|
||||||
|
|
||||||
def test_rrule_expansion(self, server_mod):
|
|
||||||
# weekly event DTSTART 2026-03-02, COUNT=10 → occurrences 03-02..05-04
|
|
||||||
items = server_mod.get_events_in_range(
|
|
||||||
datetime(2026, 3, 2), datetime(2026, 5, 6)
|
|
||||||
)
|
|
||||||
recurring = [i for i in items if i["summary"] == "Présence matinale"]
|
|
||||||
assert len(recurring) == 10
|
|
||||||
first_days = sorted(i["start"][:10] for i in recurring)
|
|
||||||
# every occurrence lands on a Monday (DTSTART was a Monday)
|
|
||||||
assert all(
|
|
||||||
calmod.weekday(int(d[:4]), int(d[5:7]), int(d[8:10])) == 0
|
|
||||||
for d in first_days
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_birthday_only_with_flag(self, server_mod):
|
|
||||||
r1 = server_mod.get_events_in_range(
|
|
||||||
datetime(2026, 4, 10), datetime(2026, 4, 11), include_birthdays=False
|
|
||||||
)
|
|
||||||
assert all(i["summary"] != "Anniversaire Marc" for i in r1)
|
|
||||||
r2 = server_mod.get_events_in_range(
|
|
||||||
datetime(2026, 4, 10), datetime(2026, 4, 11), include_birthdays=True
|
|
||||||
)
|
|
||||||
assert any(i["summary"] == "Anniversaire Marc" for i in r2)
|
|
||||||
|
|
||||||
def test_calendars_aggregated_across_users(self, server_mod, radicale_tree):
|
|
||||||
# add an event to robert's calendar and check cross-aggregation
|
|
||||||
import json
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
cal_dir = radicale_tree / "collections/collection-root/robert/famille"
|
|
||||||
ics = cal_dir / "x.ics"
|
|
||||||
original = ics.read_text()
|
|
||||||
ics.write_text(
|
|
||||||
conftest.ICS_HEADER
|
|
||||||
+ "BEGIN:VEVENT\nUID:fam-1\nDTSTAMP:20260101T000000Z\n"
|
|
||||||
"DTSTART:20260317T120000\nDTEND:20260317T130000\n"
|
|
||||||
"SUMMARY:Souper famille\nEND:VEVENT\n"
|
|
||||||
+ conftest.ICS_FOOTER
|
|
||||||
)
|
|
||||||
try:
|
|
||||||
items = server_mod.get_events_in_range(
|
|
||||||
datetime(2026, 3, 17), datetime(2026, 3, 18)
|
|
||||||
)
|
|
||||||
summaries = {i["summary"]: i for i in items}
|
|
||||||
assert "Souper famille" in summaries
|
|
||||||
assert summaries["Souper famille"]["calendar"] == "Famille"
|
|
||||||
finally:
|
|
||||||
ics.write_text(original)
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------- get_agenda tool
|
|
||||||
|
|
||||||
class TestGetAgenda:
|
|
||||||
def test_end_date_default_plus_7_days(self, server_mod):
|
|
||||||
out = server_mod.get_agenda("2026-03-15")
|
|
||||||
assert out["start_date"] == "2026-03-15T00:00:00"
|
|
||||||
assert out["end_date"] == "2026-03-22T00:00:00"
|
|
||||||
assert out["count"] == len(out["items"])
|
|
||||||
|
|
||||||
def test_explicit_end_date(self, server_mod):
|
|
||||||
out = server_mod.get_agenda("2026-03-15", "2026-03-16")
|
|
||||||
assert out["end_date"] == "2026-03-16T00:00:00"
|
|
||||||
assert any(i["summary"] == "Réunion équipe" for i in out["items"])
|
|
||||||
|
|
||||||
def test_birthday_flag_forwarded(self, server_mod):
|
|
||||||
out = server_mod.get_agenda("2026-04-10", "2026-04-11", include_birthdays=True)
|
|
||||||
assert any(i["summary"] == "Anniversaire Marc" for i in out["items"])
|
|
||||||
out2 = server_mod.get_agenda("2026-04-10", "2026-04-11")
|
|
||||||
assert out2["items"] == []
|
|
||||||
|
|
||||||
def test_bad_date_returns_error_dict_not_raise(self, server_mod):
|
|
||||||
out = server_mod.get_agenda("pas-une-date")
|
|
||||||
assert "error" in out
|
|
||||||
assert "items" not in out
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------- startup config
|
|
||||||
|
|
||||||
def test_validate_startup_config_raises_when_empty(server_mod):
|
|
||||||
with pytest.raises(ValueError, match="CALDAV_DATA_PATH"):
|
|
||||||
server_mod._validate_startup_config("")
|
|
||||||
|
|
||||||
|
|
||||||
def test_validate_startup_config_accepts_value(server_mod):
|
|
||||||
server_mod._validate_startup_config("/some/path") # no exception
|
|
||||||
|
|
||||||
|
|
||||||
def test_invalid_exclude_pattern_degrades_without_crash(server_mod, caplog):
|
|
||||||
# simulate a broken pattern compile path via format_component reading None regex
|
|
||||||
with caplog.at_level(logging.ERROR, logger=server_mod.logger.name):
|
|
||||||
pass
|
|
||||||
# validate the guard exists: compile fails → regex stays None → filters not applied
|
|
||||||
import re
|
|
||||||
|
|
||||||
try:
|
|
||||||
re.compile("(bad-pattern")
|
|
||||||
raised = False
|
|
||||||
except re.error:
|
|
||||||
raised = True
|
|
||||||
assert raised # and server catches this in its startup block
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------- /health route
|
|
||||||
|
|
||||||
def test_health_endpoint(server):
|
|
||||||
from starlette.testclient import TestClient
|
|
||||||
|
|
||||||
app = server.mcp.http_app()
|
|
||||||
client = TestClient(app)
|
|
||||||
resp = client.get("/health")
|
|
||||||
assert resp.status_code == 200
|
|
||||||
assert resp.json() == {"status": "ok"}
|
|
||||||
Reference in new issue
Block a user