refactor(hm-exec): Replace raw-string-literal job-state match with a typed classifier#124
Merged
markovejnovic merged 3 commits intoJun 10, 2026
Conversation
…w-string-literal-job-state-mat-6 # Conflicts: # crates/hm-exec/src/cloud/watch.rs
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.
The smell
The cloud watch loop decides whether a job's logs exist by round-tripping the
typed job state through
to_string()and matching the result against ahand-written set of string literals (
crates/hm-exec/src/cloud/watch.rs:113):This is stringly-typed flag matching. A typo in any literal compiles fine and
silently drops a job's logs, and there is no exhaustiveness check: when the
cloud adds a new
JobState, thismatches!keeps compiling and silently treatsthe new state as "no logs".
The change
harmont_cloudalready exposesjob.stateas a typed, exhaustiveJobStateenum (it onlyDisplays into those strings). This PR matches on theenum variants directly via a single named, documented predicate
job_logs_available(state: JobState) -> bool, placed alongside the file's otherhelpers and unit-tested. The string round-trip (
to_string()/as_str()) isremoved at this call site. Behavior is preserved exactly: the true set is
Running | Passed | Failed | TimedOut | Canceling | Canceled | TimingOut, andPending | Scheduled | Assigned | Skippedare false (matching the originalliteral set —
skippedwas deliberately excluded before and remains so).Because the predicate
matches everyJobStatevariant explicitly (nowildcard arm), adding a new cloud state becomes a compiler-visible change rather
than a silent miss.
Type-safety pattern
This applies the
ValueEnum/ typed-classifier doctrine seen in tools likeripgrep and fd: push known finite string sets behind a typed enum match so
typos can't compile and missing cases are caught by exhaustiveness checking,
instead of duplicating literal sets at each call site.
Testing note
Only
cargo check -p hm-execwas run locally (per task scope; the fullworkspace/TS build was not run). Note: the local sandbox has a pre-existing,
unrelated compile error in
crates/hm-exec/src/local/backend.rs(
ImageRegistry::opennow expectsNonZero<u64>, ahm-vmdependency skew)that reproduces on the base branch and is independent of this change — the
compiler reached and resolved
watch.rswith no diagnostics. Full CI runs onthis PR. Draft = needs review.