Repository navigation
Handle Homebrew letter-suffix versions in --min-version - #23
Open
alexmikheen wants to merge 1 commit into
Open
alexmikheen wants to merge 1 commit into
alexmikheen wants to merge 1 commit into
Conversation
go-version reads "10.2p1" as the pre-release "10.2-p1" and compares
"rc10" before "rc9", so --min-version=10.2 failed on openssh 10.2p1,
"1.1.1w" failed "1.1.1", x3270 "4.5ga6" failed "4.5", and an
installed rc10 failed a floor of rc9. Under --munki-installcheck
this made Munki run the upgrade on every run.
- parseBrewVersion splits a letter suffix from the base. alpha,
beta, preview, pre, rc, and "a"/"b" with a number are
pre-releases, ranked in that order; every other letter suffix is
a later release. versionAtLeast compares the base with go-version,
then the suffix kind (pre-release < none < later release), then
the rank or letters, then the number.
- A leading "v" and a "-" before the suffix take the same path, so
"v10.2p2" and "1.0-rc1" compare like "10.2p2" and "1.0rc1".
- Suffix numbers compare as digit strings, so rc10 > rc9, p10 > p9,
and a long number cannot overflow.
- parseBrewVersion accepts exactly the strings go-version accepts
(pinned by a test; 500,000 random strings gave no difference), so
a caller that validates a minimum with go-version cannot hit a
comparison error later.
- The revision is stripped only from the installed version. A
minimum with a revision stays an error, as before.
- meetsMinimumFromOutput calls versionAtLeast once. Its error text
changes to "failed to compare versions for item "<item>":
installed version "<v>": ...".
Checked against Homebrew 7.0 Version#<=> on 2026-11-17. For every
letter-suffix version in homebrew-core compared with its base, with
itself and with base+letters, one pair differs ("3.02a09" vs
"3.02a"). On a grid of synthetic suffixes the remaining differences
are mixed cases where Homebrew's own order is not transitive (rc
against c1, dev1 or ga6; a bare "a"/"b" against the same letter with
a number), plus one real difference: without a number Homebrew puts
"pre" before "preview", while carafe ranks "preview" first.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
go-version reads
10.2p1as the pre-release10.2-p1and comparesrc10beforerc9. So--min-version=10.2failed on openssh10.2p1,1.1.1wfailed1.1.1, x32704.5ga6failed4.5, and an installedrc10failed a floor ofrc9. Under--munki-installcheckthis made Munki run the upgrade on every run.Changes
parseBrewVersionsplits a letter suffix from the base.alpha,beta,preview,pre,rc, anda/bfollowed by a number are pre-releases, ranked in that order; every other letter suffix is a later release (10.2p1,1.1.1w,2025b,4.5ga6,1.0dev1).versionAtLeastcompares the base with go-version, then the suffix kind (pre-release < none < later release), then the rank or letters, then the number.vand a-before the suffix take the same path, sov10.2p2and1.0-rc1compare like10.2p2and1.0rc1.rc10>rc9,p10>p9, and a very long number cannot overflow.parseBrewVersionaccepts exactly the strings go-version accepts (pinned byTestParseBrewVersionAcceptsSameAsGoVersion; 500,000 random strings showed no difference). A caller that validates a minimum with go-version therefore cannot hit a comparison error later._N) is stripped only from the installed version. A--min-versionwith a revision stays an error, as onmain.meetsMinimumFromOutputcallsversionAtLeastonce. Its error text changes fromfailed to parse installed version "X" for item "Y": …tofailed to compare versions for item "Y": installed version "X": ….VersionMeetsOrExceedsMinimumfollows the new order.Checked against Homebrew
Homebrew 7.0
Version#<=>(brew ruby), 2026-11-17:3.02a09vs3.02a, where Homebrew's own order is not transitive.vand-forms): the remaining differences are mixed cases where Homebrew's order is not transitive (rcagainstc1,dev1orga6; a barea/bagainst the same letter with a number, e.g.1.0b3<1.0<1.0bbut1.0b3>=1.0b), plus one real difference: without a number Homebrew puts1.0prebefore1.0preview, while carafe rankspreviewfirst.mainfails to parse now.Tests
TestCompareBrewVersions: 53 cases (openssh, openssl@1.1,1.0.2zk, tzdb-style2025b,4.5ga6,2.1c1,dev1, revisions, long suffix numbers, a/b/alpha/beta/preview/pre/rc ordering and numbers,vprefix, hyphenated suffixes).TestCompareBrewVersionsInvalid(incl. a minimum with a revision),TestParseBrewVersionAcceptsSameAsGoVersion.go test -race,golangci-lint run(v2.6.2) and the coverage check pass. Coverage: 79.5% onmain, 80.6% with this PR.Live run as root on macOS (Homebrew 7.0) with
borders1.9.0 installed,check --munki-installcheck --skip-not-installed:--min-version1.9.0p1(later release)v1.9.0p11.9.0rc1(pre-release)