Skip to content
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

Type livecheck.rb. #15279

Merged
merged 1 commit into from
May 6, 2023
Merged

Conversation

reitermarkus
Copy link
Member

@reitermarkus reitermarkus commented Apr 20, 2023

  • 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 style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

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.

Sorry, I don't think having this in livecheck is the right approach. As mentioned in Slack, audit.rb already provides throttling for formulae: we should use the same approach for casks.

Library/Homebrew/livecheck.rb Outdated Show resolved Hide resolved
Copy link
Member

@samford samford left a comment

Choose a reason for hiding this comment

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

Sorry, I don't think having this in livecheck is the right approach. As mentioned in Slack, audit.rb already provides throttling for formulae: we should use the same approach for casks.

I agree with Mike. I unfortunately wasn't explicit in past discussions but when I mentioned handling throttling outside of livecheck, I was thinking that it would be in line with the setup that we have for formulae (e.g., handled in an audit_exceptions/throttled_casks.json file in cask taps).

@reitermarkus
Copy link
Member Author

audit.rb already provides throttling for formulae

This is based on “version is a multiple of n”, which definitely will not work for most cask versions.

Also, having this in audit is the wrong approach in my opinion. It handles the symptom (open version bump PRs), not the source of the problem (opening them in the first place). At the point where we run CI for a PR, a failing audit is more maintenance work than just approving the version bump. So it should be handled in bump-* commands. (I am aware bump-* commands run audit by default, but throttling should work even with --no-audit.)

@reitermarkus reitermarkus changed the title Add throttle stanza for livecheck. Type livecheck.rb. Apr 21, 2023
@MikeMcQuaid
Copy link
Member

Happy to merge one type-checking is 💚, thanks @reitermarkus!

This is based on “version is a multiple of n”, which definitely will not work for most cask versions.

@reitermarkus can you elaborate on why you don't think this will work and what you were/are proposing instead?

(I am aware bump-* commands run audit by default, but throttling should work even with --no-audit.)

I don't agree that this is necessary, honestly. This doesn't seem different to another audit and I'd like to see evidence that these audits are being ignored in bumps before we deviate approach here.

In general: I think casks and formulae for both user and contributors should be as similar as possible. Where they deviate it adds friction, bugs and confusing for everyone. Sometimes this is necessary, many times it is not.

@SMillerDev
Copy link
Member

Ignoring audits in bumps was suggested here: Homebrew/homebrew-cask#145518

@@ -13,12 +13,9 @@
# [`brew livecheck` documentation](https://docs.brew.sh/Brew-Livecheck).
class Livecheck
extend Forwardable
extend T::Sig
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

This can (and needs to be) removed due to #15306

@reitermarkus
Copy link
Member Author

@samford and @dduugg, what do we want to do here regarding TypeErrors? Remove the explicit errors or just simplify the tests to not check the error message?

@dduugg
Copy link
Sponsor Member

dduugg commented Apr 26, 2023

@samford and @dduugg, what do we want to do here regarding TypeErrors? Remove the explicit errors or just simplify the tests to not check the error message?

Testing the specific content of error messages is fragile IME (for instance, it could also break on a sorbet update).

If you waned to be thorough, one suggestion could be a test helper that expects a TypeError with the expected and actual types, and converts that to a regexp to match against the actual TypeError message. WDYT?

@reitermarkus
Copy link
Member Author

reitermarkus commented Apr 26, 2023

I think just testing for any TypeError is fine.

My question was more a decision between these options:

  1. Remove the explicit exceptions and the test.
  2. Leave the explicit exception and adjust the test.
  3. Ensure the test runs without sorbet-runtime. Not sure if that's possible, but it's also not preferable.

@dduugg
Copy link
Sponsor Member

dduugg commented Apr 26, 2023

I think just testing for any TypeError is fine.

My question was more a decision between these options:

  1. Remove the explicit exceptions and the test.
  2. Leave the explicit exception and adjust the test.
  3. Ensure the test runs without sorbet-runtime. Not sure if that's possible, but it's also not preferable.

Ah, ok, I think I better understand now. Yeah, testing that a sig'd method raises a TypeError with the wrong type would generally not be useful. (We do have the wrinkle though that folks generally have runtime type checking disabled, but also that tests force runtime typechecking 🤕. I guess it would come down to the specific code and how likely it is for an end user to be able to force the wrong types in…)

Copy link
Member

@samford samford left a comment

Choose a reason for hiding this comment

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

What do we want to do here regarding TypeErrors? Remove the explicit errors or just simplify the tests to not check the error message?

Since type checking doesn't come into play when brew livecheck is run, we still need the manual exceptions in the DSL methods. We can't cover those lines with tests after the Livecheck DSL is typed (since Sorbet raises a TypeError before we can reach the manual exception), so keeping those test cases around wouldn't make a functional difference. We would basically be testing Sorbet at that point, which we don't want to do.

Unless we can disable Sorbet's type checking for these specific test cases, I would say: leave the manual exceptions in the Livecheck DSL methods and we can just remove the related test cases in livecheck_spec.rb. There's some related Sorbet runtime documentation that seemingly explains how to control the runtime for specific type signatures but I'm not sure if any of it is feasible in relation to how we do things with brew typecheck, brew tests, etc. I haven't looked into it but I figured I would mention it, at least.


The other test failures I'm seeing relate to the signature for package_or_resource. We should arguably be using Cask::Cask (since that's what we're working with in brew livecheck) but that leads to a bunch of type errors based on how we're creating test cask objects, so we'll need to find a way of creating the test casks as Cask::Cask objects.

I'm also seeing failures in relation to livecheckable_f in livecheck_spec.rb (e.g., Parameter 'package_or_resource': Expected type T.any(Cask::Cask, Resource, T.class_of(Formula)), got type #<Class:0x0000000116a2d4d0> with value #<Formula formula_name (sta...-core/Formula/formula_name.rb>) but I'm not immediately sure what the issue is there.

@MikeMcQuaid
Copy link
Member

Since type checking doesn't come into play when brew livecheck is run, we still need the manual exceptions in the DSL methods.

It could very easily. We could start setting HOMEBREW_SORBET_RUNTIME when running brew livecheck/all developer commands/anything when HOMEBREW_DEVELOPER is set. This seems like a much more sensible route forward than duplicating the work Sorbet is doing.

@reitermarkus
Copy link
Member Author

It could very easily.

Yes, I agree. At the very least audit should probably run with sorbet-runtime.

@samford
Copy link
Member

samford commented Apr 28, 2023

It could very easily. We could start setting HOMEBREW_SORBET_RUNTIME when running brew livecheck/all developer commands/anything when HOMEBREW_DEVELOPER is set. This seems like a much more sensible route forward than duplicating the work Sorbet is doing.

Makes sense to me. I haven't ever run livecheck with HOMEBREW_SORBET_RUNTIME but I'll have to test it out sometime. If our existing manual type checking code has been doing its job, hopefully the Sorbet runtime won't surface any new errors that we weren't already handling.

@MikeMcQuaid
Copy link
Member

Yes, I agree. At the very least audit should probably run with sorbet-runtime.
I haven't ever run livecheck with HOMEBREW_SORBET_RUNTIME but I'll have to test it out sometime.

I've opened a PR to bit the bullet and enable this for all Homebrew's developer commands and everyone with HOMEBREW_DEVELOPER set: #15326

@MikeMcQuaid
Copy link
Member

(assuming that PR gets merged: I think, yes, we can strip all TypeError checks out of all dev-cmd)

@@ -37,7 +35,8 @@ def initialize(package_or_resource)
#
# @param cask_name [String] name of cask to inherit livecheck info from
# @return [String, nil]
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

what do you think of removing the YARD type annotations? (yard-sorbet is just going to use the sig types anyway)

Copy link
Member

Choose a reason for hiding this comment

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

The YARD types are redundant (as mentioned) but the parameter descriptions are still useful for documentation purposes. If we can keep the descriptions but omit the types, that makes sense to me (i.e., we wouldn't have to waste time keeping the YARD types in line with the Sorbet method signatures).

Copy link
Member

Choose a reason for hiding this comment

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

Agreed that it'd be nice to try and drop these types.

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

It'd be nice if we could just swap out all the YARD types for sorbet sigs. I filed AaronC81/sord#167 since that's the most similar project, I should have some bandwidth to take a stab at it in the summer.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ideally, docs would be correctly generated from

sig { 
  params(
    # name of cask to inherit livecheck info from
    cask_name: String
  ).returns(T.nilable(String)) 
}

@reitermarkus reitermarkus force-pushed the livecheck-throttle branch 3 times, most recently from 5e6a11e to eb91a87 Compare May 4, 2023 18:25
Copy link
Sponsor Member

@dduugg dduugg left a comment

Choose a reason for hiding this comment

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

The requested YARD changes look good. I have a couple questions, but they aren't blocking (and apologies if i missed any earlier discussion).

Also, I'd rather we use T.absurd for exhuastiveness checking over the approach we're using here (and elsewhere), but that would require us to enable runtime errors for that specific method (which isn't difficult, just something we've consciously avoided for all sorbet runtime checks).

Library/Homebrew/livecheck.rb Outdated Show resolved Hide resolved
Library/Homebrew/livecheck.rb Show resolved Hide resolved
@samford
Copy link
Member

samford commented May 5, 2023

I ran out of time today but I'll test and review this again in the next day or two (hopefully Friday evening, EDT).

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.

One tweak needed and good to merge 👍🏻. Thanks @reitermarkus!

Library/Homebrew/livecheck.rb Outdated Show resolved Hide resolved
Library/Homebrew/livecheck.rb Show resolved Hide resolved
@reitermarkus reitermarkus merged commit 477a26c into Homebrew:master May 6, 2023
24 checks passed
@reitermarkus reitermarkus deleted the livecheck-throttle branch May 6, 2023 21:20
@github-actions github-actions bot added the outdated PR was locked due to age label Jun 6, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants