test: mutation-harden router.ts unit coverage#443
Conversation
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>
|
Warning Review limit reached
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 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 |
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>
|
Reviewed 7da4f7f: approved by maintainer; unit tests + build + git-clean green, CodeRabbit clean, comments current-behavior-only. Only reds are environmental e2e-fork. Merging. |
|
@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:
Review Effort: Would have taken 5-10 minutes Examples:
Medium (M)Characteristics:
Review Effort: Would have taken 15-30 minutes Examples:
Large (L)Characteristics:
Review Effort: Would have taken 45+ minutes Examples:
Additional Factors to ConsiderWhen deciding between sizes, also consider:
Notes:
|
Module hardened
src/router/router.ts—RainSolverRouter(route selection / quote aggregation module).Adversarial mutation-test pass on the unit suite (
src/router/router.test.ts). Tests-only:src/router/router.tsis 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 thegetErrorclassifier with uniform error types. Probed on the clean suite, these mutants survived:getMarketPricecache capvalue < 4→value <= 4— survived (no test readrouter.cache)getErrormixed-type classification (drop the balancer NoRouteFound clause) — survived (only uniform all-NoRouteFound / all-FetchFailed cases existed)Mutation matrix (all KILLED by the new tests)
value < 4→<= 4value < 4→<= 4value < 4→<= 4value < 4→<= 4++value(set(key, value))typeof value === "number"→!==this.cache.clear()this.balancer?.cache.clear()this.stabull?.cache.clear()this.sushi?.cache.clear()(negative)trueFetchFailed→NoRouteFoundbalancerError/stabullErrorctor args13/13 targeted mutants killed; source restored pristine after each (
git diff src/router/router.tsempty).Behaviours now covered
1, each subsequent call increments, capped at4(1,2,3,4,4,4); exactly one cache entry perfromToken.reset()clears the router, balancer and stabull caches and intentionally leaves the sushi cache untouched.getError(): a mixedNoRouteFound + FetchFailedresult set classifies asFetchFailed(notNoRouteFound); 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.vitest run --exclude ./src/logger/index.test.ts) → 59 files / 848 tests pass.tsc -p tsconfig.check.jsonclean;eslint src/router/router.test.tsclean.e2e fork testjobs 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.toLowerCasewithout invoking it (missing()), so the key depends only onfromToken. 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