mutmut-ratchet 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mutmut_ratchet-0.1.0/LICENSE +202 -0
- mutmut_ratchet-0.1.0/NOTICE +23 -0
- mutmut_ratchet-0.1.0/PKG-INFO +289 -0
- mutmut_ratchet-0.1.0/README.md +266 -0
- mutmut_ratchet-0.1.0/mutmut_ratchet/__init__.py +30 -0
- mutmut_ratchet-0.1.0/mutmut_ratchet/cli.py +245 -0
- mutmut_ratchet-0.1.0/mutmut_ratchet/config.py +276 -0
- mutmut_ratchet-0.1.0/mutmut_ratchet/py.typed +0 -0
- mutmut_ratchet-0.1.0/mutmut_ratchet/ratchet.py +268 -0
- mutmut_ratchet-0.1.0/mutmut_ratchet/shards.py +189 -0
- mutmut_ratchet-0.1.0/mutmut_ratchet/stats.py +87 -0
- mutmut_ratchet-0.1.0/mutmut_ratchet/targets.py +116 -0
- mutmut_ratchet-0.1.0/mutmut_ratchet/timings.py +80 -0
- mutmut_ratchet-0.1.0/mutmut_ratchet.egg-info/PKG-INFO +289 -0
- mutmut_ratchet-0.1.0/mutmut_ratchet.egg-info/SOURCES.txt +26 -0
- mutmut_ratchet-0.1.0/mutmut_ratchet.egg-info/dependency_links.txt +1 -0
- mutmut_ratchet-0.1.0/mutmut_ratchet.egg-info/entry_points.txt +2 -0
- mutmut_ratchet-0.1.0/mutmut_ratchet.egg-info/requires.txt +1 -0
- mutmut_ratchet-0.1.0/mutmut_ratchet.egg-info/top_level.txt +1 -0
- mutmut_ratchet-0.1.0/pyproject.toml +120 -0
- mutmut_ratchet-0.1.0/setup.cfg +4 -0
- mutmut_ratchet-0.1.0/tests/test_cli.py +336 -0
- mutmut_ratchet-0.1.0/tests/test_config.py +248 -0
- mutmut_ratchet-0.1.0/tests/test_ratchet.py +356 -0
- mutmut_ratchet-0.1.0/tests/test_shards.py +245 -0
- mutmut_ratchet-0.1.0/tests/test_stats.py +128 -0
- mutmut_ratchet-0.1.0/tests/test_targets.py +219 -0
- mutmut_ratchet-0.1.0/tests/test_timings.py +91 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
mutmut-ratchet
|
|
2
|
+
Copyright 2026 Andrew Berry
|
|
3
|
+
|
|
4
|
+
This product includes software extracted from two repositories in the
|
|
5
|
+
rtl-433-hass organisation, both licensed under the Apache License, Version 2.0:
|
|
6
|
+
|
|
7
|
+
- rtl-433-hass/rtl_433 (https://github.com/rtl-433-hass/rtl_433)
|
|
8
|
+
- rtl-433-hass/pyrtl_433 (https://github.com/rtl-433-hass/pyrtl_433)
|
|
9
|
+
|
|
10
|
+
The code originated as the near-identical `scripts/mutation_*.py` helpers and
|
|
11
|
+
their tests carried by both repositories:
|
|
12
|
+
|
|
13
|
+
- scripts/mutation_ratchet.py
|
|
14
|
+
- scripts/mutation_shards.py
|
|
15
|
+
- scripts/mutation_stats.py
|
|
16
|
+
- scripts/mutation_targets.py
|
|
17
|
+
- scripts/mutation_timings.py
|
|
18
|
+
- tests/test_mutation_shards.py
|
|
19
|
+
- tests/test_mutation_targets.py
|
|
20
|
+
|
|
21
|
+
Only the per-repository constants (package paths, escalation triggers, and the
|
|
22
|
+
explicit test-to-source overrides) differed; those became configuration read
|
|
23
|
+
from the consumer's pyproject.toml.
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mutmut-ratchet
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Shared mutmut CI tooling: PR scoping, time-balanced sharding, and a per-file mutation-score ratchet.
|
|
5
|
+
Author: Andrew Berry
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/rtl-433-hass/mutmut-ratchet
|
|
8
|
+
Project-URL: Repository, https://github.com/rtl-433-hass/mutmut-ratchet
|
|
9
|
+
Project-URL: Issues, https://github.com/rtl-433-hass/mutmut-ratchet/issues
|
|
10
|
+
Keywords: mutmut,mutation-testing,ci,ratchet,sharding,pytest
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
15
|
+
Classifier: Topic :: Software Development :: Testing
|
|
16
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
17
|
+
Requires-Python: >=3.14
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
License-File: NOTICE
|
|
21
|
+
Requires-Dist: mutmut>=3.6
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
|
|
24
|
+
# mutmut-ratchet
|
|
25
|
+
|
|
26
|
+
Shared CI tooling that makes a slow [mutmut](https://github.com/boxed/mutmut)
|
|
27
|
+
run usable as a **blocking** pull-request gate: scope the run to what a PR
|
|
28
|
+
touched, fan it across a time-balanced matrix, and fail only on a real per-file
|
|
29
|
+
mutation-score regression.
|
|
30
|
+
|
|
31
|
+
It is the de-duplicated form of the `scripts/mutation_*.py` helpers that were
|
|
32
|
+
copy-pasted between [`rtl-433-hass/rtl_433`](https://github.com/rtl-433-hass/rtl_433)
|
|
33
|
+
and [`rtl-433-hass/pyrtl_433`](https://github.com/rtl-433-hass/pyrtl_433). Only
|
|
34
|
+
the per-repo constants differed; those are now configuration.
|
|
35
|
+
|
|
36
|
+
## Why
|
|
37
|
+
|
|
38
|
+
A full-package mutmut run is slow (tens of minutes), and its score is not
|
|
39
|
+
perfectly reproducible. Naively gating on it either blocks every PR for an hour
|
|
40
|
+
or fails spuriously. The five subcommands fix that:
|
|
41
|
+
|
|
42
|
+
| Subcommand | What it does |
|
|
43
|
+
| --- | --- |
|
|
44
|
+
| `targets` | Turns `git diff --name-only` into the modules worth mutating, or escalates to a full run |
|
|
45
|
+
| `shards` | Deterministic LPT partition of the package into N **time**-balanced shards |
|
|
46
|
+
| `stats` | Reduces mutmut's on-disk `mutants/*.meta` into a comparable JSON payload |
|
|
47
|
+
| `ratchet` | Compares that payload to a committed baseline with a mutant-denominated tolerance band |
|
|
48
|
+
| `timings` | Records the measured per-file mutmut runtime that `shards` balances on |
|
|
49
|
+
|
|
50
|
+
Two design choices carry most of the value:
|
|
51
|
+
|
|
52
|
+
* **Shards balance by measured time, not mutant count.** Per-mutant test time
|
|
53
|
+
varies several-fold across modules, so a count-balanced split still leaves a
|
|
54
|
+
slow pole that the gate waits on. Modules are sorted heaviest first (ties by
|
|
55
|
+
path) and dropped into the lightest bin (ties by lowest index) — plain LPT,
|
|
56
|
+
within 4/3 of optimal makespan and fully reproducible, so every matrix job
|
|
57
|
+
computes the identical assignment with no coordination.
|
|
58
|
+
* **The ratchet's tolerance band is denominated in mutants.** A flat percentage
|
|
59
|
+
is wrong in both directions: 2% is ~13 mutants on a 630-mutant module but
|
|
60
|
+
*zero* mutants on a 29-mutant one. The band is
|
|
61
|
+
`max(tolerance_fraction × total, tolerance_mutants)` mutants, converted back to
|
|
62
|
+
score space. That absorbs both run-to-run noise and the scoped-vs-full gap (a
|
|
63
|
+
scoped run is a slight lower bound: some mutants are only killed by tests in
|
|
64
|
+
other files) while still failing on a genuine regression, which typically
|
|
65
|
+
costs far more mutants than the band. The baseline only ever ratchets upward.
|
|
66
|
+
|
|
67
|
+
## Install
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
uv add --dev mutmut-ratchet
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
`mutmut` itself is a dependency (the tooling reads mutmut's module walk and its
|
|
74
|
+
per-file meta through `mutmut.__main__`), so installing this pulls it in. Pin
|
|
75
|
+
the exact mutmut version you test against in your own dev group if you care
|
|
76
|
+
which one CI uses.
|
|
77
|
+
|
|
78
|
+
## Configure
|
|
79
|
+
|
|
80
|
+
All settings live in your `pyproject.toml` under `[tool.mutmut_ratchet]`. Only
|
|
81
|
+
`package_path` is required; unknown keys and wrong types are hard errors, so a
|
|
82
|
+
typo can never silently weaken the gate.
|
|
83
|
+
|
|
84
|
+
```toml
|
|
85
|
+
[tool.mutmut_ratchet]
|
|
86
|
+
package_path = "my_package"
|
|
87
|
+
escalate_paths = ["pyproject.toml", "uv.lock", "tests/conftest.py"]
|
|
88
|
+
|
|
89
|
+
[tool.mutmut_ratchet.explicit_test_sources]
|
|
90
|
+
"tests/test_urls.py" = ["_urls.py"]
|
|
91
|
+
"tests/test_mut_client_floor.py" = ["client.py"]
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
| Key | Type | Default | Meaning |
|
|
95
|
+
| --- | --- | --- | --- |
|
|
96
|
+
| `package_path` | string | *(required)* | Repo-relative path of the package under mutation, e.g. `pyrtl_433` or `custom_components/rtl_433`. |
|
|
97
|
+
| `package_dotted` | string | `package_path` with `/` → `.` | Dotted name mutmut uses in mutant filters. Set it only when the two differ (e.g. a `src/` layout). |
|
|
98
|
+
| `baseline` | string | `"scripts/mutation_baseline.json"` | Committed per-file score baseline. Relative paths anchor to the `pyproject.toml`'s directory. |
|
|
99
|
+
| `timings` | string | `"scripts/mutation_timings.json"` | Committed per-file mutmut runtime profile, used as the shard bin-pack weight. |
|
|
100
|
+
| `escalate_paths` | list of strings | `["pyproject.toml", "tests/conftest.py"]` | Changed paths that force a **full** run because they can move results package-wide. Exact repo-relative matches. |
|
|
101
|
+
| `explicit_test_sources` | table of string → list of strings | `{}` | Test file → the source modules (relative to `package_path`) it exercises, for tests the `test[_mut]_<name>.py` → `<name>.py` convention cannot resolve. Genuinely broad tests are deliberately *left out* so they still escalate. |
|
|
102
|
+
| `tolerance_fraction` | float | `0.02` | Fractional half of the band; scales the cushion on large files. |
|
|
103
|
+
| `tolerance_mutants` | int | `3` | Absolute half of the band, in mutants; protects small files where a percentage rounds to nothing. |
|
|
104
|
+
| `precision` | int | `6` | Decimals scores are rounded to before comparison. |
|
|
105
|
+
| `floor` | float | `0.70` | Advisory floor recorded into a freshly written baseline payload. |
|
|
106
|
+
| `fallback_seconds_per_mutant` | float | `1.0` | Weight used when neither a timing nor any timing profile exists at all (a fresh checkout). |
|
|
107
|
+
|
|
108
|
+
A committed baseline carries the `tolerance_fraction` / `tolerance_mutants` it
|
|
109
|
+
was written with, and those win over the config defaults — so retuning the band
|
|
110
|
+
is a baseline edit, not a workflow edit. An explicit `--tolerance-*` flag beats
|
|
111
|
+
both.
|
|
112
|
+
|
|
113
|
+
Precedence throughout is **CLI flag → `pyproject.toml` → built-in default**.
|
|
114
|
+
|
|
115
|
+
## Commands
|
|
116
|
+
|
|
117
|
+
Every subcommand also accepts `--config PYPROJECT` (default: the nearest
|
|
118
|
+
`pyproject.toml` at or above the cwd), `--package-path`, and `--package-dotted`.
|
|
119
|
+
|
|
120
|
+
```
|
|
121
|
+
mutmut-ratchet targets [PATH ...]
|
|
122
|
+
```
|
|
123
|
+
Maps changed paths to targets. With no arguments, reads whitespace-separated
|
|
124
|
+
paths from stdin. Prints three lines: `all` or `scoped`; the mutmut filter
|
|
125
|
+
patterns; the source paths. Exit 0.
|
|
126
|
+
|
|
127
|
+
Patterns are derived the same way `shards` derives them, so a package
|
|
128
|
+
`__init__.py` in scope emits the `x_*` / `xǁ*` trampoline patterns its
|
|
129
|
+
mutants are actually named after — mutmut drops the `__init__` segment from
|
|
130
|
+
mutant names, so a `<pkg>.sub.__init__.*` filter would match none of them and
|
|
131
|
+
silently run zero mutants.
|
|
132
|
+
|
|
133
|
+
```
|
|
134
|
+
mutmut-ratchet shards --shard N --of M [--restrict PATH ...] [--baseline P] [--timings P]
|
|
135
|
+
```
|
|
136
|
+
Prints two lines: this shard's filter patterns, and its source paths (both blank
|
|
137
|
+
for an empty shard). `--restrict` intersects the shard with a scoped set without
|
|
138
|
+
changing the global assignment, so a scoped PR fans across the same shards.
|
|
139
|
+
Exit 0, or 2 for out-of-range `--shard`/`--of`.
|
|
140
|
+
|
|
141
|
+
```
|
|
142
|
+
mutmut-ratchet stats [--paths PATH ...]
|
|
143
|
+
```
|
|
144
|
+
Prints the per-file stats JSON on stdout. `--paths` is **required after a
|
|
145
|
+
filtered `mutmut run`**: mutants outside the filter stay "not checked", which
|
|
146
|
+
would otherwise read as 0%. Exit 0.
|
|
147
|
+
|
|
148
|
+
```
|
|
149
|
+
mutmut-ratchet ratchet --mode floor|strict --stats FILE [--baseline P] [--update] [--tolerance-fraction F] [--tolerance-mutants N]
|
|
150
|
+
```
|
|
151
|
+
`floor` is the CI gate (improvements never fail); `strict` also fails on upward
|
|
152
|
+
drift, as a local check that the committed baseline is still representative.
|
|
153
|
+
`--update` writes current scores back, keeping the higher of baseline/current
|
|
154
|
+
per file, and refuses while regressions stand. Exit 0 pass, 1 regression/drift,
|
|
155
|
+
2 missing stats or baseline.
|
|
156
|
+
|
|
157
|
+
```
|
|
158
|
+
mutmut-ratchet timings [--out PATH]
|
|
159
|
+
```
|
|
160
|
+
Writes the runtime profile after a **full** `mutmut run`. Exit 0, or 2 when no
|
|
161
|
+
timing data exists yet.
|
|
162
|
+
|
|
163
|
+
## Worked GitHub Actions example
|
|
164
|
+
|
|
165
|
+
Scoped on PRs, full on push/schedule, sharded six ways either way, with one
|
|
166
|
+
aggregated status check.
|
|
167
|
+
|
|
168
|
+
```yaml
|
|
169
|
+
name: Mutation
|
|
170
|
+
|
|
171
|
+
on:
|
|
172
|
+
push:
|
|
173
|
+
branches: [main]
|
|
174
|
+
pull_request:
|
|
175
|
+
branches: [main]
|
|
176
|
+
schedule:
|
|
177
|
+
- cron: "0 3 * * *"
|
|
178
|
+
|
|
179
|
+
permissions: {}
|
|
180
|
+
|
|
181
|
+
jobs:
|
|
182
|
+
mutation:
|
|
183
|
+
name: "Mutation floor — shard ${{ matrix.shard }}"
|
|
184
|
+
runs-on: ubuntu-latest
|
|
185
|
+
timeout-minutes: 30
|
|
186
|
+
strategy:
|
|
187
|
+
fail-fast: false
|
|
188
|
+
matrix:
|
|
189
|
+
shard: [0, 1, 2, 3, 4, 5]
|
|
190
|
+
steps:
|
|
191
|
+
- uses: actions/checkout@v5
|
|
192
|
+
with:
|
|
193
|
+
# Need history back to the base branch to diff a PR's changed files.
|
|
194
|
+
fetch-depth: 0
|
|
195
|
+
- uses: astral-sh/setup-uv@v6
|
|
196
|
+
with:
|
|
197
|
+
enable-cache: true
|
|
198
|
+
- run: uv sync --locked --dev
|
|
199
|
+
|
|
200
|
+
- name: Determine scope for this trigger
|
|
201
|
+
id: scope
|
|
202
|
+
run: |
|
|
203
|
+
if [ "${{ github.event_name }}" = "pull_request" ]; then
|
|
204
|
+
git fetch --no-tags origin "${{ github.base_ref }}"
|
|
205
|
+
changed=$(git diff --name-only "origin/${{ github.base_ref }}...HEAD")
|
|
206
|
+
uv run mutmut-ratchet targets $changed > targets.txt
|
|
207
|
+
cat targets.txt
|
|
208
|
+
{
|
|
209
|
+
echo "mode=$(sed -n '1p' targets.txt)"
|
|
210
|
+
echo "paths=$(sed -n '3p' targets.txt)"
|
|
211
|
+
} >> "$GITHUB_OUTPUT"
|
|
212
|
+
else
|
|
213
|
+
echo "mode=all" >> "$GITHUB_OUTPUT"
|
|
214
|
+
echo "paths=" >> "$GITHUB_OUTPUT"
|
|
215
|
+
fi
|
|
216
|
+
|
|
217
|
+
- name: Determine this shard's modules
|
|
218
|
+
id: shard
|
|
219
|
+
run: |
|
|
220
|
+
if [ "${{ steps.scope.outputs.mode }}" = "all" ]; then
|
|
221
|
+
uv run mutmut-ratchet shards --shard ${{ matrix.shard }} --of 6 > shard.txt
|
|
222
|
+
elif [ -n "${{ steps.scope.outputs.paths }}" ]; then
|
|
223
|
+
uv run mutmut-ratchet shards --shard ${{ matrix.shard }} --of 6 --restrict ${{ steps.scope.outputs.paths }} > shard.txt
|
|
224
|
+
else
|
|
225
|
+
# Scoped run with nothing in scope (e.g. a docs-only PR): no work.
|
|
226
|
+
printf '\n\n' > shard.txt
|
|
227
|
+
fi
|
|
228
|
+
{
|
|
229
|
+
echo "patterns=$(sed -n '1p' shard.txt)"
|
|
230
|
+
echo "paths=$(sed -n '2p' shard.txt)"
|
|
231
|
+
} >> "$GITHUB_OUTPUT"
|
|
232
|
+
cat shard.txt
|
|
233
|
+
|
|
234
|
+
- name: Run mutation testing (this shard's modules)
|
|
235
|
+
if: steps.shard.outputs.patterns != ''
|
|
236
|
+
run: |
|
|
237
|
+
uv run mutmut run ${{ steps.shard.outputs.patterns }}
|
|
238
|
+
uv run mutmut-ratchet stats --paths ${{ steps.shard.outputs.paths }} > mutation-stats.json
|
|
239
|
+
|
|
240
|
+
- name: Enforce per-file floor vs baseline
|
|
241
|
+
if: steps.shard.outputs.patterns != ''
|
|
242
|
+
run: uv run mutmut-ratchet ratchet --mode floor --stats mutation-stats.json
|
|
243
|
+
|
|
244
|
+
- name: No modules in this shard
|
|
245
|
+
if: steps.shard.outputs.patterns == ''
|
|
246
|
+
run: echo "No modules in scope for this shard; nothing to check."
|
|
247
|
+
|
|
248
|
+
mutation-gate:
|
|
249
|
+
name: "Mutation floor"
|
|
250
|
+
needs: [mutation]
|
|
251
|
+
if: always()
|
|
252
|
+
runs-on: ubuntu-latest
|
|
253
|
+
steps:
|
|
254
|
+
- name: Aggregate shard results
|
|
255
|
+
run: |
|
|
256
|
+
if [ "${{ needs.mutation.result }}" != "success" ]; then
|
|
257
|
+
echo "One or more mutation shards failed."; exit 1
|
|
258
|
+
fi
|
|
259
|
+
echo "All mutation shards passed."
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
A simpler single-job form, for a package small enough not to need a matrix:
|
|
263
|
+
|
|
264
|
+
```yaml
|
|
265
|
+
- name: Mutation test (per-module floor ratchet)
|
|
266
|
+
run: |
|
|
267
|
+
uv run mutmut run --max-children 4
|
|
268
|
+
uv run mutmut-ratchet stats > mutation-stats.json
|
|
269
|
+
uv run mutmut-ratchet ratchet --mode floor --stats mutation-stats.json
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
Never cache the `mutants/` working tree: a stale cache can report a higher score
|
|
273
|
+
than reality and let a regression through. Caching uv's download cache is fine.
|
|
274
|
+
|
|
275
|
+
## Bootstrapping a baseline
|
|
276
|
+
|
|
277
|
+
```bash
|
|
278
|
+
uv run mutmut run # a FULL run
|
|
279
|
+
uv run mutmut-ratchet stats > mutation-stats.json
|
|
280
|
+
uv run mutmut-ratchet ratchet --mode floor --stats mutation-stats.json --update
|
|
281
|
+
uv run mutmut-ratchet timings # writes the shard weights
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
Commit both JSON files. Refresh the timings profile periodically; a stale one
|
|
285
|
+
degrades to a slightly suboptimal — never incorrect — split.
|
|
286
|
+
|
|
287
|
+
## Licence
|
|
288
|
+
|
|
289
|
+
Apache-2.0. See `LICENSE` and `NOTICE`.
|