-
-
Notifications
You must be signed in to change notification settings - Fork 629
Fix load-based precompile hook execution path #2419
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require_relative "spec_helper" | ||
|
|
||
| RSpec.describe "Shakapacker precompile hook shared script" do | ||
| before do | ||
| load File.expand_path("../support/shakapacker_precompile_hook_shared.rb", __dir__) | ||
| end | ||
|
|
||
| it "exposes run_precompile_tasks for load-based callers" do | ||
| allow(self).to receive(:build_rescript_if_needed) | ||
| allow(self).to receive(:generate_packs_if_needed) | ||
|
|
||
| run_precompile_tasks | ||
|
|
||
| expect(self).to have_received(:build_rescript_if_needed) | ||
| expect(self).to have_received(:generate_packs_if_needed) | ||
| end | ||
| end | ||
|
Comment on lines
+1
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test was not run per PR description The PR description states this test is "UNTESTED in this environment" due to a Ruby version mismatch. Per AGENTS.md policy: "Never claim a test is 'fixed' without running it locally first." The test should be verified in CI or by another contributor before merging. Additionally, the test only asserts that Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||
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.
Global method pollution from
loadinbeforeblockUsing
loadin thebeforeblock definesrun_precompile_tasks,build_rescript_if_needed,generate_packs_if_needed,find_rails_root, anddetect_package_manageras private instance methods onObject. These persist for the entire test suite run and could interfere with other specs.Consider wrapping the load in a clean module to isolate these methods:
Alternatively, at minimum, the
beforeblock should useload shared_path, true(the second argument wraps the code in an anonymous module) to prevent global leakage:Note: using
load path, truewould wrap the methods in an anonymous module, making them inaccessible from the test. So theModule.newapproach or a different isolation strategy would be needed if this is a concern.