Supersede #911: compiler_spec call-count refactor with lint unblock#920
Supersede #911: compiler_spec call-count refactor with lint unblock#920
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughExpands and hardens precompile_hook tests in Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile SummaryThis PR refactors Key changes:
Issues found:
Confidence Score: 2/5
Important Files Changed
Last reviewed commit: ad0410f |
ad0410f to
79f369b
Compare
PR Review\n\nThis is a clean test-quality improvement. |
|
PR Review This is a clean test-quality improvement that aligns with the project preferred spy assertion patterns. The core refactor is sound and the logic is correct. What works well
Issues Minor: have_received assertion missing from the nonexistent-hook test The 'warns when hook executable does not exist' test had call_count removed and hook_executable added for consistency, but unlike the other refactored tests it did not gain an explicit have_received(:capture3) assertion. The CLAUDE.md guidelines call for have_received over counter patterns. Adding one would complete the consistency story. Minor: hash_including without arguments is overly permissive In the new assertions such as with(hash_including, hook_executable, hash_including), hash_including with no arguments matches any hash. For the last arg (which always contains chdir:), using hash_including(chdir: anything) would document intent and catch regressions where chdir is accidentally dropped. Nit: duplicate conditional in shell-injection test In the 'prevents shell injection' test, args[0] == hook_executable is evaluated twice in successive lines - once for captured_args and once for the if/else. A combined expression would be slightly cleaner, though readable as-is. Verdict Approve with the suggestion to add the missing have_received assertion for the nonexistent-hook test and consider tightening the hash_including matchers. The .prettierignore change mentioned in the PR description does not appear in the diff - worth confirming if it was intentionally dropped. |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
spec/shakapacker/compiler_spec.rb (1)
253-274: Use directhave_received(...).onceassertions in the remaining hook spy examples.These examples still infer the hook call through
captured_args/captured_env. They fail if the hook never runs, but they will still pass if it runs more than once. A direct spy assertion keeps the refactor consistent and preserves the call-count protection you removed elsewhere.♻️ Prefer explicit spy assertions here too
- captured_args = [] allow(Open3).to receive(:capture3) do |env, *args| - captured_args << args if args[0] == hook_executable if args[0] == hook_executable ["", "", hook_status] else ["", "", webpack_status] end end @@ expect(Shakapacker.compiler.compile).to be true - expect(captured_args[0][0]).to eq("bin/prepare") - expect(captured_args[0][1..4]).to eq(["&&", "rm", "-rf", "/"]) + expect(Open3).to have_received(:capture3) + .with(hash_including, hook_executable, "&&", "rm", "-rf", "/", hash_including) + .once @@ - captured_env = nil allow(Open3).to receive(:capture3) do |env, *args| - captured_env = env if args[0] == hook_executable if args[0] == hook_executable ["", "", hook_status] else ["", "", webpack_status] end end @@ expect(Shakapacker.compiler.compile).to be true - expect(captured_env["FOO"]).to eq("bar") - expect(captured_env["BAZ"]).to eq("qux") + expect(Open3).to have_received(:capture3) + .with(hash_including("FOO" => "bar", "BAZ" => "qux"), hook_executable, "--arg", hash_including) + .onceAs per coding guidelines:
**/*_spec.rb: Use explicit RSpec spy assertions withhave_received/not_to have_receivedinstead of indirect counter patterns.Also applies to: 286-304
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@spec/shakapacker/compiler_spec.rb` around lines 253 - 274, The test is using an indirect captured_args pattern to assert the precompile hook ran and with specific arguments; replace those with direct RSpec spy assertions: keep the allow(Open3).to receive(:capture3) spy setup but remove the captured_args inspection and instead add explicit expectations like expect(Open3).to have_received(:capture3).once.with(kind_of(Hash), include(hook_executable), anything) or a more specific .with(...) matching the exact argument array (e.g., "bin/prepare", "&&", "rm", "-rf", "/") after calling Shakapacker.compiler.compile; apply the same replacement for the similar hook assertions around lines 286-304 so the tests assert the hook was invoked exactly once and with the intended arguments.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@spec/shakapacker/compiler_spec.rb`:
- Around line 176-193: The test currently only asserts two trailing args, which
doesn't verify correct parsing of the quoted hook path; update the spec around
Shakapacker.compiler.compile/Open3.capture3 to assert the exact parsed argv:
when precompile_hook is "'bin/my script' --arg1 --arg2" ensure capture3 is
invoked with the executable token matching hook_executable and the following
args equal to "--arg1" and "--arg2" (e.g. change the have_received matcher to
expect hash_including, hook_executable, "--arg1", "--arg2", hash_including or
otherwise explicitly assert the parsed argv produced from the hook_command).
---
Nitpick comments:
In `@spec/shakapacker/compiler_spec.rb`:
- Around line 253-274: The test is using an indirect captured_args pattern to
assert the precompile hook ran and with specific arguments; replace those with
direct RSpec spy assertions: keep the allow(Open3).to receive(:capture3) spy
setup but remove the captured_args inspection and instead add explicit
expectations like expect(Open3).to
have_received(:capture3).once.with(kind_of(Hash), include(hook_executable),
anything) or a more specific .with(...) matching the exact argument array (e.g.,
"bin/prepare", "&&", "rm", "-rf", "/") after calling
Shakapacker.compiler.compile; apply the same replacement for the similar hook
assertions around lines 286-304 so the tests assert the hook was invoked exactly
once and with the intended arguments.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 4331d69c-d4ab-4e9d-b1cd-22666925277b
📒 Files selected for processing (1)
spec/shakapacker/compiler_spec.rb
Address PR review comments: the Open3.capture3 stubs in three tests used |*args| with args[1], but since capture3 receives the env hash as its first argument, the correct pattern is |env, *args| with args[0], consistent with the other tests in the file. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…piler spec Address PR review comments: - Introduce hook_executable variable in verbose-hook and nonexistent-hook tests for consistency with other tests that separate command from executable - Add have_received(:capture3) assertions to verify hooks are actually invoked, not just that compile returns true Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
9c8cabc to
fa573e3
Compare
|
Code Review: Good refactor overall. Replacing call_count with args-based dispatching models intent rather than invocation order. See inline comments for specific issues. |
ReviewThe core refactor—replacing Scope concern The
Several new expect(Open3).to have_received(:capture3).with(hash_including, hook_executable, hash_including).once
The inconsistency is visible on line 325 (skip test) which uses Minor: redundant When |
### Summary Adds the v9.7.0 changelog section with release notes for all user-visible changes since v9.6.1: - **Added**: rspack v2 support (PR #975) - **Fixed**: Config exporter path traversal and annotation format validation (PR #914) - **Fixed**: `webpack-subresource-integrity` v5 named export handling (PR #978, fixes #972) Version diff links at the bottom of the file are updated accordingly. ### Pull Request checklist - [x] ~Add/update test to cover these changes~ - [x] ~Update documentation~ - [x] Update CHANGELOG file ### Other Information Non-user-visible PRs (#920, #965, #970, #971, #977, #979, #981, #982) were intentionally excluded per changelog policy. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Documentation-only change updating `CHANGELOG.md`; no runtime code or dependency changes are introduced in this PR. > > **Overview** > Adds a new `v9.7.0` section to `CHANGELOG.md` documenting user-visible changes (rspack v2 support and two fixes around config export security/validation and `webpack-subresource-integrity` v5 exports). > > Updates the compare links at the bottom so `[Unreleased]` now compares from `v9.7.0`, and adds the new `[v9.7.0]` tag link. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 8942a43. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added rspack v2 support * **Bug Fixes** * Improved security and validation handling <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
### Summary Adds the v9.7.0 changelog section with release notes for all user-visible changes since v9.6.1: - **Added**: rspack v2 support (PR #975) - **Fixed**: Config exporter path traversal and annotation format validation (PR #914) - **Fixed**: `webpack-subresource-integrity` v5 named export handling (PR #978, fixes #972) Version diff links at the bottom of the file are updated accordingly. ### Pull Request checklist - [x] ~Add/update test to cover these changes~ - [x] ~Update documentation~ - [x] Update CHANGELOG file ### Other Information Non-user-visible PRs (#920, #965, #970, #971, #977, #979, #981, #982) were intentionally excluded per changelog policy. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Documentation-only change updating `CHANGELOG.md`; no runtime code or dependency changes are introduced in this PR. > > **Overview** > Adds a new `v9.7.0` section to `CHANGELOG.md` documenting user-visible changes (rspack v2 support and two fixes around config export security/validation and `webpack-subresource-integrity` v5 exports). > > Updates the compare links at the bottom so `[Unreleased]` now compares from `v9.7.0`, and adds the new `[v9.7.0]` tag link. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 8942a43. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added rspack v2 support * **Bug Fixes** * Improved security and validation handling <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Supersedes #911.
Includes:
Closes #855
Note
Low Risk
Test-only refactor that changes how mocks detect the hook call; production behavior is unchanged, with minimal risk beyond potential spec brittleness.
Overview
Updates
spec/shakapacker/compiler_spec.rbto remove manualcall_countlogic in severalprecompile_hookexamples and instead branch theOpen3.capture3stub based on the invoked command/executable, using sharedhook_command/hook_executablevariables.This makes the tests align with the real
Open3.capture3(env, executable, *args, chdir: ...)signature and improves robustness for cases like quoted paths, missing executables, command chaining, and env-var-prefixed hook commands.Written by Cursor Bugbot for commit 3df53f2. Configure here.
Summary by CodeRabbit