Skip to content

test: mutation-harden gas/index unit coverage#444

Open
thedavidmeister wants to merge 5 commits into
masterfrom
2026-06-15-solver-config-coverage
Open

test: mutation-harden gas/index unit coverage#444
thedavidmeister wants to merge 5 commits into
masterfrom
2026-06-15-solver-config-coverage

Conversation

@thedavidmeister

Copy link
Copy Markdown
Contributor

Summary

Mutation-hardens the GasManager unit suite (src/gas/index.ts). A
scoped adversarial-mutation pass over the gas-estimation peripheral logic
found 10 surviving mutants in the existing src/gas/index.test.ts suite —
all in the constructor default-value logic, the onTransactionMine
threshold/deadline arithmetic, and the watchGasPrice idempotency guard.

This PR adds 6 discriminating tests (tests-only; no src/ change) that
each pass on the clean baseline and fail under the corresponding mutation.
Every previously-surviving mutant is now killed.

Mutation matrix

# Source line Mutation Before After
M1 maxGasPriceMultiplier = baseGasPriceMultiplier + 50 + 50- 50 SURVIVED KILLED
M2 if (config.txTimeThreshold !== undefined) guard → false SURVIVED KILLED
M3 if (config.gasIncreasePointsPerStep !== undefined) guard → false SURVIVED KILLED
M4 if (config.gasIncreaseStepTime !== undefined) guard → false SURVIVED KILLED
M13 gasIncreasePointsPerStep: number = 3 37 SURVIVED KILLED
M14 txTimeThreshold: number = 30_000 30_0001 SURVIVED KILLED
M15 gasIncreaseStepTime: number = 60 * 60 * 1000 1 SURVIVED KILLED
M5 if (txMineRecord.length >= this.txTimeThreshold) >=> SURVIVED KILLED
M6 this.deadline = Date.now() + this.gasIncreaseStepTime +- SURVIVED KILLED
M9 if (this.isWatchingGasPrice) return; guard → false SURVIVED KILLED

Already-covered (audited, no new test)

  • Math.min(max, multiplier + step) clamp → Math.max — KILLED by existing
    "should not increase the multiplier over the max value".
  • >=<= on the deadline-reset comparison — KILLED by existing
    "under threshold and reset" (past deadline).
  • isOk() branches in init/watchGasPrice — covered by existing
    init/interval tests.

Equivalent (intentionally not tested)

  • if (this.deadline && Date.now() >= this.deadline) — dropping the
    this.deadline && short-circuit is equivalent in practice: deadline is
    only ever undefined or a positive timestamp, and Date.now() >= undefined
    is already false, so no reachable state distinguishes the mutant.
  • >= vs > on the deadline comparison would only be discriminated by
    Date.now() === deadline exactly, which is non-deterministic.

New tests added (src/gas/index.test.ts, +94 lines)

  • should not start a second watcher when already watching (M9)
  • should apply class defaults when optional config fields are omitted (M1/M2/M3/M4/M13/M14/M15)
  • should use provided optional config values over the defaults (assignment branches)
  • should increase the multiplier when mine time equals the threshold exactly (M5)
  • should set the deadline to now plus the step time when increasing (M6)
  • should not reset the multiplier when the deadline is still in the future (future-deadline guard)

Gaps checklist

  • Constructor optional-field default branches
  • Class-field default values (points / step time / threshold)
  • maxGasPriceMultiplier = base + 50 fallback
  • onTransactionMine >= threshold boundary
  • Deadline + stepTime arithmetic
  • Future-deadline no-reset path
  • watchGasPrice double-start idempotency
  • init/watchGasPrice isErr branches — already covered by existing tests (audited)

Verification

  • tsc -p ./tsconfig.check.json clean
  • eslint ./src/gas/index.test.ts clean
  • Full vitest unit suite green: 847 tests passed (59 files + logger)
  • git diff src/ is empty — tests-only change
  • The e2e fork test jobs are a pre-existing environmental red (RPC/secrets) and are untouched by this PR.

🤖 Generated with Claude Code

Add discriminating tests to src/gas/index.test.ts that kill mutants
surviving the existing GasManager suite:

- Constructor default branches: assert class-field defaults
  (gasIncreasePointsPerStep=3, gasIncreaseStepTime=3_600_000,
  txTimeThreshold=30_000) and the maxGasPriceMultiplier = base + 50
  fallback when optional config fields are omitted, plus a companion
  test pinning the provided-value assignment branches.
- onTransactionMine boundary: a mine time exactly equal to the
  threshold must take the increase branch (>=, not >).
- Deadline arithmetic: the deadline is Date.now() + gasIncreaseStepTime
  (not minus), bracketed against before/after timestamps.
- Future-deadline guard: an under-threshold mine with a future deadline
  must not reset the multiplier.
- watchGasPrice idempotency: a second call while already watching must
  early-return and keep the same interval handle (no leaked interval).

Tests-only; src/ unchanged. 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 45 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.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

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: 2a8de2d7-f2bc-4424-9227-315c33ace998

📥 Commits

Reviewing files that changed from the base of the PR and between 3da315d and c9acc0a.

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

Restate the added gas/index test comments as present-tense facts about
what the code does, dropping mutant/process/coverage framing.

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.

2 participants