Keep seeded PRNG output strictly below 1 in checkout-pricing test - #1738
Conversation
makeRng's rand() divided by 0x7fffffff (2^31-1), returning exactly 1 when seed === 0x7fffffff, which would let pick index past the array and randInt return hi + 1. Divide by 0x80000000 (2^31) so the result is always in [0, 1). Removes the corresponding follow-up from TODO.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RJV4Bsf2owkANcSfn5sZgm
|
Warning Review limit reached
Next review available in: 23 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe deterministic test PRNG now normalizes values to the half-open range ChangesPRNG and code-quality follow-ups
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@test/lib/checkout-pricing-consistency.test.ts`:
- Around line 121-124: Update the identical LCG rand() implementation in
payment-signature.test.ts to divide by 0x80000000 instead of 0x7fffffff,
ensuring rand() remains in [0, 1) and pick() cannot index past the array.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 64436e5b-4dfb-4827-8ed4-d141ea27e62e
📒 Files selected for processing (2)
TODO.mdtest/lib/checkout-pricing-consistency.test.ts
💤 Files with no reviewable changes (1)
- TODO.md
The identical LCG in payment-signature.test.ts also divided by 0x7fffffff, so its rand() could return exactly 1. Divide by 0x80000000 for consistency. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RJV4Bsf2owkANcSfn5sZgm
Summary
Follow-up from the PR #1729 review (item #5 in
TODO.md). The seeded PRNG intest/lib/checkout-pricing-consistency.test.tsdivided by0x7fffffff(2³¹−1), sorand()returned exactly1whenseed === 0x7fffffff. That would letpickindex one past the array (undefined) andrandIntreturnhi + 1, producing invalid generated test data.Changes
makeRng'srand()now divides by0x80000000(2³¹), so the output is always in[0, 1).TODO.md.Note this shifts the seeded sequence (i.e. which random cases the property test explores); the test asserts an invariant (public ↔ webhook re-price identically) rather than hardcoded outputs, so it still passes.
Verification
deno task lint:cion the file — clean.deno check— passes.test/lib/checkout-pricing-consistency.test.ts— passes (14 steps).🤖 Generated with Claude Code
Generated by Claude Code
Summary by CodeRabbit
Tests
Documentation