Skip to content

feat(ci): per-plugin mutation survival floor (closes #1003) - #1041

Merged
robcohen merged 2 commits into
mainfrom
feat/issue-1003-per-plugin-mutation-floor
May 8, 2026
Merged

robcohen merged 2 commits into
mainfrom
feat/issue-1003-per-plugin-mutation-floor

Conversation

@robcohen

@robcohen robcohen commented May 8, 2026

Copy link
Copy Markdown
Member

Summary

Phase 3 of the plugin-testing-quality plan (#992). The aggregate mutation score in mutation.yml was permissive — a few well-tested plugins could mask many badly-tested ones. This PR adds per-plugin floor enforcement (default ≤10% survival rate) with inline PR annotations for surviving mutants, plus the #[mutants::skip] annotation pattern documented in CONTRIBUTING.md.

Acceptance criteria from #1003:

  • CI runs cargo mutants on rustledger-plugin for every PR touching plugin code (already in mutation.yml trigger paths)
  • Per-plugin survival rate ≤ 10% — enforced by scripts/per-plugin-mutation-report.sh, called from a new step in mutation.yml
  • Surviving mutants on the PR diff are commented inline — GITHUB_ANNOTATIONS=1 mode emits ::warning file=…,line=… for each missed mutant; GitHub Actions surfaces these on the diff
  • Authors can either kill mutants or annotate with #[mutants::skip] + reason — documented in CONTRIBUTING.md

What's new

File Purpose
scripts/per-plugin-mutation-report.sh Parses mutants.out/*.txt, groups by source file, computes survival rate per plugin, emits GitHub annotations, exits non-zero on floor violation
scripts/test-per-plugin-mutation-report.sh 9-case self-test for the report script (empty input, all-caught, plugin-over-floor, infrastructure-only, MUTATION_FLOOR=0 disable, missing inputs, GitHub annotations, utils/mod bucketing, exact-10% boundary)
.cargo/mutants.toml Skips <impl NativePlugin for …>::name/description mutations — metadata methods returning fixed strings; ""/"xyzzy" mutations survive because no behavior depends on the literal text
.github/workflows/mutation.yml New Per-plugin mutation floor check step running the report with MUTATION_FLOOR=10 and GITHUB_ANNOTATIONS=1
.github/workflows/ci.yml Wires the script self-test into the existing Plugin Test Quality job
CONTRIBUTING.md Documents the floor, local invocation, and #[mutants::skip] annotation pattern

Bucketing rules

  • Files matching crates/rustledger-plugin/src/native/plugins/<name>.rs → bucket <name> (enforced)
  • mod.rs, utils.rs under that path → bucket _infrastructure (reported, not enforced)
  • Everything else → bucket _infrastructure

Survival rate = missed / (caught + missed + timeout). unviable mutants didn't compile and are excluded from the denominator.

What this PR does NOT do

  • It does not actively fix any plugins that exceed the floor. The mutation workflow has trigger paths gated on crates/rustledger-plugin/src/**, so this PR's own CI run won't fire the per-plugin check (the diff doesn't touch that path). The first plugin-touching PR after this lands will surface real per-plugin scores; if any exceed 10%, that PR's author can either tighten tests or annotate with #[mutants::skip].
  • It does not run the full plugin-crate scan locally. The crate has 1044 mutants which would take ~5 hours wall time. A partial run on the 3 plugins from test(plugin): test matrices for one_commodity, check_closing, check_commodity #1038 surfaced 4 surviving mutants on description() methods — addressed by the .cargo/mutants.toml exclusion.

Test plan

  • scripts/test-per-plugin-mutation-report.sh — 9 cases pass
  • scripts/check-plugin-test-quality.sh — clean
  • Local script driven against synthetic mutants.out fixtures showing pass/fail/exit-code paths
  • Local script driven against real mutants.out from a partial scan; failure mode and GitHub annotations both verified

Closes #1003

🤖 Generated with Claude Code

Phase 3 of the plugin-testing-quality plan from #992. The aggregate
mutation score in `mutation.yml` was permissive: a few well-tested
plugins could mask many badly-tested ones. This PR adds per-plugin
floor enforcement (default ≤10% survival rate) and inline PR
annotations for surviving mutants.

What's added
- `scripts/per-plugin-mutation-report.sh`: parses `mutants.out/*.txt`,
  groups outcomes by source file, computes per-plugin survival rate
  (`missed / (caught + missed + timeout)`, excluding unviable), prints
  a table, and exits non-zero when any plugin exceeds MUTATION_FLOOR.
  Infrastructure files outside `src/native/plugins/` are reported but
  not enforced.
- `GITHUB_ANNOTATIONS=1` on the script emits `::warning file=…,line=…`
  for every surviving mutant, satisfying the "PR inline comments"
  acceptance criterion. GitHub Actions surfaces these on the diff.
- `scripts/test-per-plugin-mutation-report.sh`: 9-case self-test for
  the report script — covers empty, all-caught, plugin-over-floor,
  infrastructure-only-over-floor, MUTATION_FLOOR=0 disable, missing
  inputs (exit 2), GitHub annotations, utils/mod bucketing, and the
  exact-10% boundary. Wired into the existing `Plugin Test Quality`
  CI job.
- `.cargo/mutants.toml`: skips `<impl NativePlugin for …>::name` and
  `<impl NativePlugin for …>::description` mutations. These metadata
  methods return fixed strings used only for registry lookup; cargo-
  mutants tries `""` and `"xyzzy"` replacements that survive because
  no behavior depends on the literal text. Filtering at config level
  keeps the report honest about real coverage gaps.
- `.github/workflows/mutation.yml`: new `Per-plugin mutation floor
  check` step that runs the report script with `MUTATION_FLOOR=10`
  and `GITHUB_ANNOTATIONS=1`, gated on the plugin crate being in the
  package list.
- `CONTRIBUTING.md`: documents the floor, the local invocation, and
  the `#[mutants::skip]` annotation pattern with a required reason.

How to handle a missed mutant (when CI fails)
1. Tighten the relevant test to fail under the mutated code, OR
2. Annotate the function with `#[mutants::skip]` and a leading
   `// reason:` comment explaining why mutation testing isn't useful.

Local validation
The report script was driven through 9 synthetic scenarios via the
self-test (all pass). A partial real-data run on the 3 plugins from
\#1038 surfaced 4 surviving mutants on `description()` methods —
addressed by the `.cargo/mutants.toml` exclusion above. The CI run on
this PR validates the workflow change, but the per-plugin enforcement
won't actually fire until a future PR touches `crates/rustledger-
plugin/src/native/plugins/*.rs` (the `mutation.yml` trigger paths).

Closes #1003

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings May 8, 2026 23:10
@robcohen
robcohen requested a review from a team as a code owner May 8, 2026 23:10
@codecov

codecov Bot commented May 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds per-plugin mutation testing enforcement to prevent strong plugins from masking weak ones, and surfaces surviving mutants directly on PR diffs.

Changes:

  • Introduces scripts/per-plugin-mutation-report.sh to compute per-plugin survival rates, gate CI on a 10% floor, and optionally emit GitHub annotations for missed mutants.
  • Adds a self-test harness for the report script and wires it into CI.
  • Documents the new mutation-testing workflow and skip-annotation pattern; adds cargo-mutants exclusions for known false positives.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
scripts/per-plugin-mutation-report.sh Implements per-plugin bucketing, reporting, floor enforcement, and GitHub annotations.
scripts/test-per-plugin-mutation-report.sh Adds synthetic fixtures + assertions to validate the report script’s behavior.
CONTRIBUTING.md Documents per-plugin floor, local invocation, and #[mutants::skip] usage.
.github/workflows/mutation.yml Adds per-plugin floor check step to the mutation workflow.
.github/workflows/ci.yml Runs the report script self-test in CI.
.cargo/mutants.toml Configures cargo mutants to exclude specific known-noise mutation families.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread scripts/per-plugin-mutation-report.sh Resolved
Comment thread scripts/per-plugin-mutation-report.sh Resolved
Comment thread scripts/per-plugin-mutation-report.sh Resolved
Comment thread scripts/per-plugin-mutation-report.sh Resolved
@github-actions

github-actions Bot commented May 8, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 74%
Full AST Match 99%
Total Files 786
What's tested
  • Check: Exit codes and error counts match bean-check
  • BQL: Query results match bean-query
  • Files: ~800 test files downloaded from 10+ beancount repositories

Full results available in workflow artifacts

Five Copilot inline findings, all real and actionable:

1. Truncation bug in floor enforcement. `survival_pct = m * 100 / total`
   loses precision: 11/101 = 10.89% truncates to 10 and incorrectly
   passes the `-gt 10` check. Replace with cross-multiplication
   `m * 100 > floor * total`, which is exact integer math and strictly
   greater. Pinned by a new self-test case (case 10: 11 missed out of
   101 total → must fail).

2. Header doc mismatch. The "Usage" section called the bare invocation
   "report only" — actually wrong, since `MUTATION_FLOOR` defaults to
   10 and enforcement is active unless explicitly set to 0. Also
   referenced `::error::` annotations when the script emits
   `::warning::`. Both fixed.

3. Process churn in GitHub annotation emission. Each missed mutant
   spawned 4 sed subprocesses + an echo for parsing — 4000 fork/exec
   pairs on a 1000-line missed.txt. Replace with a single bash
   `[[ $line =~ $regex ]]` capture; in-process, deterministic, faster.

4. Annotation guidance conflict with CONTRIBUTING.md. The script's
   failure message recommended `#[cfg_attr(test, mutants::skip)]`
   but CONTRIBUTING.md documents `#[mutants::skip]` (the canonical
   form, since cargo-mutants reads the AST without compiling). Align
   the script with the docs.

5. Test-coverage gap on the truncation boundary. Case 9 covered
   exactly-10% but didn't cover just-over-10%, which is the case
   the truncation bug would silently pass. New case 10 fills that
   gap and would have caught the original bug.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@robcohen
robcohen merged commit f97b865 into main May 8, 2026
55 checks passed
@robcohen
robcohen deleted the feat/issue-1003-per-plugin-mutation-floor branch May 8, 2026 23:29
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.

Phase 3: mutation testing per-plugin survival floor (≤ 10%)

2 participants