Skip to content

test(review): mutation cleanup of 18 test files #2162

Open
0 of 1 issue completed
Open

Description

@dan-petty

What happened

The coverage audit of 2026-10-24 (per-test contexts of a full run at f4d7066) found 86 test files that cover no line of src/ that another file does not also cover. 18 of them test the review and the scanners. For several, one other file covers 84-100% of the same lines. Line coverage alone cannot show that a file is redundant, because a file can cover a line and still assert something that no other file asserts. Mutation testing can show it: a file that kills no mutant that the rest of the suite leaves alive adds no check.

File Tests Lines covered beyond the import baseline
tests/ai/review/test_cited_code.py 2 1716, 99% in tests/test_review_group_analysis.py
tests/commands/test_review.py 2 802, 100% in tests/test_review_adjudication.py
tests/commands/test_review_removed_options.py 1 8
tests/test_custom_personas.py 3 21
tests/test_review_advisory_backing.py 1 280
tests/test_review_deduplication.py 4 377, 92% in tests/test_review_pipeline.py
tests/test_review_defects_comments.py 1 171
tests/test_review_defenses_and_verification.py 7 631, 84% in tests/test_review_tool_runs.py
tests/test_review_history.py 6 1815, 98% in tests/test_review_group_analysis.py
tests/test_review_location_paths.py 5 153
tests/test_review_loop_hardening.py 5 162
tests/test_review_regression_harness.py 2 603, 94% in tests/test_review_finding_losses.py
tests/test_review_taxonomy_and_severity.py 7 163
tests/test_review_verification.py 8 1300, 85% in tests/test_review_runner.py
tests/test_structural_positional_oracles.py 3 127
tests/test_security_kubelinter.py 8 538, 88% in tests/test_security_sarif.py
tests/test_security_tflint.py 3 896, 92% in tests/test_security_kubeconform.py
tests/security/test_sarif_fuzzing.py 5 240

What should happen

Mutation runs decide, file by file, whether a file adds a check. A file that kills no mutant of its own is deleted, or its one distinct case moves into the file that covers the same lines. A file that kills a mutant of its own stays, and the pull request names the mutant.

Evidence

  • .data/agent/scratch/audit-coverage/unique-lines-nobaseline.json and subsumption.json of the 2026-10-24 coverage audit (contexts of a full pytest --cov-context=test run at f4d7066).
  • Every file in the table exists at b170358.
  • uv run devops ci mutate --help: mutmut over the given src/ files; the first run copies the tree and runs the suite once.

Key questions

  • How is a mutant "of its own" found? (proposed) For each file, mutate the functions whose lines the file covers, once with the whole suite and once with the file left out (mutmut's pytest_add_cli_args_test_selection, --ignore=<file>). A mutant that survives only when the file is left out is the file's own.

Acceptance criteria

  • The pull request gives, for each file in the table, the mutants it killed with the whole suite and the mutants that survive without it.
  • Each file with no mutant of its own is deleted, or its distinct case moves into the file that covers its lines. The line coverage and fail_under stay as they are or rise.
  • No contract suite, invariant test or test of a security guard is deleted by this item.
  • uv run devops ci passes, and the Tests & Coverage job takes no longer than before.

Related: #1328 owns the move of the ai/review tests onto fakes; a file this item deletes leaves that work. The 86 files also hold invariant and helper tests, which other issues of the same audit own.

Source: #1328

Alternatives check of 2026-11-06: not-applicable.
Class: test, no search.
Tool: none found.

Proposed design

Problem statement

The coverage audit of 2026-10-24 lists 18 review and scanner test files that cover no line of src/ that another file does not cover. Line coverage cannot show that a file adds no check. Mutation runs must show, file by file, whether a file kills a mutant that the rest of the suite leaves alive. The first mutation stats run does not finish today. The test-selection list names paths that no longer exist, and also_copy lacks openspec. Tests that need git tracking fail from mutants/, because that tree has no git checkout. The change repairs the run first and then reads its report.

Acceptance criteria

Requirement: Mutation copy list holds the OpenSpec tree

[tool.mutmut].also_copy in pyproject.toml MUST hold openspec, so a test that reads the OpenSpec tree runs from mutants/.

Scenario: the copy list

  • WHEN a test reads also_copy from pyproject.toml
  • THEN openspec is one of its entries.

Requirement: Mutation test selection names only paths that exist

Every path in [tool.mutmut].pytest_add_cli_args_test_selection MUST exist in the checkout, so pytest ignores or deselects the test that it names.

Scenario: a stale selection path

  • WHEN a test resolves each --ignore and --deselect path of the list against the repository root
  • THEN each path names a file or a test that exists.

Requirement: Tests that cannot run from mutants are deselected

The selection list MUST deselect each test that fails from mutants/ because it needs git tracking or reaches a host path without a fake, and a comment MUST give the reason.

Scenario: a git-dependent test

  • WHEN the stats run starts from mutants/ with no git checkout
  • THEN no test fails with the message 'host path reached without a fake' and the stats run ends with no failed test.

Requirement: The first mutation stats run completes

uv run devops ci mutate MUST finish its first stats run from mutants/ and report its survivors.

Scenario: a clean mutation run

  • WHEN a person runs uv run devops ci mutate src/devops_cli/ai/review/cited_code.py with no mutants/ directory
  • THEN the command exits 0 and its report lists the surviving mutants.

Requirement: The change records the mutants of each file

The design.md of the change MUST hold one row for each of the 18 files, with the mutants that it kills and the mutants that survive without it.

Scenario: the record of the runs

  • WHEN a reader counts the rows of the mutation table in the design.md of the change
  • THEN the table holds one row for each of the 18 files of the issue.

Requirement: A file with no mutant of its own leaves the suite

A file that kills no mutant that the rest of the suite leaves alive MUST leave tests/, or its one distinct case MUST move into the file that covers its lines, unless it holds a contract, an invariant or a security-guard test.

Scenario: a redundant file

  • WHEN the table marks a file as killing no mutant of its own
  • THEN the file is absent from tests/, or its row names the contract, invariant or security-guard test that keeps it.

Requirement: A file with a mutant of its own stays

A file that kills a mutant that the rest of the suite leaves alive MUST stay in tests/, and its row MUST name that mutant.

Scenario: a file with its own mutant

  • WHEN the table names a mutant that only one file kills
  • THEN that file is present in tests/.

Requirement: No contract, invariant or security-guard test is deleted

The change MUST NOT delete a contract suite, an invariant test or a test of a security guard.

Scenario: a guard with no mutant of its own

  • WHEN the table marks tests/security/test_sarif_fuzzing.py as killing no mutant of its own
  • THEN the file stays in tests/ and its row names the guard that it holds.

Requirement: The coverage floor holds

fail_under MUST stay at 85, and the covered lines of src/ MUST NOT fall below their count at the base commit.

Scenario: the coverage report

  • WHEN uv run devops ci runs the suite and the coverage report
  • THEN the report passes fail_under and its covered line count is at least the base count.

Requirement: The required check passes in its old time

uv run devops ci MUST pass, and the Tests & Coverage job MUST NOT run longer than it ran at the base commit.

Scenario: the required check

  • WHEN the pull request runs Tests & Coverage
  • THEN the job succeeds and its duration is not greater than the base duration.

Existing Tool Considered

mutmut 3.8.0 is the open, maintained mutation tool that covers the need. It is pinned in the dev group of pyproject.toml and run by uv run devops ci mutate. It generates mutants over src/ and reports survivors. It lacks a per-file attribution of killed mutants, so the change runs it twice for each file, with PYTEST_ADDOPTS=--ignore=<file> in the second run. The alternatives check gave not-applicable for the class test and found no tool. The change writes no mutation code. It repairs the settings of the run and reads its report.

Key questions

  • How does the change find the mutants that only one test file kills?: Run mutmut over the src/ functions whose lines the file covers, once with the full suite and once with PYTEST_ADDOPTS=--ignore=<file>. A mutant that survives only in the second run is the file's own. (best practice) [sources: pyproject.toml, openspec/changes/2162-mutation-runs-decide-which-of-the/design.md]
    • Chosen: Second run with PYTEST_ADDOPTS. The variable is not part of the mutmut config fingerprint, so cached test stats stay valid.
    • Rejected: Edit the selection list in pyproject.toml for each file. mutmut hashes that list, so each edit forces a new serial run of the whole suite.
    • Rejected: Read the line coverage subsumption alone. A covered line cannot show that a file misses an assertion that another file makes.
  • Do the paths in the mutation test-selection list exist today?: No. The list names tests/test_architectural_invariants.py, and the module now lives at tests/invariants/test_architectural_invariants.py. Pytest ignores a missing path, so the module still runs from mutants/ and fails. [sources: pyproject.toml, tests/invariants/test_architectural_invariants.py]
  • What repairs the first stats run, which fails on tests that touch git?: Name the current paths in pytest_add_cli_args_test_selection, add openspec to also_copy, and deselect each test that fails from mutants/ for lack of git tracking or a host-path fake, with a comment that gives the reason. The reply on the issue names tests/ai/mcp/test_mcp_roadmap_tools.py and tests/ai/agents/test_embedding_config_retention.py as failing tests. (best practice) [sources: pyproject.toml, tests/invariants/test_change_folders.py]
    • Chosen: Update the selection paths and the copy list, and deselect the failing tests. The pyproject.toml comment already states this rule for tests that rely on git tracking. The run then completes and keeps the mutation tree small.
    • Rejected: Copy the whole checkout into mutants/. The tree is 475 MB, and the copy would still hold no git tracking.
    • Rejected: Make the failing tests skip when a tree is absent. A skip inside the test hides a broken mutation run.
  • Does a file with no mutant of its own lose its one distinct case?: No. Move that case into the file that covers the same lines, then delete the file. Keep the whole file when it holds a contract, an invariant or a security-guard test. (best practice) [sources: docs/adr/0007-tests-double-only-process-edges.md]
    • Chosen: Move the one distinct case, then delete the file. The suite keeps the assertion and loses the duplicate.
    • Rejected: Delete the file with every case. The suite loses an assertion that no other file makes.
    • Rejected: Keep the file. The file adds no mutant kill and keeps its run time cost.
  • Which rule wins when a security or contract test kills no mutant of its own?: The protection rule wins. The file stays, and its row names the test and the requirement that it guards. (best practice) [sources: openspec/specs/scanner-adapters/spec.md, tests/security/test_sarif_fuzzing.py, docs/adr/0004-ci-is-the-authoritative-gate.md]
    • Chosen: The protection rule wins. The acceptance criteria of the issue forbid the deletion of a guard test.
    • Rejected: The mutation result wins. The project would lose a guard that a spec requires.
  • Where does the change record the mutation evidence?: In the design.md of the change, as one row for each file, with the mutants that it kills and the mutants that survive without it. (best practice) [sources: CONTEXT.md]
    • Chosen: The design.md of the change. The change folder is the record of the item and stays on the default branch.
    • Rejected: The pull request body. The squash merge keeps no searchable record of it.
    • Rejected: A new report file under docs/. It adds an artifact that no reader maintains.
  • Does the coverage floor change?: No. fail_under stays at 85, and the covered lines of src/ do not fall. (best practice) [sources: pyproject.toml, CONTRIBUTING.md]
    • Chosen: Keep the floor and the covered lines. The gate stays as strict as before the cleanup.
    • Rejected: Lower fail_under to admit the deletions. It weakens the gate that ADR 0004 makes authoritative.

Fit

Needs splitting into 7 items:

  1. test(ci): make the mutation run complete its first stats run, with the current test-selection paths, the openspec copy entry and the deselected git-dependent tests
  2. test(review): mutation cleanup of cited code, review command, and removed options
  3. test(review): mutation cleanup of custom personas, advisory backing, and deduplication
  4. test(review): mutation cleanup of defect comments, defenses, and history
  5. test(review): mutation cleanup of location paths, loop hardening, and regression harness
  6. test(review): mutation cleanup of taxonomy, verification, and structural oracles
  7. test(security): mutation cleanup of kubelinter, tflint, and SARIF fuzzing

Suspected block

None.

Dependencies

None.

Sub-issues

Sub-issues

0 of 1 Issues completed
Loading 1 sub-issues

Activity

  1. added
    source/agent
    type/test
    on Oct 24, 2026
  2. dan-petty commented on Oct 24, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones on the board.

    • Type: type/test. The candidate proposes changes to test behavior using mutation runs.
    • Priority: P2-Medium. This change improves test quality and reduces redundancy but is not critical for immediate functionality.
    • Value: Medium. Improving test coverage and reducing redundant tests provides moderate value to the project.
    • Effort: High. Mutation testing requires significant setup and analysis of test files to determine which ones add value.
    • Related: test(hygiene): tombstone tests for deleted code are deleted and a dead-code tool is trialled #1871, which asks for a different change. Both items deal with test hygiene but the candidate focuses on mutation testing to decide file deletions while item 1871 addresses tombstone tests for deleted code.
  3. dan-petty commented on Oct 28, 2026

    @dan-petty
    OwnerAuthor

    Status set to Ready at bb46660 (see proposed design in issue body).

  4. added
    priority/p2-medium
    status/ready
    value/medium
    effort/high
    scope/review
    on Oct 28, 2026
  5. devops-cli-service commented on Nov 1, 2026

    @devops-cli-service
    Contributor

    Staged: branch test/2162-mutation-runs-decide-which-of-the, draft pull request #2979. The pull request plans the item and closes no issue.

    The task groups, with the tokens of the inputs of each step, for a budget of 40000 tokens:

    1. Run mutation testing and write the report: 4232 tokens
    2. Delete or merge files with no unique mutant: 4283 tokens
    3. Verify CI passes and mark tasks complete: 4062 tokens

    These paths of the plan are no file on the default branch, and no group creates them: openspec/changes/2162-mutation-review-scanner/mutation-report.md, tests/test_custom_personas.py, tests/test_review_advisory_backing.py, tests/test_review_deduplication.py, tests/test_review_defects_comments.py, tests/test_review_defenses_and_verification.py, tests/test_review_history.py, tests/test_review_location_paths.py, tests/test_review_loop_hardening.py, tests/test_review_regression_harness.py, tests/test_review_taxonomy_and_severity.py, tests/test_review_verification.py, tests/test_structural_positional_oracles.py, tests/test_security_kubelinter.py, tests/test_security_tflint.py, openspec/changes/2162-mutation-review-scanner/tasks.md. A person checks that the plan names them right.

  6. 3 remaining items

  7. added
    owner/agent
    on Nov 1, 2026
  8. added a commit that references this issue on Nov 1, 2026
  9. removed
    owner/agent
    on Nov 1, 2026
  10. changed the title [-]test(review): mutation runs decide which of the 18 review and scanner test files that add no covered line of their own are merged or deleted[/-] [+]test(review): mutation cleanup of 18 test files[/+] on Nov 6, 2026
  11. dan-petty commented on Nov 6, 2026

    @dan-petty
    OwnerAuthor

    The job shortened the title of this item. The summary had 126 characters, and the limit is 60. The type and the scope stay.

  12. added
    owner/agent
    on Nov 6, 2026
  13. dan-petty commented on Nov 6, 2026

    @dan-petty
    OwnerAuthor

    The plan cannot be built as written. The stop rule of design.md applies: the first stats run of uv run devops ci mutate does not end, so no mutation run of the 17 files can start.

    Evidence, from origin/main at c7145511, in a clean worktree:

    1. Run 1 of uv run devops ci mutate src/devops_cli/ai/personas/__init__.py stopped after 8 min. mutmut copies the tree to mutants/, and [tool.mutmut].also_copy in pyproject.toml has no openspec entry. tests/roadmap/test_roadmap_stage_form.py fails at collection with FileNotFoundError: .../mutants/openspec/config.yaml. The stats run stops: "failed to collect stats. runner returned 1".
    2. I added "openspec" to also_copy and ran again. Mutant generation took 572 s (706 files). The stats run then took 7.5 min for 5 tests and stopped after 2 failures. tests/ai/agents/test_agent.py::test_ollama_stream_400_raises_client_error fails with "host path reached without a fake: /.git" (the host-path guard; the tests run from mutants/, inside the checkout). Total run time: 21 min 25 s, and mutants/mutmut-stats.json was not written.
    3. A fix for each failure is a second fix on a fix, and each try costs about 20 min before the next failure shows. The suite has more cases that run in mutants/ than the [tool.mutmut] table names. The plan lists pytest_add_cli_args_test_selection as complete, and that was not true. Feasibility checked only --dry-run, never a first run.
    4. Size of the rest of the work: devops ci coverage on this tree runs 19819 tests in 749 s with 16 workers (3895 s of CPU). The serial stats run needs about 65 min of CPU at the least, before the two runs per file for 17 files in 10 groups, each up to 14400 s.

    I changed no file and made no commit. The base line coverage of main is 95% (TOTAL 106689 statements, 5720 missed).

    Suggested re-scope: first fix devops ci mutate so that a first run ends (the also_copy list, the tests that read the checkout or .git from mutants/), with a check that runs the stats step. Then plan this item again, ideally as smaller items of 3 to 4 files each, so that one pull request needs fewer mutation hours. Item #2176 (26 test files, same method) has the same dependency.

  14. added
    status/new
    and removed
    status/planned
    on Nov 6, 2026
  15. devops-cli-service commented on Nov 6, 2026

    @devops-cli-service
    Contributor

    The proposal at f1130d3 needs splitting into 6 items. A person splits the item into the items below, or replies in a comment or edits the body to keep one item, and the next refine round looks at the item again.

    1. test(review): mutation cleanup of cited code, review command, and removed options
    2. test(review): mutation cleanup of custom personas, advisory backing, and deduplication
    3. test(review): mutation cleanup of defect comments, defenses, and history
    4. test(review): mutation cleanup of location paths, loop hardening, and regression harness
    5. test(review): mutation cleanup of taxonomy, verification, and structural oracles
    6. test(security): mutation cleanup of kubelinter, tflint, and SARIF fuzzing

    The next refine round also looks at the item again when a commit on the default branch changes one of these files: pyproject.toml, tests/roadmap/test_roadmap_stage_form.py, tests/ai/agents/test_agent.py.

  16. devops-cli-service commented on Nov 6, 2026

    @devops-cli-service
    Contributor

    The proposal at 89daf41 needs splitting into 7 items. A person splits the item into the items below, or replies in a comment or edits the body to keep one item, and the next refine round looks at the item again.

    1. test(ci): make the mutation run complete its first stats run, with the current test-selection paths and the openspec copy entry
    2. test(review): mutation cleanup of cited code, review command, and removed options
    3. test(review): mutation cleanup of custom personas, advisory backing, and deduplication
    4. test(review): mutation cleanup of defect comments, defenses, and history
    5. test(review): mutation cleanup of location paths, loop hardening, and regression harness
    6. test(review): mutation cleanup of taxonomy, verification, and structural oracles
    7. test(security): mutation cleanup of kubelinter, tflint, and SARIF fuzzing
  17. devops-cli-service commented on Nov 6, 2026

    @devops-cli-service
    Contributor

    Alternatives check: not-applicable

    Class: test. The check makes no search and no model call for an item of this class.

    Tool: none found

    Checked on 2026-11-06. A person decides what this means for the item. The check changes no label and closes no issue.

  18. dan-petty commented on Nov 9, 2026

    @dan-petty
    OwnerAuthor

    The premise fails. The first mutation stats run cannot finish in one command.

    mutmut executes all tests serially in mutants/. Tests that touch git fail the sandbox check with 'host path reached without a fake' because mutants/ has no git tracking.

    A run of uv run devops ci mutate src/devops_cli/ai/personas/init.py passed 1328 tests and stopped after failures in tests/ai/mcp/test_mcp_roadmap_tools.py and tests/ai/agents/test_embedding_config_retention.py.

    The Stop rule in openspec/changes/2162-mutation-runs-decide-which-of-the/design.md and Rule 2 of AGENTS.md apply. This comment returns the item to New with the evidence.

  19. devops-cli-service commented on Nov 9, 2026

    @devops-cli-service
    Contributor

    The proposal at 2f20244 needs splitting into 7 items. A person splits the item into the items below, or replies in a comment or edits the body to keep one item, and the next refine round looks at the item again.

    1. test(ci): make the mutation run complete its first stats run, with the current test-selection paths, the openspec copy entry and the deselected git-dependent tests
    2. test(review): mutation cleanup of cited code, review command, and removed options
    3. test(review): mutation cleanup of custom personas, advisory backing, and deduplication
    4. test(review): mutation cleanup of defect comments, defenses, and history
    5. test(review): mutation cleanup of location paths, loop hardening, and regression harness
    6. test(review): mutation cleanup of taxonomy, verification, and structural oracles
    7. test(security): mutation cleanup of kubelinter, tflint, and SARIF fuzzing
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

    effort/highowner/agentpriority/p2-mediumscope/reviewsource/agentstatus/newtype/testvalue/medium

    Type

    No type

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions