Skip to content

feat(ci): on-demand mutation testing of changed functions (devops ci mutate) #853

Closed

Description

@dan-petty

Context & Rationale

Coverage at or above 90% shows that tests run the code, not that they check it. #601 measured a generated test passing against a multiply() that returned x + y (ROADMAP.md:546). The repo has no mutation tool; ai/review/defects.py scores only the reviewer.

Prior art:

  • Google surfaces individual mutants in code review ('Please fix this mutant', ICSE-SEIP 2023).
  • Meta's ACH generates tests that kill the mutants that survive (arXiv 2501.12862).
  • Neither gates on a score. An '80% killed' threshold has no source, and on a small diff a single surviving mutant decides it.

Scope & Deliverables

  • Deliverable:
    • Pin mutmut 3.8.x (Python 3.10-3.15) in the dev group, with a [tool.mutmut] section:
      • source_paths src/devops_cli;
      • pytest args that override -n logical;
      • also_copy for the repository files the tests read.
    • Add mutants/ to .gitignore. The CI cache fingerprint hashes untracked files (ci/cache.py:150-161).
    • devops ci mutate [PATHS] [--changed]:
      • maps lines changed since the merge base to their enclosing functions with ast;
      • runs mutmut on those function globs;
      • prints each surviving mutant (file, function, diff) and the killed, survived and timeout counts;
      • exits 0, and never prints a score.
    • An invariant test forbids pragma: no mutate under src.
  • Acceptance criteria:
    • A unit test maps a fixture diff to the expected globs and asserts that the argv disables xdist.
    • git check-ignore mutants/x succeeds.
    • Neither the devops ci stage list nor ci.yml contains a mutate step.
    • The pragma test fails on a fixture that uses the pragma.
    • The new unit tests take at most 1 s.
    • uv lock --check, uv audit and devops docs check pass.
  • Key questions:
  • Constraint: Never a gate. Report survivors, not percentages (the feat(ai): retract the false "prompt mutation testing" delivery claim #600 precedent).

Strategic Alignment

  • Milestone: Backlog
  • Depends on: none

Activity

  1. added
    type/feature
    scope/cli
    priority/p3-low
    on Oct 1, 2026
  2. added
    scope/ci
    on Oct 2, 2026
  3. added this to the v0.2.32 milestone on Oct 8, 2026
  4. dan-petty commented on Oct 8, 2026

    @dan-petty
    OwnerAuthor

    Placed in v0.2.32 on 2026-10-08 at the owner's request ("Populate 10 security and ci issues into each v0.2.30, v0.2.31, and v0.2.32 milestone"). This is a person's placement. Release theme: URLs and host keys read by the library that dials, ollama hardening, and pull-request test-quality tooling. Position 10 of 10 in the release's planned merge order. Its board Status is set to Ready, so the release-start fill keeps it.

  5. dan-petty-bot commented on Oct 9, 2026

    @dan-petty-bot
    Collaborator

    What changed

    #1513, merged into release/v0.2.32 as ed0baa3.

    Summary

    • Adds devops ci mutate [PATHS] [--changed] [--base REF] [--dry-run]. It runs mutmut 3.8.0 on chosen functions and shows each mutant no test killed, with its diff, then the killed, survived, timeout and no-tests counts. It prints no score, exits 0 whatever survives, and is neither a devops ci stage nor a ci.yml step.
    • devops_cli.ci.mutate uses ast to pick the functions mutmut mutates: top-level functions and methods of top-level classes. It leaves out decorated functions, unless the one decorator is a bare staticmethod or classmethod, and leaves out __new__, __getattribute__ and __setattr__.
      • With --changed, a function counts when its syntax tree differs from the one at the merge base with --base (default main), or the base lacks it. Untracked files under src that git does not ignore count as new.
      • A --base that names no commit is an error, not an empty selection.
      • PATHS alone select every function in the files they name or hold; with --changed, they narrow the changed ones.
    • Each function is passed to mutmut run as two globs: <module>.<mangled>__mutmut_* for its own mutants, and *<module>.<mangled> for its entry in mutmut's test stats. mutmut then runs only the covering tests and never mutates sibling functions whose names start with the same prefix. mutmut runs serially ([tool.mutmut].pytest_add_cli_args = ["-n", "0"]) and has a 4-hour timeout. --dry-run lists the mutmut requests and starts no mutmut process.
      -…

    20 file(s) changed.

    How it was verified

    Check runs at a898721:

    • Prune PR DevContainer Images: pass
    • CodeQL: pass
    • Dependency Freshness: skipping
    • Static Analysis: pass
    • Analyze (actions): pass
    • Analyze (python): pass
    • Tests & Coverage: pass
    • Changed-Test Independence: pass
    • DevContainer Image: skipping
    • Service Image: skipping

    Acceptance Criteria of docs/agent/tasks/task-853-on-demand-mutation-testing-of-changed-functions.md:

    • A unit test maps a fixture diff to the expected globs, which it builds with mutmut's own
      get_mutant_name and mangle_function_name, and asserts that the run argv disables xdist
      through [tool.mutmut].pytest_add_cli_args:
      test_changed_functions_map_to_the_globs_mutmut_names,
      test_mutate_runs_mutmut_serially_on_the_changed_function_globs.
    • git check-ignore mutants/x succeeds, and test_gitignore_keeps_mutants_out_of_the_tree
      matches it with the gitignore rules.
    • Neither the devops ci stage list nor ci.yml contains a mutate step:
      test_mutate_is_no_gate_step.
    • The pragma check fails on a fixture that uses the pragma:
      test_a_no_mutate_pragma_is_reported; test_no_source_line_exempts_itself_from_mutation
      passes on src.
    • Each new unit test takes at most 1 s.
    • uv lock --check, uv audit and devops docs check pass.
    • The key question is answered: the guard and the tripwire behave in fork mode (above).
    • Pending a person: on a quiet machine, the first-run and incremental wall times of
      rm -rf mutants && time uv run devops ci mutate --changed --base release/v0.2.32, then the same
      command again without rm -rf mutants.
  6. added a commit that references this issue on Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/p3-lowscope/ciscope/clitype/feature

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions