feat(core): implement composite identity and smart sync - #42
Merged
Conversation
- Moves identity configuration from `ops.py` to `system.py` for better cohesion. - Implements `get_identity_slug()` to generate `human-name--short-id` references. - Adds `_fetch_remote_identities()` to detect naming collisions via `git ls-remote`. - Updates `MACHINE_NAME_FILE` constant to persist the mutable human-readable name. - Updates `daemon` and `ops` to use the new composite slug for git references. This prevents device naming collisions and ensures backup references remain readable while maintaining a stable underlying machine ID.
- Updates `setup_repo` to invoke `system.configure_identity()`. - Passes the repository instance to `configure_identity` to enable remote discovery of existing machine names. This ensures that every new repository setup verifies or creates a valid machine identity before backups begin.
- Replaces bare `except Exception` blocks with specific exceptions where possible. - Updates `daemon.py` to use `logger.exception` for top-level errors, ensuring stack traces are captured in `daemon.log`. - Adds debug logging to `system.py` heuristics to expose why fallbacks occur. - Ensures `_fetch_remote_identities` logs warnings instead of failing silently. This improves observability and ensures that critical failures are not swallowed.
- Adds "Smart Identity" to the Features list. - Updates "Initialize & Identify" section to mention collision detection. - Removes "Identity Sync" from the Roadmap (Phase 3).
- Updates `test_daemon.py` to mock `system.get_identity_slug` instead of `get_machine_id`. - Fixes assertion logic in backup tests to expect composite slugs (`name--shortid`) in refspecs. - Updates `test_system.py` to verify persistence of human-readable machine names instead of raw UUIDs. - Fixes mocks in `test_cli.py` to align with the new `system.configure_identity` signature. This ensures the test suite accurately reflects the new identity architecture.
Explicitly imports and exports submodules in `src/git_pulsar/__init__.py`. This resolves `attr-defined` errors in MyPy where the `git_pulsar` package was not recognized as having attributes like `system` or `ops`.
Updates `test_configure_identity_skips_existing` to mock the `machine_name` file. Previously, only `machine_id` was mocked, causing the system to believe configuration was incomplete. This triggered an interactive prompt that failed because the mock console returned a MagicMock instead of a string.
Updates `test_setup_repo_triggers_identity_config` to use a temporary registry file. Previously, this test wrote temporary test paths to the user's actual `registry` file, causing the background daemon to trigger "missing repo" notifications when it garbage-collected the non-existent test directories.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR implements the "Smart Identity" system to prevent device naming collisions in distributed workflows. It solves the problem where multiple devices might default to the same hostname (e.g.,
macbook-pro) and overwrite each other's backup history.It also includes comprehensive test suite updates and type-hinting fixes to ensure stability.
Key Changes
{human_name}--{short_id}format (e.g.,macbook--a1b2c3d4). This combines the stability of a hardware UUID with the readability of a hostname.git ls-remoteto detect if the chosen name is already in use by another device on the remote.src/git_pulsar/system.pyfor better cohesion.src/git_pulsar/__init__.pyto resolve MyPyattr-definederrors.try/exceptblocks with properlogger.exceptioncalls to ensure daemon crashes produce stack traces.Testing
test_system.pyto verify human-readable name persistence and correct skip logic.test_daemon.pyto assert new refspec format.test_fetch_remote_identitiesto verifyls-remoteparsing.test_cli.pyby using temporary registry files during testing.git pulsar doctorreports log errors instead of swallowing them.Checklist