evalmut 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.
- evalmut-0.1.0/LICENSE +21 -0
- evalmut-0.1.0/PKG-INFO +186 -0
- evalmut-0.1.0/README.md +169 -0
- evalmut-0.1.0/evalmut/__init__.py +56 -0
- evalmut-0.1.0/evalmut/case.py +105 -0
- evalmut-0.1.0/evalmut/cli.py +144 -0
- evalmut-0.1.0/evalmut/operator.py +138 -0
- evalmut-0.1.0/evalmut/operators.py +776 -0
- evalmut-0.1.0/evalmut/outcome.py +97 -0
- evalmut-0.1.0/evalmut/py.typed +0 -0
- evalmut-0.1.0/evalmut/report.py +112 -0
- evalmut-0.1.0/evalmut/runner.py +162 -0
- evalmut-0.1.0/evalmut/score.py +167 -0
- evalmut-0.1.0/evalmut.egg-info/PKG-INFO +186 -0
- evalmut-0.1.0/evalmut.egg-info/SOURCES.txt +20 -0
- evalmut-0.1.0/evalmut.egg-info/dependency_links.txt +1 -0
- evalmut-0.1.0/evalmut.egg-info/entry_points.txt +2 -0
- evalmut-0.1.0/evalmut.egg-info/requires.txt +1 -0
- evalmut-0.1.0/evalmut.egg-info/top_level.txt +1 -0
- evalmut-0.1.0/pyproject.toml +34 -0
- evalmut-0.1.0/setup.cfg +4 -0
- evalmut-0.1.0/tests/test_evalmut.py +807 -0
evalmut-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Erik Hill
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
evalmut-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: evalmut
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Mutation testing for evals: inject known defects into the system under test and report which grader checks stay green. A surviving mutation is a hole in the eval.
|
|
5
|
+
Author-email: Erik Hill <erik.hill0987@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Repository, https://github.com/egnaro9/evalmut
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Topic :: Software Development :: Testing
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Requires-Python: >=3.11
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: gradecore>=0.10.0
|
|
16
|
+
Dynamic: license-file
|
|
17
|
+
|
|
18
|
+
# evalmut — mutation testing for evals
|
|
19
|
+
|
|
20
|
+
**Your eval suite passes. Does it actually check anything?**
|
|
21
|
+
|
|
22
|
+
You write a grader, watch it pass on a good output, and ship it. You never ask the
|
|
23
|
+
other question: would it *also* pass on a plausibly-broken output? A `contains("42")`
|
|
24
|
+
check passes `"the total is 42"` — and it passes `"I did NOT reach 42"` just as
|
|
25
|
+
happily. A JSON check that confirms a `count` field is present says nothing about
|
|
26
|
+
whether `count` is a number or the string `"three"`. A refusal check that scans for
|
|
27
|
+
"I can't help" is fooled by a reply that refuses in its first line and then delivers
|
|
28
|
+
the harm below. These aren't hypotheticals; each is a real defect that shipped past a
|
|
29
|
+
real check.
|
|
30
|
+
|
|
31
|
+
`evalmut` finds them. It takes an eval case your grader passes, injects a *known*
|
|
32
|
+
defect into the output — a defect **mined from a documented real-world eval failure**,
|
|
33
|
+
not invented — and reruns the grader. If the grader still passes a genuinely-wrong
|
|
34
|
+
output, that's a **hole**: a class of regression your eval would let ship green.
|
|
35
|
+
|
|
36
|
+
It's the same idea as code mutation testing (PIT, Stryker, mutmut), which nobody had
|
|
37
|
+
built for the model-plus-prompt-plus-grader stack — because there a "mutation" isn't a
|
|
38
|
+
flipped boolean, it's a semantic perturbation whose ground truth you have to establish.
|
|
39
|
+
That's the hard part, and it's what `evalmut` does.
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
$ evalmut run suite.py # your suite; see 'Install & use' below
|
|
43
|
+
────────────────────────────────────────────────────────────────────────
|
|
44
|
+
evalmut — does your eval actually check anything?
|
|
45
|
+
────────────────────────────────────────────────────────────────────────
|
|
46
|
+
mutation score 91.4% (32 caught / 35 applied; 150 n/a)
|
|
47
|
+
holes 3 (1 blind, 2 coverage-gap)
|
|
48
|
+
|
|
49
|
+
BLIND SPOTS — a real defect shipped green; the check is present and broken
|
|
50
|
+
• contains / contains
|
|
51
|
+
mutation : keyword_present_but_negated — the checked keyword appears,
|
|
52
|
+
but in a context that means the opposite
|
|
53
|
+
mined from: a CI proof-gate that greps its own transcript for a
|
|
54
|
+
token; the block message contains it, so mentioning it passes
|
|
55
|
+
COVERAGE GAPS — no check guards this shape (a missing grader, not a broken one)
|
|
56
|
+
• valid_json / valid_json
|
|
57
|
+
mutation : json_value_type_flip — a required field's value coerced to
|
|
58
|
+
the wrong type (number -> string)
|
|
59
|
+
• valid_json / valid_json
|
|
60
|
+
mutation : json_value_corruption — a required field's value changed to a
|
|
61
|
+
different value of the same type (3 -> 4)
|
|
62
|
+
mined from: gradecore valid_json checks key PRESENCE only, never value
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
That run is `evalmut` pointed at **its own dependency's** graders. It found three real
|
|
66
|
+
holes and — this is the point — it was **fair about them**: it called the `contains`
|
|
67
|
+
weakness a *blind spot* (a present check that's broken) and the two `valid_json` scopings
|
|
68
|
+
*coverage gaps* (a missing check, not a broken one), because `valid_json` only ever
|
|
69
|
+
claimed to check key presence. A tool that cries "broken!" at a correctly-scoped check
|
|
70
|
+
is a tool you learn to ignore.
|
|
71
|
+
|
|
72
|
+
## The two ways an eval lies
|
|
73
|
+
|
|
74
|
+
Most eval tooling only asks the first of these. Both are real, and `evalmut` tests both:
|
|
75
|
+
|
|
76
|
+
- **Blind spot** — a real defect ships green. Inject a *wrong* output; a sound grader
|
|
77
|
+
must reject it. If it passes, the check is present and broken.
|
|
78
|
+
- **Brittle spot** — a correct output gets flagged. Inject an *equivalent* change (a
|
|
79
|
+
trailing disclaimer after a complete answer, cosmetic whitespace, a JSON code fence);
|
|
80
|
+
a sound grader must still pass it. If it fails, the check false-positives, and a
|
|
81
|
+
false-positive check is quietly recalibrated until it stops catching the real thing.
|
|
82
|
+
|
|
83
|
+
## The honesty guarantee
|
|
84
|
+
|
|
85
|
+
The whole tool rests on one rule, and it is what defeats the classic equivalent-mutant
|
|
86
|
+
problem:
|
|
87
|
+
|
|
88
|
+
> **It never infers a hole from a verdict flip. It infers a hole from
|
|
89
|
+
> `(output-proven-wrong AND grader-passed)`, where wrongness is established against the
|
|
90
|
+
> case's own ground truth — independently of the grader being tested.**
|
|
91
|
+
|
|
92
|
+
An operator applies to a case *only* where it can establish the mutant's polarity for
|
|
93
|
+
that case: provably wrong (a defect) or provably still-correct (an equivalent). Where it
|
|
94
|
+
can't — no number to corrupt, no answer span to truncate, a field the grader doesn't
|
|
95
|
+
judge — it returns **N/A** and is excluded from the score. So a reported hole is never a
|
|
96
|
+
guess about an ambiguous mutant; by construction the mutant had a known correct answer
|
|
97
|
+
and the grader disagreed with it.
|
|
98
|
+
|
|
99
|
+
When the bar that decides wrongness lives inside the grader's closure — a numeric
|
|
100
|
+
tolerance, an expected tool plan, whether whitespace is cosmetic for the task — the
|
|
101
|
+
operator does **not** guess it from a module default or trust a label the grader reports
|
|
102
|
+
about itself (a composite grader can honestly carry a primitive's id yet enforce more).
|
|
103
|
+
The suite *declares* that bar on the case (`num_tol`, `expected_trajectory`, `tolerates`,
|
|
104
|
+
`content_required`), and the operator uses it — cross-checking it against the grader where
|
|
105
|
+
it can — or declines. This is the discipline **eight rounds of adversarial cold-critique**
|
|
106
|
+
paid for: every false hole those passes found was an operator asserting polarity without
|
|
107
|
+
recomputing the graded property against the grader's *real* acceptance condition — a
|
|
108
|
+
hardcoded threshold, a self-reported id, a fixed-magnitude mutant that tripped an
|
|
109
|
+
orthogonal constraint, a formatting quirk that defeated a cross-check, a text
|
|
110
|
+
transformation the grader's own tokenizer re-read differently, a decline-gate one operator
|
|
111
|
+
carried and its siblings didn't. The early rounds fixed the bulk (a dozen at the peak);
|
|
112
|
+
by round six the tool-fault false positives on a well-formed suite reached **zero** and
|
|
113
|
+
held through rounds seven and eight, which surfaced only gate-symmetry issues that bite a
|
|
114
|
+
misdeclared case, never a well-formed one. The regression tests (`test_D1`–`D4`,
|
|
115
|
+
`test_P2A`–`P2K`, `test_P3F1`–`F8`, `test_P4_*`, `test_P5_*`, `test_P6_*`, `test_P7_*`) pin
|
|
116
|
+
every one. The through-line is a single invariant:
|
|
117
|
+
**an operator asserts a hole only where it can recompute the graded property against the
|
|
118
|
+
grader's real acceptance condition; everywhere else it declines.**
|
|
119
|
+
|
|
120
|
+
## Mined, not authored
|
|
121
|
+
|
|
122
|
+
Every operator names the concrete, documented failure it reproduces — and that citation
|
|
123
|
+
is enforced as a test (`test_every_operator_names_a_real_origin`). This is not
|
|
124
|
+
decoration. An *authored* mutation only tests what its author already imagined a check
|
|
125
|
+
might miss, which is exactly the blind spot you're trying to find. A *mined* operator
|
|
126
|
+
reproduces a defect that actually happened. `evalmut`'s operators come from a real
|
|
127
|
+
corpus: model-drift's 429/MNAR truncation finding, a property test that ran with
|
|
128
|
+
`tries=1`, a proof gate that grepped a transcript for a token, an assertion that read
|
|
129
|
+
`assertTrue(result || !result)`, and gradecore's own documented grader scoping.
|
|
130
|
+
|
|
131
|
+
```
|
|
132
|
+
$ evalmut operators # every one, with its provenance
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Install & use
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
pip install evalmut # from PyPI (or: pip install -e . from a clone)
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
from gradecore import GradeInput, contains
|
|
143
|
+
from evalmut import EvalCase, run
|
|
144
|
+
|
|
145
|
+
suite = [EvalCase("sum", contains("42"),
|
|
146
|
+
GradeInput(text="the total is 42", expected="42"),
|
|
147
|
+
tags=("presence_check",))]
|
|
148
|
+
|
|
149
|
+
report = run(suite)
|
|
150
|
+
print(f"{report.score:.0%} — {len(report.blind_spots)} blind spots")
|
|
151
|
+
for h in report.blind_spots:
|
|
152
|
+
print(h.grader_id, "is blind to", h.operator_id, "—", h.real_origin)
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Or from the shell, with a CI-worthy exit code (nonzero on any vacuous/blind/brittle hole):
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
evalmut run path/to/your_suite.py -v
|
|
159
|
+
evalmut run your_suite.py --short # one line for CI
|
|
160
|
+
evalmut run your_suite.py --json # machine-readable
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
A suite file just defines `suite` (a list of `EvalCase`) and, optionally, `operators`.
|
|
164
|
+
|
|
165
|
+
> **Security — evalmut executes your suite.** Loading a suite imports and runs it, and
|
|
166
|
+
> mutation runs invoke your grader code, so `evalmut run` executes arbitrary Python from
|
|
167
|
+
> the suite file (the same trust model as `pytest`). Only run suites you trust. If you wire
|
|
168
|
+
> it into CI as a PR gate, do **not** run it against forks/untrusted PRs, and give the job no
|
|
169
|
+
> secrets it doesn't need — a malicious suite file would otherwise run with your CI credentials.
|
|
170
|
+
> Prefer a sandboxed/isolated runner for untrusted input.
|
|
171
|
+
|
|
172
|
+
## Design
|
|
173
|
+
|
|
174
|
+
- `outcome.py` — the four outcomes (caught / missed / flagged / n-a), the two polarities,
|
|
175
|
+
the three operator types (KILL / DIAGNOSTIC / SANITY) that separate a *broken* check
|
|
176
|
+
from a *missing* one.
|
|
177
|
+
- `case.py` — an `EvalCase`: a grader, the reference-correct input it passes, which
|
|
178
|
+
fields it judges, and the declared contract bars (`num_tol`, `tolerates`,
|
|
179
|
+
`expected_trajectory`, `content_required`) an operator reads instead of guessing.
|
|
180
|
+
- `operator.py` / `operators.py` — the operator contract and the mined catalog.
|
|
181
|
+
- `runner.py` — baseline-green enforcement, apply, regrade, classify. Deterministic, no
|
|
182
|
+
LLM-as-judge, so a run reproduces exactly.
|
|
183
|
+
- `score.py` / `report.py` — the score, and the holes grouped by how alarming they are.
|
|
184
|
+
|
|
185
|
+
Built on [`gradecore`](../gradecore), the deterministic no-LLM-judge grading engine — so
|
|
186
|
+
`evalmut`'s own verdicts are as reproducible as the graders it tests.
|
evalmut-0.1.0/README.md
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# evalmut — mutation testing for evals
|
|
2
|
+
|
|
3
|
+
**Your eval suite passes. Does it actually check anything?**
|
|
4
|
+
|
|
5
|
+
You write a grader, watch it pass on a good output, and ship it. You never ask the
|
|
6
|
+
other question: would it *also* pass on a plausibly-broken output? A `contains("42")`
|
|
7
|
+
check passes `"the total is 42"` — and it passes `"I did NOT reach 42"` just as
|
|
8
|
+
happily. A JSON check that confirms a `count` field is present says nothing about
|
|
9
|
+
whether `count` is a number or the string `"three"`. A refusal check that scans for
|
|
10
|
+
"I can't help" is fooled by a reply that refuses in its first line and then delivers
|
|
11
|
+
the harm below. These aren't hypotheticals; each is a real defect that shipped past a
|
|
12
|
+
real check.
|
|
13
|
+
|
|
14
|
+
`evalmut` finds them. It takes an eval case your grader passes, injects a *known*
|
|
15
|
+
defect into the output — a defect **mined from a documented real-world eval failure**,
|
|
16
|
+
not invented — and reruns the grader. If the grader still passes a genuinely-wrong
|
|
17
|
+
output, that's a **hole**: a class of regression your eval would let ship green.
|
|
18
|
+
|
|
19
|
+
It's the same idea as code mutation testing (PIT, Stryker, mutmut), which nobody had
|
|
20
|
+
built for the model-plus-prompt-plus-grader stack — because there a "mutation" isn't a
|
|
21
|
+
flipped boolean, it's a semantic perturbation whose ground truth you have to establish.
|
|
22
|
+
That's the hard part, and it's what `evalmut` does.
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
$ evalmut run suite.py # your suite; see 'Install & use' below
|
|
26
|
+
────────────────────────────────────────────────────────────────────────
|
|
27
|
+
evalmut — does your eval actually check anything?
|
|
28
|
+
────────────────────────────────────────────────────────────────────────
|
|
29
|
+
mutation score 91.4% (32 caught / 35 applied; 150 n/a)
|
|
30
|
+
holes 3 (1 blind, 2 coverage-gap)
|
|
31
|
+
|
|
32
|
+
BLIND SPOTS — a real defect shipped green; the check is present and broken
|
|
33
|
+
• contains / contains
|
|
34
|
+
mutation : keyword_present_but_negated — the checked keyword appears,
|
|
35
|
+
but in a context that means the opposite
|
|
36
|
+
mined from: a CI proof-gate that greps its own transcript for a
|
|
37
|
+
token; the block message contains it, so mentioning it passes
|
|
38
|
+
COVERAGE GAPS — no check guards this shape (a missing grader, not a broken one)
|
|
39
|
+
• valid_json / valid_json
|
|
40
|
+
mutation : json_value_type_flip — a required field's value coerced to
|
|
41
|
+
the wrong type (number -> string)
|
|
42
|
+
• valid_json / valid_json
|
|
43
|
+
mutation : json_value_corruption — a required field's value changed to a
|
|
44
|
+
different value of the same type (3 -> 4)
|
|
45
|
+
mined from: gradecore valid_json checks key PRESENCE only, never value
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
That run is `evalmut` pointed at **its own dependency's** graders. It found three real
|
|
49
|
+
holes and — this is the point — it was **fair about them**: it called the `contains`
|
|
50
|
+
weakness a *blind spot* (a present check that's broken) and the two `valid_json` scopings
|
|
51
|
+
*coverage gaps* (a missing check, not a broken one), because `valid_json` only ever
|
|
52
|
+
claimed to check key presence. A tool that cries "broken!" at a correctly-scoped check
|
|
53
|
+
is a tool you learn to ignore.
|
|
54
|
+
|
|
55
|
+
## The two ways an eval lies
|
|
56
|
+
|
|
57
|
+
Most eval tooling only asks the first of these. Both are real, and `evalmut` tests both:
|
|
58
|
+
|
|
59
|
+
- **Blind spot** — a real defect ships green. Inject a *wrong* output; a sound grader
|
|
60
|
+
must reject it. If it passes, the check is present and broken.
|
|
61
|
+
- **Brittle spot** — a correct output gets flagged. Inject an *equivalent* change (a
|
|
62
|
+
trailing disclaimer after a complete answer, cosmetic whitespace, a JSON code fence);
|
|
63
|
+
a sound grader must still pass it. If it fails, the check false-positives, and a
|
|
64
|
+
false-positive check is quietly recalibrated until it stops catching the real thing.
|
|
65
|
+
|
|
66
|
+
## The honesty guarantee
|
|
67
|
+
|
|
68
|
+
The whole tool rests on one rule, and it is what defeats the classic equivalent-mutant
|
|
69
|
+
problem:
|
|
70
|
+
|
|
71
|
+
> **It never infers a hole from a verdict flip. It infers a hole from
|
|
72
|
+
> `(output-proven-wrong AND grader-passed)`, where wrongness is established against the
|
|
73
|
+
> case's own ground truth — independently of the grader being tested.**
|
|
74
|
+
|
|
75
|
+
An operator applies to a case *only* where it can establish the mutant's polarity for
|
|
76
|
+
that case: provably wrong (a defect) or provably still-correct (an equivalent). Where it
|
|
77
|
+
can't — no number to corrupt, no answer span to truncate, a field the grader doesn't
|
|
78
|
+
judge — it returns **N/A** and is excluded from the score. So a reported hole is never a
|
|
79
|
+
guess about an ambiguous mutant; by construction the mutant had a known correct answer
|
|
80
|
+
and the grader disagreed with it.
|
|
81
|
+
|
|
82
|
+
When the bar that decides wrongness lives inside the grader's closure — a numeric
|
|
83
|
+
tolerance, an expected tool plan, whether whitespace is cosmetic for the task — the
|
|
84
|
+
operator does **not** guess it from a module default or trust a label the grader reports
|
|
85
|
+
about itself (a composite grader can honestly carry a primitive's id yet enforce more).
|
|
86
|
+
The suite *declares* that bar on the case (`num_tol`, `expected_trajectory`, `tolerates`,
|
|
87
|
+
`content_required`), and the operator uses it — cross-checking it against the grader where
|
|
88
|
+
it can — or declines. This is the discipline **eight rounds of adversarial cold-critique**
|
|
89
|
+
paid for: every false hole those passes found was an operator asserting polarity without
|
|
90
|
+
recomputing the graded property against the grader's *real* acceptance condition — a
|
|
91
|
+
hardcoded threshold, a self-reported id, a fixed-magnitude mutant that tripped an
|
|
92
|
+
orthogonal constraint, a formatting quirk that defeated a cross-check, a text
|
|
93
|
+
transformation the grader's own tokenizer re-read differently, a decline-gate one operator
|
|
94
|
+
carried and its siblings didn't. The early rounds fixed the bulk (a dozen at the peak);
|
|
95
|
+
by round six the tool-fault false positives on a well-formed suite reached **zero** and
|
|
96
|
+
held through rounds seven and eight, which surfaced only gate-symmetry issues that bite a
|
|
97
|
+
misdeclared case, never a well-formed one. The regression tests (`test_D1`–`D4`,
|
|
98
|
+
`test_P2A`–`P2K`, `test_P3F1`–`F8`, `test_P4_*`, `test_P5_*`, `test_P6_*`, `test_P7_*`) pin
|
|
99
|
+
every one. The through-line is a single invariant:
|
|
100
|
+
**an operator asserts a hole only where it can recompute the graded property against the
|
|
101
|
+
grader's real acceptance condition; everywhere else it declines.**
|
|
102
|
+
|
|
103
|
+
## Mined, not authored
|
|
104
|
+
|
|
105
|
+
Every operator names the concrete, documented failure it reproduces — and that citation
|
|
106
|
+
is enforced as a test (`test_every_operator_names_a_real_origin`). This is not
|
|
107
|
+
decoration. An *authored* mutation only tests what its author already imagined a check
|
|
108
|
+
might miss, which is exactly the blind spot you're trying to find. A *mined* operator
|
|
109
|
+
reproduces a defect that actually happened. `evalmut`'s operators come from a real
|
|
110
|
+
corpus: model-drift's 429/MNAR truncation finding, a property test that ran with
|
|
111
|
+
`tries=1`, a proof gate that grepped a transcript for a token, an assertion that read
|
|
112
|
+
`assertTrue(result || !result)`, and gradecore's own documented grader scoping.
|
|
113
|
+
|
|
114
|
+
```
|
|
115
|
+
$ evalmut operators # every one, with its provenance
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Install & use
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
pip install evalmut # from PyPI (or: pip install -e . from a clone)
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
from gradecore import GradeInput, contains
|
|
126
|
+
from evalmut import EvalCase, run
|
|
127
|
+
|
|
128
|
+
suite = [EvalCase("sum", contains("42"),
|
|
129
|
+
GradeInput(text="the total is 42", expected="42"),
|
|
130
|
+
tags=("presence_check",))]
|
|
131
|
+
|
|
132
|
+
report = run(suite)
|
|
133
|
+
print(f"{report.score:.0%} — {len(report.blind_spots)} blind spots")
|
|
134
|
+
for h in report.blind_spots:
|
|
135
|
+
print(h.grader_id, "is blind to", h.operator_id, "—", h.real_origin)
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Or from the shell, with a CI-worthy exit code (nonzero on any vacuous/blind/brittle hole):
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
evalmut run path/to/your_suite.py -v
|
|
142
|
+
evalmut run your_suite.py --short # one line for CI
|
|
143
|
+
evalmut run your_suite.py --json # machine-readable
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
A suite file just defines `suite` (a list of `EvalCase`) and, optionally, `operators`.
|
|
147
|
+
|
|
148
|
+
> **Security — evalmut executes your suite.** Loading a suite imports and runs it, and
|
|
149
|
+
> mutation runs invoke your grader code, so `evalmut run` executes arbitrary Python from
|
|
150
|
+
> the suite file (the same trust model as `pytest`). Only run suites you trust. If you wire
|
|
151
|
+
> it into CI as a PR gate, do **not** run it against forks/untrusted PRs, and give the job no
|
|
152
|
+
> secrets it doesn't need — a malicious suite file would otherwise run with your CI credentials.
|
|
153
|
+
> Prefer a sandboxed/isolated runner for untrusted input.
|
|
154
|
+
|
|
155
|
+
## Design
|
|
156
|
+
|
|
157
|
+
- `outcome.py` — the four outcomes (caught / missed / flagged / n-a), the two polarities,
|
|
158
|
+
the three operator types (KILL / DIAGNOSTIC / SANITY) that separate a *broken* check
|
|
159
|
+
from a *missing* one.
|
|
160
|
+
- `case.py` — an `EvalCase`: a grader, the reference-correct input it passes, which
|
|
161
|
+
fields it judges, and the declared contract bars (`num_tol`, `tolerates`,
|
|
162
|
+
`expected_trajectory`, `content_required`) an operator reads instead of guessing.
|
|
163
|
+
- `operator.py` / `operators.py` — the operator contract and the mined catalog.
|
|
164
|
+
- `runner.py` — baseline-green enforcement, apply, regrade, classify. Deterministic, no
|
|
165
|
+
LLM-as-judge, so a run reproduces exactly.
|
|
166
|
+
- `score.py` / `report.py` — the score, and the holes grouped by how alarming they are.
|
|
167
|
+
|
|
168
|
+
Built on [`gradecore`](../gradecore), the deterministic no-LLM-judge grading engine — so
|
|
169
|
+
`evalmut`'s own verdicts are as reproducible as the graders it tests.
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"""evalmut — mutation testing for evals.
|
|
2
|
+
|
|
3
|
+
Your eval suite passes. Does it actually check anything? evalmut injects known
|
|
4
|
+
defects into the system-under-test's output — mutations mined from real, documented
|
|
5
|
+
eval failures — and reruns the graders that were supposed to be watching. A mutation
|
|
6
|
+
the grader catches is a check doing its job. A mutation that survives is a hole: a
|
|
7
|
+
class of defect that would ship green (a blind spot) or a class of correct output the
|
|
8
|
+
check breaks on (a brittle spot). Every operator names the real failure it reproduces.
|
|
9
|
+
|
|
10
|
+
from evalmut import EvalCase, run, catalog
|
|
11
|
+
from gradecore import GradeInput, contains
|
|
12
|
+
|
|
13
|
+
suite = [EvalCase("adds", contains("42"), GradeInput(text="the answer is 42"),
|
|
14
|
+
intent="reply must contain the sum")]
|
|
15
|
+
report = run(suite)
|
|
16
|
+
print(report.score, "-", len(report.holes), "holes")
|
|
17
|
+
for h in report.blind_spots:
|
|
18
|
+
print(h.grader_id, "is blind to", h.real_origin)
|
|
19
|
+
"""
|
|
20
|
+
from __future__ import annotations
|
|
21
|
+
|
|
22
|
+
from typing import Optional, Sequence
|
|
23
|
+
|
|
24
|
+
from .case import EvalCase, case
|
|
25
|
+
from .operator import MutationOperator, applies_to_tag, operator, with_text
|
|
26
|
+
from .operators import CORE_OPERATORS, catalog
|
|
27
|
+
from .outcome import OperatorType, Outcome, Polarity, outcome_for
|
|
28
|
+
from .report import render, render_short
|
|
29
|
+
from .runner import BaselineError, MutationResult, run_case, run_suite
|
|
30
|
+
from .score import Report, Tally, score
|
|
31
|
+
|
|
32
|
+
__version__ = "0.1.0"
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def run(suite: Sequence[EvalCase],
|
|
36
|
+
operators: Optional[Sequence[MutationOperator]] = None) -> Report:
|
|
37
|
+
"""The one-call entry point: run the (default or given) operators over the suite
|
|
38
|
+
and return a scored report. Baseline failures are attached to the report so a
|
|
39
|
+
mis-specified case is loud, not silent."""
|
|
40
|
+
import dataclasses
|
|
41
|
+
ops = tuple(operators) if operators is not None else catalog()
|
|
42
|
+
results, baseline_failures = run_suite(suite, ops)
|
|
43
|
+
report = score(results)
|
|
44
|
+
if baseline_failures:
|
|
45
|
+
report = dataclasses.replace(report, baseline_failures=tuple(baseline_failures))
|
|
46
|
+
return report
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
__all__ = [
|
|
50
|
+
"EvalCase", "case", "run", "run_case", "run_suite",
|
|
51
|
+
"MutationOperator", "operator", "applies_to_tag", "with_text",
|
|
52
|
+
"CORE_OPERATORS", "catalog",
|
|
53
|
+
"Outcome", "Polarity", "OperatorType", "outcome_for",
|
|
54
|
+
"Report", "Tally", "score", "MutationResult", "BaselineError",
|
|
55
|
+
"render", "render_short",
|
|
56
|
+
]
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"""An eval case: a grader and a reference-correct output it passes.
|
|
2
|
+
|
|
3
|
+
This is the unit a mutation is applied to. The crucial field is `good`: a
|
|
4
|
+
GradeInput the grader is known to PASS. Mutation testing needs a green baseline
|
|
5
|
+
for the same reason code mutation testing does — you cannot ask "would this check
|
|
6
|
+
catch a defect I introduce?" if the check is already failing on the clean input.
|
|
7
|
+
The runner refuses to score a case whose baseline is red and tells you which, so a
|
|
8
|
+
mis-specified reference is a loud error rather than a silently skipped one.
|
|
9
|
+
|
|
10
|
+
`good` is also the ground truth every operator reasons against. Because the grader
|
|
11
|
+
passes it, `good` is by definition a correct output for this task; an operator that
|
|
12
|
+
transforms `good` into something wrong has, relative to this reference, injected a
|
|
13
|
+
real defect — no separate oracle required.
|
|
14
|
+
|
|
15
|
+
Some operators need to know a bar that lives inside the grader's closure and is
|
|
16
|
+
invisible from the outside — a numeric tolerance, a grounding threshold, which
|
|
17
|
+
cosmetic changes this task's contract treats as still-correct, the expected tool
|
|
18
|
+
plan. The honest answer is never to guess it (guessing a module default, or trusting
|
|
19
|
+
a grader-emitted id label, is exactly what manufactured evalmut's own false findings
|
|
20
|
+
in cold-critic pass 2). Instead the suite author DECLARES it here, and the operator
|
|
21
|
+
either uses the declared bar or declines. Every such field defaults to the value that
|
|
22
|
+
makes the dependent operator DECLINE, so an undecorated case can only ever be
|
|
23
|
+
under-tested, never falsely accused.
|
|
24
|
+
"""
|
|
25
|
+
from __future__ import annotations
|
|
26
|
+
|
|
27
|
+
from dataclasses import dataclass, field
|
|
28
|
+
|
|
29
|
+
from gradecore import GradeInput, Grader
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@dataclass(frozen=True)
|
|
33
|
+
class EvalCase:
|
|
34
|
+
name: str
|
|
35
|
+
grader: Grader
|
|
36
|
+
good: GradeInput
|
|
37
|
+
# Which GradeInput fields the grader actually judges. A mutation is only a defect
|
|
38
|
+
# relative to what the task grades: blanking `text` is a real defect for "answer the
|
|
39
|
+
# question" but not for "did the agent avoid a denylisted tool", where the text is
|
|
40
|
+
# incidental and the grader rightly ignores it. Defaulting to ("text",) covers the
|
|
41
|
+
# overwhelming majority (scalar/text/safety graders); a tool or retrieval case names
|
|
42
|
+
# its own fields so text operators don't fire on it and manufacture false findings.
|
|
43
|
+
judges: tuple[str, ...] = ("text",)
|
|
44
|
+
|
|
45
|
+
# ── declared contract bars (each defaults to "operator declines") ────────────
|
|
46
|
+
# The numeric acceptance band the grader uses, if this is a numeric-answer task. A
|
|
47
|
+
# near-miss is a defect only if it falls OUTSIDE the tolerance — and that band lives in
|
|
48
|
+
# the grader's closure, invisible to an operator. Declaring it lets the numeric operator
|
|
49
|
+
# perturb to just past the band; it also cross-checks the declaration against the grader
|
|
50
|
+
# before trusting it. Left None, the numeric operator declines.
|
|
51
|
+
num_tol: float | None = None
|
|
52
|
+
# This task's grader is supposed to require CONTENT in the answer (an exact/contains/
|
|
53
|
+
# number/JSON-style check), so a blank or unrelated output is a provable defect and the
|
|
54
|
+
# SANITY probes may fire. For gradecore's content graders this is inferred from grader_id;
|
|
55
|
+
# a custom grader must opt in, because a blank output is legitimately fine for an ABSENCE
|
|
56
|
+
# grader (injection_resistance, tool_misuse) and calling that vacuous is false (pass-2 C).
|
|
57
|
+
content_required: bool = False
|
|
58
|
+
# The cosmetic changes THIS task's contract treats as still-correct — any of
|
|
59
|
+
# "whitespace", "fence", "disclaimer". An EQUIVALENT operator claims "still correct" only
|
|
60
|
+
# when the change is declared here, because equivalence is a property of the task's
|
|
61
|
+
# contract, not something readable from a grader-emitted id: a composite grader can
|
|
62
|
+
# honestly carry a primitive's id yet also enforce length or format, so a fence or added
|
|
63
|
+
# whitespace legitimately fails it (cold-critic pass-2 B). Declared here, the equivalence
|
|
64
|
+
# claim rests on the author, not on a label the grader controls. Undeclared -> decline.
|
|
65
|
+
tolerates: tuple[str, ...] = ()
|
|
66
|
+
# The expected ordered tool plan, for a trajectory case. trajectory_drop_step proves a
|
|
67
|
+
# defect only by dropping a step whose removal pushes LCS coverage below the threshold —
|
|
68
|
+
# which requires knowing the plan (it lives in the grader closure). Left empty, the
|
|
69
|
+
# operator declines rather than blindly dropping the last call (cold-critic pass-2 E).
|
|
70
|
+
expected_trajectory: tuple[str, ...] = ()
|
|
71
|
+
# The trajectory coverage threshold the grader enforces (gradecore's default is 1.0, but a
|
|
72
|
+
# lenient grader may accept partial coverage). Defaults to None = DECLINE: 1.0 is the STRICTEST
|
|
73
|
+
# bar, not a safe default — trusting it flags a lenient grader that correctly accepts a partial
|
|
74
|
+
# trajectory as a blind spot (cold-critic pass-3 F3). Declare it (with expected_trajectory) to
|
|
75
|
+
# let trajectory_drop_step fire.
|
|
76
|
+
trajectory_threshold: float | None = None
|
|
77
|
+
|
|
78
|
+
# The gradecore CONTRACT FAMILY this grader behaves like, when the grader is external and does
|
|
79
|
+
# not carry a gradecore grader_id (e.g. a promptfoo `is-json` port). Operators gate some
|
|
80
|
+
# behavior on the grader's contract family; for an in-house gradecore grader that family is read
|
|
81
|
+
# from its own grader_id, but an external grader must DECLARE it here (e.g. "valid_json",
|
|
82
|
+
# "number", "grounding", "contains", "injection_resistance"). Declared, it lets evalmut run
|
|
83
|
+
# against a framework's graders unmodified while the grader keeps reporting its own honest id.
|
|
84
|
+
grader_family: str | None = None
|
|
85
|
+
# Optional human-readable notes surfaced in reports; never load-bearing.
|
|
86
|
+
intent: str = ""
|
|
87
|
+
tags: tuple[str, ...] = field(default_factory=tuple)
|
|
88
|
+
|
|
89
|
+
def baseline(self):
|
|
90
|
+
"""The grader's verdict on the clean reference. Must pass, or the case is
|
|
91
|
+
mis-specified and the runner will refuse to mutate it."""
|
|
92
|
+
return self.grader(self.good)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def case(name: str, grader: Grader, good: GradeInput, *, judges: tuple[str, ...] = ("text",),
|
|
96
|
+
num_tol: float | None = None, content_required: bool = False,
|
|
97
|
+
tolerates: tuple[str, ...] = (), expected_trajectory: tuple[str, ...] = (),
|
|
98
|
+
trajectory_threshold: float | None = None, grader_family: str | None = None,
|
|
99
|
+
intent: str = "", tags: tuple[str, ...] = ()) -> EvalCase:
|
|
100
|
+
"""Terse constructor for suites written as data."""
|
|
101
|
+
return EvalCase(name=name, grader=grader, good=good, judges=judges,
|
|
102
|
+
num_tol=num_tol, content_required=content_required, tolerates=tolerates,
|
|
103
|
+
expected_trajectory=expected_trajectory,
|
|
104
|
+
trajectory_threshold=trajectory_threshold, grader_family=grader_family,
|
|
105
|
+
intent=intent, tags=tags)
|