Skip to content

Refactor: Architecture cleanup, performance fixes, and robust logging - #43

Merged
JacksonFergusonDev merged 11 commits into
mainfrom
fix/optimization
Feb 15, 2026
Merged

Refactor: Architecture cleanup, performance fixes, and robust logging#43
JacksonFergusonDev merged 11 commits into
mainfrom
fix/optimization

Conversation

@JacksonFergusonDev

Copy link
Copy Markdown
Owner

Summary

This PR addresses technical debt by enforcing strict separation of concerns between the CLI and Service layers, eliminating silent failures via robust logging, and optimizing resource-intensive operations.

Key Changes

🏗 Architecture & DRY

  • Service Logic Extraction: Moved OS-specific service checks (systemd/launchd) from cli.py to service.py. The CLI now queries the service module rather than executing system calls directly.
  • Registry Helper: Centralized registry parsing logic into system.get_registered_repos(), removing duplicated file-reading code across cli.py and daemon.py.

🚀 Performance

  • Optimized Sync: git pulsar sync now fetches only the specific branch history (refs/heads/wip/pulsar/*/<branch>) instead of the entire backup namespace, significantly reducing network usage.
  • Config Caching: Config.load() now caches the global configuration in memory, reducing disk I/O during the daemon's repetitive loop.
  • Non-Blocking Checks: Removed a blocking time.sleep(1.0) in the daemon's lock detection, allowing it to fail fast and proceed to other repositories instead of stalling the entire process.

🛡 Robustness & Logging

  • Silent Failures: Added logging to GitRepo methods (rev_parse, list_refs) and SystemStrategy (battery/notifications) that previously swallowed exceptions silently.
  • Error Granularity: The daemon now logs specific errors for timestamp retrieval and large file scans.

🧪 Tests

  • Fixed test fragility in test_cli.py regarding registry mocking.
  • Added a clear_config_cache fixture to prevent test pollution.
  • Critical Fix: Patched REGISTRY_FILE in test_setup_repo_triggers_identity_config to prevent tests from writing junk paths to the user's actual ~/.local/state/git-pulsar/registry.

Checklist

  • Tests pass locally (uv run pytest)
  • Linter checks pass
  • Manual verification of daemon logging

Moves the low-level `_is_service_enabled` logic from the presentation layer (`cli.py`) to the service management module (`service.py`).

This fixes a Separation of Concerns violation where the CLI was directly managing OS-specific system calls (systemd/launchd) instead of delegating to the appropriate backend module.
Extracts the repeated logic for reading and stripping lines from the registry file into a reusable `get_registered_repos` helper in `system.py`. Applied this helper across `cli.py` and `daemon.py`.
Replaces manual git plumbing in `daemon.py` with calls to `GitRepo` methods (`commit_tree`, `update_ref`) and `ops.get_backup_ref`. This ensures consistency in backup reference generation and reduces code duplication.
Adds logging to `GitRepo` methods (`rev_parse`, `list_refs`, `get_last_commit_time`) that previously swallowed exceptions silently. This improves visibility into git corruption or runtime errors.
Ensures that battery checks, notifications, and machine ID resolution failures are logged rather than silently ignored. This prevents cases where the daemon might drain the battery or fail to identify the machine without any trail.
Adds explicit logging to `_get_ref_timestamp` and `has_large_files` to catch and report specific errors instead of swallowing them.
Modifies the `sync_session` operation to fetch backup references only for the current branch, rather than fetching the entire backup namespace. This reduces network usage and fetch time.
Removes the 1-second `time.sleep` call when a git lock file is detected. The daemon will now fail fast for that specific repository and proceed to the next one, rather than blocking the entire loop.
Implements a caching mechanism in `Config.load` to read the global configuration file only once per process, significantly reducing disk I/O when iterating over multiple repositories in the daemon.
Updates `show_status` to use `system.get_registered_repos()` instead of manually parsing the registry file. This ensures consistent logic across the application and respects the new architectural boundary.
Updates the test suite to align with recent architectural and performance changes:
- test(ops): update sync test to expect optimized single-branch fetch.
- test(cli): mock `system.get_registered_repos` dependencies correctly.
- test(config): add fixture to clear global config cache between tests.
- test(git): add coverage for silent failure logging in `GitRepo`.
- fix(test): patch registry constant in `setup_repo` test to prevent leaking test paths into the user's real registry file.
@JacksonFergusonDev
JacksonFergusonDev merged commit d287325 into main Feb 15, 2026
4 checks passed
@JacksonFergusonDev
JacksonFergusonDev deleted the fix/optimization branch February 15, 2026 01:12
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