import carddav: a card in two address books is one card in both #35

Merged
jcoffey-dev merged 1 commits from fix/card-in-two-address-books into main 2026-10-30 15:13:52 +00:00
Owner

Roadmap item 11, part two: a contact in two address books goes into both, instead of failing on every run.

The archive keeps one row per card UID. When a CardDAV server lists the same card in two address books, the second INSERT used to fail on every run. Now:

  • The second book is added to the first row's address_book_ids.
  • sync_id_dav lets two server items point at one archive row. Older archives are rebuilt without that UNIQUE, keeping their rows.
  • If a card vanishes from one book while another book still holds it, only that book is taken off. The card is deleted when no book holds it any more.
  • Deleting an address book deletes only the cards no other book holds (db::cards::remove_book).
  • If the two copies differ, the one read last is kept.

Takeout doesn't need this: it puts every card in a single default book.

Tests:

  • tests/mock_import_carddav_books.rs runs in CI. It covers a card in two books, a re-run, the card leaving one book, coming back, its first book being deleted, and the card going away entirely. It fails on old main (failed: 1) and passes here.
  • The in-memory DAV server from mock_export_dav.rs moves to tests/fake_dav/, gaining multiget REPORT, DELETE and a configurable list of refused paths.
  • New unit tests cover the migration, items_for_local, and the book-set helpers. The old test that asserted the UNIQUE is replaced.
  • Live runs: integration_radicale, integration_baikal and integration_export_dav all pass. sync_carddav fails while provisioning its Stalwart server (FileNode/set rejects nodeType), before any import runs. That's a drift between that rig's image and its seed code, not this change.

Checks: fmt, clippy -D warnings, cargo test --locked (1480 passed).

Roadmap item 11, part two: a contact in two address books goes into both, instead of failing on every run. The archive keeps one row per card UID. When a CardDAV server lists the same card in two address books, the second INSERT used to fail on every run. Now: - The second book is added to the first row's `address_book_ids`. - `sync_id_dav` lets two server items point at one archive row. Older archives are rebuilt without that `UNIQUE`, keeping their rows. - If a card vanishes from one book while another book still holds it, only that book is taken off. The card is deleted when no book holds it any more. - Deleting an address book deletes only the cards no other book holds (`db::cards::remove_book`). - If the two copies differ, the one read last is kept. Takeout doesn't need this: it puts every card in a single default book. Tests: - `tests/mock_import_carddav_books.rs` runs in CI. It covers a card in two books, a re-run, the card leaving one book, coming back, its first book being deleted, and the card going away entirely. **It fails on old main (`failed: 1`) and passes here.** - The in-memory DAV server from `mock_export_dav.rs` moves to `tests/fake_dav/`, gaining multiget REPORT, DELETE and a configurable list of refused paths. - New unit tests cover the migration, `items_for_local`, and the book-set helpers. The old test that asserted the `UNIQUE` is replaced. - Live runs: `integration_radicale`, `integration_baikal` and `integration_export_dav` all pass. `sync_carddav` fails while provisioning its Stalwart server (`FileNode/set` rejects `nodeType`), before any import runs. That's a drift between that rig's image and its seed code, not this change. Checks: fmt, clippy `-D warnings`, `cargo test --locked` (1480 passed).
jcoffey-dev added 1 commit 2026-10-30 15:10:40 +00:00
import carddav: a card in two address books is one card in both
ci / test (pull_request) Skipped
github/ci (branch) GitHub Actions
ci / github (pull_request) Successful in 2m51s
ci / announce (pull_request) Skipped
974c7745cf
The archive keeps one row per card UID, so a CardDAV server that lists
the same card in two address books made the second INSERT fail, on every
run. The second book now joins the first row's address_book_ids, and
sync_id_dav lets two server items map to one local row (older archives
are rebuilt without that UNIQUE). A vanished item takes only its book
off a card another item still maps; deleting an address book deletes
only the cards no other book holds.

The in-memory DAV server from mock_export_dav moves to tests/fake_dav,
gaining multiget and DELETE, and drives a new import test that fails on
the old code.
jcoffey-dev merged commit 2861955315 into main 2026-10-30 15:13:52 +00:00
jcoffey-dev deleted branch fix/card-in-two-address-books 2026-10-30 15:13:52 +00:00
Sign in to join this conversation.