refactor(types): introduce strong typing for domain concepts - #84
Merged
Conversation
- Define git_pulsar.types containing domain enumerations (Preset, RepoStatus, DaemonStatus, SkipReason, ConfigSection), distinct identifiers (MachineId, MachineName, MachineSlug, GitRef, BranchName, GitOID, CommitSHA, TreeSHA, Seconds, ByteSize), and structured types (BatteryStatus, DiffStat, DriftState, RemoteDriftResult, BackupRefInfo). - Update config.py to use Preset, ConfigSection, ByteSize, and Seconds domain types. - Update git_wrapper.py to return strongly-typed BranchName, GitOID, TreeSHA, CommitSHA, DiffStat, and GitRef. - Update system.py to return BatteryStatus, MachineId, MachineSlug, and MachineName. - Update ops.py to return and accept domain identifiers and structured drift state results. - Update daemon.py to use SkipReason enum and GitRef. - Update cli.py to use DaemonStatus, RepoStatus, and GitRef. - Add test coverage in tests/test_types.py for all newly introduced domain types.
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.
Summary
Refactor raw primitive types (
str,int,bool, primitive tuples) used throughout the codebase into strongly typed domain representations. This eliminates primitive obsession and enhances static type safety across git operations, configuration parsing, background daemon workflows, telemetry, and CLI interactions.Key Changes
New Module
git_pulsar.types:enum.StrEnum):Preset: Fixed set of backup intensity presets (paranoid,aggressive,balanced,lazy).RepoStatus: Operational state of repositories (Active,Paused,Missing,Error,Unknown).DaemonStatus: Daemon process status (Active (Running),Active (Idle),Stopped).SkipReason: Explicit reasons for skipping backup iterations (Path missing,Paused by user,System under load,Battery critical).ConfigSection: Valid configuration sections (core,daemon,limits,files).typing.NewType):MachineId: Unique persistent machine UUID string.MachineName: User-assigned human-readable machine name.MachineSlug: Composite machine identifier ({name}--{short_id}).GitRef: Namespaced Git reference string.BranchName: Git branch name.GitOID: Generic 40-character Git object identifier.CommitSHA: Derived commit object identifier.TreeSHA: Derived tree object identifier.Seconds: Time intervals in seconds.ByteSize: File and log sizes in bytes.typing.NamedTuple/dataclass):BatteryStatus: Containspercent: intandis_plugged: boolwith full tuple unpacking backward compatibility.DiffStat: Containsfiles_changed: int,insertions: int,deletions: int.DriftState: Containslast_check_ts: float,warned_remote_ts: int.RemoteDriftResult: Containsdrift_detected: bool,newest_ts: int,newest_machine: MachineSlug | str,warning: str.BackupRefInfo: Strongly-typed dataclass for parsed backup refs.Refactored Modules:
git_pulsar/config.py: IntegratedPreset,ConfigSection,ByteSize, andSeconds.git_pulsar/git_wrapper.py: UpdatedGitRepomethods (current_branch,write_tree,commit_tree,diff_shortstat,list_refs,rev_parse) with domain types.git_pulsar/system.py: Updated platform strategies and identifier helpers to returnBatteryStatus,MachineId,MachineSlug, andMachineName.git_pulsar/ops.py: Updated reference parsing, remote drift detection, and state persistence with domain types.git_pulsar/daemon.py: Updated skip conditions and reference handlers withSkipReasonandGitRef.git_pulsar/cli.py: IntegratedDaemonStatus,RepoStatus, andGitReffor status and listing views.git_pulsar/__init__.py: Exportedtypesmodule.Tests & Verification:
tests/test_types.pycovering enums, newtypes, and structured data classes.