Skip to content

Conversation

@justin808
Copy link
Member

@justin808 justin808 commented Sep 29, 2025

Summary

Changes

Security Improvements

  • Refactored shell command execution in server.rb to prevent injection attacks
    • Commands are now passed as argument arrays instead of interpolated strings
    • Uses spawn(*args) and system(*args) for safer execution

Database Reset Improvements

  • Reordered state reset operations in state_reset_middleware.rb
    • after_state_reset hook now runs after cleanup (as requested in review)
    • Added support for disable_referential_integrity when available
    • Uses proper table name quoting with quote_table_name

Other Fixes

  • Added missing require 'fileutils' to server.rb
  • Used File.expand_path for folder detection

Test Plan

  • Run existing test suite (bundle exec rspec)
  • Test with a Rails app using the gem
  • Verify database reset works correctly
  • Confirm command injection protection

References

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added rake tasks to open/run Cypress and Playwright with automatic Rails server start/stop and init.
    • Introduced configurable server lifecycle hooks and a transactional test server option.
    • Added state reset middleware/endpoint for reliable, isolated test runs.
    • Provided server host/port configuration and automatic port detection.
  • Documentation
    • Updated README with recommended rake-task workflow and server hooks configuration.
    • Added an Unreleased changelog with details on new test automation features and a Migration Guide for moving from manual setups.

justin808 and others added 3 commits September 28, 2025 16:19
This enhancement brings cypress-rails functionality to cypress-playwright-on-rails:

- Added rake tasks for cypress:open, cypress:run, playwright:open, playwright:run
- Implemented automatic Rails server management with dynamic port selection
- Added server lifecycle hooks (before_server_start, after_server_start, etc.)
- Added transactional test mode for automatic database rollback
- Added state reset middleware for /cypress_rails_reset_state endpoint
- Support for CYPRESS_RAILS_HOST and CYPRESS_RAILS_PORT environment variables

These changes make cypress-playwright-on-rails a more complete replacement for
cypress-rails, providing the same developer-friendly test execution experience
while maintaining all the existing cypress-on-rails functionality.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Added detailed migration instructions for:
- Users currently using manual server management (old way)
- Users migrating from cypress-rails gem

The migration guide clearly shows the before/after comparison and
provides step-by-step instructions for both scenarios.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add require 'fileutils' to server.rb
- Refactor shell command execution to prevent injection attacks
  - Use argument arrays instead of string interpolation
  - Pass commands as arrays to spawn() and system()
- Improve database state reset safety
  - Move after_state_reset hook to run after cleanup
  - Add support for disable_referential_integrity when available
  - Use proper table name quoting with quote_table_name
- Use File.expand_path for folder detection

These changes address security concerns about command injection
and improve compatibility across different Rails environments.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Sep 29, 2025

Walkthrough

Introduces server lifecycle management for test runs via a new Server class, Rake tasks for Cypress/Playwright, state reset middleware, and configuration hooks and options. Updates documentation and initializer template with configuration and migration guidance. Railtie now loads rake tasks and wires the reset middleware.

Changes

Cohort / File(s) Summary
Docs & Guides
CHANGELOG.md, README.md, lib/generators/cypress_on_rails/templates/config/initializers/cypress_on_rails.rb.erb
Adds Unreleased notes, rake-task-based usage, server hooks/config examples, migration guide, and duplicated config snippet under VCR; template gains commented hook/config examples.
Configuration API
lib/cypress_on_rails/configuration.rb
Adds public attrs: before_server_start, after_server_start, after_transaction_start, after_state_reset, before_server_stop, server_host, server_port, transactional_server; initializes defaults and env-driven host/port.
Railtie Integration
lib/cypress_on_rails/railtie.rb
Registers rake tasks loader and inserts StateResetMiddleware after existing Cypress middleware.
Server Management
lib/cypress_on_rails/server.rb
New Server class to init/open/run tests; auto-detects ports and install folder; manages Rails server lifecycle, env vars, hooks, transactional DB handling, runner commands (Cypress/Playwright), and cleanup.
State Reset Middleware
lib/cypress_on_rails/state_reset_middleware.rb
New middleware handling /__cypress__/reset_state and /cypress_rails_reset_state to reset DB, cache, dependencies, and run after_state_reset hook; otherwise passes through.
Rake Tasks
lib/tasks/cypress.rake
Adds cypress:open/run/init and playwright:open/run tasks delegating to Server with framework selection.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Dev as Developer
  participant Rake as Rake Task (cypress/playwright)
  participant Srv as CypressOnRails::Server
  participant Rails as Rails Server
  participant MW as StateResetMiddleware
  participant DB as DB/DBCleaner
  participant Runner as Test Runner (Cypress/Playwright)

  Dev->>Rake: rake cypress:open | run
  Rake->>Srv: new(...).open/run
  Note over Srv: before_server_start hook
  Srv->>Rails: spawn bin/rails server (-p, -b)
  Srv->>Rails: wait until listening
  Note over Srv: after_server_start hook
  alt transactional_server=true
    Srv->>DB: BEGIN transaction
    Note over Srv: after_transaction_start hook
  end
  Srv->>Runner: launch/open or run tests
  Runner->>Rails: test requests
  opt reset state call
    Runner->>Rails: GET /__cypress__/reset_state
    Rails->>MW: call(env)
    MW->>DB: reset via DatabaseCleaner or truncate
    MW-->>Rails: 200 "State reset completed"
  end
  Runner-->>Srv: exit status
  Note over Srv: before_server_stop hook
  alt transactional_server=true
    Srv->>DB: ROLLBACK
  end
  Srv->>Rails: terminate server
  Srv-->>Rake: success/failure
  Rake-->>Dev: exit code (0/1)
Loading
sequenceDiagram
  autonumber
  participant Dev as Developer
  participant Rake as rake cypress:init
  participant Srv as CypressOnRails::Server
  Dev->>Rake: rake cypress:init
  Rake->>Srv: new.init
  Srv->>Srv: detect/create install folder
  Srv-->>Dev: initialized
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

I thump the ground—new tasks appear,
A server wakes, its port is clear.
Hooks hop in before and after,
Transactions roll with quiet laughter.
Reset the fields, then tests take flight—
Cypress, Playwright, all alight.
Carrots merged, the build’s just right. 🥕🧪

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.17% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title accurately captures the primary purpose of the pull request by indicating that it addresses security and stability concerns identified in the review of PR #179, and it is concise without extraneous details.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-pr179-review-comments

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 RuboCop (1.80.2)
lib/cypress_on_rails/server.rb

Could not find gem 'rspec' in locally installed gems.
/usr/lib/ruby/3.1.0/bundler/resolver.rb:269:in block in verify_gemfile_dependencies_are_found!' /usr/lib/ruby/3.1.0/bundler/resolver.rb:252:in map!'
/usr/lib/ruby/3.1.0/bundler/resolver.rb:252:in verify_gemfile_dependencies_are_found!' /usr/lib/ruby/3.1.0/bundler/resolver.rb:48:in start'
/usr/lib/ruby/3.1.0/bundler/resolver.rb:23:in resolve' /usr/lib/ruby/3.1.0/bundler/definition.rb:269:in resolve'
/usr/lib/ruby/3.1.0/bundler/definition.rb:468:in materialize' /usr/lib/ruby/3.1.0/bundler/definition.rb:190:in specs'
/usr/lib/ruby/3.1.0/bundler/runtime.rb:85:in block in definition_method' /var/lib/gems/3.1.0/gems/rubocop-1.80.2/lib/rubocop/config_loader_resolver.rb:296:in gem_config_path'
/var/lib/gems/3.1.0/gems/rubocop-1.80.2/lib/rubocop/config_loader_resolver.rb:84:in block (2 levels) in resolve_inheritance_from_gems' /var/lib/gems/3.1.0/gems/rubocop-1.80.2/lib/rubocop/config_loader_resolver.rb:82:in reverse_each'
/var/lib/gems/3.1.0/gems/rubocop-1.80.2/lib/rubocop/config_loader_resolver.rb:82:in block in resolve_inheritance_from_gems' /var/lib/gems/3.1.0/gems/rubocop-1.80.2/lib/rubocop/config_loader_resolver.rb:76:in each_pair'
/var/lib/gems/3.1.0/gems/rubocop-1.80.2/lib/rubocop/config_loader_resolver.rb:76:in resolve_inheritance_from_gems' /var/lib/gems/3.1.0/gems/rubocop-1.80.2/lib/rubocop/config_loader.rb:58:in load_file'
/var/lib/gems/3.1.0/gems/rubocop-1.80.2/lib/rubocop/config_store.rb:29:in options_config=' /var/lib/gems/3.1.0/gems/rubocop-1.80.2/lib/rubocop/cli.rb:167:in act_on_options'
/var/lib/gems/3.1.0/gems/rubocop-1.80.2/lib/rubocop/cli.rb:49:in block in run' /var/lib/gems/3.1.0/gems/rubocop-1.80.2/lib/rubocop/cli.rb:87:in profile_if_needed'
/var/lib/gems/3.1.0/gems/rubocop-1.80.2/lib/rubocop/cli.rb:45:in run' /var/lib/gems/3.1.0/gems/rubocop-1.80.2/exe/rubocop:15:in <top (required)>'
/usr/local/bin/rubocop:25:in load' /usr/local/bin/rubocop:25:in

'

lib/cypress_on_rails/configuration.rb

Could not find gem 'rspec' in locally installed gems.
/usr/lib/ruby/3.1.0/bundler/resolver.rb:269:in block in verify_gemfile_dependencies_are_found!' /usr/lib/ruby/3.1.0/bundler/resolver.rb:252:in map!'
/usr/lib/ruby/3.1.0/bundler/resolver.rb:252:in verify_gemfile_dependencies_are_found!' /usr/lib/ruby/3.1.0/bundler/resolver.rb:48:in start'
/usr/lib/ruby/3.1.0/bundler/resolver.rb:23:in resolve' /usr/lib/ruby/3.1.0/bundler/definition.rb:269:in resolve'
/usr/lib/ruby/3.1.0/bundler/definition.rb:468:in materialize' /usr/lib/ruby/3.1.0/bundler/definition.rb:190:in specs'
/usr/lib/ruby/3.1.0/bundler/runtime.rb:85:in block in definition_method' /var/lib/gems/3.1.0/gems/rubocop-1.80.2/lib/rubocop/config_loader_resolver.rb:296:in gem_config_path'
/var/lib/gems/3.1.0/gems/rubocop-1.80.2/lib/rubocop/config_loader_resolver.rb:84:in block (2 levels) in resolve_inheritance_from_gems' /var/lib/gems/3.1.0/gems/rubocop-1.80.2/lib/rubocop/config_loader_resolver.rb:82:in reverse_each'
/var/lib/gems/3.1.0/gems/rubocop-1.80.2/lib/rubocop/config_loader_resolver.rb:82:in block in resolve_inheritance_from_gems' /var/lib/gems/3.1.0/gems/rubocop-1.80.2/lib/rubocop/config_loader_resolver.rb:76:in each_pair'
/var/lib/gems/3.1.0/gems/rubocop-1.80.2/lib/rubocop/config_loader_resolver.rb:76:in resolve_inheritance_from_gems' /var/lib/gems/3.1.0/gems/rubocop-1.80.2/lib/rubocop/config_loader.rb:58:in load_file'
/var/lib/gems/3.1.0/gems/rubocop-1.80.2/lib/rubocop/config_store.rb:29:in options_config=' /var/lib/gems/3.1.0/gems/rubocop-1.80.2/lib/rubocop/cli.rb:167:in act_on_options'
/var/lib/gems/3.1.0/gems/rubocop-1.80.2/lib/rubocop/cli.rb:49:in block in run' /var/lib/gems/3.1.0/gems/rubocop-1.80.2/lib/rubocop/cli.rb:87:in profile_if_needed'
/var/lib/gems/3.1.0/gems/rubocop-1.80.2/lib/rubocop/cli.rb:45:in run' /var/lib/gems/3.1.0/gems/rubocop-1.80.2/exe/rubocop:15:in <top (required)>'
/usr/local/bin/rubocop:25:in load' /usr/local/bin/rubocop:25:in

'

lib/tasks/cypress.rake

Could not find gem 'rspec' in locally installed gems.
/usr/lib/ruby/3.1.0/bundler/resolver.rb:269:in block in verify_gemfile_dependencies_are_found!' /usr/lib/ruby/3.1.0/bundler/resolver.rb:252:in map!'
/usr/lib/ruby/3.1.0/bundler/resolver.rb:252:in verify_gemfile_dependencies_are_found!' /usr/lib/ruby/3.1.0/bundler/resolver.rb:48:in start'
/usr/lib/ruby/3.1.0/bundler/resolver.rb:23:in resolve' /usr/lib/ruby/3.1.0/bundler/definition.rb:269:in resolve'
/usr/lib/ruby/3.1.0/bundler/definition.rb:468:in materialize' /usr/lib/ruby/3.1.0/bundler/definition.rb:190:in specs'
/usr/lib/ruby/3.1.0/bundler/runtime.rb:85:in block in definition_method' /var/lib/gems/3.1.0/gems/rubocop-1.80.2/lib/rubocop/config_loader_resolver.rb:296:in gem_config_path'
/var/lib/gems/3.1.0/gems/rubocop-1.80.2/lib/rubocop/config_loader_resolver.rb:84:in block (2 levels) in resolve_inheritance_from_gems' /var/lib/gems/3.1.0/gems/rubocop-1.80.2/lib/rubocop/config_loader_resolver.rb:82:in reverse_each'
/var/lib/gems/3.1.0/gems/rubocop-1.80.2/lib/rubocop/config_loader_resolver.rb:82:in block in resolve_inheritance_from_gems' /var/lib/gems/3.1.0/gems/rubocop-1.80.2/lib/rubocop/config_loader_resolver.rb:76:in each_pair'
/var/lib/gems/3.1.0/gems/rubocop-1.80.2/lib/rubocop/config_loader_resolver.rb:76:in resolve_inheritance_from_gems' /var/lib/gems/3.1.0/gems/rubocop-1.80.2/lib/rubocop/config_loader.rb:58:in load_file'
/var/lib/gems/3.1.0/gems/rubocop-1.80.2/lib/rubocop/config_store.rb:29:in options_config=' /var/lib/gems/3.1.0/gems/rubocop-1.80.2/lib/rubocop/cli.rb:167:in act_on_options'
/var/lib/gems/3.1.0/gems/rubocop-1.80.2/lib/rubocop/cli.rb:49:in block in run' /var/lib/gems/3.1.0/gems/rubocop-1.80.2/lib/rubocop/cli.rb:87:in profile_if_needed'
/var/lib/gems/3.1.0/gems/rubocop-1.80.2/lib/rubocop/cli.rb:45:in run' /var/lib/gems/3.1.0/gems/rubocop-1.80.2/exe/rubocop:15:in <top (required)>'
/usr/local/bin/rubocop:25:in load' /usr/local/bin/rubocop:25:in

'

  • 2 others

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 Sep 29, 2025

Code Review for PR #184: Fix security and stability issues

Thank you for addressing the security concerns from PR #179! This is a significant addition to the gem that brings automated server management and improved security. Here's my detailed review:

✅ Strengths

  1. Excellent security improvements in server.rb:

    • Proper use of argument arrays with spawn(*args) and system(*args) instead of string interpolation
    • Prevents command injection vulnerabilities
    • Good use of splatting for safe command execution
  2. Well-structured server lifecycle management:

    • Clean separation of concerns with hooks
    • Proper cleanup in ensure blocks
    • Transactional test support with automatic rollback
  3. Good backwards compatibility:

    • Maintains support for existing manual server management
    • Provides migration guide in CHANGELOG
    • Compatible with cypress-rails endpoints

🔍 Issues & Suggestions

1. Missing Error Handling in server.rb:

  • Line 46-50: detect_install_folder silently defaults to 'e2e' even if no folders exist. Consider warning the user when no test folder is found.

  • Line 105-108: wait_for_server could benefit from visual feedback (like dots) during the wait period to show progress.

2. Potential Race Condition in state_reset_middleware.rb:

  • Line 31-40: Database operations without transaction protection could lead to partial state if interrupted. Consider wrapping the table clearing logic in a transaction block for atomicity.

3. Missing Validation in server.rb:

  • Line 14: Port should be validated to be within valid range (1-65535) after conversion to integer.

4. Performance Consideration:

  • Line 177: command_exists? shells out for each check. Consider caching results to avoid repeated system calls for the same command.

🔒 Security Assessment

✅ Command injection vulnerabilities properly addressed
✅ No hardcoded secrets or credentials
✅ Proper use of quote_table_name for SQL safety
✅ Environment variables handled safely

📝 Test Coverage Recommendations

The PR mentions tests are pending. Consider adding specs for:

  1. Server#spawn_server with different command availability scenarios
  2. StateResetMiddleware with and without DatabaseCleaner
  3. Port detection and validation logic
  4. Hook execution order and error handling
  5. Transactional mode with nested transactions

💡 Minor Suggestions

  1. Add logging for debugging:

    • Log when hooks are executed
    • Log server startup parameters
    • Log state reset operations
  2. Consider adding a --verbose flag for rake tasks to help with debugging

  3. Document the precedence of configuration options (ENV vars vs config file)

Overall Assessment

This is a solid improvement that significantly enhances the gem's security posture and usability. The automated server management will be a great quality-of-life improvement for users. With the suggested error handling improvements and test coverage, this will be production-ready.

Great work addressing the security concerns! 🎉

Copy link

@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: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d50de89 and 18f01a4.

📒 Files selected for processing (8)
  • CHANGELOG.md (1 hunks)
  • README.md (2 hunks)
  • lib/cypress_on_rails/configuration.rb (2 hunks)
  • lib/cypress_on_rails/railtie.rb (1 hunks)
  • lib/cypress_on_rails/server.rb (1 hunks)
  • lib/cypress_on_rails/state_reset_middleware.rb (1 hunks)
  • lib/generators/cypress_on_rails/templates/config/initializers/cypress_on_rails.rb.erb (1 hunks)
  • lib/tasks/cypress.rake (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
lib/cypress_on_rails/state_reset_middleware.rb (2)
lib/cypress_on_rails/server.rb (2)
  • initialize (10-19)
  • run_hook (191-195)
lib/cypress_on_rails/configuration.rb (2)
  • initialize (36-38)
  • configuration (76-78)
lib/cypress_on_rails/server.rb (2)
lib/cypress_on_rails/state_reset_middleware.rb (4)
  • initialize (2-57)
  • initialize (3-5)
  • run_hook (54-56)
  • call (7-14)
lib/cypress_on_rails/configuration.rb (2)
  • initialize (36-38)
  • configuration (76-78)
🪛 Brakeman (7.0.2)
lib/cypress_on_rails/server.rb

[medium] 188-188: Possible command injection
Type: Command Injection
Confidence: Medium
More info: https://brakemanscanner.org/docs/warning_types/command_injection/

(Command Injection)

⏰ 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). (3)
  • GitHub Check: rails_8
  • GitHub Check: rails_7_2
  • GitHub Check: rails_6_1

Comment on lines +78 to +91
if @transactional && defined?(ActiveRecord::Base)
ActiveRecord::Base.connection.begin_transaction(joinable: false)
run_hook(config.after_transaction_start)
end

yield

ensure
run_hook(config.before_server_stop)

if @transactional && defined?(ActiveRecord::Base)
ActiveRecord::Base.connection.rollback_transaction if ActiveRecord::Base.connection.transaction_open?
end

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Transactional rollback never applies to the spawned server process.

Line 79 starts a transaction in the rake task, but spawn_server boots Rails in a separate process that opens its own DB connection. That child process never sees the parent’s transaction, so nothing is rolled back—data leaks between runs even though transactional_server defaults to true. Please move the transaction management into the server process itself (e.g., via Rack middleware or by running the server in-process with a shared connection), or disable this code path until it actually isolates state.

🤖 Prompt for AI Agents
In lib/cypress_on_rails/server.rb around lines 78 to 91, the code begins a DB
transaction in the parent rake process but the spawned server runs in a separate
process and therefore does not share that transaction; move transaction
management into the server process or disable it here. Remove or bypass the
ActiveRecord::Base.connection.begin_transaction/rollback_transaction calls in
the parent when spawn_server is used, and instead implement transactional
isolation inside the server process (for example add a Rack middleware that
begins a transaction on request start and rolls back on completion, or run the
server in-process with a shared DB connection so parent transactions apply), or
detect spawned-server mode and set @transactional = false to avoid the
misleading noop rollback. Ensure any change cleanly logs the chosen behavior and
keeps existing hooks (after_transaction_start/before_server_stop) consistent.

Comment on lines +7 to +13
def call(env)
if env['PATH_INFO'] == '/__cypress__/reset_state' || env['PATH_INFO'] == '/cypress_rails_reset_state'
reset_application_state
[200, { 'Content-Type' => 'text/plain' }, ['State reset completed']]
else
@app.call(env)
end
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Require POST (or stronger) for state reset endpoint

As written, any GET/HEAD/etc. to /__cypress__/reset_state or /cypress_rails_reset_state will wipe the database. That means a stray <img> tag, CSRF, or an automated link scanner can nuke test data—exactly the class of security issue we’re trying to eliminate. We need to restrict resets to an explicit POST (and ideally return 405 for other verbs) before calling reset_application_state.

Apply this diff to enforce a POST guard:

-      if env['PATH_INFO'] == '/__cypress__/reset_state' || env['PATH_INFO'] == '/cypress_rails_reset_state'
+      if reset_state_request?(env)
         reset_application_state
         [200, { 'Content-Type' => 'text/plain' }, ['State reset completed']]
       else
         @app.call(env)
       end
     end
+
+    def reset_state_request?(env)
+      return false unless env['REQUEST_METHOD'] == 'POST'
+      path = env['PATH_INFO']
+      path == '/__cypress__/reset_state' || path == '/cypress_rails_reset_state'
+    end
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def call(env)
if env['PATH_INFO'] == '/__cypress__/reset_state' || env['PATH_INFO'] == '/cypress_rails_reset_state'
reset_application_state
[200, { 'Content-Type' => 'text/plain' }, ['State reset completed']]
else
@app.call(env)
end
def call(env)
if reset_state_request?(env)
reset_application_state
[200, { 'Content-Type' => 'text/plain' }, ['State reset completed']]
else
@app.call(env)
end
end
def reset_state_request?(env)
return false unless env['REQUEST_METHOD'] == 'POST'
path = env['PATH_INFO']
path == '/__cypress__/reset_state' || path == '/cypress_rails_reset_state'
end
🤖 Prompt for AI Agents
In lib/cypress_on_rails/state_reset_middleware.rb around lines 7–13, the
middleware currently performs a reset for any HTTP verb; change it to only
perform reset when env['PATH_INFO'] matches the reset paths AND
env['REQUEST_METHOD'] == 'POST'. If the path matches but the method is not POST,
return a 405 response with an Allow: POST header and an appropriate plain-text
body; otherwise continue to @app.call(env). Ensure the code checks both paths as
before and only invokes reset_application_state for POST requests.

@justin808
Copy link
Member Author

Closing this PR - these changes should be added to PR #179 instead

@justin808 justin808 closed this Sep 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants