refactor(hm-config): Replace stringly-typed backend: String with a closed enum#126
Merged
markovejnovic merged 5 commits intoJun 10, 2026
Conversation
…stringly-typed-backend-string-wi-23 # Conflicts: # crates/hm-config/src/lib.rs
…stringly-typed-backend-string-wi-23
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.
Smell
Config.backendwas a stringly-typedStringdefaulting to"docker"via adefault_backend()helper. The set of valid values is closed ("docker","cloud"), yet it was matched at consumer sites with string-literal comparisons (e.g.cfg.backend == "cloud"incrates/hm/src/commands/init.rs). A typo in either aconfig.tomlfile or a comparison would silently compile and mis-dispatch the run to the wrong backend.Change
crates/hm-config/src/lib.rs:#[serde(default)] pub backend: Backendand dropped thedefault_backend()string helper.Backend::as_str+Displayso call sites that still operate on the lowercase wire name (the existing--backend/--cloudstring resolution inrun/mod.rs) keep working unchanged and behavior-preserving.init.rswith an exhaustivematchthe compiler checks.hm-configandcrates/hm/tests/cmd_init.rsto assert against the enum.I deliberately did not add a clap
ValueEnumderive:hm-confighas no clap dependency today, and the--backendflag in thehmbinary remains anOption<String>resolved through the same lowercase names. Wiring clapValueEnumis left as a follow-up to keep this diff minimal.Pattern applied
ValueEnum / enum-over-stringly-typed for closed CLI choice setsplusparse-once at the boundary(reference: thefdCLI, which models closed choice sets as enums parsed at the argument/config boundary rather than carrying raw strings through the program). Invalid backend strings are now rejected at deserialize time instead of mis-dispatching later, comparisons become exhaustive matches, and adding a future backend variant forces every call site to be revisited.CI / verification note
Important
Only
cargo check -p hm-configwas run locally (per workflow scope). This worktree's base branch has a pre-existing, unrelated compile break inhm-config:save_toandcreds.rscallhm_util::os::fs::blocking::write_atomic_restrictedwith bare integer literals (0o644,0o700,0o600) where the currenthm-utilAPI expectsFileMode/DirModenewtypes. That break exists on the base commit (verified viagit stash) and is untouched by this PR. As a result the localcargo check -p hm-configdoes not go green, but no error is attributable to this refactor — the only diagnostics are the pre-existing newtype mismatch in code this PR does not modify. Opening as draft so a reviewer can confirm the refactor against a green base (full CI runs on this PR).