Skip to content

test: mutation-harden router.ts unit coverage#443

Merged
thedavidmeister merged 2 commits into
masterfrom
2026-06-15-solver-router-coverage
Jun 15, 2026
Merged

test: mutation-harden router.ts unit coverage#443
thedavidmeister merged 2 commits into
masterfrom
2026-06-15-solver-router-coverage

Conversation

@thedavidmeister

Copy link
Copy Markdown
Contributor

Module hardened

src/router/router.tsRainSolverRouter (route selection / quote aggregation module).

Adversarial mutation-test pass on the unit suite (src/router/router.test.ts). Tests-only: src/router/router.ts is unchanged. Adds 7 tests (30 → 37), all mutation-validated — each new test passes on clean source and fails under a targeted source mutation.

Gaps found (previously surviving mutants)

The existing suite exercised the create/sort/selection happy paths but never inspected the router's runtime cache, never called reset(), and only exercised the getError classifier with uniform error types. Probed on the clean suite, these mutants survived:

  • getMarketPrice cache cap value < 4value <= 4survived (no test read router.cache)
  • getError mixed-type classification (drop the balancer NoRouteFound clause) — survived (only uniform all-NoRouteFound / all-FetchFailed cases existed)

Mutation matrix (all KILLED by the new tests)

# Location Mutation Result
A getMarketPrice L146 value < 4<= 4 KILLED
C1 tryQuote L186 value < 4<= 4 KILLED
C2 findBestRoute L224 value < 4<= 4 KILLED
C3 getTradeParams L258 value < 4<= 4 KILLED
D getMarketPrice L146 drop ++value (set(key, value)) KILLED
E getMarketPrice L145 typeof value === "number"!== KILLED
F1 reset L316 drop this.cache.clear() KILLED
F2 reset L317 drop this.balancer?.cache.clear() KILLED
F3 reset L318 drop this.stabull?.cache.clear() KILLED
F4 reset L318 add this.sushi?.cache.clear() (negative) KILLED
B getError L334 balancer NoRouteFound clause → true KILLED
G getError L329 default FetchFailedNoRouteFound KILLED
H getError L347/348 swap balancerError/stabullError ctor args KILLED

13/13 targeted mutants killed; source restored pristine after each (git diff src/router/router.ts empty).

Behaviours now covered

  • Per-pair query cache across all four query methods: first call records 1, each subsequent call increments, capped at 4 (1,2,3,4,4,4); exactly one cache entry per fromToken.
  • reset() clears the router, balancer and stabull caches and intentionally leaves the sushi cache untouched.
  • getError(): a mixed NoRouteFound + FetchFailed result set classifies as FetchFailed (not NoRouteFound); each underlying router error is carried into its correct slot (sushiError/balancerError/stabullError) and concatenated into the top-level message.

Verification

  • vitest run src/router/router.test.ts → 37/37 pass.
  • Full unit suite (vitest run --exclude ./src/logger/index.test.ts) → 59 files / 848 tests pass.
  • tsc -p tsconfig.check.json clean; eslint src/router/router.test.ts clean.
  • The e2e fork test jobs are a pre-existing environmental red (require RPC/secrets) and are unrelated to this change.

Note (not fixed here — tests-only)

The cache key in all four methods reads params.toToken.address.toLowerCase without invoking it (missing ()), so the key depends only on fromToken. Behaviour is deterministic (the bad fragment is constant), so the cache still functions per-fromToken; surfaced here for visibility but left untouched per the tests-only scope of this PR.

🤖 Generated with Claude Code

Add discriminating unit tests for RainSolverRouter behaviours that the
existing suite left uncovered (mutation-validated: each new test fails
under a targeted source mutation and passes on clean source):

- Per-method query cache: getMarketPrice/tryQuote/findBestRoute/getTradeParams
  increment a per-pair counter on each call and cap it at 4 (1,2,3,4,4,4).
  Kills mutants on the `value < 4` cap, the `++value` increment, and the
  `typeof value === "number"` guard.
- reset(): clears the router, balancer and stabull caches but intentionally
  leaves the sushi cache untouched. Kills mutants dropping any of the three
  clears or adding a sushi clear.
- getError() error classification: a mixed result set (NoRouteFound +
  FetchFailed) classifies as FetchFailed, not NoRouteFound; each underlying
  router error is propagated into the correct slot and its message is
  concatenated into the top-level message.

Tests only; src/router/router.ts is unchanged.

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 27 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: 198c9783-d8fd-419c-81f3-224a8be30517

📥 Commits

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

📒 Files selected for processing (1)
  • src/router/router.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 2026-06-15-solver-router-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.

The two section banner comments described the testing process
("mutation-hardening") rather than what the code does. State the
present-tense behavior each block exercises instead.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@thedavidmeister

Copy link
Copy Markdown
Contributor Author

Reviewed 7da4f7f: approved by maintainer; unit tests + build + git-clean green, CodeRabbit clean, comments current-behavior-only. Only reds are environmental e2e-fork. Merging.

@thedavidmeister thedavidmeister merged commit 08492e8 into master Jun 15, 2026
10 of 13 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

@coderabbitai assess this PR size classification for the totality of the PR with the following criterias and report it in your comment:

S/M/L PR Classification Guidelines:

This guide helps classify merged pull requests by effort and complexity rather than just line count. The goal is to assess the difficulty and scope of changes after they have been completed.

Small (S)

Characteristics:

  • Simple bug fixes, typos, or minor refactoring
  • Single-purpose changes affecting 1-2 files
  • Documentation updates
  • Configuration tweaks
  • Changes that require minimal context to review

Review Effort: Would have taken 5-10 minutes

Examples:

  • Fix typo in variable name
  • Update README with new instructions
  • Adjust configuration values
  • Simple one-line bug fixes
  • Import statement cleanup

Medium (M)

Characteristics:

  • Feature additions or enhancements
  • Refactoring that touches multiple files but maintains existing behavior
  • Breaking changes with backward compatibility
  • Changes requiring some domain knowledge to review

Review Effort: Would have taken 15-30 minutes

Examples:

  • Add new feature or component
  • Refactor common utility functions
  • Update dependencies with minor breaking changes
  • Add new component with tests
  • Performance optimizations
  • More complex bug fixes

Large (L)

Characteristics:

  • Major feature implementations
  • Breaking changes or API redesigns
  • Complex refactoring across multiple modules
  • New architectural patterns or significant design changes
  • Changes requiring deep context and multiple review rounds

Review Effort: Would have taken 45+ minutes

Examples:

  • Complete new feature with frontend/backend changes
  • Protocol upgrades or breaking changes
  • Major architectural refactoring
  • Framework or technology upgrades

Additional Factors to Consider

When deciding between sizes, also consider:

  • Test coverage impact: More comprehensive test changes lean toward larger classification
  • Risk level: Changes to critical systems bump up a size category
  • Team familiarity: Novel patterns or technologies increase complexity

Notes:

  • the assessment must be for the totality of the PR, that means comparing the base branch to the last commit of the PR
  • the assessment output must be exactly one of: S, M or L (single-line comment) in format of: SIZE={S/M/L}
  • do not include any additional text, only the size classification
  • your assessment comment must not include tips or additional sections
  • do NOT tag me or anyone else on your comment

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