Skip to content

Remove dead API methods and move generated_hash! to tests#23095

Merged
MikeMcQuaid merged 1 commit into
mainfrom
api-deadcode
Jul 14, 2026
Merged

Remove dead API methods and move generated_hash! to tests#23095
MikeMcQuaid merged 1 commit into
mainfrom
api-deadcode

Conversation

@dduugg

@dduugg dduugg commented Jul 14, 2026

Copy link
Copy Markdown
Member

Another extraction from my typecheck-deadcode branch (following #22733), which runs Spoom's dead code analysis over Library/Homebrew. This slice covers the Homebrew::API files.

What this removes

Four methods with no callers anywhere:

Method Callers in brew Callers in homebrew-core / homebrew-cask Callers on GitHub
Homebrew::API.cached_formula_json_file_path 0 0 0
Homebrew::API::Cask.all_renames 0 (2 RSpec stubs) 0 0
Homebrew::API::Formula.all_renames 0 (2 RSpec stubs) 0 0
APIHashable#generated_hash! 0 (tests only) 0 0

The GitHub code search for cached_formula_json_file_path returns hits only in vendored copies and forks of brew itself, i.e. the definition site, so there are no third-party consumers.

Why all_renames is dead

Renames are resolved through Homebrew::API.formula_renames and Homebrew::API.cask_renames, which read the internal API (Homebrew::API::Internal). Those are the methods Formulary, Cask::CaskLoader, CoreTap, CoreCaskTap and bundle actually call. The all_renames pair on the JSON API classes is left over from before that path existed, and nothing reaches it. Its only remaining references were two RSpec stubs that stub a method no code under test calls, so those go too.

Why generated_hash! moves to a test helper instead

generating_hash! applies global monkeypatches (it swaps out HOMEBREW_PREFIX and sets HOME and GIT_CONFIG_GLOBAL) so that generated JSON contains placeholders. generated_hash! is the inverse, reverting them.

In production nothing ever reverts: brew generate-formula-api, brew generate-cask-api and brew generate-internal-api call generating_hash! and then exit, so the process dies with the monkeypatches still applied. The only callers of generated_hash! are two specs, which need it precisely so that the monkeypatching does not leak into other examples.

That makes it a test helper living in production code, so I moved it to test/support/helper/api_hashable.rb rather than deleting it outright. Behaviour is unchanged, and the two specs still pass.


  • 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 Hyperfine benchmarks.
  • 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?

  • AI was used to generate or assist with generating this PR.

Claude Code was used to run the dead code analysis, audit each candidate for callers (inside brew, in homebrew-core and homebrew-cask checkouts, and via GitHub code search), and prepare the diff. I reviewed the result and verified it locally with brew lgtm.

No new tests are added because this is a removal. The existing specs are the check: they exercise every method touched here, and they were run before and after. The all_renames stub removals and the generated_hash! move are both covered by test/formulary_spec.rb, test/cask/cask_loader/from_api_loader_spec.rb, test/cask/cask_spec.rb and test/service_spec.rb.


Extracted from the typecheck-deadcode branch (#22733 was the
first extraction), which uses Spoom to find code with no static callers.

Remove four methods with no callers:

- Homebrew::API.cached_formula_json_file_path
- Homebrew::API::Cask.all_renames
- Homebrew::API::Formula.all_renames
- APIHashable#generated_hash!

Renames are resolved through Homebrew::API.formula_renames and
Homebrew::API.cask_renames, which read the internal API, so the
all_renames pair on the JSON API classes is unused. The only remaining
references were vestigial RSpec stubs, so drop those too.

APIHashable#generated_hash! reverts the global monkeypatches applied by
generating_hash!. The generate-*-api commands exit once they are done and
never call it, so it is only needed to stop tests leaking global state.
Move it to a test helper rather than keeping it in production code.
@dduugg dduugg marked this pull request as ready for review July 14, 2026 06:10
Copilot AI review requested due to automatic review settings July 14, 2026 06:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR removes dead code in the Homebrew::API surface area and relocates APIHashable#generated_hash! into the test suite, keeping production behavior intact while preserving test isolation for API-generation monkeypatches.

Changes:

  • Removed unused API methods: Homebrew::API.cached_formula_json_file_path, Homebrew::API::Formula.all_renames, and Homebrew::API::Cask.all_renames.
  • Moved APIHashable#generated_hash! from production (Library/Homebrew/api_hashable.rb) into a new test helper and loaded it via test/spec_helper.rb.
  • Updated affected specs to stop stubbing the removed all_renames methods.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
Library/Homebrew/test/support/helper/api_hashable.rb Adds test-only APIHashable#generated_hash! to revert API-generation monkeypatches.
Library/Homebrew/test/spec_helper.rb Requires the new APIHashable test helper for the test suite.
Library/Homebrew/test/formulary_spec.rb Removes stubbing of deleted Homebrew::API::Formula.all_renames.
Library/Homebrew/test/cask/cask_loader/from_api_loader_spec.rb Removes stubbing of deleted Homebrew::API::Cask.all_renames.
Library/Homebrew/api/formula.rb Deletes dead Homebrew::API::Formula.all_renames.
Library/Homebrew/api/cask.rb Deletes dead Homebrew::API::Cask.all_renames.
Library/Homebrew/api.rb Deletes dead Homebrew::API.cached_formula_json_file_path.
Library/Homebrew/api_hashable.rb Removes APIHashable#generated_hash! from production code.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Thanks!

@MikeMcQuaid MikeMcQuaid added this pull request to the merge queue Jul 14, 2026
Merged via the queue into main with commit a3ef52c Jul 14, 2026
43 checks passed
@MikeMcQuaid MikeMcQuaid deleted the api-deadcode branch July 14, 2026 07:28
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.

4 participants