Skip to content

test: remove coverage-redundant test files after a mutation check #6420

Open

Description

@dan-petty

Problem

A per-test coverage run of 2026-11-19 covered 178,278 branch arcs in src/ with 26,012 tests. A greedy set of 6,160 tests (24%) covers all of them. 264 test files (2,739 tests) hold no test of that set. They take 245 s of the 3,376 s of summed module time (7.3%).

The run used coverage.py with COVERAGE_CORE=ctrace. On Python 3.14 the default sys.monitoring core records a line only once per process, and it lost the contexts of 15,243 tests.

Coverage shows which lines a test runs, not what the test asserts. The greedy set is also only one of many equal covering sets. So coverage alone cannot show that a file adds nothing.

Change

  • Compute the candidate list again with the method above: per-test contexts with COVERAGE_CORE=ctrace, a greedy set cover of the branch arcs, then the files with no test in the set. Do not commit the list or local paths.
  • Work in waves by test folder, one PR per wave.
  • For each candidate file, mutate the src/ modules that it covers with mutmut (devops ci mutate). Delete the file only when the remaining tests kill every mutant that the file kills. A file that kills a mutant of its own stays, or its distinct case moves into the file that covers the same lines. The PR names the mutant.
  • Guard tests of the repository itself stay, for example test_isolation_tripwire.py (tests never write to the real home folder) and the test-tree gate (test_source_tree.py), unless the owner rule of 2026-11-16 on config-value tests removes them.
  • test(cli): Use mutation to merge or delete 26 test files #2176 (26 files of the audit of 2026-10-24) goes first: it repairs the mutation test selection that this item uses. test(review): mutation cleanup of 18 test files #2162 owns the review and scanner files of the same finding.

Proof

  • Each wave PR lists, for each deleted file, the mutants that it killed with the whole suite, and shows that the rest of the suite kills them without it.
  • Line and branch coverage and fail_under stay the same or rise.
  • uv run devops ci passes, and the Tests & Coverage job takes no longer than before.

Depends on: #2176

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

Proposed design

Problem statement

Run the campaign in waves after the mutation selection repair. A wave deletes a candidate test file only when a mutation check shows that the remaining suite kills every mutant that the file kills. Coverage alone cannot show that a file adds no assertion. The waves leave the 18 review and scanner test files to #2162. The waves start after the #2162 items and after the #7905 stats run, if that run still fails. This item keeps the mutation selection repair and defers the 8 #2176 campaign rows to a new issue.

Acceptance criteria

Requirement: Mutation test selection repair

The [tool.mutmut] test selection and copy list MUST name the current package module paths and every test-read top-level path, including openspec.

Scenario: The repaired selection runs

  • WHEN uv run devops ci mutate runs after the repair
  • THEN the command selects the current package module paths and the openspec tests, and no test selection error names a stale path

Requirement: Candidate list from per-test branch coverage

Each wave MUST compute candidates from a COVERAGE_CORE=ctrace branch-arc run, a greedy set cover, and the files with no test in the set.

Scenario: A wave computes its candidates

  • WHEN the wave runs the per-test coverage command with COVERAGE_CORE=ctrace and --cov-context=test on the commit it starts from
  • THEN the command records one context for each test, the set cover selects the branch arcs, and the wave commits no list or local path

Requirement: Mutation proof before deletion

A wave SHALL delete a candidate test file only when the remaining suite kills every mutant that the file kills.

Scenario: A candidate file kills a mutant of its own

  • WHEN a uv run devops ci mutate run without the file leaves alive a mutant that the whole-suite run kills
  • THEN the file stays, or its distinct case moves into a file that covers the same lines before the wave deletes it

Requirement: Unjudged tests stay

A test whose check no mutant can reach MUST stay, whatever its count of own mutants.

Scenario: A candidate test asserts data that no mutant reaches

  • WHEN uv run devops ci mutate gives the test 0 own mutants because mutmut mutates only function bodies
  • THEN the campaign records the test as unjudged and the file stays

Requirement: Coverage floor after a wave

Line and branch coverage of src/ MUST stay at or above fail_under after each wave.

Scenario: CI coverage after a wave

  • WHEN uv run devops ci runs on the wave branch
  • THEN the command exits 0 and the coverage report shows line and branch coverage at or above 85%

Requirement: Guard tests stay

The guard tests of the repository MUST stay in the test tree unless the owner rule of 2026-11-16 removes them.

Scenario: No project rule removes a guard test

  • WHEN uv run devops ci test tests/config/test_isolation_tripwire.py tests/invariants/test_source_tree.py runs after a wave
  • THEN both modules pass and neither file is missing

Requirement: Wave plan records each deletion

Each test that a wave deletes MUST be named as path::name in the ## Weakened checks section, with the mutant that it killed.

Scenario: A wave plan deletes a test that the section does not name

  • WHEN uv run devops ci test tests/roadmap/implement/test_roadmap_implement_step_tests_kept.py runs a step that deletes a test that its plan does not name
  • THEN the step stops with tests_lost and its reason names the file and the lost test

Requirement: Tests & Coverage duration

The Tests & Coverage job MUST take no longer than before the wave.

Scenario: CI duration after a wave

  • WHEN the Tests & Coverage job runs on the wave branch
  • THEN its duration is at or below the duration of the base commit

Existing Tool Considered

The alternatives check in the issue body records a not-applicable verdict and names no tool. The work uses the existing coverage.py with pytest-cov and mutmut 3.8.1. coverage.py with COVERAGE_CORE=ctrace and --cov-context=test records the branch arcs that each test runs (src/devops_cli/commands/ci.py:2338, src/devops_cli/core/coverage_index.py:18). mutmut runs the mutation check through uv run devops ci mutate (pyproject.toml:295, docs/commands/ci.md:324). What they lack: coverage.py does not show what a test asserts. mutmut 3.8.1 keeps no record of the test that killed a mutant, so the campaign runs the same mutants twice, once with the whole suite and once with the candidate file left out (openspec/changes/2176-use-mutation-to-merge-or-delete/design.md:16). The [tool.mutmut] test selection and copy list name stale paths and miss openspec until the repair in this item (pyproject.toml:303, openspec/changes/2176-use-mutation-to-merge-or-delete/design.md:14). The change writes no maintained tool: the greedy set cover is a one-off query over coverage.py's JSON. It adds no tokens or elapsed time to keep and fix code.

Key questions

  • What happens to the moved test(cli): Use mutation to merge or delete 26 test files #2176 campaign rows?: Keep task 1.1, the mutation selection repair, in this item. Defer the 8 open campaign task groups of test(cli): Use mutation to merge or delete 26 test files #2176 to a new issue. The new issue audits the 26 files of the 2026-10-24 finding with devops ci mutate. (best practice) [sources: pyproject.toml:303]
    • Chosen: Defer the 8 campaign rows to a new issue. The rows are a separate audit. They are not all coverage-redundant, and this item is already split into waves for the 264 files.
    • Rejected: Include the rows in the waves. The rows are not all coverage-redundant. The item would be too big for one plan.
    • Rejected: Keep test(cli): Use mutation to merge or delete 26 test files #2176 as a dependency. The repair task is in this item. The campaign rows are a separate audit.
  • Which tool performs the mutation check?: mutmut 3.8.1 runs through uv run devops ci mutate. The command exits 0 whatever survives, so the campaign reads the killed and survived counts and the mutant keys, not the exit status. coverage.py supplies the per-test branch contexts; mutmut supplies the mutation run. (best practice) [sources: docs/commands/ci.md:324, docs/commands/ci.md:330, pyproject.toml:295]
    • Chosen: mutmut 3.8.1 through devops ci mutate. The repository already uses it, and the command records the mutant keys and the killed and survived counts.
    • Rejected: A new mutation script. The repository has a maintained mutation command. A new script adds code to keep and fix.
  • What coverage floor must the wave keep?: 85% of the lines and branches of src/, the fail_under value in pyproject.toml. Branch measurement is on (branch = true). [sources: pyproject.toml:267, pyproject.toml:272, CONTRIBUTING.md:34, docs/TESTING.md:218]
  • Why must the candidate run use COVERAGE_CORE=ctrace?: On Python 3.14 the default sysmon core does not support dynamic contexts and disables lines after the first hit. It attributes coverage almost entirely to the first test that ran. ctrace records one context for each test. [sources: src/devops_cli/core/coverage_index.py:18, openspec/changes/archive/2026-10-27-2356-coverage-floor-and-test-cost/design.md:26]
  • Which tests must stay?: Keep the guard tests of the repository: tests/config/test_isolation_tripwire.py and tests/invariants/test_source_tree.py, with the other invariant tests of tests/invariants/. The owner rule of 2026-11-16 (test(k8s): Drop the tests that repeat third-party version pins #6060) removes only a test that asserts a value of a manifest or config file. Neither guard does that. Keep also every test that no mutant can reach. Such a test reads module data, class data, an import, a decorator option, a committed file or the source text. It kills no mutant whatever it checks. A count of 0 own mutants does not show that it adds no check. (best practice) [sources: docs/TESTING.md:61, docs/TESTING.md:99, tests/config/test_isolation_tripwire.py:1, tests/invariants/test_source_tree.py:1]
    • Chosen: Keep the guard tests. The owner rule removes config-value tests. These tests assert test-session isolation and source-tree rules.
    • Rejected: Remove them with the owner rule. The rule in docs/TESTING.md:61 and openspec/changes/archive/2026-11-16-6060-drop-config-value-tests/proposal.md:4 does not reach these guard tests.
  • When does a candidate file stay?: A file stays when a mutant that the whole suite kills survives when the file is left out of the selection. Its distinct case moves into a file that covers the same lines. A test that no mutant can reach stays as unjudged, whatever its count of own mutants. (best practice) [sources: docs/ROADMAP_WORKFLOW.md:241]
    • Chosen: Delete after mutation proof. The remaining suite must kill every mutant that the file kills. A mutant that survives without the file is the file's own and keeps it.
    • Rejected: Delete on coverage alone. Coverage shows the lines a test runs, not what it asserts. The greedy set is one of many equal covering sets.
  • How should the work split?: Split into a prerequisite item for the mutation selection repair. Then make one item for each top-level test folder that holds a candidate file. Order the items by summed module time, from largest to smallest. Each item delivers one PR. Each wave recomputes the candidate list and commits neither the list nor a local path. (best practice) [sources: CONTEXT.md:12, CONTEXT.md:36, tests/module_durations.json]
    • Chosen: Prerequisite plus one item per top-level test folder. The issue asks for waves by test folder. Each item takes one PR. The order by summed module time takes the largest saving first.
    • Rejected: One PR for all 264 files. The change is too big for one review. CONTEXT.md:36 splits anything bigger than one pull request.
    • Rejected: One PR per test file. That makes too many PRs for the time each saves.
  • Which candidate files does this issue leave to test(review): mutation cleanup of 18 test files #2162?: The 18 review and scanner test files that test(review): mutation cleanup of 18 test files #2162 lists in its Impact. The reply counts 18, so the earlier list of 17 in this body is short by one. The waves use the test(review): mutation cleanup of 18 test files #2162 list as the source and leave every path in it out. The waves start after the test(review): mutation cleanup of 18 test files #2162 items. The stats run of test(ci): make the mutation run complete its first stats run #7905 comes first if it still fails. (best practice) [sources: openspec/changes/2162-mutation-runs-decide-which-of-the/proposal.md:28]
  • Where does the wave record the mutation proof?: The wave plan's ## Weakened checks section names each deleted test as path::name with the mutant that it killed. The PR body lists, for each deleted file, the mutants that it killed with the whole suite and the tests that kill them without it. The implement guard stops a step that removes a test that the section does not name. (best practice) [sources: docs/ROADMAP_WORKFLOW.md:241, src/devops_cli/roadmap/implement/implement_test_names.py:54, src/devops_cli/roadmap/plan_read.py:122]
    • Chosen: Plan and PR body. The plan record lets the guard allow the deletion. The PR body gives the reviewer the mutant evidence that the issue asks for.
    • Rejected: PR body only. The implement guard reads the plan on the default branch, not the PR body. A body-only record would not waive the deletion.

Fit

Needs splitting into 4 items:

  1. Prerequisite: repair the [tool.mutmut] test selection and copy list in pyproject.toml; one PR.
  2. Wave 1: the top-level test folder with the highest summed module time in tests/module_durations.json that holds a candidate file; one PR.
  3. Wave 2: the top-level test folder with the second highest summed module time that holds a candidate file; one PR.
  4. Wave 3 and later: each remaining top-level test folder that holds a candidate file; one PR per folder, in descending summed module time.

Suspected block

None.

Dependencies

#7905, #2162

Activity

  1. dan-petty commented on Nov 19, 2026

    @dan-petty
    OwnerAuthor
  2. added
    type/test
    source/agent
    status/new
    value/medium
    effort/high
    priority/p2-medium
    on Nov 19, 2026
  3. devops-cli-service commented on Nov 19, 2026

    @devops-cli-service
    Contributor

    Next step: a person splits the item, or replies in a comment or edits the body to keep one item. See Fit in the section Proposed design of the body.

  4. dan-petty commented on Nov 29, 2026

    @dan-petty
    OwnerAuthor

    Continuing open tasks moved from closed issue #2176 (openspec/changes/2176-use-mutation-to-merge-or-delete/tasks.md, removed under #7356), where 0 of 9 task groups ran before #2176 closed:

    1. 1.1 Repair mutation test selection and copy list (pyproject.toml) — update --ignore and --deselect entries in pytest_add_cli_args_test_selection to current package module paths, remove deleted entries, and add missing test-read top-level paths (including openspec) to also_copy.
    2. 2.1 Measure scope of all 17 campaign rows — run per-test coverage with COVERAGE_CORE=ctrace and --cov-context=test, and map each line context via mutable_functions (src/devops_cli/ci/mutate.py).
    3. 3.1 Campaign six AI client rows — run own-mutant vs remaining-suite campaigns and settle kept/trimmed/deleted on:
      • tests/ai/client/test_ai_client_credentials.py
      • tests/ai/client/test_ai_gateway_base_url.py
      • tests/ai/test_ai_client_style_request.py
      • tests/ai/test_pydantic_ai_format_prompt.py
      • tests/ai/spend/test_ai_spend_dispatch.py
      • tests/ai/retries/test_pydantic_ai_retries.py
    4. 4.1 Campaign toolsets row — run both campaigns as one unit on tests/ai/toolsets/test_function_toolset.py, tests/ai/toolsets/test_toolset_authoring.py, and tests/ai/toolsets/test_toolset_combinators.py.
    5. 5.1 Campaign three configuration rows — settle tests/config/test_settings_cache.py, tests/config/test_headless_auth.py, and tests/commands/test_config.py (moving distinct uncovered rules into tests/config/test_config_key_removal.py or tests/config/test_config_file_that_is_not_yaml.py if needed).
    6. 6.1 Campaign four core, HTTP, and Valkey rows — settle tests/core/test_cleanup_fuzzing.py, tests/core/test_consolidation_binaries.py, tests/http/test_http_async_client.py, and tests/valkey/test_valkey_cache_tier.py.
    7. 7.1 Campaign three docs, benchmark, and audit rows — settle tests/docs/test_exceptions.py, tests/ai/benchmark/test_data_dir_configuration.py, and tests/commands/test_dependency_audit.py.
    8. 8.1 Record coverage total and gate result — confirm all required PR checks pass and fail_under in pyproject.toml remains 85.
    9. 9.1 Record Tests & Coverage time — check uv run devops ci job-time --runs 20 vs PR duration.
  5. devops-cli-service commented on Nov 29, 2026

    @devops-cli-service
    Contributor

    Next step: a person splits the item, or replies in a comment or edits the body to keep one item. See Fit in the section Proposed design of the body.

  6. dan-petty commented on Nov 30, 2026

    @dan-petty
    OwnerAuthor

    Overlap with #2162. Both use devops ci mutate to delete test files. #2162 owns the review and scanner files listed in its table. Wave PRs of this item must leave those 18 files out, so that one file is not decided twice. Order: the stats run of #7905 (if it still fails) first, then the #2162 items, then the waves of this item.

  7. devops-cli-service commented on Dec 1, 2026

    @devops-cli-service
    Contributor

    Next step: a person splits the item, or replies in a comment or edits the body to keep one item. See Fit in the section Proposed design of the body.

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/highpriority/p2-mediumsource/agentstatus/newtype/testvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions