refactor(hm-vm): Magic "ephemeral" sentinel string passed through snapshot() label couples vm.rs and docker.rs#121
Merged
markovejnovic merged 1 commit intoJun 10, 2026
Conversation
…pshot() label couples vm.rs and docker.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.
Smell
Vm::snapshottook a&strlabelthat carried two orthogonal meanings plus an implicit grammar:vm.rs, when the caching policy wasCachingPolicy::None, the label was the literal magic string"ephemeral"; otherwise it was the cache key.docker.rs,snapshot()re-parsed that string as a mini-language:splitn(2, ':')to extractrepo:tag, treating a bare label (the"ephemeral"case) specially by tagging the commit with the container id.So a single
&strencoded (a) cache-key-vs-ephemeral-marker and (b) an implicitrepo:taggrammar. The producer (vm.rs) and consumer (docker.rs) had to agree on this convention out-of-band, and the"ephemeral"literal was duplicated across files where it could silently drift.Change
Introduce a typed
SnapshotLabelenum inhm-vm:Vm::snapshotnow takes&SnapshotLabelinstead of&str.vm.rsmapsCachingPolicy::None -> SnapshotLabel::EphemeralandCachingPolicy::Cache { key } -> SnapshotLabel::Cached(key.clone())— the"ephemeral"magic string is gone from the producer.Ephemeralcommits under the container-id tag;Cached(key)parsesrepo:tagfrom the key. The magic literal and thesplitnconvention become a single typed contract.Behavior is preserved exactly: the ephemeral path still tags with the container id, and the cached path still splits on the first
:(split_once(':')matches the oldsplitn(2, ':')semantics, including bare keys falling back to the container-id tag).Type-safety pattern
Applies fd's "Token/Template enums for a mini-language instead of raw strings" pattern, and the general "parse once into a typed value" doctrine: the ephemeral-vs-cached distinction is now a compiler-checked enum rather than an implicit naming convention shared across two files.
CI / validation note
Only
cargo check -p hm-vm(incl.--tests) was run locally, per the scope of this change; it passes. Full CI runs on this PR. The transformation is mechanical and behavior-preserving, but this is a draft pending review.