Avoid requiring add-ons that are copied into the workspace #3669
+53
−4
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.
Motivation
Addresses #3279 (comment)
If users have gems copied inside their workspace without pointing their BUNDLE_PATH to it, requiring project add-ons will require incorrect versions of gems by accident - leading to unpredictable behaviour.
In #3279, it seems that the workspace had gems in
vendor/bundle
despiteBUNDLE_PATH
not pointing to it. In that situation, we get the reported bug. This is a pretty odd setup, but we shouldn't crash in hard to debug ways.Implementation
The essence of the problem is discovering an add-on for the same gem twice. The correct discovery always comes from
Gem.find_files
, so I propose that we create an array of glob patterns to reject from the list of correctly discovered add-ons.Then we reject any occurrences inside of the workspace that match the glob pattern, regardless of the gem version. Hopefully, this can avoid any form of requiring multiple versions of the same add-on.
Automated Tests
Added a test that reproduces the issue.