Skip to content

test: mutation-harden math unit coverage#448

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

test: mutation-harden math unit coverage#448
thedavidmeister wants to merge 2 commits into
masterfrom
2026-06-15-solver-misc-coverage

Conversation

@thedavidmeister

Copy link
Copy Markdown
Contributor

Module hardened

src/math/index.ts — selected as the weakest qualifying module from vitest run --coverage over the in-scope modules (excluding order/, router/, gas/, the core solve loop, index, and config). It had the lowest branch coverage (73.33%), driven entirely by two exported functions that had zero test coverage: toNumber and isBigNumberish. Every mutant planted in them survived the existing suite.

This PR is tests-only — no source line changed (git diff touches only src/math/index.test.ts).

Mutation matrix

Each mutation was applied to the exact source line, the math suite re-run, then the line restored.

Pre-existing coverage — already killed by existing tests (audited, left as-is)

Behavior Mutation Result
scaleTo18 down-branch value / 10^(d-18)* KILLED
scaleTo18 up-branch value * 10^(18-d)/ KILLED
scaleTo18 operand repeat(d-18)repeat(18-d) KILLED
scaleFrom18 up-branch * / KILLED
scaleFrom18 down-branch / * KILLED
calculatePrice18 zero guard amountIn === 0n!== 0n KILLED
calculatePrice18 numerator out18 * ONE18out18 / ONE18 KILLED
calculatePrice18 denominator / amountIn18* amountIn18 KILLED
calculatePrice18 out decimals decimalsOutdecimalsIn KILLED
calculatePrice18 in decimals decimalsIndecimalsOut KILLED

New coverage — mutants that SURVIVED before, now KILLED by added tests

Behavior Mutation Before After
toNumber scaling formatUnits(v, 18)17 SURVIVED KILLED
toNumber scaling formatUnits(v, 18)19 SURVIVED KILLED
isBigNumberish int check value % 1 === 0!== 0 SURVIVED KILLED
isBigNumberish number branch drop branch (→ false) SURVIVED KILLED
isBigNumberish string branch drop branch (→ false) SURVIVED KILLED
isBigNumberish regex sign /^-?[0-9]+$/ → drop -? SURVIVED KILLED
isBigNumberish regex dot /^-?[0-9]+$/ → allow . SURVIVED KILLED
isBigNumberish isHex branch drop isHex(value) SURVIVED KILLED
isBigNumberish bigint branch drop typeof === "bigint" SURVIVED KILLED
isBigNumberish isBytes branch drop isBytes(value) SURVIVED KILLED
isBigNumberish null guard value != null== null SURVIVED KILLED

Gaps checklist

  • toNumber — fully covered (4 discriminating values pinning the 18-decimal scale).
  • isBigNumberish — every OR-branch independently pinned by a discriminating case.
  • scaleTo18 / scaleFrom18 / calculatePrice18 — pre-existing tests audited, all mutants killed.
  • scaleTo18 / scaleFrom18 boundary > 18>= 18: equivalent mutant (at exactly 18 decimals both branches compute value * 1 == value / 1 == value); no test can distinguish — left uncovered intentionally.

Verification

  • tsc -p tsconfig.check.json clean.
  • eslint clean on the changed test file.
  • Full vitest unit suite green: 847 tests passed (was 841; +6 new tests), 59 files.
  • e2e fork test jobs are a pre-existing environmental red (RPC/secrets), out of scope and not touched.

🤖 Generated with Claude Code

Adds discriminating unit tests for the two previously-untested exports in
src/math/index.ts: toNumber and isBigNumberish. Before this change both
functions had zero test coverage (math/index.ts branch coverage was the
weakest qualifying module at 73.33%) so every mutant in them survived.

toNumber: pins the 18-decimal scaling (1e18 -> 1, 1.5e18 -> 1.5, 123e18 ->
123, 0 -> 0); kills decimal-shift mutations of the formatUnits argument.

isBigNumberish: one discriminating case per OR-branch so removing or
inverting any single branch is caught -- integer vs non-integer number
(value % 1 === 0), all-digit/signed string vs decimal/non-numeric string
(the /^-?[0-9]+$/ regex incl. the -? prefix and dot rejection), hex-string
via isHex, bigint, byte-array via isBytes, and the value != null nullish guard.

Tests only; no src/ behavior change. Full vitest unit suite green (847 tests).

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 31 minutes and 45 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: 1b5ff05b-ce27-4a51-a3c1-9c2a78f44ce9

📥 Commits

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

📒 Files selected for processing (1)
  • src/math/index.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 2026-06-15-solver-misc-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 each assertion verifies as present-tense fact, without
referencing the mutations they kill.

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