[Debt] Consolidate duplicated calendar sync source finalization paths #14

Closed
opened 2026-07-13 17:21:08 +02:00 by zemion · 1 comment
Owner

Created from add-ideas/govoplan#3 after triaging /mnt/DATA/git/govoplan/audit-reports/govoplan-full-20260711-1857/jscpd/jscpd-report.json.

Evidence

jscpd reports calendar sync duplication in src/govoplan_calendar/backend/service.py, including:

  • lines 964-1001 and 1666-1703

The duplicated code updates sync status, scheduling, stats, notification/error handling, and source finalization. These paths are easy to drift across CalDAV, ICS/webcal, and due-sync flows.

Desired Shape

Extract narrow helpers for successful sync finalization, failed sync finalization, due-source result assembly, and notification emission where behavior is truly common.

Acceptance Criteria

  • CalDAV and ICS/webcal sync paths share common finalization helpers without obscuring protocol-specific behavior.
  • Error status, next_sync_at, notification emission, and session flush behavior are covered by tests.
  • Existing CalDAV/ICS sync tests pass.
  • jscpd no longer reports the listed service-level finalization clone.
Created from add-ideas/govoplan#3 after triaging `/mnt/DATA/git/govoplan/audit-reports/govoplan-full-20260711-1857/jscpd/jscpd-report.json`. ## Evidence jscpd reports calendar sync duplication in `src/govoplan_calendar/backend/service.py`, including: - lines 964-1001 and 1666-1703 The duplicated code updates sync status, scheduling, stats, notification/error handling, and source finalization. These paths are easy to drift across CalDAV, ICS/webcal, and due-sync flows. ## Desired Shape Extract narrow helpers for successful sync finalization, failed sync finalization, due-source result assembly, and notification emission where behavior is truly common. ## Acceptance Criteria - CalDAV and ICS/webcal sync paths share common finalization helpers without obscuring protocol-specific behavior. - Error status, `next_sync_at`, notification emission, and session flush behavior are covered by tests. - Existing CalDAV/ICS sync tests pass. - jscpd no longer reports the listed service-level finalization clone.
Author
Owner

Codex State: done

Summary

  • Extracted shared sync success/error finalization helpers for status, error, next-sync scheduling, stats token updates, calendar marking, and flushing.
  • Routed all-source and CalDAV-only due sync through a shared due-source runner that owns result assembly and notification emission.
  • Added regression coverage for ICS 304 success, ICS failure status/scheduling, and due-sync recovery notification emission.

Changed Files

  • src/govoplan_calendar/backend/service.py
  • tests/test_caldav.py
  • tests/test_sync_sources.py

Verification

  • python -m py_compile: calendar service and sync tests passed
  • python -m unittest tests.test_caldav tests.test_sync_sources: 23 passed
  • npx --yes jscpd --absolute --min-tokens 80 service.py: listed finalization/due-source clone removed; remaining clones are import-resource loops
  • python -m ruff check touched core/campaign/files/calendar files: passed
  • git diff --check in core/campaign/files/calendar: passed

Next / Blocked

  • Full-service jscpd still reports import-resource loop duplication between ICS and CalDAV import paths; this is outside the finalization clone tracked here and should be its own slice if desired.
## Codex State: done ### Summary - Extracted shared sync success/error finalization helpers for status, error, next-sync scheduling, stats token updates, calendar marking, and flushing. - Routed all-source and CalDAV-only due sync through a shared due-source runner that owns result assembly and notification emission. - Added regression coverage for ICS 304 success, ICS failure status/scheduling, and due-sync recovery notification emission. ### Changed Files - `src/govoplan_calendar/backend/service.py` - `tests/test_caldav.py` - `tests/test_sync_sources.py` ### Verification - `python -m py_compile: calendar service and sync tests passed` - `python -m unittest tests.test_caldav tests.test_sync_sources: 23 passed` - `npx --yes jscpd --absolute --min-tokens 80 service.py: listed finalization/due-source clone removed; remaining clones are import-resource loops` - `python -m ruff check touched core/campaign/files/calendar files: passed` - `git diff --check in core/campaign/files/calendar: passed` ### Next / Blocked - Full-service jscpd still reports import-resource loop duplication between ICS and CalDAV import paths; this is outside the finalization clone tracked here and should be its own slice if desired.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: add-ideas/govoplan-calendar#14
No description provided.