Skip to content

refactor: simplify sync logic and remove unused pydantic dependency#8

Merged
va1ha11a merged 16 commits into
mainfrom
fix/idempotency
Mar 2, 2026
Merged

refactor: simplify sync logic and remove unused pydantic dependency#8
va1ha11a merged 16 commits into
mainfrom
fix/idempotency

Conversation

@va1ha11a
Copy link
Copy Markdown
Contributor

@va1ha11a va1ha11a commented Mar 2, 2026

Summary

  • Removes the unused pydantic dependency (was never imported in the codebase)
  • Simplifies sync.py: removes the redundant remote setup block that duplicated what push_to_remote already does, simplifies the private_repo.close() call by dropping the unnecessary hasattr guard, and collapses the double return at the end into a single return
  • Simplifies the force-push expression: True if last_synced_sha else forceforce or bool(last_synced_sha)
  • Removes the standalone _decode_message helper and inlines the bytes/str decode at its two call sites
  • Simplifies find_last_synced_sha in marker.py to use next() with a walrus operator instead of a manual for loop

All 14 integration tests pass unchanged.

va1ha11a added 16 commits March 2, 2026 02:04
- Add hash verification (get_file_hashes, verify_sync_integrity)
- Add commit message marker parsing/appending (parse_marker,
  append_marker_to_commit, find_last_synced_sha)
- Add locking mechanism (check_sync_lock, acquire_sync_lock,
  release_sync_lock)
- Add corresponding unit tests
Split into:
- verify.py: hash verification (get_file_hashes, verify_sync_integrity)
- marker.py: commit message markers (parse_marker, append_marker_to_commit, find_last_synced_sha)
- lock.py: locking mechanism (check_sync_lock, acquire_sync_lock, release_sync_lock)
- sync.py: main sync logic, re-exports for backwards compatibility
- Remove __all__ re-export list from sync.py
- Update test imports to use new module locations
Add new CLI options:
- --marker-prefix: prefix for sync marker in commit messages (default: synced)
- --reset: reset sync state and re-sync all commits from beginning

Update sync() function signature to accept new parameters.
Add tests for:
- Marker in commit message
- Idempotent sync (no duplicates)
- New commits only on subsequent syncs
- Reset flag functionality
- Hash verification
- Lock checking

Some tests expected to fail until idempotency is wired in.
- Add locking check before sync
- Add marker rewriting after filter
- Add helper functions for finding last synced SHA
- Basic idempotency working (markers, no duplicates)
- Remaining: incremental sync (filter only new commits)
Production code:
- Remove _clone_commits_since (dead helper, logic already inline)
- Remove acquire_sync_lock / release_sync_lock (never called in production)
- Remove double fetch: check_sync_lock no longer fetches (caller does it)
- Remove extraneous fetch in push_to_remote dry-run path
- Use append_marker_to_commit from marker.py instead of inline duplicate
- Add _decode_message helper to deduplicate bytes/str decode pattern
- Remove last_synced_sha from SyncResult (was computed but never read)
- Replace SyncConfig Pydantic model with a simple _validate_branch helper
  (the model was a 1:1 pass-through adding a pydantic dependency with no
   real behaviour; the glob_translate validator accepted everything)

Tests:
- Add tests/integration/conftest.py with git_env fixture and run_git helper
- Update integration tests to use conftest instead of copy-pasted env blocks
- Fix test_verify_sync_integrity to use separate mocks per repo (was passing
  same mock as both private and public, not testing two-repo comparison)
- Fix test_sync_lock: remove tests for dead acquire/release stubs, add a
  meaningful third case (dest branch != lock branch)
- Fix reset test: assert marker present rather than SHA changed (SHAs are
  deterministic from identical content so the previous assertion was wrong)
@va1ha11a va1ha11a merged commit dce1682 into main Mar 2, 2026
10 checks passed
@va1ha11a va1ha11a deleted the fix/idempotency branch March 2, 2026 06:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant