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

Fix prereleases not being considered by gem version promoter when there's no lockfile #6537

Merged
merged 2 commits into from
Mar 28, 2023

Conversation

siegfault
Copy link
Contributor

What was the end-user or developer problem that led to this PR?

Pulled out some spec changes as a result of #5258 (review) (

However, the specs added in the last commit raise some questions, since the current behavior feels quite surprising and I suspect we may want to tweak the implementation instead of codifying the current behavior in specs. I also have some minor comments about wording.

) and a bug fix mentioned in #5258 (comment).

What is your fix for the problem, implemented in this PR?

Spec changes

Add tests for pre, move more of the setup into a helper method, and restructure tests.

There seem to be five considerations for these tests (level, pre, strict, locked, and whether the current version is a prerelease version, though the last one overlaps with pre and didn't seem to behave how I expected under test). Rather than write out the 16 (/32 if the last consideration is real) combinations, I wrote most with independent tests for each value. The existing combined tests were maintained (level vs strict) because these seem the most interrelated.

Bug Fix

Prereleases are NOT considered even when the dependency specification includes a prerelease segment, if the dependency is not locked. To me that doesn't make sense, because I could create a Gemfile with say gem "rails", ">= 7.0.0.beta1" and I'd expect prereleases considered there even if there's no lock file yet.

Make sure the following tasks are checked

Michael Siegfried and others added 2 commits March 23, 2023 22:08
Add tests for pre, move more of the setup into a helper method, and
restructure tests.

There seem to be five considerations for these tests (level, pre, strict,
locked, and whether the current version is a prerelease version, though
the last one overlaps with pre and didn't seem to behave how I expected
under test). Rather than write out the 16 (/32 if the last consideration
is real) combinations, I wrote most with independent tests for each
value. The existing combined tests were maintained (level vs strict)
because these seem the most interrelated.
Prereleases are NOT considered even when the dependency specification
includes a prerelease segment, if the dependency is not locked. To me
that doesn't make sense, because I could create a Gemfile with say gem
"rails", ">= 7.0.0.beta1" and I'd expect prereleases considered there
even if there's no lock file yet.

Co-authored-by: David Rodríguez <deivid.rodriguez@riseup.net>
@siegfault
Copy link
Contributor Author

@deivid-rodriguez the tests are more or less the same commit from that original PR. I made sure all the cases are still covered, and fixed some new kwargs that have been added since. Re: your comment, I wonder whether the current behavior feeling surprising is due to how I worded some of the tests w.r.t. 'favors'. Ultimately, what the GemVersionPromoter returns is flipped (I believe here:

@gem_version_promoter.sort_versions(package, versions).reverse
), so what's favored here is ultimately the opposite of what's selected/used. Very open to better wording to make this less confusing! As well as any other suggestions you had. Thank you!

Copy link
Member

@deivid-rodriguez deivid-rodriguez left a comment

Choose a reason for hiding this comment

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

Looks awesome, thanks for following up on this!

Bundler::GemVersionPromoter.new.tap do |gvp|
gvp.level = :minor
gvp.strict = true
it "keeps downgrades" do
Copy link
Member

Choose a reason for hiding this comment

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

I think this is what was surprising to me. The other levels remove downgrades, but this one (the default), does not. I think this complicates things for Bundler outside of the gem version promoter because it needs to explicit add lower bound requirements to dependencies and I think it may be to workaround this.

Nothing to fix in this PR, but I think we may be able to remove a bit of complexity but making level=major behave like the other levels.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, gotcha. Yeah that had tripped me up a couple times. I'm not currently at the computer, but I wonder if changing

return specs if locked_version.nil? || major?
with

-       return specs if locked_version.nil? || major?
+       return specs if locked_version.nil?

would fix that. Happy to try it either on this branch or a follow up!

@simi simi added this pull request to the merge queue Mar 27, 2023
Merged via the queue into rubygems:master with commit 3421ec3 Mar 28, 2023
@siegfault siegfault deleted the add_gem_version_promoter_specs branch March 28, 2023 02:04
@deivid-rodriguez deivid-rodriguez changed the title Add gem version promoter specs Fix prereleases not being considered by gem version promoter when there's no lockfile Apr 10, 2023
deivid-rodriguez pushed a commit that referenced this pull request Apr 10, 2023
Add gem version promoter specs

(cherry picked from commit 3421ec3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants