Add brew info caching to speed up munki installcheck scripts#16
Merged
grahamgilbert merged 5 commits intomainfrom Mar 31, 2026
Merged
Add brew info caching to speed up munki installcheck scripts#16grahamgilbert merged 5 commits intomainfrom
grahamgilbert merged 5 commits intomainfrom
Conversation
Cache `brew info --json --installed` to disk (60s TTL by default) so that multiple `carafe check` invocations during a munki run share a single brew call instead of one per formula. Also eliminates the redundant second brew call that occurred when --min-version was set. New flags on `check`: --no-cache to disable, --cache-ttl to override the TTL. Caching is on by default. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Move cache from world-writable /tmp to /var/root/.carafe/ (mode 0700) so non-root users cannot pre-create or symlink-attack the cache file - Fall back to a direct brew call on cache miss rather than synthesising a "not installed" response, so typos and unresolved aliases still produce an error instead of silently passing --skip-not-installed - Update README cache location and add missing cache tests - Extract cache path strings to constants; remove redundant ttl variable Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Extract buildRootCmd() so the cobra command is testable without running main(). Add tests for invalid --cache-ttl strings, --no-cache flag, and valid TTL values. Also fixes a latent bug where the -ldflags version injection was targeting a local variable instead of a package-level one. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
WardsParadox
approved these changes
Mar 31, 2026
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.
Summary
brew info --json --installedon disk so multiplecarafe checkinvocations during a munki run share a single brew call instead of one per formula. In a typical munki run with N packages, this reduces N (or 2N with--min-version) brew invocations to 1.--no-cacheto disable,--cache-ttlto override (e.g.--cache-ttl=30s). No changes needed to existing plist scripts./var/root/.carafe/(mode0700) rather than/tmp, preventing symlink and injection attacks when running as root.brew infocall so typos/aliases still produce errors rather than silently passing--skip-not-installed.Checkwith--min-versionpreviously calledbrew infotwice per formula; it now reuses the first result for the version comparison.Test plan
TestLoadOrRefreshCache_CacheMiss— cache miss triggers brew call and writes cacheTestLoadOrRefreshCache_CacheHit— fresh cache is read without calling brewTestLoadOrRefreshCache_CacheStale— stale cache triggers refreshTestLoadOrRefreshCache_CorruptedCacheFile— corrupt JSON triggers refreshTestLoadOrRefreshCache_BrewError— brew failure propagates correctlyTestInfoOutputCached_FormulaFound— installed formula served from cacheTestInfoOutputCached_FormulaNotInstalled— cache miss falls back to direct brew callTestGetInfoOutput_NoCaching/TestGetInfoOutput_NegativeTTL— TTL ≤ 0 bypasses cache🤖 Generated with Claude Code