Skip to content

test: mutation-harden log unit coverage#447

Open
thedavidmeister wants to merge 8 commits into
masterfrom
2026-06-15-solver-core-coverage
Open

test: mutation-harden log unit coverage#447
thedavidmeister wants to merge 8 commits into
masterfrom
2026-06-15-solver-core-coverage

Conversation

@thedavidmeister

@thedavidmeister thedavidmeister commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Mutation-hardens the unit tests for src/core/process/log.ts (transaction-receipt income / clear-amount accounting helpers), the weakest qualifying module found in a scoped adversarial-mutation pass over the core solve/processing logic (src/core/**).

The existing tests asserted only weak properties — a "_18" suffix for getActualPrice, and typeof === "bigint" / > 0n for getTotalIncome — so arithmetic and argument mutations on the actual money math passed undetected. This PR pins the exact computed values and adds the missing branch.

Tests-only. No source changes (git diff src/ is empty apart from the test file).

Mutation matrix (log.ts)

Function · behavior Mutation Before After
getActualPrice · * ONE18 scaling * ONE18/ ONE18 SURVIVED KILLED
getActualPrice · scaleTo18(value, tokenDecimals) decimals arg → 0 SURVIVED KILLED
getTotalIncome · input price/income pairing input branch uses outputTokenPrice SURVIVED KILLED
getTotalIncome · input / ONE18 divisor / ONE18* ONE18 SURVIVED KILLED
getActualClearAmount · AfterClearV2 normalize-fail n/a (new branch coverage) uncovered covered

Already-covered behaviors confirmed by mutation (existing tests killed the mutant): getIncome token-address filter, value compare, and to === signer filter; getActualClearAmount branch selector, Transfer from === ob filter, AfterClear event selection, and AfterClearV2 decimals arg; getActualPrice to === arb / from !== orderbook filters; getTotalIncome both-undefined guard and the sign of the final sum.

What was added / strengthened

  • getActualPrice — strengthened the existing "formatted price" test to pin the exact price; added a non-18 (6) decimals test so the scaleTo18 decimals argument and the ONE18 scaling are both exercised.
  • getTotalIncome — pinned exact per-branch and summed values (4n / 9n / 13n); added a distinct-price/distinct-income case (19n vs swapped 25n) so each income is verified to pair with its own token price and the ONE18 divisor is verified.
  • getActualClearAmount — added a test for the AfterClearV2 normalize-failure branch returning undefined (unparsable aliceOutput).

Exact expected values are deterministic from the test file's existing formatUnits / parseUnits mocks combined with the real scaleTo18, so the assertions discriminate correct vs. mutated output.

Gaps checklist

  • getActualPrice price arithmetic pinned (scaling + divisor + decimals)
  • getTotalIncome exact value, price↔income pairing, and divisor pinned
  • getActualClearAmount AfterClearV2 normalize-failure branch covered
  • No surviving fillable mutants remain in log.ts after this pass
  • Note: removing the if (outputResult.isErr()) guard is an equivalent mutant (an Err result's .value is also undefined), so it is not separately killable; the negated-guard variant is killed by the existing valid-float test.

Verification

  • log.test.ts: 15 → 18 tests, all green on baseline.
  • src/core unit suite: 224 tests green (was 221).
  • tsc -p tsconfig.check.json: clean. eslint: clean.
  • Full vitest unit suite green (the src/logger test requires the project's --disableConsoleIntercept invocation, which is a pre-existing harness quirk, in an out-of-scope module, and passes under its own npm script).
  • e2e / hardhat fork tests are a pre-existing environmental red (RPC/secrets) and are out of scope.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Expanded coverage for log-processing helpers with new edge cases.
    • Added checks for failed normalization, exact formatted price output, and token-decimal scaling.
    • Strengthened income calculations with exact expected values and verified prices are matched to the correct token.

Strengthen and extend the unit tests for src/core/process/log.ts so they
kill previously-surviving mutants in the income/clear-amount accounting
helpers. The existing tests asserted only weak properties (a "_18" suffix
for getActualPrice, and typeof/positivity for getTotalIncome), which let
arithmetic and argument mutations pass undetected.

- getActualPrice: pin the exact computed price and add a non-18 decimals
  case so the scaleTo18 decimals argument and the ONE18 scaling are checked.
- getTotalIncome: pin exact per-branch and summed values, and add a case
  with distinct prices and incomes so each income is verified to pair with
  its own token price (not swapped) and the ONE18 divisor is verified.
- getActualClearAmount: cover the AfterClearV2 normalize-failure branch
  returning undefined.

Tests-only; no source changes.

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

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 34355f3b-fe76-4d0a-b656-3a7cb59a44a4

📥 Commits

Reviewing files that changed from the base of the PR and between b80c903 and 1f6af44.

📒 Files selected for processing (1)
  • src/core/process/log.test.ts

Walkthrough

Test coverage for three log-processing helpers is updated: a new edge case is added for getActualClearAmount returning undefined when aliceOutput cannot be normalized; getActualPrice assertions are changed to exact strings and a decimal-scaling case is added; getTotalIncome expectations are changed from > 0 to exact bigint values with a new token-price pairing test.

Changes

Log helper test tightening

Layer / File(s) Summary
Tightened assertions and new edge-case tests
src/core/process/log.test.ts
Adds un-normalizable aliceOutput test for getActualClearAmount; replaces suffix checks with exact formatted strings and adds decimal-scaling test for getActualPrice; replaces > 0 checks with exact bigint values and adds token-price pairing test for getTotalIncome.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the tests-only hardening of log unit coverage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 2026-06-15-solver-core-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.

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.

2 participants