Skip to content

sorbet: Typecheck even more tests#22575

Open
issyl0 wants to merge 7 commits into
mainfrom
sorbet-even-more-tests
Open

sorbet: Typecheck even more tests#22575
issyl0 wants to merge 7 commits into
mainfrom
sorbet-even-more-tests

Conversation

@issyl0
Copy link
Copy Markdown
Member

@issyl0 issyl0 commented Jun 7, 2026


  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them? Performance claims (e.g. "this is faster") must include Hyperfine benchmarks.
  • Have you written new tests (excluding integration tests) for your changes? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) with your changes locally?

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

Copilot CLI with model OpenAI GPT 5.3 (Medium) for some of the more tedious bits of the first, third and penultimate commits, with human review.


  • See commits for more details.

@issyl0 issyl0 force-pushed the sorbet-even-more-tests branch 3 times, most recently from a0a0e6a to a8e2413 Compare June 7, 2026 15:26
issyl0 added 4 commits June 7, 2026 16:29
- So that Formula class methods like `keg_only` and `url` can be used in
  more typechecked tests.
- Set the `RSpec/DescribedClass` RuboCop rule to have config `SkipBlocks`
  because Sorbet errors on `T.bind(self, T.class_of(described_class))`,
  because it should be a full class name reference.
- Sorbet was picking up this `formula` helper method whose args were
  different to other `formula` methods, leading to errors like:

```
formula("test") do
  url "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz"
end

Too many arguments provided for method <describe 'Formula'>#formula. Expected: 0, got: 1
```
- Otherwise Sorbet couldn't understand them. And it's easier to read
  them as separate tests IMO.

```
test/cmd/bundle_spec.rb:148: Method expect does not exist on T.class_of(<describe 'Homebrew::Cmd::Bundle'>) https://srb.help/7003
     148 |        expect(Homebrew::Cmd::Bundle::ExecSubcommand).to receive(:run_external_command)
                  ^^^^^^
  Got T.class_of(<describe 'Homebrew::Cmd::Bundle'>) originating from:
    test/cmd/bundle_spec.rb:9:
     9 |RSpec.describe Homebrew::Cmd::Bundle do
        ^
```
@github-code-quality
Copy link
Copy Markdown

github-code-quality Bot commented Jun 7, 2026

Code Coverage Overview

Languages: Ruby

Ruby / code-coverage/simplecov

The overall coverage in the branch remains at 78%, unchanged from the branch.

Show a code coverage summary of the most impacted files.
File c6a08de ad1d2ad +/-
api/cask.rb 88% 75% -13%
api/formula.rb 90% 80% -10%
rubocops/install_steps.rb 100% 93% -7%
formula.rb 85% 84% -1%
api.rb 88% 92% +4%
manpages.rb 50% 54% +4%
dev-cmd/formula-analytics.rb 17% 22% +5%
services/cli.rb 62% 69% +7%
extend/pathname.rb 75% 82% +7%
rubocops/unreferenced_let.rb 0% 100% +100%

Updated June 07, 2026 16:18 UTC
Code Coverage is in Public Preview. Learn more and provide us with your feedback.

@issyl0 issyl0 marked this pull request as ready for review June 7, 2026 15:49
Copilot AI review requested due to automatic review settings June 7, 2026 15:49
issyl0 added 3 commits June 7, 2026 16:59
- Ensure `join` is called on a Pathname of `config.appdir`, because
  `config.appdir` is typed in `cask/config.rbi` as a String, but in the
  real method sig can be either a String or a Pathname.

- `Formulary.cache.delete` can take a String or a Pathname, but Sorbet
  only sees the String type, so call `to_s` on the argument passed to
  it.
- There were 34 of these errors across the remaining `typed: false`
  tests when bumping them to `typed: true`.
@issyl0 issyl0 force-pushed the sorbet-even-more-tests branch from a8e2413 to ad1d2ad Compare June 7, 2026 16:00
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 increases Sorbet typechecking coverage across the Homebrew test suite by tightening # typed: sigils (many to strict/true) and adding explicit Sorbet annotations where the test DSL previously relied on dynamic typing.

Changes:

  • Upgrade many test files from # typed: false/true to # typed: true/strict.
  • Add Sorbet annotations in specs (e.g., T.bind, T.let) to satisfy stricter typechecking, especially in formula DSL blocks and mutable locals.
  • Adjust a few tests/helpers for typing expectations (e.g., Pathname(...) wrapping, to_s conversions, RuboCop test config).
Show a summary per file
File Description
Library/Homebrew/test/version/parser_spec.rb Tighten Sorbet sigil (strict).
Library/Homebrew/test/utils/topological_hash_spec.rb Add T.bind for formula DSL typing.
Library/Homebrew/test/utils/timer_spec.rb Tighten Sorbet sigil (strict).
Library/Homebrew/test/utils/gzip_spec.rb Tighten Sorbet sigil (strict).
Library/Homebrew/test/utils/fork_spec.rb Tighten Sorbet sigil (strict).
Library/Homebrew/test/utils/bottles/tag_spec.rb Tighten Sorbet sigil (strict).
Library/Homebrew/test/utils/bottles/bottles_spec.rb Use to_s for cache key typing.
Library/Homebrew/test/utils/autoremove_spec.rb Enable typing + add T.bind in formula blocks.
Library/Homebrew/test/uninstall_spec.rb Enable typing + add T.bind in formula blocks.
Library/Homebrew/test/test_runner_formula_spec.rb Enable typing + add T.bind in formula blocks.
Library/Homebrew/test/test_bot/test_spec.rb Tighten Sorbet sigil (strict).
Library/Homebrew/test/test_bot/formulae_dependents_spec.rb Enable typing + add T.bind in formula blocks.
Library/Homebrew/test/test_bot/bottles_fetch_spec.rb Tighten Sorbet sigil (strict).
Library/Homebrew/test/tab_spec.rb Add T.bind in formula blocks; expand one-liners.
Library/Homebrew/test/support/helper/cask/install_helper.rb Wrap appdir with Pathname(...) for typing.
Library/Homebrew/test/service_spec.rb Add T.bind for formula DSL typing.
Library/Homebrew/test/sbom_spec.rb Enable typing + add T.bind in formula blocks.
Library/Homebrew/test/sandbox_shared_spec.rb Add T.bind in formula blocks.
Library/Homebrew/test/reinstall_spec.rb Tighten Sorbet sigil (strict).
Library/Homebrew/test/patch_spec.rb Enable typing.
Library/Homebrew/test/os/os_spec.rb Tighten Sorbet sigil (strict).
Library/Homebrew/test/os/linux_spec.rb Tighten Sorbet sigil (strict).
Library/Homebrew/test/os_spec.rb Tighten Sorbet sigil (strict).
Library/Homebrew/test/livecheck/skip_conditions_spec.rb Add T.bind in formula blocks.
Library/Homebrew/test/livecheck/livecheck_spec.rb Add T.bind + type locals with T.let.
Library/Homebrew/test/livecheck_spec.rb Add T.bind in formula blocks.
Library/Homebrew/test/lazy_object_spec.rb Tighten Sorbet sigil (strict).
Library/Homebrew/test/language/python/virtualenv_spec.rb Add T.bind in formula blocks.
Library/Homebrew/test/language/python/shebang_spec.rb Enable typing + add T.bind in formula blocks.
Library/Homebrew/test/language/php/shebang_spec.rb Enable typing + add T.bind in formula blocks.
Library/Homebrew/test/language/perl/shebang_spec.rb Enable typing + add T.bind in formula blocks.
Library/Homebrew/test/language/node/shebang_spec.rb Enable typing + add T.bind in formula blocks.
Library/Homebrew/test/installed_dependents_spec.rb Add T.bind for formula DSL typing.
Library/Homebrew/test/github_runner_matrix_spec.rb Enable typing + add T.bind in formula blocks.
Library/Homebrew/test/github_packages_spec.rb Enable typing.
Library/Homebrew/test/formula_validation_spec.rb Add T.bind in formula blocks.
Library/Homebrew/test/formula_spec.rb Add T.bind and other typing annotations in formula/service blocks.
Library/Homebrew/test/formula_spec_selection_spec.rb Tighten Sorbet sigil (strict) + add T.bind.
Library/Homebrew/test/formula_installer_spec.rb Add T.bind, T.let, and adjust cache key typing.
Library/Homebrew/test/formula_installer_bottle_spec.rb Expand stubbed formula loaders + add T.bind.
Library/Homebrew/test/formula_info_spec.rb Tighten Sorbet sigil (strict).
Library/Homebrew/test/formula_auditor_spec.rb Add T.bind and expand stubbed formula loaders.
Library/Homebrew/test/download_strategies/vcs_spec.rb Enable typing.
Library/Homebrew/test/dev-cmd/which-update_spec.rb Tighten Sorbet sigil (strict).
Library/Homebrew/test/dev-cmd/ruby_spec.rb Tighten Sorbet sigil (strict).
Library/Homebrew/test/dev-cmd/livecheck_spec.rb Tighten Sorbet sigil (strict).
Library/Homebrew/test/dev-cmd/linkage_spec.rb Tighten Sorbet sigil (strict) + add T.bind.
Library/Homebrew/test/dev-cmd/generate-internal-api_spec.rb Tighten Sorbet sigil (strict).
Library/Homebrew/test/dev-cmd/edit_spec.rb Tighten Sorbet sigil (strict).
Library/Homebrew/test/dev-cmd/bump-formula-pr_spec.rb Enable typing + add T.bind in formula blocks.
Library/Homebrew/test/dependencies_helpers_spec.rb Add T.bind in formula blocks.
Library/Homebrew/test/cmd/uses_spec.rb Tighten Sorbet sigil (strict).
Library/Homebrew/test/cmd/upgrade_spec.rb Enable typing + add T.bind in formula blocks.
Library/Homebrew/test/cmd/untap_spec.rb Add T.bind in formula blocks.
Library/Homebrew/test/cmd/unpin_spec.rb Tighten Sorbet sigil (strict).
Library/Homebrew/test/cmd/uninstall_spec.rb Tighten Sorbet sigil (strict).
Library/Homebrew/test/cmd/source_spec.rb Tighten Sorbet sigil (strict).
Library/Homebrew/test/cmd/services/restart_subcommand_spec.rb Tighten Sorbet sigil (strict).
Library/Homebrew/test/cmd/services/list_subcommand_spec.rb Tighten Sorbet sigil (strict).
Library/Homebrew/test/cmd/services/info_subcommand_spec.rb Tighten Sorbet sigil (strict).
Library/Homebrew/test/cmd/services/cleanup_subcommand_spec.rb Tighten Sorbet sigil (strict).
Library/Homebrew/test/cmd/reinstall_spec.rb Tighten Sorbet sigil (strict).
Library/Homebrew/test/cmd/readall_spec.rb Tighten Sorbet sigil (strict) + type locals with T.let.
Library/Homebrew/test/cmd/pin_spec.rb Tighten Sorbet sigil (strict).
Library/Homebrew/test/cmd/link_spec.rb Add T.bind in formula blocks.
Library/Homebrew/test/cmd/leaves_spec.rb Tighten Sorbet sigil (strict).
Library/Homebrew/test/cmd/info_spec.rb Add T.bind in formula blocks.
Library/Homebrew/test/cmd/doctor_spec.rb Tighten Sorbet sigil (strict).
Library/Homebrew/test/cmd/desc_spec.rb Tighten Sorbet sigil (strict).
Library/Homebrew/test/cmd/bundle/exec_subcommand_spec.rb Add T.bind to stubs for strict typing.
Library/Homebrew/test/cmd/bundle/cleanup_subcommand_spec.rb Add T.bind in formula blocks; typed helpers.
Library/Homebrew/test/cmd/bundle/add_subcommand_spec.rb Expand stub loader + add T.bind.
Library/Homebrew/test/cmd/bundle_spec.rb Restructure --check specs for stricter typing.
Library/Homebrew/test/cmd/--prefix_spec.rb Tighten Sorbet sigil (strict).
Library/Homebrew/test/cmd/--cellar_spec.rb Tighten Sorbet sigil (strict).
Library/Homebrew/test/cmd/--caskroom_spec.rb Tighten Sorbet sigil (strict).
Library/Homebrew/test/cmd/--cache_spec.rb Tighten Sorbet sigil (strict).
Library/Homebrew/test/checksum_verification_spec.rb Make helper method typing-friendly (T.bind, optional block).
Library/Homebrew/test/caveats_spec.rb Enable typing + add T.bind in formula/service blocks.
Library/Homebrew/test/cask/upgrade_spec.rb Wrap appdir with Pathname(...) for typing.
Library/Homebrew/test/cask/uninstall_spec.rb Wrap appdir with Pathname(...) for typing.
Library/Homebrew/test/cask/tab_spec.rb Add T.bind in formula blocks.
Library/Homebrew/test/cask/reinstall_spec.rb Tighten Sorbet sigil (strict).
Library/Homebrew/test/cask/macos_spec.rb Tighten Sorbet sigil (strict).
Library/Homebrew/test/cask/list_spec.rb Wrap appdir with Pathname(...) for typing.
Library/Homebrew/test/cask/installer_spec.rb Wrap appdir with Pathname(...); adjust cache deletes for typing.
Library/Homebrew/test/cask/caskroom_spec.rb Tighten Sorbet sigil (strict).
Library/Homebrew/test/cask/cask_loader/from_uri_loader_spec.rb Tighten Sorbet sigil (strict).
Library/Homebrew/test/cask/artifact/uninstall_spec.rb Type state via T.let and simplify assertions.
Library/Homebrew/test/cask/artifact/two_apps_correct_spec.rb Wrap appdir with Pathname(...) for typing.
Library/Homebrew/test/cask/artifact/suite_spec.rb Wrap appdir with Pathname(...) for typing.
Library/Homebrew/test/cask/artifact/preflight_block_spec.rb Type locals with T.let.
Library/Homebrew/test/cask/artifact/postflight_block_spec.rb Type locals with T.let.
Library/Homebrew/test/cask/artifact/install_steps_spec.rb Type nilable local with T.let.
Library/Homebrew/test/cask/artifact/generic_artifact_spec.rb Wrap appdir with Pathname(...) for typing.
Library/Homebrew/test/cask/artifact/generated_completion_spec.rb Type captured args and normalize to strings for assertions.
Library/Homebrew/test/cask/artifact/app_spec.rb Wrap appdir with Pathname(...) for typing.
Library/Homebrew/test/cask/artifact/alt_target_spec.rb Wrap appdir with Pathname(...) for typing.
Library/Homebrew/test/cask/artifact/abstract_uninstall_spec.rb Remove untyped temporaries; simplify expectations.
Library/Homebrew/test/bundle/brew_spec.rb Add T.bind and typed stubs for stricter Sorbet checking.
Library/Homebrew/test/api/cask_struct_spec.rb Tighten Sorbet sigil (strict).
Library/Homebrew/test/api_spec.rb Type local state via T.let.
Library/Homebrew/test/.rubocop.yml Adjust RuboCop RSpec cop config for typed specs.

Copilot's findings

Tip

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

  • Files reviewed: 103/103 changed files
  • Comments generated: 7

Comment thread Library/Homebrew/test/cmd/bundle/exec_subcommand_spec.rb
Comment on lines +30 to +33
stub_formula_loader formula("pkgconf") {
T.bind(self, T.class_of(Formula))
url "pkgconf-1.0"
}
Comment thread Library/Homebrew/test/bundle/brew_spec.rb
Comment on lines 456 to 460
stub_formula_loader formula(formula_name) {
T.bind(self, T.class_of(Formula))
url "mysql-1.0"
conflicts_with "mysql55"
}
Comment thread Library/Homebrew/test/bundle/brew_spec.rb
Comment on lines +642 to +645
stub_formula_loader formula("bar") {
T.bind(self, T.class_of(Formula))
url "bar-1.0"
}
Comment thread Library/Homebrew/test/cmd/bundle/cleanup_subcommand_spec.rb
Copy link
Copy Markdown
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Thanks, looks good when 🟢!

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.

3 participants