Skip to content

test: mutation-harden protection unit coverage#442

Open
thedavidmeister wants to merge 2 commits into
masterfrom
2026-06-15-solver-order-coverage
Open

test: mutation-harden protection unit coverage#442
thedavidmeister wants to merge 2 commits into
masterfrom
2026-06-15-solver-order-coverage

Conversation

@thedavidmeister

Copy link
Copy Markdown
Contributor

Module hardened

src/order/protection.tsdownscaleProtection, 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 in src/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 (verified git diff src/order/protection.ts empty). It adds a downscaleProtection limit-divide arithmetic block 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.

# Mutation (behavior) Pre-existing 3 tests With new tests
1 Math.max(round(limit/avgCut), 1) → drop max (min-1 clamp) KILLED KILLED
2 Math.roundMath.trunc (rounding) KILLED KILLED
3 cuts.reduce(+)/cuts.length → drop /length (per-token cut averaging) SURVIVED KILLED
4 reduce((a,b)=>a+b)(a,b)=>a (cut sum) KILLED KILLED
5 ownerTotal / BigInt(vaults.length) → drop divide (per-vault avg) SURVIVED KILLED
6 obTokenBalance - ownerTotal+ (other-owners balance) SURVIVED KILLED
7 === 0n ? 100n? 1n (zero-balance ratio short-circuit) SURVIVED KILLED
8 avgBalance * 100n* 50n (ratio percent scaling) SURVIVED KILLED
9 Math.min(., 3)min(., 2) (segment cap) SURVIVED KILLED
10 - 4- 5 (segment offset) KILLED KILLED
11 / 25n/ 20n (segment width) SURVIVED KILLED
12 admin-limit continue → disabled (skip admin-set owners) SURVIVED KILLED
13 obTokenBalance === undefined) continue → disabled (skip failed read) SURVIVED KILLED

Gaps checklist (behaviors now pinned)

  • 4-segment divide factor across every band: [0,25)→4, [25,50)→3, [50,75)→2, [75,100)→1, ≥100→1 (parametrized)
  • zero other-owner balance short-circuits ratio to 100% → factor 1 → limit unchanged
  • per-vault balance averaging (total/count, not sum) before the ratio
  • per-token divide-factor averaging (avgCut = sum(cuts)/count)
  • max(round(limit/avgCut), 1) — both the rounding (2.5→3, not 2) and the min-of-1 clamp
  • admin-configured owners skipped entirely (no readContract, limit untouched)
  • token whose orderbook balance read fails is skipped (contributes no cut)
  • orderbook token balance cached per (orderbook, token) — one readContract for two vaults of the same token

Verification

  • tsc -p tsconfig.check.json clean; eslint src/order/protection.test.ts clean.
  • Order suite: 8 files, 92 tests pass (was 79; +13).
  • Full vitest unit suite: 59 files, 854 tests pass.
  • The e2e fork test jobs are a pre-existing environmental red (RPC/secrets), unrelated to this change; no e2e/fork tests touched.

🤖 Generated with Claude Code

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>
@thedavidmeister thedavidmeister self-assigned this Jun 15, 2026
@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@thedavidmeister, we couldn't start this review because you've reached your PR review rate limit.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 085bf8f8-8683-4257-8260-8df961f166b3

📥 Commits

Reviewing files that changed from the base of the PR and between 4928590 and f44859d.

📒 Files selected for processing (1)
  • src/order/protection.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 2026-06-15-solver-order-coverage

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.

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>
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.

1 participant