Skip to content

feat(core): implement composite identity and smart sync - #42

Merged
JacksonFergusonDev merged 8 commits into
mainfrom
feat/identity
Feb 14, 2026
Merged

feat(core): implement composite identity and smart sync#42
JacksonFergusonDev merged 8 commits into
mainfrom
feat/identity

Conversation

@JacksonFergusonDev

@JacksonFergusonDev JacksonFergusonDev commented Feb 14, 2026

Copy link
Copy Markdown
Owner

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

  • Composite Slugs: Backup references now use a {human_name}--{short_id} format (e.g., macbook--a1b2c3d4). This combines the stability of a hardware UUID with the readability of a hostname.
  • Identity Sync: When initializing or configuring a repo, Pulsar now runs git ls-remote to detect if the chosen name is already in use by another device on the remote.
  • Refactor: Centralized identity logic into src/git_pulsar/system.py for better cohesion.
  • Type Safety: Explicitly exported submodules in src/git_pulsar/__init__.py to resolve MyPy attr-defined errors.
  • Observability: Replaced silent try/except blocks with proper logger.exception calls to ensure daemon crashes produce stack traces.

Testing

  • Updated test_system.py to verify human-readable name persistence and correct skip logic.
  • Updated test_daemon.py to assert new refspec format.
  • Added test_fetch_remote_identities to verify ls-remote parsing.
  • Fixed registry leaks in test_cli.py by using temporary registry files during testing.
  • Verified git pulsar doctor reports log errors instead of swallowing them.

Checklist

  • Logic implementation
  • Tests updated & passing
  • Documentation updated
  • Static analysis (MyPy) passing

- 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.
@JacksonFergusonDev
JacksonFergusonDev merged commit f36190b into main Feb 14, 2026
4 checks passed
@JacksonFergusonDev
JacksonFergusonDev deleted the feat/identity branch February 14, 2026 08:07
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