-
Notifications
You must be signed in to change notification settings - Fork 110
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
Add missing .realpath checks that was causing validation error #65
Conversation
78b3786
to
f197497
Compare
f197497
to
cb28507
Compare
lib/packwerk/configuration.rb
Outdated
path = Pathname.new(path_string) | ||
|
||
next unless path.exist? | ||
# ignore paths outside of the Rails root | ||
next unless path.exist? && path.realpath.fnmatch(Rails.root.join("**").to_s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously we did the check to see if the path exist and if the realpath version matches a path inside the rails root. The latter part of the check was removed in this PR: https://github.com/Shopify/packwerk/pull/21/files#diff-e43184d1a960a3c3821da21b3eb72c83379c2dcc996f6bcfac9aadd6898cd374L64
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: it feels a bit clearer to me if these two conditionals exist on their own lines:
next unless path.exist?
next unless path.realpath.fnmatch(Rails.root.join("**").to_s)
path.exist?
is a precondition for the rest of the loop, not just for your new Rails path condition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we test this new condition in configuration_test? Maybe by appending an external path to Rails.application.config.autoload_paths
beforehand? Don't forget to restore the paths to their old value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we test this new condition in configuration_test? Maybe by appending an external path to Rails.application.config.autoload_paths beforehand? Don't forget to restore the paths to their old value.
Tested in #68 where this logic was moved into its own class.
@@ -329,7 +329,8 @@ def package_glob | |||
end | |||
|
|||
def package_manifests(glob_pattern) | |||
PackageSet.package_paths(@configuration.root_path, glob_pattern).map(&:to_s) | |||
PackageSet.package_paths(@configuration.root_path, glob_pattern) | |||
.map { |f| File.realpath(f) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The .realpath
was removed in this PR: https://github.com/Shopify/packwerk/pull/38/files#diff-5ca9dcd54fd0b9eeef94e00ba6adc7822dc83e5dd2bfb9e8d96fd3c356de8b8aL328
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I verified that File.realpath(Pathname)
returns a string, so there's no need to add to_s
like in the old code.
[9] pry(main)> File.realpath(Pathname.new("."))
=> "/Users/rochlefebvre/src/github.com/Shopify/parsnip"
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\nit I'm thinking out loud here, but could it make sense to add a method to the PackageSet that returns all the realpaths for the given packages instead of ApplicationValidator being aware of retrieving that information? 🤔
cb28507
to
320a2c2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we can add a test, we can merge this. Thank you, Maple!
I know this is not optimal, but I tried testing and it is hard. Two changes in this PR:
I don't want to avoid testing. Can you see any easy test suite I can add to account for either these two cases? Otherwise I vote to ship this change/release and work on the test in another PR. |
The way I see it,
The part that broke was |
0e59851
to
94598e1
Compare
paths.map { |path| path.relative_path_from(rails_root).to_s } | ||
paths | ||
.map { |path| path.relative_path_from(rails_root).to_s } | ||
.uniq |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need this .uniq
because #filter_relevant_paths
may result in some added load paths. This was causing a failure when I tophatted on Core.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The .uniq
was removed from ApplicationValidator
here, but I figure it is best to add it in this class so we can also test for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code change looks correct to me. I tophatted it on core and it works. Thank you!
Apologies for the breakage, everyone! I was just looking at the latest version and spotted that I managed to break an entire release. 🤦 It worked on our codebase! |
What are you trying to accomplish?
There are two bugs in
v1.0.1
that results inpackwerk validate
failure because the paths were not real paths as it was recently removed. Because there was no test to catch it, this ended up in a release.What approach did you choose and why?
There are two fixes in this PR. I have linked the appropriate PRs / line change that caused the bug.
What should reviewers focus on?
We should get this change out ASAP.
You can help by confirming this change with the steps below:
bin/spring packwerk validate
- this will failType of Change
Additional Release Notes
Include any notes here to include in the release description. For example, if you selected "breaking change" above, leave notes on how users can transition to this version.
If no additional notes are necessary, delete this section or leave it unchanged.
Checklist