Skip to content

test(cli): Use mutation to merge or delete 26 test files #2176

Closed

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. 26 of them test the AI client, agents, configuration, RAG, Valkey, OpenSpec and the CLI output. 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/commands/test_config.py 1 743, 95% in tests/test_telemetry_collector_export.py
tests/core/test_cleanup_fuzzing.py 2 8
tests/test_agent.py 9 1220, 77% in tests/test_pydantic_agent.py
tests/test_ai_client_credentials.py 3 1457, 94% in tests/test_ai_client_retries.py
tests/test_ai_client_style_request.py 7 1738, 90% in tests/test_ai_client_providers_and_embeddings.py
tests/test_ai_gateway_base_url.py 5 243
tests/test_ai_init.py 2 0
tests/test_ai_spend_dispatch.py 7 1817, 97% in tests/test_ai_client_providers_and_embeddings.py
tests/test_ai_task_loader.py 1 3
tests/test_config_settings_cache.py 5 187
tests/test_data_dir_configuration.py 9 145
tests/test_exceptions.py 10 526, 96% in tests/test_pydantic_ai_exceptions.py
tests/test_headless_auth.py 2 11
tests/test_http_async_client.py 1 31
tests/test_language_catalogs.py 4 0
tests/test_pydantic_ai_format_prompt.py 5 0
tests/test_pydantic_ai_retries.py 8 71
tests/test_pydantic_ai_toolsets.py 13 247
tests/test_rag_loopback_policy.py 4 1079, 88% in tests/test_rag_embeddings.py
tests/test_rag_rrf.py 1 20
tests/test_third_party_telemetry.py 10 0
tests/test_valkey_cache_tier.py 3 121
tests/test_openspec_scaffold.py 8 159
tests/test_cli_format_adoption.py 3 370, 100% in tests/test_all_commands_help_dryrun.py
tests/test_consolidation_binaries.py 3 45
tests/test_dependency_audit.py 5 170

A file with 0 lines beyond the baseline covers only what importing devops-cli runs.

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. A file whose subject is a committed file and not src/ behaviour moves to #2164, which turns such checks into devops ci rows.

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.

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 and no invariant test is deleted by this item.
  • uv run devops ci passes, and the Tests & Coverage job takes no longer than before.

Related: #2162 owns the review and scanner files of the same finding. #1331, #1333 and #1329 move these packages' tests onto fakes; a file this item deletes leaves that work.

Source: #2162

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

Proposed design

Problem statement

The 2026-10-24 coverage audit found 26 test files that cover no line of src/ that another file does not also cover. Line coverage cannot show that such a file adds no check, because a file can 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. This item runs the mutation campaign for each file, then deletes or merges the files that add no check.

Acceptance criteria

Requirement: Mutation record per file

The pull request SHALL record, for each of the 26 files of the table, the mutants that the whole suite kills and the mutants that survive when the file is left out.

Scenario: Record names every table path

  • WHEN A reader opens the mutation record in the change folder of the item
  • THEN The record holds one entry for each of the 26 table paths, and each entry holds the command, the duration, a killed-mutant list and a surviving-mutant list.

Requirement: Consolidation path corrected

The record MUST name tests/core/test_consolidation_binaries.py for the table row that gives tests/test_consolidation_binaries.py.

Scenario: Table row resolved to the real path

  • WHEN A test compares the 26 paths of the record with the table
  • THEN The record holds tests/core/test_consolidation_binaries.py and holds no tests/test_consolidation_binaries.py.

Requirement: File with no own mutant removed

The change SHALL delete each file that kills no mutant of its own, or move its one distinct case into the file that covers the same lines.

Scenario: File with no own mutant

  • WHEN The entry of a file holds no mutant that survives only when the file is left out
  • THEN git diff --name-status shows that path deleted, or shows its case in the target file that the entry names.

Requirement: File with an own mutant kept

The change MUST keep each file that kills at least one mutant of its own, and the entry SHALL name that mutant and the test that kills it.

Scenario: File with an own mutant

  • WHEN The entry of a file holds at least one mutant that survives only when the file is left out
  • THEN The path stays in the tree, and the entry names the mutant key and the test that kills it.

Requirement: Coverage floor kept

The change SHALL keep the total line coverage and the fail_under value at the baseline level or higher.

Scenario: Coverage step of the gate

  • WHEN The coverage step of uv run devops ci runs on the change
  • THEN The total is at least the baseline that the record holds, and fail_under in pyproject.toml is unchanged or higher.

Requirement: Protected suites untouched

The change MUST NOT delete a contract suite or an invariant test.

Scenario: Deleted paths checked

  • WHEN A test compares the deleted paths of the diff with the protected list
  • THEN No deleted path is tests/test_architectural_invariants.py or under tests/invariants/, and each deleted path is one of the 26 table paths.

Requirement: CI gate passes

The change SHALL pass uv run devops ci with a Tests & Coverage duration that does not grow.

Scenario: Gate run on the change

  • WHEN uv run devops ci runs on the change
  • THEN It exits 0, and the Tests & Coverage job takes no longer than the duration that the record holds for the base commit.

Existing Tool Considered

The alternatives check of 2026-11-02 gave the verdict not-applicable for this item: its class is test, so the check made no search and found no tool. The tool that covers the need is mutmut, and the project already uses it through uv run devops ci mutate. What mutmut lacks: a per-file test selection that keeps its test stats. Each change of pytest_add_cli_args_test_selection in pyproject.toml changes test_selection in its config fingerprint. Thus the run pays one serial whole-suite run, and one run can take hours.

Key questions

  • How is a mutant of its own found?: Edit pytest_add_cli_args_test_selection in pyproject.toml for each file. Run the campaign once with the whole suite, and once with the file left out. A mutant that dies in the first run and survives in the second is the file's own. Mutate only the src/ files that the file covers, to bound the cost. Each edit changes test_selection in mutmut's config fingerprint, so the second run pays one serial whole-suite run, and one run can take hours. (best practice) [sources: pyproject.toml:283, openspec/changes/2162-mutation-runs-decide-which-of-the/design.md:61, tests/fixtures/roadmap_eval/stage/2162-mutation-runs-decide-which-of-the/case.json:57]
    • Chosen: Edit pytest_add_cli_args_test_selection for each file. It is the supported test-selection switch, and it changes the config fingerprint, so mutmut recomputes the stats for the new selection.
    • Rejected: Pass --ignore=<file> in PYTEST_ADDOPTS. PYTEST_ADDOPTS is not in the fingerprint, so mutmut reuses the baseline stats and reports a mutant as killed by a test that did not run.
    • Rejected: Use the line coverage and the subsumption data alone. A file can cover a line and still assert what no other file asserts, so line coverage cannot show that a file adds no check.
  • Which paths hold the invariant tests that the change must not delete?: The invariant tests are tests/test_architectural_invariants.py and the files under tests/invariants/, such as tests/invariants/test_agents_md.py. None of the 26 table paths is one of them. [sources: docs/adr/0004-ci-is-the-authoritative-gate.md, tests/invariants/test_agents_md.py]
  • Does the Tests column of the table hold the number of test functions of each file?: No. The code of tests/commands/test_config.py holds 12 test functions, and the table gives 1. The column is no test count, so the change does not use it to size the work. [sources: tests/commands/test_config.py]
  • Which path holds the consolidation binaries test?: The path is tests/core/test_consolidation_binaries.py. The table gives tests/test_consolidation_binaries.py, and the repository tree holds the file under tests/core/. [sources: tests/core/test_consolidation_binaries.py]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

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 is about test file management and mutation testing, which falls under the test type.
    • Priority: P2-Medium. This change impacts test suite health but does not block core functionality or introduce critical fixes.
    • Value: Medium. Improves test suite quality by removing redundant tests, benefiting maintainability and coverage accuracy.
    • Effort: High. Mutation testing requires significant setup and analysis; determining mutant ownership per file is complex.
    • Related: ci(gate): checks of committed files and tool configuration run as devops ci rows, not as pytest tests that start the tool #2164, which asks for a different change. Both items relate to test file cleanup but differ in approach: this one uses mutation testing while #2164 focuses on committed file checks running as devops ci rows.
  3. dan-petty commented on Oct 28, 2026

    @dan-petty
    OwnerAuthor

    Refine cannot set this item to Ready at bb46660 until a person answers the questions below. Reply in a comment or edit the body, and the next refine round looks at the item again.

    • 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=). A mutant that survives only when the file is left out is the file's own.
  4. added
    priority/p2-medium
    status/new
    value/medium
    effort/high
    scope/cli
    on Oct 28, 2026
  5. devops-cli-service commented on Nov 2, 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-02. A person decides what this means for the item. The check changes no label and closes no issue.

  6. changed the title [-]test(cli): mutation runs decide which of the 26 ai, config and cli test files that add no covered line of their own are merged or deleted[/-] [+]test(cli): Use mutation to merge or delete 26 test files[/+] on Nov 6, 2026
  7. 7 remaining items

  8. added 3 commits that reference this issue on Nov 14, 2026
  9. added
    status/planned
    and removed
    status/ready
    on Nov 14, 2026
  10. dan-petty commented on Nov 19, 2026

    @dan-petty
    OwnerAuthor

    #6420 continues this method for 264 files from a per-test coverage run of 2026-11-19 (coverage.py with COVERAGE_CORE=ctrace). It uses the mutation test selection that this item repairs, so this item merges first.

  11. added
    owner/agent
    status/in-progress
    and removed
    status/planned
    on Nov 19, 2026
  12. removed
    status/in-progress
    owner/agent
    on Nov 19, 2026
  13. dan-petty commented on Nov 29, 2026

    @dan-petty
    OwnerAuthor

    PR #6436 closed #2176, but all nine task groups in openspec/changes/2176-use-mutation-to-merge-or-delete/tasks.md (0 of 9 completed) remained open and unbuilt:

    1. Repair mutation test selection and copy list (1.1) — update --ignore/--deselect in pyproject.toml (pytest_add_cli_args_test_selection) and add required paths (including openspec) to also_copy.
    2. Measure scope of all 17 campaign rows (2.1) — run COVERAGE_CORE=ctrace + --cov-context=test and map lines with mutable_functions (src/devops_cli/ci/mutate.py).
    3. Campaign six AI client rows (3.1): 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. Campaign toolsets row (4.1): tests/ai/toolsets/test_function_toolset.py, tests/ai/toolsets/test_toolset_authoring.py, tests/ai/toolsets/test_toolset_combinators.py as one unit.
    5. Campaign three configuration rows (5.1): tests/config/test_settings_cache.py, tests/config/test_headless_auth.py, tests/commands/test_config.py (with tests/config/test_config_key_removal.py and tests/config/test_config_file_that_is_not_yaml.py).
    6. Campaign four core, HTTP, and Valkey rows (6.1): tests/core/test_cleanup_fuzzing.py, tests/core/test_consolidation_binaries.py, tests/http/test_http_async_client.py, tests/valkey/test_valkey_cache_tier.py.
    7. Campaign three docs, benchmark, and audit rows (7.1): tests/docs/test_exceptions.py, tests/ai/benchmark/test_data_dir_configuration.py, tests/commands/test_dependency_audit.py.
    8. Record coverage total and gate result (8.1) — verify fail_under in pyproject.toml stays at 85.
    9. Record Tests & Coverage duration (9.1) — compare against the 20-run mean on main.

    Where this work is now: All nine open task groups continue on open issue #6420 (where these open tasks have now been posted). As part of #7356, the stale folder openspec/changes/2176-use-mutation-to-merge-or-delete/ was removed.

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-mediumscope/clisource/agenttype/testvalue/medium

    Type

    No type

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions