Repository navigation
Fail closed in check --munki-installcheck when the check errors - #22
Open
alexmikheen wants to merge 1 commit into
Open
alexmikheen wants to merge 1 commit into
alexmikheen wants to merge 1 commit into
Conversation
With --munki-installcheck, exit 1 means "nothing to do". Any error from check used to exit 1, so a broken brew, a formula from an untrusted tap (Homebrew tap trust), an unparseable installed version or a typo in --min-version looked compliant to Munki. - brew.Check returns the failing code for the selected mode on every error path (exit 0 under --munki-installcheck, 1 otherwise). Two paths returned the passing code. - The check command passes that code to main() through exitCodeError / exitCodeFor. Other commands still exit 1. - Argument errors (an invalid formula name, --skip-not-installed without --min-version, a --min-version that go-version cannot parse) take the same failing code, so a bad pkginfo makes the Munki item fail visibly. They wrap the new brew.ErrUsage and still print usage help. A revision such as "2.50.1_1" is rejected. - With --skip-not-installed, "No available formula with the name "<item>"" counts as not installed only when the Cellar has no keg for the item. This covers a typo, a formula removed from its tap and a tap that is not tapped, so they do not become "install needed" on every Mac; a keg that is still installed fails closed. The match is case-insensitive (brew prints the name in lower case) and only for the requested name, so a missing dependency or a formula file that cannot be loaded still fails closed. - Runtime check errors no longer print the usage text, and the error is printed once instead of twice. - cudo.MockOSFunc gets an optional StatFunc for per-path answers. - README: exit codes on error and the cases that still exit 1 (no Homebrew, no console user, an unparseable command line). 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.
With
--munki-installcheck, exit 1 means "nothing to do". Any error fromcheckused to exit 1, so a broken brew, a formula from an untrusted tap (Homebrew's tap trust), an unparseable installed version or a typo in--min-versionlooked compliant to Munki.Changes
brew.Checkreturns the failing code for the selected mode on every error path (0 under--munki-installcheck, 1 otherwise). Two paths returned the passing code.checkreturns anexitCodeErrorthat carries that code;main()uses it viaexitCodeFor. Other commands still exit 1 on error.--skip-not-installedwithout--min-version, and a--min-versionthat go-version cannot parse (a Homebrew revision such as2.50.1_1is rejected). They wrap a new exportedbrew.ErrUsageand still print usage help.--skip-not-installed, brew'sNo available formula with the name "<item>"counts as not installed only when<prefix>/Cellar/<name>does not exist. A typo, a formula removed from homebrew-core, or one from a tap that is not tapped no longer turns into "install needed" on every Mac, while a keg that is still in the Cellar (formula removed from its tap after install, or tap untapped with--force) fails closed. The match is case-insensitive (brew prints the name in lower case) and only for the requested name, so a missing dependency, or a formula file that exists but cannot be loaded, fails closed.main()prints it).cudo.MockOSFuncgets an optionalStatFuncfor per-path answers in tests.Behaviour changes to be aware of
carafe upgradefails on every run until the cause is fixed. Examples: brew broken after a macOS update, a stale API cache with no network, aHEAD-…install, or one of the ~20 core formulae whose version go-version cannot parse (such as x264r3222). Before, these were silently reported as compliant.--min-version, invalid name, missing--min-versionwith--skip-not-installed) now exits 0 under--munki-installcheck, also when the formula is not installed. Plain mode still exits 1.--munki-installcheck: no Homebrew at all, no console user (exec.NewConfigfails before the command runs), and a command line that cobra cannot parse (unknown flag, wrong number of arguments).--skip-not-installedand no keg in the Cellar now exits 0 with"installed": falseJSON (onmainit was an error, exit 1).brewpackage):Checkreturns the failing code on all error paths, including argument errors, andErrUsageis new.Behaviour (
--munki-installcheck)--skip-not-installed, no keg--skip-not-installed, keg still in Cellar--skip-not-installed--min-version/ invalid name / skip without minTests
brew/check_test.go:TestCheckErrorsFailClosed,TestCheckUnknownFormulaAndUsageErrors(mixed case, through the cache, untapped tap, keg still in the Cellar, broken formula file, dependency named in the error, usage errors in both modes).main_test.go:TestCheckCmd_CheckErrorExitCode,TestCheckCmd_SkipNotInstalledNeedsMinVersion,TestCheckCmd_InvalidFormulaNameExitCode,TestCheckCmd_InvalidMinVersionIsUsageError,TestCheckCmd_RuntimeErrorHasNoUsage(no usage text, no duplicate error),TestExitCodeFor.go test ./...,go test -race ./...,golangci-lint run(v2.6.2, Go 1.25.1) and the repo's coverage check pass, alone and merged with the other two PRs. Coverage (go-test-coverage with.testcoverage.yml): 79.5% onmain, 80.7% with this PR.Live run as root on macOS (Apple Silicon, Homebrew 7.0),
mainvs this PR,--munki-installcheck:--skip-not-installed(direct, via cache, mixed-case name)--skip-not-installed--min-version=v2.x/--min-version=1.0_1/ skip without min / name../xinfo, no-opupgrade