Fix incorrect removal of ruby platform when auto-healing corrupted lockfiles #6495
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What was the end-user or developer problem that led to this PR?
In certain situations, when auto-healing a corrupted lockfile we will end up removing the "RUBY" platform from the lockfile, when not necessary.
This is because we sometimes also "heal" the lockfile PLATFORMS section, because some old lockfiles including the "RUBY" platform incorrectly and can't bundle in newer bundler versions, so we remove it for backwards compatibility.
However, our check to detect these corrupt lockfiles that are locked to the RUBY platform but don't work with it, sometimes was triggering incorrectly.
One is for lockfile with empty SPECS section, another one is for lockfile missing dependencies.
I found these bugs while working on #5700, where I plan to generate a "universal lockfile" by default (with more than just the current platform), so this kind of issue surfaces more since we deal with multiple lockfile platforms in more cases.
What is your fix for the problem, implemented in this PR?
Fixing the latter bug made me realize we were relying too much on state (keeping
@incomplete_platforms
and propagating it throughSpecSet
s), making this bug easy to happen. I refactored things by extracting anIncompleteSpecification
class that makes things easier to follow and more consistent with how we handle missing specifications.Make sure the following tasks are checked