Skip to content

Conversation

@JacksonFergusonDev
Copy link
Owner

Summary

This PR transitions git-pulsar from a prototype script to a robust system service. It standardizes file locations, type-checks configuration, and implements atomic file operations to prevent data corruption during power loss or concurrent access.

Key Changes

1. 📂 XDG Base Directory Compliance

  • Moved runtime state and logs out of ~ and into ~/.local/state/git-pulsar/ (or $XDG_STATE_HOME).
  • Files affected: src/constants.py, src/service.py.

2. 🛡️ Typed Configuration

  • Replaced the raw dictionary CONFIG with dataclasses (CoreConfig, LimitsConfig, etc.).
  • Eliminates KeyError risks at runtime and provides structural validation on load.
  • Files affected: src/daemon.py.

3. 📜 Standard Logging Implementation

  • Removed: Custom manual log() function and file rotation logic.
  • Added: Python's standard logging module with:
    • RotatingFileHandler for atomic log rotation.
    • Split-stream logging: stdout for interactive mode, stderr for systemd/launchd capture.
  • Files affected: src/daemon.py.

4. ⚛️ Atomic Registry Operations

  • Implemented an atomic "write-tmp-and-swap" pattern for prune_registry.
  • Ensures the registry file is never left in a truncated or zero-byte state if the daemon crashes mid-write.
  • Files affected: src/daemon.py.

5. 🧪 Test Suite Updates

  • Updated test_daemon.py to mock the new CONFIG object, isolating tests from the host machine's configuration.
  • Fixed a regression in test_properties.py related to newline handling in registry files.

Verification

  • Unit Tests: All tests passed (uv run pytest).
  • Property Tests: Hypothesis regression fixed.
  • Type Check: Config dataclasses validate correctly.

- Modifies `prune_registry` to write `clean_line + "\n"` instead of appending a newline to an existing line that already contains one.
- Prevents the registry file from growing with empty vertical whitespace after successive prune operations.
- Fixes `AssertionError` in `test_prune_registry_removes_only_target` by removing stale tests for the deprecated manual logging system.
- Updates `test_daemon.py` to explicitly mock `src.daemon.CONFIG`. This prevents tests from reading the developer's local `~/.config/git-pulsar/config.toml`, ensuring deterministic test results regardless of the host environment.
@JacksonFergusonDev JacksonFergusonDev merged commit 6c27eff into main Jan 19, 2026
2 checks passed
@JacksonFergusonDev JacksonFergusonDev deleted the last branch January 19, 2026 18:01
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.

2 participants