test: mutation-harden protection unit coverage#442
Conversation
Adds discriminating unit tests for downscaleProtection in src/order/protection.ts. The pre-existing 3 tests left 9 of 13 arithmetic/branch mutants alive (per-vault balance averaging, per-token cut averaging, the otherOwnersBalances subtraction, the zero-balance ratio short-circuit, the *100n ratio scaling, the /25n segmentation and its min(.,3) cap, the admin-limit skip, and the failed-balance-read skip). The new cases pin each intermediate to an exact value so every one of those mutants is now killed. Tests-only: no change to src/order/protection.ts. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Warning Review limit reached
More reviews will be available in 38 minutes and 17 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
State what the tests assert now, present-tense, dropping the "would"/mutant-framing and sum-instead-of-avg/truncation narration. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Module hardened
src/order/protection.ts—downscaleProtection, the owner spam-protection that reduces each owner's per-round order limit by comparing the owner's average vault balance of a token against the rest of the orderbook's balance of that token. It was the weakest-covered qualifying module insrc/order/**(branch coverage 68.75%, only 3 tests for 100 lines of dense limit-divide arithmetic and owner/token/vault grouping).This PR is tests-only — no change to
src/order/protection.ts(verifiedgit diff src/order/protection.tsempty). It adds adownscaleProtection limit-divide arithmeticblock with 13 discriminating cases that pin each intermediate of the calculation to an exact value.Mutation matrix
Each behavior's source line was mutated and the protection suite re-run. The pre-existing 3 tests left 9 of 13 mutants alive; the new tests kill all 13.
Math.max(round(limit/avgCut), 1)→ dropmax(min-1 clamp)Math.round→Math.trunc(rounding)cuts.reduce(+)/cuts.length→ drop/length(per-token cut averaging)reduce((a,b)=>a+b)→(a,b)=>a(cut sum)ownerTotal / BigInt(vaults.length)→ drop divide (per-vault avg)obTokenBalance - ownerTotal→+(other-owners balance)=== 0n ? 100n→? 1n(zero-balance ratio short-circuit)avgBalance * 100n→* 50n(ratio percent scaling)Math.min(., 3)→min(., 2)(segment cap)- 4→- 5(segment offset)/ 25n→/ 20n(segment width)continue→ disabled (skip admin-set owners)obTokenBalance === undefined) continue→ disabled (skip failed read)Gaps checklist (behaviors now pinned)
[0,25)→4,[25,50)→3,[50,75)→2,[75,100)→1,≥100→1(parametrized)total/count, not sum) before the ratioavgCut = sum(cuts)/count)max(round(limit/avgCut), 1)— both the rounding (2.5→3, not 2) and the min-of-1 clampreadContract, limit untouched)(orderbook, token)— onereadContractfor two vaults of the same tokenVerification
tsc -p tsconfig.check.jsonclean;eslint src/order/protection.test.tsclean.e2e fork testjobs are a pre-existing environmental red (RPC/secrets), unrelated to this change; no e2e/fork tests touched.🤖 Generated with Claude Code