sorbet: Typecheck even more tests#22575
Open
issyl0 wants to merge 7 commits into
Open
Conversation
a0a0e6a to
a8e2413
Compare
- 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 ^ ```
Code Coverage OverviewLanguages: Ruby Ruby / code-coverage/simplecovThe overall coverage in the branch remains at 78%, unchanged from the branch. Show a code coverage summary of the most impacted files.
Updated |
- 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`.
a8e2413 to
ad1d2ad
Compare
Contributor
There was a problem hiding this comment.
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/trueto# 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_sconversions, 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 on lines
+30
to
+33
| stub_formula_loader formula("pkgconf") { | ||
| T.bind(self, T.class_of(Formula)) | ||
| url "pkgconf-1.0" | ||
| } |
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 on lines
+642
to
+645
| stub_formula_loader formula("bar") { | ||
| T.bind(self, T.class_of(Formula)) | ||
| url "bar-1.0" | ||
| } |
MikeMcQuaid
approved these changes
Jun 8, 2026
Member
MikeMcQuaid
left a comment
There was a problem hiding this comment.
Thanks, looks good when 🟢!
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.
brew lgtm(style, typechecking and tests) with your changes locally?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.