Skip to content

feat(ci): surviving mutants of changed lines as a sticky PR comment, with reviewer-style operators - #1338

Merged
xaleryb merged 10 commits into
intel:mainfrom
vchamarthi:ci/mutation-survivors-report
Nov 28, 2026
Merged

xaleryb merged 10 commits into
intel:mainfrom
vchamarthi:ci/mutation-survivors-report

Conversation

@vchamarthi

Copy link
Copy Markdown
Contributor

Summary

"Removing X leaves every test green" is found by reviewers today, although mutate_changed.py already finds much of it on every PR: the result sits in a warn-only job log. This puts the survivors in one sticky PR comment, adds the breaks reviewers make by hand that the mutator did not, and adds an opt-in gate.

Closes #1296

Changes

  1. scripts/mutate_changed.py: new operators for the breaks reviewers write by hand — a comparison moved across its boundary (<= to <), a clause dropped from and/or, one branch of a conditional expression taken, a filter clause dropped from a comprehension, an element dropped from a literal tuple, list or set of constants, and a statement deleted (a call, an augmented assignment, a raise, a continue, an assignment to an attribute or subscript). Not mutated: value or "text" fallbacks, logging and print calls, plain name assignments, break and return.
  2. --json gains survivors and waived (file, line, mutation, tests run) and waivers_without_reason. A new --comment-json writes the compact form the comment is built from.
  3. Waiver: # mutation-ok: <reason> at the end of the mutated line, or alone on the line above. An empty reason waives nothing and is listed.
  4. ci.yml mutation-diff: up to 80 mutants (was 40) with no new mutant started after 900 s; keeps its read-only token and uploads mutation-diff-result, also when the gate fails the step.
  5. cli-interface-comment.yml also follows ci and posts the result through the same validated workflow_run path: size caps, PR and head checks, one sticky comment, too-large handling. Every cell is an escaped code span and rows are capped.
  6. Gate: the repository variable MUTATION_GATE=true fails the job on an unwaived survivor. It ships unset.
  7. scripts/ci_local.py treats vars.MUTATION_GATE as unset, so make ci-local keeps running the mutation step.
  8. Docs: AGENTS.md, dokimi/CONTRIBUTING.md, changelog fragment.

Risk

  • The job does more work: on ten merged PRs replayed at these settings, the slowest run took 810 s, inside the 900 s budget and the job's timeout. A run that hits the budget lists its unrun mutants as not run.
  • The comment is new noise on PRs: on those ten replays, 7 of 10 left at least one survivor. The gate ships off for that reason; turning it on is the owner's call.
  • The comment job is tied to the ci workflow name and the artifact name; tests/test_mutation_comment_workflow.py reads both workflow files and fails on the PR that renames either.
  • When static fails, mutation-diff is skipped and uploads nothing, so an earlier comment stays as it was.
  • The posting path has been tested against a fake client only; whether workflow_run fires for ci is seen only after merge.

Testing

  • New tests cover each operator and each exclusion, waiver placement (reason, no reason, wrong line), the result and comment-result shape, the summary text, the gate on and off, and the poster under node (rows, clean, error, hostile text, size cap, malformed result, stale head, wrong artifact or workflow).
  • 18 breaks reviewers wrote by hand on dokimi PRs, rerun against the file as they saw it: the operators on main make 3, this PR makes 15. Not made: a return of another value, a dropped dict entry, one return True.
  • Replayed on ten merged PRs at the CI settings: slowest run 810 s.
  • make ci-local CI_LOCAL_ARGS='--offline --jobs static,typecheck': 0 failed, 17 passed, 3 skipped.
  • Full suite on Python 3.14 (Linux, arm64), rebased on current main: 29,926 passed; 2 fail the same way on main without this change (test_help_text_reads_a_real_help, which needs pip in the venv, and test_the_row_p_places_zero_where_large_deltas_round_p_at_zero_apart, a float result on arm64).

Open questions

None. The gate does not count inconclusive survivors: the script defines one as a survivor whose module has a candidate test file that did not run, so it is not evidence of a gap; they stay listed in the comment.

Revert

Revert the commit. A sticky comment already posted on open PRs stays until deleted by hand; unset MUTATION_GATE if it was set.

Checklist

  • Tests added/updated and pytest passes
  • ruff, mypy, and schema checks pass
  • Docs updated (or N/A) — see the docs-drift checklist in CONTRIBUTING.md
  • Self-reviewed per "Before opening a PR" in AGENTS.md
  • Each new raise/exit and test names the doc, contract or issue it traces to
  • No ad-hoc run artifacts committed
  • New files carry the SPDX license header (or are exempt in .github/.licenserc.yaml)

…mutation-ok waivers, MUTATION_GATE switch

mutate_changed.py lists survivors and waived mutants in --json and writes a compact --comment-json. `# mutation-ok: <reason>` on the mutated line, or alone on the line above, waives a survivor; an empty reason waives nothing.

mutation-diff keeps its read-only token and uploads the result; cli-interface-comment.yml also follows ci and posts it through the same validated workflow_run path. The repository variable MUTATION_GATE=true fails the job on an unwaived survivor; it ships unset, with no date to turn it on.

Signed-off-by: vchamarthi <123653452+vchamarthi@users.noreply.github.com>
@exai-bot

exai-bot commented Nov 27, 2026 •

Copy link
Copy Markdown

✅ OpenCodeReview: Found nothing that must be fixed in this commit.

CI at 3234057: 21 passing, 4 skipped.

Review limit reached. This PR has had 6 reviews, so it will only be reviewed again when you ask.
To ask: re-request review from exai-bot in the Reviewers list.

Other findings not posted (1)

1 not shown by a run

Review details
  • Commit reviewed: 3234057 against merge base 74eeae1
  • Coverage: 12 files in 4 groups
  • Engine: OpenCodeReview v1.13.5-exai.4.8f73eada, us.openai.gpt-6.1-sol
  • Usage: 949k tokens (664k from cache), 1m25s
  • Tool calls: 52 (27 file_read, 12 pr_threads, 5 code_search, 5 file_read_diff, 1 ci_log_search, 1 code_comment, 1 local_check_results)
  • Mutation survivor tooling and CI reporting: 6 files
  • CLI interface comment workflow: 2 files
  • Local CI runner and tests: 2 files
  • Contributor and agent guidance: 2 files

Comment thread dokimi/scripts/mutate_changed.py Resolved
Comment thread dokimi/scripts/mutate_changed.py Resolved
Comment thread dokimi/scripts/mutate_changed.py Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

2 open issues
What changed in this PR

This PR enhances the “mutation of changed lines” CI signal by expanding mutation operators, adding waiver support, and publishing survivors as a single sticky PR comment via a safe workflow_run poster, with an optional repository-variable gate.

Changes:

  • Add multiple new mutation operators plus # mutation-ok: <reason> waivers and reporting for survivors/waived.
  • Emit a compact --comment-json artifact and post/update a sticky PR comment (with hostile-text hardening and size caps).
  • Add an opt-in gate (vars.MUTATION_GATE=true) and keep local CI behavior warn-only by default.
File Description
dokimi/​tests/​test_mutation_comment_workflow.py New tests for the mutation-survivors sticky PR comment and CI job/artifact contracts.
dokimi/​tests/​test_mutate_changed.py Expands tests for new mutation operators, waivers, comment-result shape, and gate behavior.
dokimi/​tests/​test_cli_interface_comment_workflow.py Updates workflow_run poster tests to support posting both CLI and mutation results.
dokimi/​tests/​test_ci_local.py Verifies local CI treats vars.MUTATION_GATE as unset.
dokimi/​scripts/​mutate_changed.py Implements new operators, waiver parsing/application, and --comment-json output.
dokimi/​scripts/​ci_local.py Adds local workflow context value for vars.MUTATION_GATE.
dokimi/​changelog.d/​20261125_180000_vchamarthi_mutation-survivors-comment.md Changelog entry describing the new PR comment and gate.
dokimi/​CONTRIBUTING.md Documents the changed-lines mutation job, sticky comment, waivers, and gate.
AGENTS.md Updates reviewer guidance to reference sticky comment, waivers, and increased mutant cap.
.gitignore Ignores the new mutation-diff-comment.json output.
.github/​workflows/​cli-interface-comment.yml Extends poster workflow to handle mutation results (validation, escaping, caps) and to post on failed ci runs.
.github/​workflows/​ci.yml Produces/upload mutation comment artifact, raises max mutants, and adds optional gate flagging.

Review effort: Lite

Comment thread dokimi/scripts/mutate_changed.py Resolved
@codecov-commenter

codecov-commenter commented Nov 27, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.21%. Comparing base (74eeae1) to head (3234057).
⚠️ Report is 2 commits behind head on main.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1338      +/-   ##
==========================================
- Coverage   96.21%   96.21%   -0.01%     
==========================================
  Files         502      502              
  Lines       67062    67062              
  Branches    11645    11645              
==========================================
- Hits        64524    64522       -2     
  Misses       1565     1565              
- Partials      973      975       +2     

see 6 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- a text in the middle of an `or` chain is a decision, not a fallback:
  only a trailing string constant is left unmutated
- `warnings.append`/`extend` collect results; only log methods are skipped
- a `mutation-ok:` with no reason is listed whatever its mutant's status
- the waiver reason in the summary is a code span
- the poster counts its "more in" notes and keeps room for the waived table

Signed-off-by: vchamarthi <123653452+vchamarthi@users.noreply.github.com>
@vchamarthi

Copy link
Copy Markdown
Contributor Author

This is ready for another look: I've pushed 1 commit on ci/mutation-survivors-report (352190f..8dbb230).

Threads and comments:

  • I answered each one in its thread: 5 fixed.

What I checked on the new commit: all 5 new tests fail before the fix and pass after it; the full test suite passes with main merged in (34,450 tests), apart from 1 failure main has too.

What each test shows
  • text in the middle of an or chain still gets operators: fails before, passes after.
  • warnings.append is mutated, log calls are not: fails before, passes after.
  • reasonless waiver listed for a killed mutant: fails before, passes after.
  • waiver reason is a code span: fails before, passes after.
  • table caps: fails before, passes after.

Comment thread dokimi/scripts/mutate_changed.py Resolved
Signed-off-by: vchamarthi <123653452+vchamarthi@users.noreply.github.com>
An incomplete run (candidate tests failing or not run) was posted as
clean because the compact result dropped that information: carry
untested counts through it and show them in the comment, and post
even with no earlier comment. Give each followed workflow its own
poster concurrency group so a pending cli-interface post and ci post
no longer cancel each other.

Signed-off-by: vchamarthi <123653452+vchamarthi@users.noreply.github.com>
@vchamarthi

Copy link
Copy Markdown
Contributor Author

This is ready for another look: I've pushed 2 commits on ci/mutation-survivors-report (8dbb230..39598b3).

Changes:

  • A mutation result with zero mutants and uncovered changed lines is posted as incomplete, not clean.

Threads and comments:

  • I answered each one in its thread: 2 fixed.

Not caused by this PR:

  • Outside the PR: dokimi/dokimi/eval/plugin_delta.py:72; compare_plugin_runs raises PluginDeltaError: cannot compute plugin delta across different seed_requested: 1 vs 2 for two otherwise matching runs whose run_config is {"seed": None, "seed_requested": 1, "seed_status": "unsupported"} and the same with seed_requested 2; replicate_key in report/model_compare.py already leaves seed_requested out.

What I checked on the new commit: all 4 new tests fail before the fix and pass after it; the full test suite passes with main merged in (34,622 tests), apart from 1 failure main has too.

What each test shows
  • concurrency group includes the followed workflow: fails before, passes after.
  • incomplete run is not posted as clean: fails before, passes after.
  • comment_result carries untested counts: fails before, passes after.
  • a run that mutated nothing because no changed line was covered is not shown as clean: fails before, passes after.

A run that hit its time budget leaves mutants as 'not run'; the comment
treated that as clean and could replace survivors with 'No surviving
mutants'. Count not-run mutants as incomplete and say so in the comment.

Signed-off-by: vchamarthi <123653452+vchamarthi@users.noreply.github.com>
@vchamarthi

Copy link
Copy Markdown
Contributor Author

This is ready for another look: I've pushed 1 commit on ci/mutation-survivors-report (39598b3..237661d).

Changes:

  • A result with not run: 1, no survivors and zero untested counts is now reported as incomplete.

Threads:

  • I answered each one in its thread: 1 fixed.

What I checked on the new commit: the new test fails before the fix and passes after it; the full test suite passes with main merged in (34,713 tests), apart from 1 failure main has too.

What each test shows
  • A run with unrun mutants is not shown as clean: fails before, passes after.

…t shown as clean

The poster's incomplete check reads failing_tests and tests_not_run, but
only failing_tests was tested: dropping the tests_not_run clause left
every test green. Each count now has its own case.

Signed-off-by: Alexander Rybkin <alexander.rybkin@intel.com>
…an on every changed line

comment_result() dropped mutants_covered, so a run where --max-mutants
left most covered mutants untried was posted as "No surviving mutants on
the changed lines". It now carries `capped`; the poster validates it,
says how many the cap left out and no longer claims every line is clean.

Signed-off-by: Alexander Rybkin <alexander.rybkin@intel.com>
@xaleryb

xaleryb commented Nov 28, 2026

Copy link
Copy Markdown
Contributor
  • Ran: the head plus two commits, merged with current main. Full suite, ruff, mypy, bandit, check_growth, check_comment_blocks and docs check --strict, plus mutants of the poster and of comment_result.
  • Waiver scope (open): a waiver covers every operator on its line and outlives edits to that line. Example: a waiver written for the shift-boundary mutant of if x <= limit:, after the line is changed to if x <= limit and x != 0 or limit < 0:. Observed: --fail-on-survivor exits 0 with 7 mutants waived. Expected: only that shift-boundary mutant is waived, and the gate fails on the rest. Proposal: # mutation-ok[<operator>]: <reason>, where a waiver that names no operator waives nothing.
  • Commits to push:
    • 1484a7f: tests tests_not_run on its own. Before it, removing that clause from the incomplete check broke no test.
    • 1dc0a1a: the result now carries capped. A run the cap cut says how many mutants it left out, instead of "No surviving mutants on the changed lines".
  • Left for the author: the waiver syntax.

`${total} mutants of the lines this PR changes, at ${sha}: ${c.killed} killed, ` +
`**${r.survivors.length} survived**, ${r.waived.length} waived, ${c.inconclusive} inconclusive, ` +
`${c.timeout} timed out, ${c.error} errors, ${c['not run']} not run.\n`];
if (r.capped) parts.push(`The mutant cap left out ${r.capped} more mutants of covered changed lines.\n`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

bug · not shown by a run
Impact: the cap warning is silently omitted on the first survivor-free run.

Trigger: no existing mutation comment, all selected mutants killed, zero untested counts, and capped > 0 (for example, 80 killed out of 94 covered mutants).

Evidence: the early return at line 221 checks only survivors, existing comment and incomplete; capped affects none of these, so this new message is never reached. The new cap regression only uses comments=OLD, hiding the first-comment path. Let the early return apply only when r.capped === 0 as well, and test both OLD and [] with producer-consistent counts.

Workaround: inspect the run summary for omitted mutants.

Not shown by a run: A check of this claim did not show the problem.

Signed-off-by: Alexander Rybkin <alexander.rybkin@intel.com>
`# mutation-ok[<operator>]: <reason>` waives that operator's mutants on its
line; one with no operator, an unknown one or no reason waives nothing and
is listed, so a waiver kept after its line is rewritten no longer hides the
new clauses. Main has no mutation-ok uses to convert.

Signed-off-by: Alexander Rybkin <alexander.rybkin@intel.com>
…he run

With no comment yet, no survivor and nothing untested, the poster returned
before saying the cap left mutants out, so a capped sample went unreported.

Signed-off-by: Alexander Rybkin <alexander.rybkin@intel.com>
@xaleryb

xaleryb commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Pushed to this branch:

  • 37ca82ac9 merges current main (no conflicts).
  • 171c7a5c6 scopes waivers by operator: # mutation-ok[<operator>]: <reason> (several: [a, b]) waives only that operator's mutants on its line. A waiver with no operator, an unknown operator or no reason waives nothing and is listed. Before, # mutation-ok: <reason> waived every mutant on its line even after the line was rewritten. That case is now a test (exit 1). main has no waivers to convert; the docs and the comment hint show the new syntax.
  • 3234057a6 (cap thread at cli-interface-comment.yml): a first run the cap cut, with no survivor and nothing untested, now posts its comment with the cap line; tested with and without an earlier comment.
    Nothing left for the author from our side.

@xaleryb xaleryb 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.

Approved on 3234057. The job posts surviving mutants of changed lines as one sticky comment and fails on survivors when asked; our commits make a capped or incomplete run never read as clean (also on the first comment) and scope each mutation-ok waiver to the operator it names. Full suite and gates are green on the head merged with main. Windows smoke had not started (the hosted Windows queue was stuck); every other check passed.

@xaleryb
xaleryb merged commit 26e3083 into intel:main Nov 28, 2026
25 checks passed
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.

ci: post surviving mutants of changed lines on the PR, and add the breaks reviewers make by hand

5 participants