-
-
Notifications
You must be signed in to change notification settings - Fork 633
Fix bin/dev failing with 'Unknown argument' when using --route flag #2273
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
Conversation
WalkthroughAdds a FLAGS_WITH_VALUES constant and an extract_command_from_args(args) helper in ReactOnRails::Dev::ServerManager to skip flags and their values (e.g., Changes
Sequence Diagram(s)(omitted — changes are local argument-parsing logic without multi-component sequential interactions) Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 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 |
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
react_on_rails/lib/react_on_rails/dev/server_manager.rb (1)
151-152: LGTM! The constant correctly identifies flags that consume values.The constant is complete for the current OptionParser configuration (--route and --rails-env are the only flags taking values).
Optional: Improve maintainability
Consider adding a comment to remind future developers to update this constant when adding new flags with values:
# Flags that take a value as the next argument (not using = syntax) +# NOTE: When adding new flags to OptionParser that take values, update this list FLAGS_WITH_VALUES = %w[--route --rails-env].freeze
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
react_on_rails/lib/react_on_rails/dev/server_manager.rb
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rb
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.rb: Runbundle exec rubocopand fix ALL violations before every commit/push
Runbundle exec rubocop(MANDATORY) before every commit to ensure zero offenses
Files:
react_on_rails/lib/react_on_rails/dev/server_manager.rb
🧠 Learnings (5)
📓 Common learnings
Learnt from: CR
Repo: shakacode/react_on_rails PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-19T18:57:59.314Z
Learning: Applies to /{CHANGELOG.md,CHANGELOG_PRO.md} : Use format `[PR 1818](https://github.com/shakacode/react_on_rails/pull/1818) by [username](https://github.com/username)` in changelog entries (no hash in PR number)
📚 Learning: 2025-12-19T18:57:59.314Z
Learnt from: CR
Repo: shakacode/react_on_rails PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-19T18:57:59.314Z
Learning: Applies to /CHANGELOG_PRO.md : Update `/CHANGELOG_PRO.md` for user-visible changes in the Pro-only react_on_rails_pro gem and npm packages
Applied to files:
react_on_rails/lib/react_on_rails/dev/server_manager.rb
📚 Learning: 2025-12-19T18:57:59.314Z
Learnt from: CR
Repo: shakacode/react_on_rails PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-19T18:57:59.314Z
Learning: Applies to sig/react_on_rails/**/*.rbs : RBS signatures in `sig/react_on_rails/` should be added for new Ruby files in `lib/react_on_rails/`, included in Steepfile, validated with `bundle exec rake rbs:validate`, and type-checked with `bundle exec rake rbs:steep`
Applied to files:
react_on_rails/lib/react_on_rails/dev/server_manager.rb
📚 Learning: 2025-12-19T18:57:59.314Z
Learnt from: CR
Repo: shakacode/react_on_rails PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-19T18:57:59.314Z
Learning: Applies to react_on_rails/spec/dummy/e2e/playwright/app_commands/**/*.rb : Create custom Rails app commands in `e2e/playwright/app_commands/` directory with .rb files for reusable helpers in Playwright tests
Applied to files:
react_on_rails/lib/react_on_rails/dev/server_manager.rb
📚 Learning: 2025-12-19T18:57:59.314Z
Learnt from: CR
Repo: shakacode/react_on_rails PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-19T18:57:59.314Z
Learning: Applies to /CHANGELOG.md : Update `/CHANGELOG.md` for user-visible changes in the open-source react_on_rails gem and npm package (features, bug fixes, breaking changes, deprecations, performance improvements)
Applied to files:
react_on_rails/lib/react_on_rails/dev/server_manager.rb
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: dummy-app-integration-tests (3.4, 22, latest)
- GitHub Check: rspec-package-tests (3.4, latest)
- GitHub Check: build
- GitHub Check: claude-review
🔇 Additional comments (2)
react_on_rails/lib/react_on_rails/dev/server_manager.rb (2)
160-161: Excellent fix! This correctly delegates to the new extraction logic.The updated comment clearly explains the problem being solved, and delegating to
extract_command_from_argsproperly handles flag values.
222-246: Logic is sound, but RuboCop compliance verification required.The
extract_command_from_argsmethod correctly:
- Skips argument values that follow flags in
FLAGS_WITH_VALUES(currently--routeand--rails-env)- Ignores all flags starting with
-or--- Returns the first non-flag, non-value argument as the command
- Returns
nilif no command is foundThe implementation properly handles the documented examples. Before merging, verify this file passes RuboCop without violations, as required by your coding guidelines.
Code Review - PR #2273OverviewThis is a well-executed bug fix addressing a regression from PR #2092. The implementation is clean and surgical. Strengths
Critical Issue: Missing Automated Test CoverageThe fix lacks regression tests. Add tests for:
Without tests, future refactors could re-introduce this bug. Additional Recommendations
Security and Performance
Final AssessmentCode Quality: 4/5 stars Great fix that solves a real user-facing issue! Please add regression tests either in this PR or as immediate follow-up. |
Code Review - PR #2273This PR fixes a critical bug where bin/dev fails after running rails generate react_on_rails:install due to incorrect command extraction when using the --route flag. Strengths
Code QualityArchitecture: Follows Single Responsibility Principle with extract_command_from_args method. Security: No concerns - only parses structure, validation exists elsewhere (lines 458-464). Performance: Negligible - O(n) with early return, runs once at startup. Suggestions
RecommendationAPPROVE with minor suggestions This is a high-quality fix that solves a critical user-facing bug with excellent test coverage. Before Merging:
Great work identifying this regression and providing a clean fix! Review completed by Claude Code |
|
Claude finished @justin808's task in 1m 2s —— View job Unable to Access PR #2309I cannot access PR #2309 directly due to tool limitations (GitHub CLI and web fetch require additional permissions). What I can confirm about THIS PR (#2273): This PR is currently on branch
To answer your question about PR #2309: Could you clarify what PR #2309 addresses? Specifically:
If you can share the PR #2309 URL or description, I can better assess whether they're duplicates or if one supersedes the other. |
|
@justin808 @claude PR #2309 fixes the default case (the generated However, the parser bug still exists. Per https://docs.ruby-lang.org/en/3.0/OptionParser.html, both bin/dev --route=hello_world # works
bin/dev --route hello_world # fails with "Unknown argument: hello_world"This PR fixes the early command extraction to handle both formats correctly, and adds unit tests for argument parsing. |
The early command extraction in `run_from_command_line` was incorrectly picking up flag values as commands. For example, when bin/dev passes `["--route", "hello_world"]`, the method found "hello_world" as the "command" instead of recognizing it as the value for --route. This was introduced in PR #2092 which moved command extraction before OptionParser to enable skipping precompile hooks for kill/help commands. The fix adds `extract_command_from_args` that properly skips values following flags like --route and --rails-env. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add comprehensive unit tests for ServerManager.run_from_command_line argument parsing. These tests follow Rails' CLI testing pattern (testing argument parsing without starting actual processes). Tests cover: - --route flag with separate value (generator default) - --route=value syntax - Command positioning relative to flags - --rails-env flag parsing - --verbose/-v flag parsing - Multiple flags in various orders - Unknown command error handling These tests would have caught the --route parsing bug that this PR fixes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
73a1451 to
f43a957
Compare
Code Review - PR #2273SummaryThis PR fixes a critical bug where ✅ Strengths1. Problem Identification & Root Cause Analysis
2. Implementation Quality
3. Test Coverage
4. Documentation
🔍 Observations & Suggestions1. Generator Template Discrepancy argv_with_defaults.push("--route=\#{DEFAULT_ROUTE}")However, the PR description states the generator passes
Recommendation: Verify all generator templates use the 2. Edge Case: What if a flag value looks like a command? bin/dev --route staticCurrent behavior: Would correctly treat 3. Edge Case: Equals sign in separate arg syntax bin/dev --route "my=route"This should work fine, but worth adding a test if this is a valid use case. 4. FLAGS_WITH_VALUES Maintainability Potential enhancement (not blocking): # Could add a comment reminder
# Flags that take a value as the next argument (not using = syntax)
# IMPORTANT: When adding new flags to OptionParser, update this list if they take values
FLAGS_WITH_VALUES = %w[--route --rails-env].freeze5. Security: No injection risks 📋 Testing RecommendationsBefore Merge:
After Merge:
🎯 Performance Considerations
🏆 Best Practices AdherencePer
✨ Final RecommendationAPPROVE with minor suggestions This is a well-implemented fix for a critical bug. The code is clean, well-tested, and solves the problem elegantly. The suggestions above are mostly for documentation and future maintainability, not blockers. Action Items (Optional):
Great work on the thorough testing and clear problem analysis! 🎉 |
Summary
Fixes
bin/devfailing with "Unknown argument: hello_world" immediately after runningrails generate react_on_rails:install.Problem
The generator creates a
bin/devscript that passes["--route", "hello_world"]toServerManager.run_from_command_line. The early command extraction (added in PR #2092) was incorrectly picking up "hello_world" as the command instead of recognizing it as the value for--route.Root Cause
PR #2092 moved command extraction before OptionParser to enable skipping precompile hooks for
kill/helpcommands:Solution
Added
extract_command_from_argsmethod that properly skips values following flags like--routeand--rails-env:Test Plan
server_manager_spec.rbtests pass./bin/devworksbin/dev help,bin/dev kill,bin/dev staticstill work correctly🤖 Generated with Claude Code
Summary by CodeRabbit
Refactor
Tests
✏️ Tip: You can customize this high-level summary in your review settings.