Skip to content

refactor(core): unify repository registry management and atomic file operations - #82

Merged
JacksonFergusonDev merged 1 commit into
mainfrom
refactor/unify-registry-management
Aug 22, 2026
Merged

refactor(core): unify repository registry management and atomic file operations#82
JacksonFergusonDev merged 1 commit into
mainfrom
refactor/unify-registry-management

Conversation

@JacksonFergusonDev

Copy link
Copy Markdown
Owner

Summary

This PR consolidates repository registry file operations and concurrency locking into a centralized, thread-safe, and process-safe API in system.py:

  1. Centralized Registry Management API:

    • Enhanced get_registered_repos(registry_path: Path | None = None) -> list[Path] to evaluate the registry path dynamically and safely handle non-existent files.
    • Added add_repo_to_registry(repo_path: Path | str, registry_path: Path | None = None) -> bool for atomic path registration with fcntl.LOCK_EX and duplicate prevention.
    • Added remove_repo_from_registry(repo_path: Path | str, registry_path: Path | None = None) -> bool for atomic path removal with fcntl.LOCK_EX, .tmp swap, and os.fsync.
    • Added write_registered_repos(repos: Sequence[Path | str], registry_path: Path | None = None) -> bool for atomic full-registry overwrites (used by doctor cleanup).
  2. Refactored Callers:

    • daemon.prune_registry: Simplified from ~40 lines of manual locking/swapping to a concise call to system.remove_repo_from_registry.
    • cli.setup_repo: Simplified registration logic using system.add_repo_to_registry.
    • cli.unregister_repo: Simplified removal logic using system.remove_repo_from_registry.
    • cli.doctor and cli.diagnostics: Replaced raw file reads and writes with system.write_registered_repos and system.get_registered_repos.
    • Removed duplicate import fcntl from daemon.py and cli.py.
  3. Automated Tests:

    • Added unit tests in tests/test_system.py covering path addition, deduplication, removal, atomic writing, and OSError resilience.
    • Verified property-based tests in tests/test_properties.py.

Verification

  • All 166 pytest tests passing locally.
  • Pre-commit hooks (ruff check, ruff format, mypy) passing cleanly.

…operations

- Add add_repo_to_registry, remove_repo_from_registry, and write_registered_repos in system.py
- Enhance get_registered_repos with dynamic registry path support and locking
- Replace ad-hoc registry file manipulations and locking in daemon.py and cli.py
- Remove redundant fcntl imports from daemon.py and cli.py
- Add unit tests for registry operations and error handling in test_system.py
@JacksonFergusonDev
JacksonFergusonDev merged commit ce0d8d8 into main Aug 22, 2026
7 checks passed
@JacksonFergusonDev
JacksonFergusonDev deleted the refactor/unify-registry-management branch August 22, 2026 19:05
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