Make Rails engine path check more specific #1925
Merged
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
We load Rails engines that are defined inside the current gem's directory and extract symbols to process from that engine's eager auto load paths.
When Rails is installed through a release version, this works perfectly because each gem is placed in a sibling directory
However, when Rails is installed via a git source, Bundler nests all of the sub-gems inside the same directory
The result is that we get symbols that belong to the sub-gems (activestorage, actionmailbox) placed inside the Rails RBI, which is incorrect. Note that this problem only happens if another gem eagerly requires one of the engines.
Implementation
Currently, we are checking if the engine's root is anywhere inside the gem's full path.
I'm proposing that we changed to be more specific and only check if the engine root is exactly equal to the gem path.
I don't know the original logic was intentional. If we do need to check sub-directories, then I'm not sure how we would go about fixing this. Maybe we can verify if the gem was installed through a git source and only do the more specific matching in that case?
I did verify this change on Core and everything looks fine.
Tests
Added a test that reproduces the behaviour.