test(worker): cover signup daily rate-limit branches (daily_ip_limit / daily_email_limit) - #161
Conversation
…/ daily_email_limit) F7 from the product-tests sweep: both 429 branches in enforceAgentLimits (per-IP cap of 20/day and per-email soft cap of 5/day) had zero coverage in the worker suite, so either cap could silently invert without any test going red. Adds four tests in the existing test-agent-worker.mjs style, driving real per-bucket counters through a CountingDB fake: - per-IP cap: 20 succeed, the 21st from the same IP returns 429 daily_ip_limit (fresh email proves the IP cap fires on its own) - per-email cap: 5 succeed, the 6th for the same email returns 429 daily_email_limit (fresh IP proves the email cap fires on its own) - both caps reset when the UTC day rolls over, driven by an injected AGENT_LIMITS_NOW clock override (never sleeping) The clock override is a test-only env binding: production never sets AGENT_LIMITS_NOW, so runtime behaviour is unchanged when it is absent. Mutation-proved: disabling each comparison makes its tests go red (2 failures each), restoring them goes green again.
There was a problem hiding this comment.
nish3451 has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe worker now accepts an injected timestamp for daily agent limits. Test infrastructure tracks per-bucket usage and verifies IP and email limits, independent operation, JSON ChangesAgent daily limits
Estimated code review effort: 3 (Moderate) | ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
nish3451 has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.
There was a problem hiding this comment.
nish3451 has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.
There was a problem hiding this comment.
nish3451 has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.
There was a problem hiding this comment.
nish3451 has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.
There was a problem hiding this comment.
nish3451 has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.
There was a problem hiding this comment.
nish3451 has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
What
Closes F7 from the product-tests sweep (report-product-tests.md): both 429 branches in
enforceAgentLimits— the per-IP daily cap (MAX_AGENT_RUNS_PER_IP_PER_DAY= 20) and the per-email daily soft cap (SOFT_AGENT_RUNS_PER_EMAIL_PER_DAY= 5) — had zero coverage inscripts/test-agent-worker.mjs(rgfordaily_ip_limit|daily_email_limit|429returned nothing). Either cap could silently invert — over-granting abusers or locking out legitimate customers — with the suite staying green.Tests added (4, in the existing suite style, driving real per-bucket counters via a
CountingDBfake)429with{"ok":false,"error":"daily_ip_limit"}.429with{"ok":false,"error":"daily_email_limit"}.AGENT_LIMITS_NOWclock override — deterministic, never sleeping.Production change (smallest possible)
enforceAgentLimitsnow computes its bucket fromnew Date(env.AGENT_LIMITS_NOW || Date.now()).AGENT_LIMITS_NOWis a test-only binding that production never sets, so runtime behaviour is byte-identical when absent. No limit values, no signup behaviour, nothing else touched.Mutation proof (both limits)
0 > MAX_AGENT_RUNS_PER_IP_PER_DAY): tests 56 + 59 go RED ("the 21st request from the same IP must be refused"); restore → GREEN.0 > SOFT_AGENT_RUNS_PER_EMAIL_PER_DAY): tests 57 + 58 go RED ("the 6th request for the same email must be refused"); restore → GREEN.Validation
npm testexit 0: 96 tests pass (baseline 92 + 4 new; worker suite 55 → 59).sgscanexit 1 — warnings only, none in this diff (exit 2 would block; it did not).crgate --agent— CodeRabbit not signed in on this machine; per packet, noted and continued.Not merged per packet rules — Nish reviews and merges.
Summary by CodeRabbit
Bug Fixes
429errors identifying the applicable limit.Tests