Skip to content

Look up formula cache file names by name only - #24395

Merged
MikeMcQuaid merged 1 commit into
mainfrom
formula-cache-name-loader
Oct 30, 2026
Merged

MikeMcQuaid merged 1 commit into
mainfrom
formula-cache-name-loader

Conversation

@p-linnane

Copy link
Copy Markdown
Contributor

stale_formula? passed the part of a HOMEBREW_CACHE file name before its version to Formulary.from_rack, whose fallback to Formulary.factory also tries the path and bottle loaders, so a name like foo.rb could load a matching file from the working directory, and . or .. made Keg.from_rack try to build kegs outside the Cellar and abort cleanup. Cleanup now rejects anything that isn't a formula name, including after stripping _bottle_manifest, and passes from_cache: true so from_rack and from_keg only use the API, tap, name and keg loaders; new examples cover these names in normal and dry-run cleanup, including through bottle manifests and installed kegs.


  • Have you followed our Contributing guidelines?
  • Have you checked for other open Pull Requests for the same change?
  • Have you explained what your changes do? Performance claims (e.g. "this is faster") must include brew benchmark results.
  • Have you explained why you'd like these changes included, not just what they do?
  • For bug fixes, have you given step-by-step brew commands to reproduce the bug?
  • Have you written new tests (excluding integration tests)? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) locally?

  • I did not use AI/LLM to create this PR, or I disclosed the tool/model below and reviewed its output; I did not attribute commits to AI and will answer maintainer questions and review comments myself without AI/LLM.

Codex (GPT-6 Sol with Daybreak) wrote the change and tests, checked that each new example fails without its guard and ran brew lgtm. Claude Code (Opus 5.5) suggested the change, reviewed it and its callers, asked for the bottle manifest and installed keg examples, simplified the loader selection and tests, checked that the new examples still fail without the change and ran brew lgtm --online.


- `stale_formula?` passed the part of a `HOMEBREW_CACHE` file name
  before its version to `Formulary.from_rack`, whose fallback to
  `Formulary.factory` also tries the path and bottle loaders, so a
  name like `foo.rb` could load a matching file from the working
  directory.
- `.` and `..` made `Keg.from_rack` try to build kegs outside the
  Cellar, which raised and aborted cleanup.
- Reject anything that isn't a formula name, including after
  stripping `_bottle_manifest`, and pass `from_cache: true` so
  `from_rack` and `from_keg` only use the API, tap, name and keg
  loaders.

Signed-off-by: Patrick Linnane <patrick@linnane.io>
@coderabbitai

coderabbitai Bot commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3f366742-aa62-4905-a856-36b455012ff2
Commits

Reviewing files that changed from the base of the PR and between 9226bdf and 2e099fe.

Files selected for processing: 3
  • Library/Homebrew/cleanup.rb
  • Library/Homebrew/formulary.rb
  • Library/Homebrew/test/cleanup_spec.rb

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Cleanup now checks cached formula names before loading them and avoids resolving cached entries through local bottle or path files.
    • This reduces the chance of unintended formula evaluation during cleanup, including when processing bottle manifests or installed kegs.

Cache cleanup validates extracted formula names before loading them and uses cache-specific formula lookup. Formulary excludes bottle, URI and path loaders for cleanup lookups. Tests cover name validation and lookup behaviour.

Changes: Formula cache cleanup

Layer / File(s) Summary
Cache-specific formula lookup
Library/Homebrew/formulary.rb
from_rack and from_keg accept from_cache. Cache lookups use the :cleanup source, which excludes bottle, URI and path loaders. Other lookup sources retain their existing loader list.
Cache name validation and cleanup tests
Library/Homebrew/cleanup.rb, Library/Homebrew/test/cleanup_spec.rb
Cleanup rejects extracted names that are . or .. or do not match HOMEBREW_TAP_FORMULA_NAME_REGEX. Valid names use from_cache: true. Tests cover invalid names, local formula evaluation, bottle-loader attempts and updated lookup arguments.

Priority: Normal

Merge Risk: Minimal · up to 2e099

Cache cleanup is restricted to the intended lookup sources, with no identified merge-blocking issue.

Pre-merge checks: Passed 4
Check name Status Explanation
Title check Passed The title names the main change: formula cache file names are now looked up by name only. The changeset adds name validation in cleanup.rb and passes from_cache: true to Formulary loaders, which match…
Description check Passed The description explains the problem and the fix. It covers stale_formula? passing cache name fragments to Formulary.from_rack, the rejection of invalid names including after _bottle_manifest is strip…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: formula cache file names are now looked up by name only. The changeset adds name validation in cleanup.rb and passes from_cache: true to Formulary loaders, which matches the title. No search was needed; the assessment rests on the supplied context.

Full details: Description check

Explanation

The description explains the problem and the fix. It covers stale_formula? passing cache name fragments to Formulary.from_rack, the rejection of invalid names including after _bottle_manifest is stripped, and the from_cache: true loader restriction. It also lists the new examples. The description is on-topic and specific to the changeset.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@MikeMcQuaid MikeMcQuaid left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks!

@MikeMcQuaid
MikeMcQuaid added this pull request to the merge queue Oct 30, 2026
Merged via the queue into main with commit 85e4eeb Oct 30, 2026
54 checks passed
@MikeMcQuaid
MikeMcQuaid deleted the formula-cache-name-loader branch October 30, 2026 08:50
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.

2 participants

⌂ 换网址