Skip to content

fix(brew): preserve user-owned preinstall packages - #1109

Open
Danathar wants to merge 1 commit into
projectbluefin:mainfrom
Danathar:fix/brew-preinstall-user-ownership-915
Open

Danathar wants to merge 1 commit into
projectbluefin:mainfrom
Danathar:fix/brew-preinstall-user-ownership-915

Conversation

@Danathar

Copy link
Copy Markdown

Summary

Fixes #915.

Root cause

brew-preinstall previously wrote every formula and cask declared by the
current managed Brewfiles into brew-preinstall-state.json after a successful
brew bundle. Because brew bundle is idempotent, a package already installed
by the user was indistinguishable from one installed by Bluefin. If the
declaration was later removed, the persisted entry authorized Bluefin to
uninstall the user's package.

What changed

  • Snapshot installed formulae and casks immediately before the bundle pass.
  • Preserve declarations already present in the previous managed state.
  • Add a declaration to managed state only when it was absent from the
    pre-bundle inventory and the bundle pass succeeds.
  • Fail closed without bundling or writing state if either inventory query fails.
  • Continue using the existing basename-aware matching for tap-qualified names,
    the existing hash fast path, cask lifecycle, ChairLift handoff, atomic state
    writes, and legacy state files without a casks key.

Formulae and casks now follow the same ownership rule: previously user-owned
items remain outside Bluefin's managed state and therefore remain installed
when their temporary Brewfile declaration disappears. Items installed by the
managed reconciliation remain removable, and previously managed items remain
managed across later reconciliations.

Regression coverage

Added BATS coverage for:

  • user-owned formula and cask adoption followed by declaration removal;
  • Bluefin-owned formula and cask installation followed by removal;
  • previously managed formulae and casks remaining managed;
  • legacy formula state compatibility;
  • fail-closed behavior when pre-bundle inventory cannot be collected.

The new ownership tests fail against the pre-fix implementation: both the
formula and cask user-owned cases were adopted into state.

Validation

  • /var/tmp/bats-core/bin/bats tests/test_brew_preinstall.bats — 56/56 pass.
  • bash -n system_files/shared/usr/libexec/brew-preinstall — pass.
  • shellcheck -S warning system_files/shared/usr/libexec/brew-preinstall — pass.
  • just check — pass.
  • python3 scripts/generate_skill_index.py --check — pass.
  • PATH=/var/tmp/bluefin-common-validation/bin:$PATH pre-commit run --all-files — pass.
  • PATH=/var/tmp/bluefin-common-validation/bin:/var/tmp/bats-core/bin:$PATH just test — all 109 Python tests pass; the suite then reaches 5 existing tests/test_ujust.bats command-availability failures. The same failures reproduce on origin/main.
  • Full BATS suite excluding the documented libvirt integration test — 426/433 pass; the 7 failures are the same baseline failures in tests/test_shared_just.bats (2) and tests/test_ujust.bats (5), with no brew-preinstall failures.
  • git diff --check — pass.

Snapshot installed formulas and casks before bundle reconciliation so declarations already present on the system are not adopted into Bluefin managed state. Preserve prior managed entries and fail closed when inventory cannot be collected.

Fixes projectbluefin#915

Assisted-by: GPT-5 via GitHub Copilot

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Danathar <doug.baggett@gmail.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.

brew: brew-preinstall adopts user-installed packages into the managed set

1 participant