Skip to content

sorbet: Less RBI duplication to successfully typecheck RSpec tests#22540

Merged
issyl0 merged 6 commits into
mainfrom
less-duplication-in-sorbet-rbis
Jun 5, 2026
Merged

sorbet: Less RBI duplication to successfully typecheck RSpec tests#22540
issyl0 merged 6 commits into
mainfrom
less-duplication-in-sorbet-rbis

Conversation

@issyl0
Copy link
Copy Markdown
Member

@issyl0 issyl0 commented Jun 4, 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.

GPT-5.3-Codex (Medium) for commit c2c1e92 because it was quite tedious.


@issyl0 issyl0 force-pushed the less-duplication-in-sorbet-rbis branch from 5a192b5 to cb184f4 Compare June 4, 2026 21:55
@issyl0 issyl0 marked this pull request as ready for review June 4, 2026 22:02
Copilot AI review requested due to automatic review settings June 4, 2026 22:02
@issyl0 issyl0 enabled auto-merge June 4, 2026 22:02
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 reduces Sorbet RBI duplication for RSpec test typechecking by moving helper method type information into the real test helper modules and tightening a number of test/helper sigils and bindings so typed specs typecheck cleanly.

Changes:

  • Refactors the RSpec shim RBI to include typed helper modules instead of duplicating method signatures directly in rspec.rbi.
  • Adds/strengthens Sorbet signatures (sig) and typed: levels in test helper modules, and updates specs with targeted T.bind calls in DSL blocks.
  • Updates Tapioca require mappings and RuboCop RBIs/trimming allowlist to include CopHelper.
Show a summary per file
File Description
Library/Homebrew/test/utils/analytics_spec.rb Adds T.bind inside formula DSL blocks for better static typing.
Library/Homebrew/test/test_bot/formulae_spec.rb Removes unsafe casts and adds T.bind to formula definitions.
Library/Homebrew/test/support/helper/subcommand.rb Adds sigs for subcommand helpers and types Bundle::SubcommandContext.
Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb Moves integration helpers into a typed module and includes it from the shared context.
Library/Homebrew/test/support/helper/mktmpdir.rb Makes the helper typed: strict and adds a generic return sig.
Library/Homebrew/test/support/helper/formula.rb Makes the helper typed: strict and tightens signatures for formula helpers.
Library/Homebrew/test/support/helper/cask.rb Makes the helper typed: strict and adds a sig for stub_cask_loader.
Library/Homebrew/test/resource_spec.rb Adds T.bind inside patch DSL block for correct receiver typing.
Library/Homebrew/test/messages_spec.rb Adds T.bind to formula DSL blocks used by the tests.
Library/Homebrew/test/language/node_spec.rb Adds T.bind to a formula DSL block.
Library/Homebrew/test/language/java_spec.rb Adds T.bind to a formula DSL block.
Library/Homebrew/test/install_spec.rb Upgrades file to typed: strict.
Library/Homebrew/test/dev-cmd/bump_spec.rb Adds T.bind to a formula DSL block.
Library/Homebrew/test/description_cache_store_spec.rb Adds T.bind to a formula DSL block.
Library/Homebrew/test/cmd/reinstall_spec.rb Adds T.bind to a formula DSL block.
Library/Homebrew/test/cmd/install_spec.rb Adds T.bind to multiple formula DSL blocks.
Library/Homebrew/test/cmd/home_spec.rb Adds T.bind to a formula DSL block.
Library/Homebrew/test/cmd/bundle/dump_subcommand_spec.rb Adds T.bind to a stubbed formula DSL block.
Library/Homebrew/test/cmd/bundle/check_subcommand_spec.rb Adds T.bind to stubbed formula DSL blocks.
Library/Homebrew/test/cmd/--cache_spec.rb Upgrades file from typed: false to typed: true.
Library/Homebrew/test/cli/named_args_spec.rb Adds T.bind to formula DSL blocks.
Library/Homebrew/test/bundle/skipper_spec.rb Adds T.bind to a stubbed formula DSL block.
Library/Homebrew/test/bundle/mac_app_store_spec.rb Adds T.bind to a stubbed formula DSL block.
Library/Homebrew/test/bottle_filename_spec.rb Adds T.bind to a formula DSL block.
Library/Homebrew/sorbet/tapioca/require.rb Ensures additional requires load RuboCop RSpec helpers needed for RBIs.
Library/Homebrew/sorbet/rbi/shims/rspec.rbi Removes duplicated method stubs and includes typed helper modules instead.
Library/Homebrew/sorbet/rbi/gems/rubocop@1.86.2.rbi Adds CopHelper definitions and adjusts some Rainbow presenter types.
Library/Homebrew/dev-cmd/typecheck.rb Updates RuboCop RBI trimming allowlist to keep CopHelper.

Copilot's findings

Tip

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

Files not reviewed (2)
  • Library/Homebrew/sorbet/rbi/gems/rubocop@1.86.2.rbi: Language not supported
  • Library/Homebrew/sorbet/rbi/shims/rspec.rbi: Language not supported
  • Files reviewed: 26/28 changed files
  • Comments generated: 1

Comment thread Library/Homebrew/test/support/helper/formula.rb
issyl0 added 5 commits June 4, 2026 23:40
- Don't duplicate all of `formula.rbi` in the `rspec.rbi` shim because
  it's a terrible pattern.
- I also noticed a supposedly typechecked file
  `test/test_bot/formulae_spec.rb` that was definitely cheating through
  the use of `T.bind(self, T.untyped)` and `T.unsafe`. So, follow the
  same `T.bind(self, T.class_of(Formula))` pattern in test files to make
  sure we're getting proper type checking in `formula` blocks.
- Instead of duplicating all the methods in `rspec.rbi`, transfer the
  type sigs to the actual helper method definitions.
- Rather than duplicating all of the methods in `rspec.rbi` and
  `test/support/helper/spec/shared_context/integration_test.rb`, we can
  move the methods into a test helper module and include that in both
  places.
- `CopHelper` is a RuboCop module, so include it in the generated
  RuboCop RBI rather than hand-writing it.
@issyl0 issyl0 force-pushed the less-duplication-in-sorbet-rbis branch from cb184f4 to 14e04fc Compare June 4, 2026 22:41
@github-code-quality
Copy link
Copy Markdown

github-code-quality Bot commented Jun 4, 2026

Code Coverage Overview

Languages: Ruby

Ruby / code-coverage/simplecov

The overall coverage in the branch is 75%. The coverage in the branch is 78%.

Show a code coverage summary of the most impacted files.
File c6a08de f1f6e9f +/-
cask/info.rb 96% 0% -96%
cask/installer.rb 91% 28% -63%
cask/artifact/a...ct_uninstall.rb 89% 32% -57%
cask/audit.rb 63% 25% -38%
cask/cask_loader.rb 96% 65% -31%
bundle/extensions/flatpak.rb 37% 94% +57%
extend/os/linux/diagnostic.rb 0% 67% +67%
os/linux/elf.rb 0% 86% +86%
extend/os/linux/sandbox.rb 0% 95% +95%
extend/os/linux...ystem_config.rb 0% 99% +99%

Updated June 04, 2026 23:52 UTC
Code Coverage is in Public Preview. Learn more and provide us with your feedback.

- To teach Sorbet about RSpec's `alias_matcher` method without having to
  hand-write the RBI shim.
- Use `extend` where the others are `include` here because
  `alias_matcher` is a class method, not an instance method.
- Hence we can bump a bunch more tests to Sorbet `typed: true`.
@issyl0 issyl0 force-pushed the less-duplication-in-sorbet-rbis branch from f01b0fe to f1f6e9f Compare June 4, 2026 23:35
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.

Much nicer, great work!

@issyl0 issyl0 added this pull request to the merge queue Jun 5, 2026
Merged via the queue into main with commit 8cf7601 Jun 5, 2026
40 checks passed
@issyl0 issyl0 deleted the less-duplication-in-sorbet-rbis branch June 5, 2026 13:14
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