Pin secret_key_base in the test app to stop a flaky Rails 8 CI failure - #449
Conversation
Rails 8.x generate_local_secret checks, creates, writes and then reads tmp/local_secret.txt. The file is gitignored, so it is missing when CI starts, and the parallel spec workers boot Rails at the same time. One child can read the file before another has written it and get an empty string, which Rails 8.0+ rejects. A fixed value skips the file entirely.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughChangesRails test configuration
Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to Rails test boots now use a stable secret key, preventing parallel workers from observing an incomplete local secret file. The change is limited to test configuration and has no remaining merge-blocking risk. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
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 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #449 +/- ##
=======================================
Coverage 98.42% 98.42%
=======================================
Files 29 29
Lines 1144 1144
Branches 222 222
=======================================
Hits 1126 1126
Partials 18 18 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Tick the box to add this pull request to the merge queue (same as
|
Problem
The
test (ruby:4.0, 8.1.2, coverage)job fails now and then with this error.spec/apps/rails/tmp/local_secret.txtis gitignored, so it does not exist when CI starts.scripts/parallel_rspecstarts 4 workers at once, and each spawns a Rails child against the same app root. Rails'generate_local_secretchecks for the file, creates it, writes it and then reads it. A child can read the file after another child created it but before it was written. That returns an empty string. Rails 8.0+ rejects an empty string in thesecret_key_base=setter, so only the Rails 8.x jobs fail, and only sometimes.Seen on #448. A local simulation of the Rails code with 4 concurrent processes hit the empty read 15 times in 300 trials.
Fix
Set a fixed
config.secret_key_basein the test environment. Rails then never touchestmp/local_secret.txt. The setting works the same way on Rails 6.1 through 8.1.Verification
Removed the local secret files and ran
bundle exec scripts/parallel_rspecon Rails 8.0.2. All 88 examples passed and the secret file was not recreated.🤖 Generated with Claude Code