Skip to content

services: fix timed? and keep_alive? return type to T::Boolean#21950

Open
hyuraku wants to merge 3 commits intoHomebrew:mainfrom
hyuraku:fix-formula-wrapper-boolean-type
Open

services: fix timed? and keep_alive? return type to T::Boolean#21950
hyuraku wants to merge 3 commits intoHomebrew:mainfrom
hyuraku:fix-formula-wrapper-boolean-type

Conversation

@hyuraku
Copy link
Copy Markdown
Contributor

@hyuraku hyuraku commented Apr 8, 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?
  • 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. Please specify below how you used AI to help you, and what steps you have taken to manually verify the changes.

solve

# TODO: this should either be T::Boolean or renamed to `timed`

  • Change the method signatures from T.nilable(T::Boolean) to T::Boolean

Copilot AI review requested due to automatic review settings April 8, 2026 14:05
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 updates Homebrew::Services::FormulaWrapper#timed? and #keep_alive? to always return T::Boolean (returning false when no service exists) and aligns the corresponding specs and to_hash expectations.

Changes:

  • Change timed? and keep_alive? Sorbet signatures from T.nilable(T::Boolean) to T::Boolean and return false when service? is falsey.
  • Update service wrapper specs to expect false (not nil) when no service is present.
  • Update to_hash expectations so schedulable is false instead of nil for non-service formulas.

Reviewed changes

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

File Description
Library/Homebrew/services/formula_wrapper.rb Makes timed? / keep_alive? return false when no service, matching T::Boolean signatures.
Library/Homebrew/test/services/formula_wrapper_spec.rb Adjusts specs (including schedulable) to reflect the new boolean return behavior.

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

Comment on lines +55 to +61
@timed ||= T.let(
if service?
load_service.timed?
else
false
end, T.nilable(T::Boolean)
)
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

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

@timed ||= ... will re-run the block whenever the computed value is false (Ruby ||= doesn’t memoize falsey values). This means load_service.timed? (and service?) can be evaluated multiple times for non-timed services, including within a single to_hash call (it calls timed? for schedulable and again via status_symbol). Consider memoizing with a nil sentinel instead (e.g., initialize @timed as T.nilable(T::Boolean) and only compute when it’s nil).

Copilot uses AI. Check for mistakes.
Comment on lines +67 to +73
@keep_alive ||= T.let(
if service?
load_service.keep_alive?
else
false
end, T.nilable(T::Boolean)
)
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

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

@keep_alive ||= ... has the same ||= memoization issue: if load_service.keep_alive? returns false, this will recompute on every call, potentially re-loading the service repeatedly. Prefer memoizing with a nil sentinel so both true and false are cached.

Copilot uses AI. Check for mistakes.
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, one nit!

Comment on lines +57 to +58
@timed = T.let(service? && load_service.timed?, T.nilable(T::Boolean))
T.must(@timed)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
@timed = T.let(service? && load_service.timed?, T.nilable(T::Boolean))
T.must(@timed)
@timed = T.let(service? && load_service.timed?, T.nilable(T::Boolean))

don't use T.must here, instead us if or || to ensure the result is always true or false

return @keep_alive unless @keep_alive.nil?

@keep_alive = T.let(service? && load_service.keep_alive?, T.nilable(T::Boolean))
T.must(@keep_alive)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same here

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