Skip to content

Conversation

@justin808
Copy link
Member

@justin808 justin808 commented Nov 21, 2025

Summary

Fixes #2084 - Pack generation now works correctly when running bin/dev from within a Bundler context.

Problem

When running bin/dev, pack generation was failing with:

πŸ“¦ Generating packs... βœ…
Running `bundle react_on_rails:generate_packs` with bundler 2.4.17
Could not find command "react_on_rails:generate_packs".
❌ Pack generation failed

The pack generation actually succeeded (note the βœ…), but then Bundler tried to execute bundle react_on_rails:generate_packs as a gem executable command instead of bundle exec rake react_on_rails:generate_packs, which failed.

Root Cause

In lib/react_on_rails/dev/pack_generator.rb, the run_via_bundle_exec method uses:

system("bundle", "exec", "rake", "react_on_rails:generate_packs")

When this is called from within an existing Bundler context (which is the case when running bin/dev), Bundler intercepts the system call and tries to parse the arguments. It sees "react_on_rails:generate_packs" and attempts to execute it as a gem executable via Bundler's auto-exec feature, rather than passing it through to rake.

Solution

The fix wraps the bundle exec subprocess call with Bundler.with_unbundled_env to prevent Bundler from intercepting when already running inside a Bundler context:

def run_via_bundle_exec(silent: false)
  # Need to unbundle to prevent Bundler from intercepting our bundle exec call
  # when already running inside a Bundler context (e.g., from bin/dev)
  with_unbundled_context do
    # ... system calls ...
  end
end

Added a with_unbundled_context helper method that supports both new (with_unbundled_env) and legacy (with_clean_env) Bundler APIs for backwards compatibility.

Testing

  • All existing RSpec tests pass
  • Pre-commit hooks verified (RuboCop, trailing newlines)
  • The fix follows the same pattern already used in process_manager.rb

Impact

This fix affects all users of bin/dev in react_on_rails when:

  • Running from a Bundler context (which is typical)
  • Rails isn't pre-loaded (which is normal for bin/dev)

πŸ€– Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Fixed pack generation failure in bin/dev when running from Bundler context. Resolves the error "Could not find command 'react_on_rails:generate_packs'" that previously prevented successful pack initialization.
  • Tests

    • Added comprehensive test coverage for pack generation across various Bundler context scenarios, ensuring compatibility with different Bundler API versions and fallback cases.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 21, 2025

Walkthrough

The PR fixes a bug where pack generation fails when running bin/dev from within a Bundler context. The fix adds a helper method to execute bundle commands in an unbundled Bundler environment, preventing Bundler from intercepting subprocess calls and attempting to resolve commands as gem executables.

Changes

Cohort / File(s) Summary
Changelog Documentation
CHANGELOG.md
Adds a new bug fix subsection under Unreleased documenting the resolution of pack generation failures in bin/dev when running from a Bundler context.
Pack Generator Implementation
lib/react_on_rails/dev/pack_generator.rb
Adds with_unbundled_context helper method to safely execute code outside active Bundler contexts with fallback support for Bundler.with_unbundled_env, Bundler.with_clean_env, or direct execution. Wraps the run_via_bundle_exec method to execute bundle calls within an unbundled context.
Pack Generator Tests
spec/react_on_rails/dev/pack_generator_spec.rb
Adds comprehensive test context covering Bundler context unwrapping behavior: verification of with_unbundled_env invocation, fallback to with_clean_env, direct execution when neither method exists, and handling when Bundler is undefined.

Sequence Diagram

sequenceDiagram
    participant Caller
    participant PackGenerator
    participant BundlerAPI
    participant System

    Caller->>PackGenerator: run_via_bundle_exec(silent: false)
    PackGenerator->>PackGenerator: with_unbundled_context(&block)
    
    alt Bundler defined
        alt with_unbundled_env available
            PackGenerator->>BundlerAPI: Bundler.with_unbundled_env
            activate BundlerAPI
            BundlerAPI->>System: system("bundle", "exec", "rake", ...)
            System-->>BundlerAPI: success
            deactivate BundlerAPI
        else with_clean_env fallback
            PackGenerator->>BundlerAPI: Bundler.with_clean_env
            activate BundlerAPI
            BundlerAPI->>System: system("bundle", "exec", "rake", ...)
            System-->>BundlerAPI: success
            deactivate BundlerAPI
        else neither available
            PackGenerator->>System: system("bundle", "exec", "rake", ...)
            System-->>PackGenerator: success
        end
    else Bundler not defined
        PackGenerator->>System: system("bundle", "exec", "rake", ...)
        System-->>PackGenerator: success
    end
    
    PackGenerator-->>Caller: completion
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • New helper method is straightforward conditional logic with clear fallback chain
  • Existing method modification is minimal and isolated
  • Test coverage is comprehensive and verifies each conditional path
  • Focused change set with consistent pattern application

Possibly related PRs

  • PR #1907 β€” Addresses the same pack generation failure by adding a direct rake-task execution path when inside Bundler, offering an alternative approach to the same underlying issue.
  • PR #1833 β€” Implements the same with_unbundled_context helper pattern and fallbacks to with_unbundled_env/with_clean_env for executing external commands outside active Bundler contexts.
  • PR #1916 β€” Modifies the same PackGenerator class and changes the generation flow, potentially affected by or related to this Bundler context fix.

Suggested labels

bug, review-needed

Suggested reviewers

  • AbanoubGhadban
  • ihabadham

Poem

🐰 A bundler unwrapped, the packs now run free,
No more interception from Bundler's decree!
With context unbundled, the subprocess flies,
Bundle exec succeeds, no more "command" lies! πŸ“¦βœ¨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
βœ… Passed checks (4 passed)
Check name Status Explanation
Description Check βœ… Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check βœ… Passed The title accurately describes the main change: fixing pack generation in bin/dev by preventing Bundler interception.
Linked Issues check βœ… Passed The PR fully addresses issue #2084 by implementing the with_unbundled_context helper and wrapping bundle exec calls to prevent Bundler interception.
Out of Scope Changes check βœ… Passed All changes are directly scoped to fixing the Bundler interception issue; no extraneous modifications detected.
✨ Finishing touches
  • πŸ“ Generate docstrings
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch jg-/fix-pack-gen-bundler

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.

❀️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@claude
Copy link

claude bot commented Nov 21, 2025

Code Review - PR #2085

βœ… Overall Assessment

This PR successfully fixes the pack generation failure in bin/dev by preventing Bundler auto-exec interception. The solution is well-implemented, follows existing patterns in the codebase, and includes clear documentation.


🎯 Strengths

  1. Root Cause Analysis: The PR description provides excellent analysis of why Bundler was intercepting the bundle exec call - this is valuable documentation for future maintainers.

  2. Consistent Pattern: The with_unbundled_context implementation exactly matches the pattern already used in process_manager.rb (lines 120-129), maintaining consistency across the codebase.

  3. Backwards Compatibility: The helper method gracefully handles both modern (with_unbundled_env) and legacy (with_clean_env) Bundler APIs, plus a fallback for very old versions.

  4. Minimal Scope: The change is surgical - only wrapping the system call with the unbundled context, without unnecessary refactoring.

  5. Clear Documentation: Inline comments explain why the unbundling is necessary, referencing the specific use case (bin/dev).


πŸ” Code Quality Observations

Good:

  • Clean separation of concerns - the new with_unbundled_context method is DRY and reusable
  • Proper error handling maintained (existing error paths unchanged)
  • No behavioral changes to the happy path

Potential Consideration:

  • Code Duplication: The with_unbundled_context method is now duplicated between pack_generator.rb (lines 160-173) and process_manager.rb (lines 120-129). This is currently acceptable since:

    • Each class may be used independently
    • The duplication is minimal (13 lines of defensive code)
    • Extracting to a shared module might add unnecessary complexity

    However, if this pattern spreads to a third location, consider extracting it to a shared utility module like ReactOnRails::Dev::BundlerUtils.


πŸ§ͺ Test Coverage

Current Coverage: The existing test suite in spec/react_on_rails/dev/pack_generator_spec.rb has comprehensive coverage:

  • Tests when Bundler context is present (lines 44-143)
  • Tests when Bundler context is absent (lines 145-185)
  • Tests various error conditions

Gap Identified: The new with_unbundled_context method wrapping is not explicitly tested. Consider adding a test case that:

  1. Mocks Bundler.with_unbundled_env to verify it's called when running bundle exec
  2. Verifies the fallback chain works correctly (with_unbundled_env β†’ with_clean_env β†’ bare yield)

Example test structure:

context "when calling bundle exec from within Bundler context" do
  it "unwraps the Bundler context before executing" do
    stub_const("Bundler", Module.new)
    allow(Bundler).to receive(:respond_to?).with(:with_unbundled_env).and_return(true)
    allow(Bundler).to receive(:with_unbundled_env).and_yield
    
    described_class.generate(verbose: false)
    
    expect(Bundler).to have_received(:with_unbundled_env)
  end
end

πŸ”’ Security & Performance

Security: βœ… No security concerns. The change only affects how subprocesses are spawned.

Performance: βœ… Negligible impact. The unbundling operation is lightweight and only affects the bundle exec code path (fallback case).


πŸ“‹ Checklist Items (from CLAUDE.md)

  • βœ… RuboCop compliance: Mentioned in PR description
  • βœ… Trailing newlines: Verified via pre-commit hooks
  • βœ… Follows existing patterns: Matches process_manager.rb implementation
  • ⚠️ Test coverage: Existing tests pass, but new wrapper not explicitly tested
  • βœ… No manual formatting: Code follows RuboCop standards
  • ❓ CHANGELOG update: This is a bug fix affecting bin/dev users - should be added to CHANGELOG.md

πŸ“ Recommendations

  1. Add explicit test coverage for the with_unbundled_context wrapper to ensure the Bundler API compatibility chain works correctly.

  2. Update CHANGELOG.md with an entry like:

    #### Bug Fixes
    - [PR 2085](https://github.com/shakacode/react_on_rails/pull/2085) by [justin808](https://github.com/justin808): Fix pack generation in bin/dev when running from Bundler context
  3. Consider future consolidation: If this pattern appears in a third file, extract with_unbundled_context to a shared module.

  4. Manual verification: Before merging, verify the fix works with:

    # In spec/dummy or a test app
    bundle exec bin/dev
    # Should see: πŸ“¦ Generating packs... βœ…

πŸŽ“ Educational Note

This is an excellent example of a subtle Bundler interaction bug. The issue occurs because:

  1. bin/dev runs with Bundler loaded
  2. Calling system("bundle", "exec", "rake", "task:name") from within Bundler
  3. Bundler's auto-exec feature intercepts and tries to parse "task:name" as a gem executable
  4. Solution: Temporarily unbundle the environment before spawning the subprocess

This pattern is worth documenting in the project's knowledge base for future reference.


Overall: LGTM with minor suggestions πŸ‘

The core fix is solid and addresses the reported issue. The suggestions are minor enhancements rather than blockers.

@claude
Copy link

claude bot commented Nov 21, 2025

Code Review - PR #2085

βœ… Summary

This PR successfully fixes a real bug where pack generation fails when running bin/dev from within a Bundler context. The solution is clean, well-tested, and follows existing patterns in the codebase.


🎯 Strengths

1. Correct Root Cause Analysis

  • The PR correctly identifies that Bundler intercepts system() calls when already in a Bundler context
  • The fix mirrors the existing pattern in process_manager.rb:120-129 which uses the same with_unbundled_context helper

2. Excellent Test Coverage

  • Added 4 comprehensive test cases (lines 210-293) covering all scenarios:
    • βœ… Modern Bundler API (with_unbundled_env)
    • βœ… Legacy Bundler API (with_clean_env)
    • βœ… Very old Bundler versions (neither method available)
    • βœ… No Bundler defined
  • Tests use proper mocking to isolate behavior without external dependencies

3. Good Code Quality

  • DRY helper method with clear documentation
  • Backwards compatibility with legacy Bundler APIs
  • Graceful fallback for edge cases

4. Proper Changelog Entry

  • Follows changelog guidelines from CLAUDE.md (user-facing bug fix)
  • Correct format with PR link and author

πŸ” Observations & Suggestions

1. Code Duplication Opportunity (Minor)

The with_unbundled_context helper is now duplicated between:

  • lib/react_on_rails/dev/pack_generator.rb:160-173
  • lib/react_on_rails/dev/process_manager.rb:120-129

Note: The process_manager.rb version does NOT check if defined?(Bundler) but the pack_generator.rb version does (lines 161-172).

Question: Should these be consolidated into a shared module/concern? Or is the duplication acceptable given the small size?

If you want to DRY this up, consider:

# lib/react_on_rails/dev/bundler_context.rb
module ReactOnRails
  module Dev
    module BundlerContext
      def with_unbundled_context(&block)
        if defined?(Bundler)
          if Bundler.respond_to?(:with_unbundled_env)
            Bundler.with_unbundled_env(&block)
          elsif Bundler.respond_to?(:with_clean_env)
            Bundler.with_clean_env(&block)
          else
            yield
          end
        else
          yield
        end
      end
    end
  end
end

Then include it in both classes. However, this is optional - the current duplication is minimal and may be acceptable.

2. Inconsistency with process_manager.rb

process_manager.rb doesn't check if defined?(Bundler) before calling Bundler.respond_to?. This could raise a NameError if Bundler isn't loaded. Your implementation is actually safer.

Recommendation: Either:

  • Update process_manager.rb to match your safer implementation (add if defined?(Bundler))
  • Or leave as-is if process_manager.rb always runs in contexts where Bundler is guaranteed to be available

βœ… Security & Performance

Security: βœ… No concerns

  • No user input handling
  • No new attack surface

Performance: βœ… No concerns

  • The with_unbundled_env wrapper has negligible overhead
  • Only affects the subprocess spawn path (not the direct rake execution path)

πŸ§ͺ Testing Verification

Question: Have you manually tested this with:

  1. Running bin/dev in the spec/dummy app?
  2. Verifying pack generation succeeds without the error message?

The automated tests look excellent, but a quick manual verification would confirm the fix works end-to-end.


πŸ“ Final Recommendation

Approve with optional follow-up:

βœ… Merge as-is - The fix is correct and well-tested

πŸ”„ Optional follow-up: Consider DRYing up the with_unbundled_context helper into a shared module if code duplication becomes an issue in the future.

Great work identifying and fixing this subtle Bundler interaction issue! πŸš€

@claude
Copy link

claude bot commented Nov 21, 2025

Code Review - PR #2085

Summary

This PR fixes a critical bug where pack generation fails when running bin/dev from within a Bundler context. The fix is well-designed and follows existing patterns in the codebase.


βœ… Strengths

1. Excellent Problem Analysis

  • The issue description clearly explains the root cause (Bundler auto-exec interception)
  • The PR correctly identifies that this happens when system('bundle', 'exec', 'rake', ...) is called from within an existing Bundler context

2. Consistent with Existing Patterns

  • The with_unbundled_context helper already exists in process_manager.rb:120-129 with identical implementation
  • The fix follows the exact same pattern, ensuring consistency across the codebase

3. Backward Compatibility Handled Well

  • Supports both modern (with_unbundled_env) and legacy (with_clean_env) Bundler APIs
  • Gracefully falls back when neither method is available (very old Bundler versions)
  • Handles cases where Bundler isn't defined at all

4. Comprehensive Test Coverage

  • Added 4 test cases covering all code paths:
    • βœ… Modern Bundler API (with_unbundled_env)
    • βœ… Legacy Bundler API (with_clean_env)
    • βœ… Fallback when neither API is available
    • βœ… No Bundler defined
  • Tests use proper mocking and stubbing techniques
  • All tests verify the expected behavior

5. Proper Changelog Entry

  • Follows the project's changelog format
  • Clearly explains the bug and the fix
  • Includes PR and author attribution

πŸ” Observations & Suggestions

1. Code Duplication (Minor)

The with_unbundled_context method is now duplicated between:

  • lib/react_on_rails/dev/process_manager.rb:120-129
  • lib/react_on_rails/dev/pack_generator.rb:160-171

Suggestion for future refactoring (not blocking for this PR):
Consider extracting this to a shared module like ReactOnRails::Dev::BundlerHelpers to follow DRY principles. However, given that:

  1. This is a small helper method
  2. The duplication is localized to the Dev module
  3. It maintains consistency with existing code

The current approach is acceptable, especially for a bug fix. The duplication could be addressed in a follow-up refactoring PR.

2. Test Organization

The new tests are well-organized and placed in an appropriate context block. The use of stub_const and module mocking is appropriate for testing the Bundler API compatibility chain.

3. Security Considerations

βœ… No security concerns identified:

  • No user input is processed
  • No dynamic code execution
  • No path traversal risks
  • Uses Bundler's official APIs

4. Performance Considerations

βœ… Minimal performance impact:

  • The with_unbundled_env wrapper adds negligible overhead
  • Only runs when pack generation is triggered (typically once at app startup)

🎯 Testing Recommendations

While the unit tests are comprehensive, consider these additional manual tests:

  1. Test from within bin/dev:

    bin/dev
    # Verify pack generation succeeds without errors
  2. Test without Bundler context:

    bundle exec rake react_on_rails:generate_packs
    # Should still work
  3. Test with different Bundler versions (if feasible):

    • Modern: Bundler 2.4+
    • Legacy: Bundler 1.x (if still supported)

πŸ“‹ Checklist

  • βœ… Code follows project conventions (RuboCop compliant)
  • βœ… Changelog updated appropriately
  • βœ… Test coverage is comprehensive
  • βœ… Backward compatibility maintained
  • βœ… Follows existing patterns in codebase
  • βœ… No security concerns
  • βœ… No performance regressions
  • βœ… Git hooks would pass (RuboCop, trailing newlines)

πŸš€ Recommendation

APPROVE - This PR is ready to merge once CI passes. The fix is:

  • Well-tested
  • Follows existing patterns
  • Solves a real user-facing bug
  • Maintains backward compatibility
  • Has no security or performance concerns

The minor code duplication noted above is acceptable for a bug fix and can be addressed in a future refactoring if desired.


Great work on the thorough analysis and implementation! The detailed issue description and comprehensive test coverage make this an exemplary bug fix PR.

justin808 and others added 2 commits November 20, 2025 19:09
…eption

When running bin/dev, pack generation was failing with "Could not find
command 'react_on_rails:generate_packs'" because Bundler was intercepting
the system call and trying to execute it as a gem executable command
instead of passing it through to rake.

The fix wraps the bundle exec subprocess call with Bundler.with_unbundled_env
to prevent Bundler from intercepting when already running inside a Bundler
context.

Added with_unbundled_context helper method that supports both new
(with_unbundled_env) and legacy (with_clean_env) Bundler APIs for
backwards compatibility.

Fixes #2084

πŸ€– Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
- Added comprehensive test coverage for the with_unbundled_context wrapper
  to verify the Bundler API compatibility chain:
  * Tests with_unbundled_env (modern Bundler API)
  * Tests with_clean_env (legacy Bundler API)
  * Tests fallback when neither method is available
  * Tests execution when Bundler is not defined

- Updated CHANGELOG.md with bug fix entry for issue #2084

All 18 examples in pack_generator_spec.rb pass.

πŸ€– Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@claude
Copy link

claude bot commented Nov 21, 2025

Code Review Summary

This PR successfully fixes the Bundler auto-exec interception issue in pack generation. The implementation is solid, well-tested, and follows established patterns in the codebase. βœ…


βœ… Strengths

1. Correct Root Cause Analysis

The PR correctly identifies that Bundler intercepts system() calls when already running in a Bundler context, causing it to misinterpret react_on_rails:generate_packs as a gem executable rather than a rake task argument.

2. Follows Existing Patterns

The with_unbundled_context helper method is an exact duplicate of the implementation in process_manager.rb:120-129, which is appropriate given:

  • Both files are in the same namespace (ReactOnRails::Dev)
  • Both need identical Bundler context management
  • The duplication is minimal (13 lines)
  • Extract-to-module would add complexity without clear benefit at this scale

3. Excellent Backwards Compatibility

The with_unbundled_context method gracefully handles:

  • Modern Bundler (with_unbundled_env) βœ…
  • Legacy Bundler (with_clean_env) βœ…
  • Very old Bundler (direct yield fallback) βœ…
  • No Bundler defined (direct yield) βœ…

4. Comprehensive Test Coverage

The test suite covers all code paths:

  • with_unbundled_env available (modern Bundler)
  • with_clean_env fallback (legacy Bundler)
  • Neither method available (ancient Bundler)
  • Bundler not defined
  • Silent vs verbose modes

The tests properly use stub_const and method stubbing to simulate different Bundler versions, which is the correct approach for testing API compatibility.

5. Clear Documentation


πŸ’‘ Minor Observations

1. Code Duplication with process_manager.rb

The with_unbundled_context method is duplicated between:

  • lib/react_on_rails/dev/pack_generator.rb:160-173
  • lib/react_on_rails/dev/process_manager.rb:120-129

Analysis: This is acceptable because:

  • Both files are in the same logical module (ReactOnRails::Dev)
  • The duplication is small and unlikely to change
  • Extracting to a shared module would require creating a new file for just 13 lines
  • The comments are identical, reducing maintenance risk

Recommendation: If a third file needs this pattern, consider extracting to ReactOnRails::Dev::BundlerHelpers or similar.

2. Test Assertions Could Be More Explicit

In lines 217-236 of the test file, the test verifies with_unbundled_env was called, but doesn't verify that the system call happened within the unbundled context.

Current behavior: βœ… Correct (the yield ensures it)
Potential improvement: Could add a test that verifies execution order, but this is likely overkill.

3. Changelog Entry Formatting

The changelog entry follows the required format correctly:

  • Uses PR number without hash βœ…
  • Includes author link βœ…
  • Provides clear description βœ…
  • Properly placed under "Bug Fixes" section βœ…

πŸ”’ Security Considerations

No security concerns identified:

  • No user input is processed
  • No dynamic code execution beyond controlled rake task invocation
  • Bundler context switching is a well-established safe pattern

⚑ Performance Considerations

Minimal impact:

  • The respond_to? checks add negligible overhead (cached by Ruby)
  • with_unbundled_env is a lightweight environment variable manipulation
  • Only executes when Rails is not available, which is the less-common path

πŸ§ͺ Test Coverage

Coverage: Excellent βœ…

The new tests cover:

  • All four Bundler API compatibility scenarios
  • Both verbose and silent modes
  • Integration with existing test suites

Test quality:

  • Proper use of stub_const for isolating Bundler
  • Correct mocking strategy (stub at boundaries)
  • Output verification using to_stdout_from_any_process
  • Clear test names describing scenarios

πŸ“ Recommendations

Before Merge

  1. βœ… RuboCop passing (required per CLAUDE.md)
  2. βœ… All tests passing
  3. βœ… Trailing newlines verified
  4. βœ… Changelog updated

Future Considerations

  1. If this pattern appears in a third file, extract to shared module
  2. Consider adding integration test that actually runs bin/dev in CI (though this may be overkill)

🎯 Conclusion

Verdict: Ready to merge βœ…

This PR:

The implementation is production-ready and aligns with the project's quality standards per CLAUDE.md.


Review conducted using React on Rails project guidelines from CLAUDE.md

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 (2)
lib/react_on_rails/dev/pack_generator.rb (1)

143-172: Bundler unbundling helper looks correct; consider DRY’ing with process_manager later

run_via_bundle_exec now correctly executes the rake task inside with_unbundled_context, and with_unbundled_context’s with_unbundled_env/with_clean_env/yield fallback mirrors the existing pattern in lib/react_on_rails/dev/process_manager.rb. Return values from system propagate as before, so run_pack_generation semantics are preserved. If this pattern continues to be reused, you might eventually want a shared dev helper module to avoid duplication between PackGenerator and ProcessManager. Based on learnings.

CHANGELOG.md (1)

30-32: Wording tweak to match legacy Bundler fallback behavior

The implementation wraps the bundle exec call in a helper that prefers Bundler.with_unbundled_env but also falls back to Bundler.with_clean_env (or a no-op) for older Bundler versions. Consider updating the text to something like β€œwraps the bundle exec call in an unbundled Bundler context (via Bundler.with_unbundled_env or Bundler.with_clean_env when available)” so the changelog precisely reflects the behavior.

πŸ“œ Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between e2ca31a and 86594f2.

πŸ“’ Files selected for processing (3)
  • CHANGELOG.md (1 hunks)
  • lib/react_on_rails/dev/pack_generator.rb (1 hunks)
  • spec/react_on_rails/dev/pack_generator_spec.rb (1 hunks)
🧰 Additional context used
🧠 Learnings (7)
πŸ““ Common learnings
Learnt from: AbanoubGhadban
Repo: shakacode/react_on_rails PR: 1833
File: lib/react_on_rails/dev/process_manager.rb:72-83
Timestamp: 2025-09-29T14:45:42.687Z
Learning: In Ruby bundler contexts, when bundler intercepts system commands for executables not in the Gemfile, both version checks (like `system("foreman", "--version")`) and execution commands (like `system("foreman", "start", ...)`) fail equally, both returning false. This means availability checks using version flags accurately reflect whether execution commands will work in the current bundler context.
Learnt from: AbanoubGhadban
Repo: shakacode/react_on_rails PR: 1833
File: lib/react_on_rails/dev/process_manager.rb:72-83
Timestamp: 2025-09-29T14:45:42.687Z
Learning: In Ruby bundler contexts, when bundler intercepts system commands for executables not in the Gemfile, both version checks (like `system("foreman", "--version")`) and execution commands (like `system("foreman", "start", ...)`) fail equally, both returning false. This means availability checks using version flags accurately reflect whether execution commands will work in the current bundler context.
πŸ“š Learning: 2025-04-26T21:55:55.874Z
Learnt from: alexeyr-ci2
Repo: shakacode/react_on_rails PR: 1732
File: spec/dummy/client/app-react16/startup/ReduxSharedStoreApp.client.jsx:40-44
Timestamp: 2025-04-26T21:55:55.874Z
Learning: In the react_on_rails project, files under `app-react16` directories are copied/moved to corresponding `/app` directories during the conversion process (removing the `-react16` suffix), which affects their relative import paths at runtime.

Applied to files:

  • CHANGELOG.md
πŸ“š Learning: 2025-09-16T08:01:11.146Z
Learnt from: justin808
Repo: shakacode/react_on_rails PR: 1770
File: lib/generators/react_on_rails/templates/base/base/app/javascript/src/HelloWorld/ror_components/HelloWorld.client.jsx:2-2
Timestamp: 2025-09-16T08:01:11.146Z
Learning: React on Rails uses webpack CSS Modules configuration with namedExports: true, which requires the import syntax `import * as style from './file.module.css'` rather than the default export pattern. This configuration enables better tree shaking and bundle size optimization for CSS modules.

Applied to files:

  • CHANGELOG.md
πŸ“š Learning: 2025-04-09T12:56:10.756Z
Learnt from: AbanoubGhadban
Repo: shakacode/react_on_rails PR: 1696
File: node_package/src/RSCPayloadContainer.ts:0-0
Timestamp: 2025-04-09T12:56:10.756Z
Learning: In the react_on_rails codebase, RSC payloads are already stringified using `JSON.stringify()` before being processed by the `escapeScript` function, which handles escaping of special characters. The function only needs to handle specific HTML markers like comments and closing script tags.

Applied to files:

  • CHANGELOG.md
πŸ“š Learning: 2025-02-18T13:08:01.477Z
Learnt from: AbanoubGhadban
Repo: shakacode/react_on_rails PR: 1644
File: lib/react_on_rails/helper.rb:190-197
Timestamp: 2025-02-18T13:08:01.477Z
Learning: RSC support validation in React on Rails Pro is handled through a chain of validations:
1. Pro version check in `run_stream_inside_fiber`
2. RSC support check during pack generation via `ReactOnRailsPro.configuration.enable_rsc_support`
3. RSC support validation during component registration
This makes additional validation in the helper methods unnecessary.

Applied to files:

  • CHANGELOG.md
πŸ“š Learning: 2025-09-29T14:45:42.687Z
Learnt from: AbanoubGhadban
Repo: shakacode/react_on_rails PR: 1833
File: lib/react_on_rails/dev/process_manager.rb:72-83
Timestamp: 2025-09-29T14:45:42.687Z
Learning: In Ruby bundler contexts, when bundler intercepts system commands for executables not in the Gemfile, both version checks (like `system("foreman", "--version")`) and execution commands (like `system("foreman", "start", ...)`) fail equally, both returning false. This means availability checks using version flags accurately reflect whether execution commands will work in the current bundler context.

Applied to files:

  • lib/react_on_rails/dev/pack_generator.rb
  • spec/react_on_rails/dev/pack_generator_spec.rb
πŸ“š Learning: 2024-06-27T05:22:46.156Z
Learnt from: justin808
Repo: shakacode/react_on_rails PR: 1622
File: spec/dummy/spec/rake/assets_precompile_rake_spec.rb:12-12
Timestamp: 2024-06-27T05:22:46.156Z
Learning: When stubbing environment variables in RSpec tests, use `before` and `after` hooks to ensure that the original values are restored after the tests, preventing any side effects on other tests. Example provided by justin808:
```ruby
describe "My test" do
  before do
    original_value = ENV["VARIABLE_NAME"]
    allow(ENV).to receive(:[]).with("VARIABLE_NAME").and_return("stubbed_value")
  end

  after do
    allow(ENV).to receive(:[]).with("VARIABLE_NAME").and_call_original
    ENV["VARIABLE_NAME"] = original_value
  end

  it "tests something" do
    # Your test code here
  end
end
```
This practice ensures test isolation and reliability.

Applied to files:

  • spec/react_on_rails/dev/pack_generator_spec.rb
🧬 Code graph analysis (2)
lib/react_on_rails/dev/pack_generator.rb (2)
lib/react_on_rails/dev/process_manager.rb (1)
  • with_unbundled_context (120-129)
spec/react_on_rails/dev/pack_generator_spec.rb (5)
  • respond_to? (219-221)
  • respond_to? (241-243)
  • respond_to? (263-265)
  • with_unbundled_env (223-225)
  • with_clean_env (245-247)
spec/react_on_rails/dev/pack_generator_spec.rb (1)
lib/react_on_rails/dev/pack_generator.rb (2)
  • generate (27-175)
  • generate (29-52)
⏰ 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 (1)
spec/react_on_rails/dev/pack_generator_spec.rb (1)

210-293: Thorough coverage of Bundler context unwrapping behavior

These examples nicely exercise all branches of with_unbundled_context: with_unbundled_env, with_clean_env, and the plain-yield paths (including when Bundler is undefined), while still asserting the system invocation and user-facing output. This gives good confidence that run_via_bundle_exec behaves correctly across Bundler versions and environments.

@justin808 justin808 merged commit 924fb00 into master Nov 21, 2025
17 checks passed
@justin808 justin808 deleted the jg-/fix-pack-gen-bundler branch November 21, 2025 05:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pack generation fails in bin/dev due to Bundler auto-exec interception (16.2.0.beta.11)

2 participants