feat(M7): synchronisation différentielle CalDAV
Implémente la synchronisation des événements Pronote vers un calendrier CalDAV (Nextcloud) de façon idempotente et sécurisée. Production : - sync/serialization.py : sérialisation Lesson/Homework/SchoolEvent vers VEVENT, signature sémantique (exclut DTSTAMP/CREATED/LAST-MODIFIED), enveloppe VCALENDAR complète avec VERSION:2.0 et PRODID - sync/caldav.py : passerelle CalDAV isolant caldav>=1.3.0, résolution du calendrier via principal().calendars() avec boundary matching, upsert par UID (fetch-then-save), exceptions expurgées et __context__ propre, mot de passe non stocké en clair, context manager - sync/planner.py : calcul explicite du CalDAVSyncPlan (add/update/remove par comparaison de signatures sémantiques, routage par préfixe d'UID) - sync/executor.py : exécution du plan avec dry-run (aucune écriture), isolation des erreurs par événement, statut FAILED/SKIPPED/SUCCESS - sync/synchronizer.py : orchestration en trois phases (scan, plan, exécution), SKIPPED si CalDAV non configuré - sync/__init__.py : export synchronize() - sources/pronote/client.py : normalisation UID via normalize_pronote_uid/ generate_deterministic_uid (parité avec ical.py) - config/settings.py : CalDAVSettings durci (url SecretStr, validation HTTPS, allow_insecure_http pour localhost, serializer redact_url) Tests (381 passés, couverture 95.58%) : - tests/unit/test_sync_serialization.py (21 tests) - tests/unit/test_caldav_planner.py (16 tests) - tests/unit/test_caldav_executor.py (18 tests) - tests/unit/test_caldav_gateway.py (24 tests) - tests/unit/test_caldav_security.py (18 tests) - tests/unit/test_uid_equivalence.py (8 tests) - tests/integration/test_caldav_sync.py (11 tests, faux serveur en mémoire) - tests/conftest.py : fixtures partagées Documentation : - GUIDE_DEV_PYTHON.md §7 : API réelle caldav>=1.3.0, principal().calendars(), VCALENDAR complet, upsert par UID, pas d'état local, événements non gérés protégés, CalDAVSettings durci (SecretStr, HTTPS, allow_insecure_http) - TODO.md : M7 coché - .env.example : CALDAV_ALLOW_INSECURE_HTTP=false Co-authored-by: opencode/coder <coder@agents.invalid> Co-authored-by: opencode/test-engineer <test-engineer@agents.invalid> Co-authored-by: opencode/tech-writer <tech-writer@agents.invalid>
This commit is contained in:
@@ -23,6 +23,7 @@ from pronote_sync.models.agenda import Lesson, LessonStatus
|
||||
from pronote_sync.models.homework import Homework
|
||||
from pronote_sync.models.message import Message, MessageType
|
||||
from pronote_sync.utils.redaction import redact_exception
|
||||
from pronote_sync.utils.uid import generate_deterministic_uid, normalize_pronote_uid
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -270,6 +271,12 @@ class PronoteClient:
|
||||
def get_lessons(self, start: date, end: date) -> list[Lesson]:
|
||||
"""Récupère les cours via ``pronotepy`` (repli iCal).
|
||||
|
||||
Les UIDs des cours sont normalisés comme ceux du flux iCal via
|
||||
:func:`normalize_pronote_uid` afin que la même leçon produise le
|
||||
même identifiant quelle que soit la source ; en l'absence d'UID
|
||||
exploitable, un UID déterministe est généré via
|
||||
:func:`generate_deterministic_uid`.
|
||||
|
||||
Les exceptions ne sont pas attrapées : elles se propagent afin que
|
||||
l'appelant puisse détecter l'échec et déclencher le repli (ou une
|
||||
erreur explicite).
|
||||
@@ -288,9 +295,21 @@ class PronoteClient:
|
||||
lessons: list[Lesson] = []
|
||||
for lesson in client.lessons(start, end):
|
||||
content = lesson.content
|
||||
raw_uid = lesson.id
|
||||
if raw_uid:
|
||||
uid = normalize_pronote_uid(raw_uid)
|
||||
else:
|
||||
uid = generate_deterministic_uid(
|
||||
start=lesson.start,
|
||||
end=lesson.end,
|
||||
subject=lesson.subject.name if lesson.subject is not None else "",
|
||||
teachers=list(lesson.teacher_names or ()),
|
||||
rooms=list(lesson.classrooms or ()),
|
||||
group=lesson.group_name,
|
||||
)
|
||||
lessons.append(
|
||||
Lesson(
|
||||
id=lesson.id,
|
||||
id=uid,
|
||||
start=lesson.start,
|
||||
end=lesson.end,
|
||||
subject=lesson.subject.name if lesson.subject is not None else "",
|
||||
|
||||
Reference in New Issue
Block a user