Skip to content

Handle Homebrew letter-suffix versions in --min-version - #23

Open
alexmikheen wants to merge 1 commit into
macadmins:mainfrom
alexmikheen:fix/letter-suffix-versions
Open

alexmikheen wants to merge 1 commit into
macadmins:mainfrom
alexmikheen:fix/letter-suffix-versions

Conversation

@alexmikheen

@alexmikheen alexmikheen commented Nov 17, 2026 •

Copy link
Copy Markdown

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.

Changes

  • parseBrewVersion splits a letter suffix from the base. alpha, beta, preview, pre, rc, and a/b followed 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). 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 very long number cannot overflow.
  • parseBrewVersion accepts exactly the strings go-version accepts (pinned by TestParseBrewVersionAcceptsSameAsGoVersion; 500,000 random strings showed no difference). A caller that validates a minimum with go-version therefore cannot hit a comparison error later.
  • The revision (_N) is stripped only from the installed version. A --min-version with a revision stays an error, as on main.
  • meetsMinimumFromOutput calls versionAtLeast once. Its error text changes from failed to parse installed version "X" for item "Y": … to failed to compare versions for item "Y": installed version "X": ….
  • Library API: the exported VersionMeetsOrExceedsMinimum follows the new order.
  • README: the comparison rules and the known differences from Homebrew.

Checked against Homebrew

Homebrew 7.0 Version#<=> (brew ruby), 2026-11-17:

  • 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, where Homebrew's own order is not transitive.
  • A grid of synthetic suffixes (including v and - forms): the remaining differences are mixed cases where Homebrew's order is not transitive (rc against c1, dev1 or ga6; a bare a/b against the same letter with a number, e.g. 1.0b3 < 1.0 < 1.0b but 1.0b3 >= 1.0b), plus one real difference: without a number Homebrew puts 1.0pre before 1.0preview, while carafe ranks preview first.
  • No version that parsed on main fails to parse now.

Tests

  • TestCompareBrewVersions: 53 cases (openssh, openssl@1.1, 1.0.2zk, tzdb-style 2025b, 4.5ga6, 2.1c1, dev1, revisions, long suffix numbers, a/b/alpha/beta/preview/pre/rc ordering and numbers, v prefix, hyphenated suffixes).
  • TestCompareBrewVersionsInvalid (incl. a minimum with a revision), TestParseBrewVersionAcceptsSameAsGoVersion.
  • All existing tests pass unchanged; go test -race, golangci-lint run (v2.6.2) and the coverage check pass. Coverage: 79.5% on main, 80.6% with this PR.

Live run as root on macOS (Homebrew 7.0) with borders 1.9.0 installed, check --munki-installcheck --skip-not-installed:

--min-version main this PR
1.9.0p1 (later release) 1 (compliant, wrong) 0 (install needed)
v1.9.0p1 1 (wrong) 0
1.9.0rc1 (pre-release) 1 1

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>
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