Fix install generator --pretend side effects and crash#2536
Fix install generator --pretend side effects and crash#2536
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughAdds pretend-mode guards and option propagation to the install and base generators so shell commands, raw File.chmod calls, and several install-related creation steps are skipped and report pretend-status messages when Changes
Sequence DiagramsequenceDiagram
participant User
participant Generator
participant ShellCmd
participant FileSystem
User->>Generator: run generator (rails g react_on_rails:install [--pretend])
rect rgba(100,150,255,0.5)
Note over Generator: Normal mode (no --pretend)
Generator->>ShellCmd: run bundle add / bundle install / rails shakapacker:install
ShellCmd->>FileSystem: modify Gemfile, install gems, create shakapacker files
Generator->>FileSystem: File.chmod bin scripts
Generator-->>User: report installation complete
end
rect rgba(255,150,100,0.5)
Note over Generator: Pretend mode (--pretend)
Generator->>Generator: check options[:pretend]
Generator-->>ShellCmd: skip shell commands (pretend)
Generator-->>FileSystem: skip file writes & File.chmod (pretend)
Generator-->>User: emit pretend-status messages / show preview
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
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 fixes two
Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant InstallGenerator
participant FileSystem as FileSystem / Bundler
User->>InstallGenerator: rails g react_on_rails:install --pretend
InstallGenerator->>InstallGenerator: ensure_shakapacker_installed()
InstallGenerator->>InstallGenerator: shakapacker_configured? → false
InstallGenerator->>InstallGenerator: options[:pretend]? → true
InstallGenerator-->>User: say_status(:pretend, "Skipping...")
Note over FileSystem: bundle add / bundle install / rails shakapacker:install — NOT run
InstallGenerator->>InstallGenerator: add_bin_scripts()
InstallGenerator->>InstallGenerator: directory(...) — Thor pretend-aware, logs only
InstallGenerator->>InstallGenerator: Dir.chdir / Dir.glob → collect filenames
InstallGenerator->>InstallGenerator: options[:pretend]? → skip File.chmod
Note over FileSystem: No files created, no chmod executed
Last reviewed commit: b0c71a5 |
|
Review: Fix install generator --pretend side effects and crash The fix is well-scoped and correctly addresses the two reported issues from #2490. Guarding raw Ruby file operations with options[:pretend] is the right pattern when Thor actions cannot be used. What is done well
Potential issues / follow-ups Issue 1 - Other raw file operations are still not pretend-safe (pre-existing, worth tracking) The same class has additional raw file/dir operations not guarded by options[:pretend]:
These are pre-existing issues but would still cause real filesystem side effects under --pretend. Worth a follow-up issue. Issue 2 - add_bin_scripts test does not stub use_rsc? The test does not stub use_rsc? or gsub_file. Because the generator is initialized without --rsc, use_rsc? returns false and the gsub_file branch is skipped today. Explicitly stubbing use_rsc? to return false would make the test intent clearer and prevent future breakage if default option handling changes. Issue 3 - Dir.glob is globally mocked in the chmod test allow(Dir).to receive(:glob).with('*') applies globally for the test duration. Likely fine in practice but broader than needed. Overall this is a correct, minimal fix. The issues above are minor or pre-existing and should not block merging. |
b0c71a5 to
b8ee23e
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b8ee23ec46
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Review: Fix install generator --pretend side effects and crash This is a well-scoped, correct fix. The crashes and side effects in --pretend mode are real bugs and the guards are placed appropriately. Overall assessment The core changes are sound:
Minor inconsistencies
None of these are regressions — the actual bugs (crash and side effects) are fixed correctly. |
3f8001d to
8ef0385
Compare
Review SummaryThe core fix is well-scoped and correct — adding A few issues worth addressing: Bug:
|
Review SummaryThe fix is well-scoped and correctly addresses the reported What's good
Minor issues
Pre-existing gap: VerdictThe core bug fix is correct and complete for the reported crash and side effects. The pre-existing webpack-config gap is out of scope here. Approving with the minor notes above for follow-up. |
Honor --pretend by skipping automatic shakapacker installation commands and raw chmod calls that can crash when files are not written in dry-run mode. Add focused regression specs for both paths.
Document the install generator dry-run fix in Unreleased with PR reference.
Address review feedback by making the add_bin_scripts test explicit about non-RSC behavior and removing global Dir stubs. Also guard TypeScript file writes in pretend mode to prevent dry-run filesystem side effects.
Prevent pretend-mode chmod crash in BaseGenerator, add pretend status messages for TypeScript file generation, and add regression specs covering these paths.
8ef0385 to
6c9af04
Compare
|
Overall: Good, well-scoped fix for the reported --pretend crash. The core changes are correct and test coverage is reasonable. What works well: Guards on File.chmod in both install_generator.rb and base_generator.rb directly fix the Errno::ENOENT crash. The ensure_shakapacker_installed pretend guard prevents bundle add/install and rails shakapacker:install side effects. Guards on create_css_module_types and create_typescript_config prevent raw File.write/FileUtils.mkdir_p calls in pretend mode. One gap: install_typescript_dependencies is not guarded. In invoke_generators (~line 132), when --pretend --typescript is passed, install_typescript_dependencies executes before create_css_module_types and create_typescript_config. The latter two are now guarded but install_typescript_dependencies is not — it calls add_typescript_dependencies -> add_packages -> add_npm_dependencies, which runs real npm/yarn commands. This is the same class of side effect as the Shakapacker installation that is correctly skipped. See inline comment. Pre-existing issue (out of scope): handle_custom_webpack_config in base_generator.rb line 223 has FileUtils.cp(webpack_config_path, backup_path) without a pretend guard — worth a follow-up. |
| add_typescript_dependencies | ||
| end | ||
|
|
||
| def create_css_module_types |
There was a problem hiding this comment.
These two methods (create_css_module_types and create_typescript_config) use raw FileUtils.mkdir_p and File.write instead of Thor actions like empty_directory and create_file. The pretend guard here fixes the crash, but it produces a static status message rather than Thor's built-in "would create ..." output that users expect from a dry run.
Converting to Thor actions would make --pretend work natively without any explicit guard:
def create_css_module_types
say Rainbow("📝 Creating CSS module type definitions...").yellow
empty_directory "app/javascript/types"
create_file "app/javascript/types/css-modules.d.ts", css_module_types_content
endNot a blocker for this PR (the guard is correct as-is), but worth a follow-up since this is the root cause of why the guard is needed at all.
| end | ||
|
|
||
| def setup_react_dependencies | ||
| if options[:pretend] |
There was a problem hiding this comment.
The same if options[:pretend] / say_status / return pattern now appears 6+ times in this file and once in base_generator.rb. Consider extracting a private helper to eliminate the repetition:
def skip_in_pretend_mode!(message)
return false unless options[:pretend]
say_status :pretend, "#{message} in --pretend mode", :yellow
true
endThen each guard becomes a single line, e.g.:
def setup_react_dependencies
return if skip_in_pretend_mode!("Skipping React dependency setup")
setup_js_dependencies
end| install_generator.send(:create_typescript_config) | ||
| end | ||
|
|
||
| it "forwards pretend mode to base and react_no_redux generators" do |
There was a problem hiding this comment.
The TypeScript install branch (install_typescript_dependencies, create_css_module_types, create_typescript_config) is skipped here because install_generator has no typescript: true, but this is implicit. Adding a negative expectation would make the test intent explicit and guard against accidental regressions if the default ever changes:
expect(install_generator).not_to receive(:install_typescript_dependencies)
Summary
Fixes
rails g react_on_rails:install --pretendso it behaves like a real dry run.--pretendmode (prevents realbundle add/installandrails shakapacker:installside effects)File.chmodinadd_bin_scriptsduring--pretend(preventsErrno::ENOENTcrash when files are not created)Fixes #2490
Testing
bundle exec rspec react_on_rails/spec/react_on_rails/generators/install_generator_spec.rbbundle exec rspec react_on_rails/spec/react_on_rails/generators/install_generator_spec.rb:1019 react_on_rails/spec/react_on_rails/generators/install_generator_spec.rb:1032bundle exec rubocop react_on_rails/lib/generators/react_on_rails/install_generator.rb react_on_rails/spec/react_on_rails/generators/install_generator_spec.rbNote
Low Risk
Small, well-scoped changes limited to generator side effects and tests; main risk is inadvertently skipping required setup outside
--pretend, but behavior is gated on the option.Overview
Fixes
react_on_rails:installto behave like a real dry-run under--pretendby skipping automatic Shakapacker installation (avoids runningbundle add/installandrails shakapacker:install) and avoidingFile.chmodon bin scripts when files aren’t created.Adds regression specs covering both pretend-mode paths (Shakapacker install skip message + no chmod).
Written by Cursor Bugbot for commit 206004e. Configure here.
Summary by CodeRabbit
Bug Fixes
Tests
Documentation