-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
services: typed: strict
#21230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
services: typed: strict
#21230
Conversation
There was a problem hiding this 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, andservice_fileby wrapping if-elsif conditionals inT.must - Refactoring the
status_output_success_typemethod to return a customStatusOutputSuccessTypeclass instead of a tuple for better type safety - Renaming
take_root_ownershiptotake_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.
3343421 to
ee02315
Compare
MikeMcQuaid
left a comment
There was a problem hiding this 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]>
Signed-off-by: botantony <[email protected]>
ee02315 to
51a3971
Compare
Signed-off-by: botantony <[email protected]>
51a3971 to
b9279f2
Compare
MikeMcQuaid
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, almost there!
Signed-off-by: botantony <[email protected]>
642d71b to
1453831
Compare
Signed-off-by: botantony <[email protected]>
brew lgtm(style, typechecking and tests) with your changes locally?Part of #17297
There are a lot of nilable values like
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
niland wrap them inT.mustbrew/Library/Homebrew/cmd/services.rb
Lines 87 to 90 in 07cf715