Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-11-13
77 changes: 77 additions & 0 deletions openspec/changes/2176-use-mutation-to-merge-or-delete/design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Design

## Decisions

- **Settle each of the 26 table rows against this tree before any campaign**: The table is the tree of b170358e. Commit 513bb31f2 moved each root-level file of the table into its package folder, and later commits deleted, split or renamed some of them, so the record gives each row the path that holds its tests now.
- **Campaign a split row at the paths that hold its tests now**: Commit 2475fa2cb split `tests/ai/agents/test_pydantic_ai_toolsets.py` into `tests/ai/toolsets/test_function_toolset.py`, `tests/ai/toolsets/test_toolset_authoring.py` and `tests/ai/toolsets/test_toolset_combinators.py`. That row still has tests, so it is a campaign row. The campaign leaves the three files out together, because together they hold the tests of the one table file. Commit b6af763bf renamed `tests/ai/rag/test_rag_loopback_policy.py` to `tests/ai/rag/test_example_config_loopback_rag.py` and put one case in `tests/ai/client/test_example_config_loopback_endpoints.py`. That row also has tests, but it is an invariant test, so it is `unjudged`.
- **Settle only the two rows whose tests no file holds**: Commit 5edd7a547 deleted `tests/ai/agents/test_agent.py` when it replaced `PydanticAgent` with the pydantic-ai `Agent`, and commit b6af763bf deleted `tests/ai/rag/test_rag_rrf.py` and put its fusion case into `tests/ai/rag/test_hybrid_search.py` (`test_fusion_keeps_documents_found_by_only_one_ranker`).
- **Do not decide a row or a case that no mutant can reach**: mutmut 3.8.1 mutates only the bodies of functions and methods: `mutmut/mutation/file_mutation.py:411` says "Else we keep the original node without modifications." A test whose distinct check reads module data, class data, an import, an option that a decorator builds, a committed file or the source text kills no mutant whatever it checks, so a count of 0 own mutants does not show that it adds no check. Such a test is `unjudged`: it gets no campaign and it stays. The seven unjudged rows are in `## Record rows`. Eight cases of campaign files are unjudged too and stay in their files. `test_each_error_class_declares_the_codes_of_its_catalog_row`, `test_one_error_code_maps_to_one_exit_status` and `test_no_error_class_has_an_init_that_only_forwards_to_its_base` of `tests/docs/test_exceptions.py` check class data, `docs/ERRORS.md` or the source text. `test_format_as_xml_reexport` of `tests/ai/test_pydantic_ai_format_prompt.py` checks an import. `test_the_style_request_asks_for_the_bottom_line_in_the_first_line` and `test_every_free_text_call_sends_the_callers_prompt_then_the_style_request` of `tests/ai/test_ai_client_style_request.py` check the text of the committed prompt `style_ste100.md`; the second checks it through its snapshot. `test_default_data_constants_and_settings` of `tests/ai/benchmark/test_data_dir_configuration.py` checks module constants and class data. `test_every_command_of_the_audit_check_has_a_reading` of `tests/commands/test_dependency_audit.py` stops a command with no reading, and that is a change of module data that no mutant makes.
- **Keep the invariant tests of the table**: `tests/core/test_third_party_telemetry.py` reads the manifests under `k8s/`, `tests/commands/test_openspec_scaffold.py` reads the committed OpenSpec files, and the two files of the loopback row send requests to the loopback endpoints of the committed `config.example.yaml`. A mutation run of `src/` cannot see a change of these files, and criterion 3 forbids the deletion of an invariant test, so the three rows are `unjudged` and `## Weakened checks` names none of their tests.
- **Keep the task loader row out of the delete rule**: `pyproject.toml:302:"--ignore=tests/test_ai_task_loader.py",` leaves the loader test out of each mutation run because it reads `src/` as data. Group 2 points that entry at `tests/ai/test_ai_task_loader.py`, so a campaign counts 0 killed mutants for it and the settle rule deletes it. The row is `unjudged` instead, and group 2 can run in any order before the campaigns.
- **Decide each campaign row in the group that campaigns it**: Group 1 writes the 26 rows with the decision `pending` on each of the 17 campaign rows, and its census test asserts only what stays true while groups 3 to 7 replace `pending`: a `pending`, `kept`, `trimmed` or `unjudged` row names files that exist, and a `deleted` or `moved` row names no file. Each campaign group asserts its own rows, and group 7 asserts that no row is `pending`.
- **Name each test that a group may remove in `## Weakened checks`**: The implement guard (`implement_test_names.lost_tests`) stops a step with `tests_lost` for each test that a file loses, a move included, unless the merged plan names it as `path::name`. The owner decided on 2026-11-14 that the plan may delete tests as needed, so the plan names the 106 judged tests of the 17 campaign rows, each with the mutation result that must hold before a task removes it.
- **Use seven decision words**: `pending` (campaign row before its group), `kept` (at least one own mutant, the file stays whole), `trimmed` (0 own mutants, the judged cases go and the unjudged cases stay), `deleted` (0 own mutants, the files of the row go), `moved` (0 own mutants, the files go and a case whose rule no target case holds moves unchanged into a named module), `settled` (no file holds the tests of the row) and `unjudged` (no mutant can reach the row).
- **Repair the mutation test selection and the copy list inside this change**: `pyproject.toml:298:"--ignore=tests/test_architectural_invariants.py",` names a path that no file of this tree holds, so the module that it meant to leave out runs against mutmut's generated code; `pyproject.toml:315:also_copy = [` holds no `openspec` entry, and `tests/openspec/test_openspec_new.py:243:real_spec = REPO_ROOT / CONST_OPENSPEC_SPECS_DIR / "roadmap-refine/selection/spec.md"` reads a real spec, so the stats run fails until both are repaired.
- **Check the selection in `tests/ci/test_ci_mutate.py`**: `tests/ci/test_ci_mutate.py:319:pytest_args = tomllib.loads((REPO_ROOT / "pyproject.toml").read_text(encoding="utf-8"))` already reads `[tool.mutmut]` and asserts its `pytest_add_cli_args`, so the selection check joins that module and adds no invariant file.
- **Attribute a mutant to a file with two runs of the same mutants**: mutmut 3.8.1 keeps no record of the test that killed a mutant, so a mutant that the whole suite kills and the run without the file leaves alive is the file's own. The record gives the mutants that the whole suite kills as a count, because one row can count hundreds and the command of the row lists them again with `mutmut results`, and it gives the mutants that survive without the file as their keys, which criterion 1 asks for and the settle rule reads.
- **Keep the record in `docs/TESTING.md`, with plain-text paths**: A task group may not write a path of the plan's own change folder, and the testing guide is already a page of the docs site. `tests/invariants/test_agents_md.py:623:def test_the_test_rules_name_only_test_files_that_exist` fails on a backticked `tests/` path of `docs/TESTING.md` that no file holds, and the record names the root-level paths of the table and the paths that the campaigns delete, so the record writes each path as plain text.
- **List the census file in the invariant list of `docs/TESTING.md`**: `tests/invariants/test_source_tree.py:741:def test_invariant_files_are_listed_in_testing_doc` fails on a file of `tests/invariants/` that the list at `docs/TESTING.md:95` does not name, so group 1 adds `test_mutation_decisions.py` to that list in the same change.
- **Move a configuration case only after the campaign decides**: Task 5.1 moves no case unless the record gives `tests/commands/test_config.py` 0 own mutants. Then a case whose rule no case of `tests/config/test_config_key_removal.py` or `tests/config/test_config_file_that_is_not_yaml.py` holds moves into that module unchanged, and the other cases go.
- **Move a configuration case into the mirror module of its subject, not into the audit's covering file**: `tests/telemetry/test_telemetry_collector_export.py:1:"""devops-cli telemetry reaches the cluster's collector, or says it does not (#547).` names the telemetry collector as its subject, and `tests/config/test_config_key_removal.py` holds the removal and dry-run cases of the configuration file.
- **Read the `Tests & Coverage` time with `devops ci job-time` and `devops gh api`**: `uv run devops ci job-time` gives the mean of the job on the last push runs of `main`, and `uv run devops gh api` reads the check runs of the head commit of the pull request, so group 9 runs no bare `gh`.
- **Take a new capability for the mutation selection**: The capability `ci-test-selection` covers the path arguments of `devops ci test` only, and no capability holds a rule for the tests that the mutation run selects.
- **Leave `docs/agent/archive/historical-phases-1-to-50.md` unchanged**: `references("test_pydantic_ai_toolsets")` names it, and it is a historical record of past phases that no test and no command reads.

## Record rows

The 26 rows that group 1 writes into `## Mutation decisions` of `docs/TESTING.md`, in the order of the issue table. "Group" is the group that campaigns a `pending` row.

| Table path | Path now | Decision at group 1 | Reason, commit or group |
| :--- | :--- | :--- | :--- |
| tests/commands/test_config.py | tests/commands/test_config.py | pending | group 5 |
| tests/core/test_cleanup_fuzzing.py | tests/core/test_cleanup_fuzzing.py | pending | group 6 |
| tests/test_agent.py | none | settled | 513bb31f2 moved it to tests/ai/agents/test_agent.py, and 5edd7a547 deleted it |
| tests/test_ai_client_credentials.py | tests/ai/client/test_ai_client_credentials.py | pending | group 3 |
| tests/test_ai_client_style_request.py | tests/ai/test_ai_client_style_request.py | pending | group 3 |
| tests/test_ai_gateway_base_url.py | tests/ai/client/test_ai_gateway_base_url.py | pending | group 3 |
| tests/test_ai_init.py | tests/ai/analyze/test_ai_init.py | unjudged | it checks the export lists of two packages, module data that no mutant changes |
| tests/test_ai_spend_dispatch.py | tests/ai/spend/test_ai_spend_dispatch.py | pending | group 3 |
| tests/test_ai_task_loader.py | tests/ai/test_ai_task_loader.py | unjudged | the mutation selection leaves it out, because it reads src as data |
| tests/test_config_settings_cache.py | tests/config/test_settings_cache.py | pending | group 5 |
| tests/test_data_dir_configuration.py | tests/ai/benchmark/test_data_dir_configuration.py | pending | group 7 |
| tests/test_exceptions.py | tests/docs/test_exceptions.py | pending | group 7 |
| tests/test_headless_auth.py | tests/config/test_headless_auth.py | pending | group 5 |
| tests/test_http_async_client.py | tests/http/test_http_async_client.py | pending | group 6 |
| tests/test_language_catalogs.py | tests/lang/test_language_catalogs.py | unjudged | it checks catalog data, class data that no mutant changes |
| tests/test_pydantic_ai_format_prompt.py | tests/ai/test_pydantic_ai_format_prompt.py | pending | group 3 |
| tests/test_pydantic_ai_retries.py | tests/ai/retries/test_pydantic_ai_retries.py | pending | group 3 |
| tests/test_pydantic_ai_toolsets.py | tests/ai/toolsets/test_function_toolset.py, tests/ai/toolsets/test_toolset_authoring.py, tests/ai/toolsets/test_toolset_combinators.py | pending | group 4 |
| tests/test_rag_loopback_policy.py | tests/ai/rag/test_example_config_loopback_rag.py, tests/ai/client/test_example_config_loopback_endpoints.py | unjudged | an invariant test: it sends requests to the loopback endpoints of config.example.yaml |
| tests/test_rag_rrf.py | none | settled | 513bb31f2 moved it to tests/ai/rag/test_rag_rrf.py, and b6af763bf deleted it and put its case into tests/ai/rag/test_hybrid_search.py |
| tests/test_third_party_telemetry.py | tests/core/test_third_party_telemetry.py | unjudged | an invariant test: it reads the manifests under k8s/ |
| tests/test_valkey_cache_tier.py | tests/valkey/test_valkey_cache_tier.py | pending | group 6 |
| tests/test_openspec_scaffold.py | tests/commands/test_openspec_scaffold.py | unjudged | an invariant test: it reads the committed OpenSpec files |
| tests/test_cli_format_adoption.py | tests/commands/test_cli_format_adoption.py | unjudged | it checks the options that the command decorators build and a constant of the test file |
| tests/test_consolidation_binaries.py | tests/core/test_consolidation_binaries.py | pending | group 6 |
| tests/test_dependency_audit.py | tests/commands/test_dependency_audit.py | pending | group 7 |

## Rejected alternatives

- **Delete the files on the line-coverage audit alone**: The issue states that 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.
- **Record only the mutation results now, and name the deletions in a later plan**: The vet of 2026-11-14 offered this option, and the owner decided on 2026-11-14 "yes, delete tests as needed", so this plan names the tests that its groups may remove.
- **Delete a file that the campaign cannot reach because it counts 0 own mutants**: A count of 0 is certain for a test that checks data that mutmut does not mutate, so it shows nothing about that test, and criterion 3 forbids the deletion of an invariant test.
- **Campaign the task loader row before group 2 repairs the selection**: The stats run fails before group 2 adds `openspec` to the copy list, so no campaign can run before group 2.
- **Run the campaign against the paths of the table**: `tests/test_agent.py` and `tests/test_ai_client_credentials.py` are no files of this commit, and commit 513bb31f2 moved them.
- **Add `tests/invariants/test_mutmut_selection.py`**: `tests/ci/test_ci_mutate.py` already reads `[tool.mutmut]`, so a new invariant file splits one subject over two files.
- **Move the configuration cases into `tests/telemetry/test_telemetry_collector_export.py`, the covering file of the audit**: Its first line names the telemetry collector as its subject, so a configuration case there sits in the wrong package.
- **Write the mutation record into the change folder of the item**: A task group may not change or create a path of the plan's own change folder under `openspec/changes/`, because the job writes that folder before the groups run.
- **Build a harness that records which test killed each mutant**: mutmut 3.8.1 is pinned and `devops ci mutate` runs it; a harness costs tokens to write, keep and fix, and copies the tool.
- **Leave the mutation selection as it is and run the campaigns**: The selection names modules of the old root-level tests folder, so the modules it meant to leave out run inside the mutants tree against mutmut's generated code and the stats run fails.

## Unchanged references

- `docs/agent/archive/historical-phases-1-to-50.md` (quoted target): A historical record of past phases that no test and no command reads, so the toolsets row changes no line of it.

## Security

The mutation run copies the repository into `mutants/` and runs the suite there, and this change adds `openspec` to that copy list, so the living specs enter the copy and nothing else does; the specs hold requirement text and no secret. A person must confirm that the copy list still holds no keyring file, no environment file and no installation token, and that no selection entry leaves the tree. The cases of `tests/ci/test_ci_mutate.py` fail if an entry names a path that no file of this tree holds or the copy list drops `openspec`. The deletions remove tests only: each removed test is named in `## Weakened checks` of `proposal.md`, and the implement guard stops a step that removes any other test.
Loading