Skip to content

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

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

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

Conversation

@thedavidmeister

@thedavidmeister thedavidmeister commented Jun 15, 2026

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

Summary by CodeRabbit

  • Tests
    • Expanded coverage for gas pricing behavior, including repeated watch calls, stop watching, default configuration handling, and gas adjustment timing.
    • Added checks for edge cases around transaction mining, such as exact threshold timing and preserving pending adjustment windows.

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

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: 45acb8fd-4a44-4613-a21d-75e070652a54

📥 Commits

Reviewing files that changed from the base of the PR and between fc791fb and 27578b6.

📒 Files selected for processing (1)
  • src/gas/index.test.ts

Walkthrough

Adds 93 lines of new tests to src/gas/index.test.ts covering three areas: watchGasPrice idempotency (no duplicate intervals, unwatchGasPrice clears state), GasManager constructor defaults and overrides, and onTransactionMine edge cases (exact threshold, deadline arithmetic, no multiplier reset when deadline is future).

Changes

GasManager test coverage

Layer / File(s) Summary
watchGasPrice, constructor defaults, and onTransactionMine tests
src/gas/index.test.ts
Adds tests asserting a second watchGasPrice call reuses the existing handle; constructor applies defaults for omitted fields and respects provided overrides; onTransactionMine increases multiplier at exact threshold, sets deadline to Date.now() + gasIncreaseStepTime on increase, and skips multiplier reset when existing deadline is still future.

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 reflects the test-only gas/index coverage hardening and is concise.
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-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.

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