Skip to content

fix(update): compare versions semantically, not as strings - #729

Merged
LeMyst merged 2 commits into
cooklang:mainfrom
drawmeanelephant:fix/718-semver-version-compare
Oct 17, 2026
Merged

LeMyst merged 2 commits into
cooklang:mainfrom
drawmeanelephant:fix/718-semver-version-compare

Conversation

@drawmeanelephant

Copy link
Copy Markdown
Contributor

Closes #718

cook update and cook doctor's update check compared version strings lexicographically: "0.38.9" >= "0.38.10", so crossing a digit-width boundary would hide the newer release. Both sites now go through version_is_newer, which parses with semver::Version (already in the dependency tree via self_update, now an optional dep of the self-update feature) and keeps the previous string ordering only as a fallback for unparseable values.

Test plan

  • cargo test update:: — new unit tests cover the 0.38.9→0.38.10 boundary, equality, and the unparseable fallback

@LeMyst LeMyst left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. This is correct:

  • semver 1.x is already in Cargo.lock through self_update, so no new crate version comes in. It is optional, behind self-update.
  • Both comparisons in update.rs are switched, and cook doctor's update check goes through check_for_updates, so it's fixed too.
  • Pre-release versions compare correctly, and an unparseable version falls back to the old order.

An option to consider: self_update::version::bump_is_greater(current, other) -> Result<bool> does the same comparison without a direct dependency. That would also avoid a Cargo.toml conflict.

Conflicts:

  • With #728 in src/update.rs: trivial, adjacent lines.
  • With #650, which is still open: both add to the self-update feature line (dep:sha2 there, dep:semver here), and both add a #[cfg(test)] mod tests at the end of update.rs, which must become one module. #650 still compares versions as strings, so this fix is still needed on top of it.

🤖 Analysis and recommendations made by Claude (Anthropic's AI assistant), posted on behalf of @LeMyst.

`cook update` and `cook doctor`'s version check ordered versions
lexicographically, so `0.38.9 >= 0.38.10` and the first release across
a digit-width boundary would report "already on the latest version".
Compare with `semver::Version` (already in the tree via `self_update`),
keeping the old string ordering only for unparseable values.

Closes #718
clippy::items_after_test_module denies items below the tests block;
get_target_triple sat under it.
@drawmeanelephant
drawmeanelephant force-pushed the fix/718-semver-version-compare branch from ba0c71b to 5854628 Compare October 15, 2026 23:46
@LeMyst

LeMyst commented Oct 17, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the rebase. I checked it again on 5854628:

  • version_is_newer gives the right answer for 0.9.0/0.10.0 and for equal versions.
  • Pre-releases order correctly: 0.40.0-rc.1 is older than 0.40.0 and newer than 0.39.0, and rc.10 is newer than rc.9.
  • It doesn't panic on empty or garbage input.
  • cook update --check-only still says "You are already on the latest version!" against v0.38.1.

It merges cleanly with main and looks good to merge.

One heads-up about #650, which also rewrites src/update.rs. Whichever of the two lands second has to resolve two textual conflicts: the self-update feature line in Cargo.toml, and the get_target_triple/release_platform hunk. Git also merges the end of src/update.rs without reporting a conflict, but leaves two #[cfg(test)] mod tests blocks, which fails to build with E0428. Folding these three tests into #650's module, whose use super::* covers version_is_newer, builds and passes. If this one lands first, I'll take care of that on #650.


🤖 Analysis and recommendations made by Claude (Anthropic's AI assistant), posted on behalf of @LeMyst.

@LeMyst
LeMyst merged commit 94d7162 into cooklang:main Oct 17, 2026
6 checks passed
@drawmeanelephant

Copy link
Copy Markdown
Contributor Author

Thanks — and since this landed first, the #[cfg(test)] mod tests double-up and the release_platform hunk are yours on #650; folding the three tests into its module is exactly the resolution.

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.

update and doctor compare versions as strings

2 participants