Skip to content

Conflict detection: classify local and remote changes #9

Description

@SashankBhamidi

src/calendaring_sync/conflict.py:

classify(key, local_content, remote_etag, remote_content) -> ChangeClass

resolve(key, change_class, local_content, remote_content, resolver_fn)

ChangeClass enum: REMOTE_ONLY, LOCAL_ONLY, CONFLICT, DELETED_REMOTE, DELETED_LOCAL, UNCHANGED

Four cases:

  1. Remote changed, local unchanged: server ETag differs from cached, local content matches cache. Safe to apply remote.
  2. Local changed, remote unchanged: local content differs from cache, server ETag matches cached. Safe to push local.
  3. Both changed: server ETag differs and local content differs from cache. Conflict. Surface to caller.
  4. Deleted on one side: one side has the object, the other doesn't. Surface to caller.

resolver_fn receives both versions and returns the content to keep, or raises ConflictError to abort. The library never merges or makes opinionated decisions. That's the caller's job.

Tests: one unit test per ChangeClass case. resolver_fn is called for CONFLICT, not called for REMOTE_ONLY or LOCAL_ONLY. ConflictError propagates cleanly.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions