Skip to content

Conversation

@botantony
Copy link
Member

  • 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?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) with your changes locally?

Part of #17297

There are a lot of nilable values like

if launchctl?
  x
elsif systemctl?
  y
end

It makes enabling strict typecheck on these files much harder. Because we ensure supported service managers exist on the host we can assume they are never nil and wrap them in T.must

if !Homebrew::Services::System.launchctl? && !Homebrew::Services::System.systemctl?
raise UsageError,
"`brew services` is supported only on macOS or Linux (with systemd)!"
end

Copilot AI review requested due to automatic review settings December 13, 2025 15:32
Copy link
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 enables strict type checking (typed: strict) for the services module by adding Sorbet type signatures and wrapping service manager conditional logic in T.must assertions. The changes are based on the guarantee that the services command validates a supported service manager (launchctl or systemctl) exists before execution (see cmd/services.rb:87-90).

Key changes include:

  • Converting return types from nilable to non-nilable for methods like boot_path, user_path, service_name, and service_file by wrapping if-elsif conditionals in T.must
  • Refactoring the status_output_success_type method to return a custom StatusOutputSuccessType class instead of a tuple for better type safety
  • Renaming take_root_ownership to take_root_ownership? to properly reflect its boolean return type
  • Removing tests for unsupported service manager scenarios (neither launchctl nor systemctl)

Reviewed changes

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

Show a summary per file
File Description
Library/Homebrew/services/system.rb Wrapped boot_path, user_path return values in T.must and changed return types from nilable to non-nilable Pathname
Library/Homebrew/services/formula_wrapper.rb Added strict typing, created StatusOutputSuccessType class to replace tuple return, wrapped conditional returns in T.must, added type annotations for instance variables and methods
Library/Homebrew/services/cli.rb Added initialize method for type initialization, renamed take_root_ownership to take_root_ownership? with explicit boolean returns, added method signatures
Library/Homebrew/services/system/systemctl.rb Added strict typing and method signatures for run, quiet_run, popen_read, and _run
Library/Homebrew/services/commands/list.rb Added strict typing and type annotations for constants and methods
Library/Homebrew/test/services/system_spec.rb Removed tests for unsupported "unknown" service manager scenario
Library/Homebrew/test/services/formula_wrapper_spec.rb Removed tests for unsupported "other" service manager scenarios
Library/Homebrew/test/services/cli_spec.rb Updated test to use instance_double instead of string for check! method call

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

@botantony botantony marked this pull request as draft December 13, 2025 15:51
@botantony botantony force-pushed the services-typecheck branch 2 times, most recently from 3343421 to ee02315 Compare December 13, 2025 16:31
@botantony botantony marked this pull request as ready for review December 13, 2025 16:40
Copy link
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 for the PR @botantony! Some weird T.must usage that it'd be good to cleanup before merge.

There are a lot of nilable values like

```ruby
if launchctl?
  x
elsif systemctl?
  y
end
```

It makes enabling strict typecheck on these files much harder.
Because we ensure supported service managers exist on the host
we can assume they are never `nil` and wrap them in `T.must`

https://github.com/Homebrew/brew/blob/07cf715862e89bc368ff6468957f1879fe33eddd/Library/Homebrew/cmd/services.rb#L87-L90

Signed-off-by: botantony <[email protected]>
Copy link
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, almost there!

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