Skip to content

refactor(hm-vm): Magic "ephemeral" sentinel string passed through snapshot() label couples vm.rs and docker.rs#121

Merged
markovejnovic merged 1 commit into
mainfrom
cq/hm-vm-magic-ephemeral-sentinel-string-passed-t-8
Jun 10, 2026
Merged

refactor(hm-vm): Magic "ephemeral" sentinel string passed through snapshot() label couples vm.rs and docker.rs#121
markovejnovic merged 1 commit into
mainfrom
cq/hm-vm-magic-ephemeral-sentinel-string-passed-t-8

Conversation

@markovejnovic

Copy link
Copy Markdown
Contributor

Smell

Vm::snapshot took a &str label that carried two orthogonal meanings plus an implicit grammar:

  • In vm.rs, when the caching policy was CachingPolicy::None, the label was the literal magic string "ephemeral"; otherwise it was the cache key.
  • In docker.rs, snapshot() re-parsed that string as a mini-language: splitn(2, ':') to extract repo:tag, treating a bare label (the "ephemeral" case) specially by tagging the commit with the container id.

So a single &str encoded (a) cache-key-vs-ephemeral-marker and (b) an implicit repo:tag grammar. 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 SnapshotLabel enum in hm-vm:

pub enum SnapshotLabel {
    Ephemeral,
    Cached(String),
}
  • Vm::snapshot now takes &SnapshotLabel instead of &str.
  • vm.rs maps CachingPolicy::None -> SnapshotLabel::Ephemeral and CachingPolicy::Cache { key } -> SnapshotLabel::Cached(key.clone()) — the "ephemeral" magic string is gone from the producer.
  • The Docker backend matches on the variant: Ephemeral commits under the container-id tag; Cached(key) parses repo:tag from the key. The magic literal and the splitn convention 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 old splitn(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.

@markovejnovic markovejnovic marked this pull request as ready for review June 10, 2026 19:20
@markovejnovic markovejnovic merged commit 50f3b97 into main Jun 10, 2026
17 checks passed
@markovejnovic markovejnovic deleted the cq/hm-vm-magic-ephemeral-sentinel-string-passed-t-8 branch June 10, 2026 19:20
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