Skip to content

Commit 63df86e

Browse files
authored
Improve test quality grading with pseudo-mutation analysis (#10151)
Copilot-Session: 5bb645ad-728c-4491-9c7a-a3afdd0c65f3
1 parent 8f966fc commit 63df86e

4 files changed

Lines changed: 179 additions & 66 deletions

File tree

‎.agents/skills/grade-tests/SKILL.md‎

Lines changed: 114 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ name: grade-tests
33
description: >
44
Grades a specified set of test methods individually and produces a concise
55
table mapping each test (fully-qualified name) to a letter grade (A–F), a
6-
score band, and a one-line note — designed to be posted as a PR comment.
6+
score band, pseudo-mutation resilience, a one-line note, and a concrete
7+
improvement for every grade below A — designed to be posted as a PR comment.
78
Use when the caller wants per-test feedback on a curated list of methods
89
(for example, the new or modified tests in a pull request), not a
910
suite-wide audit. Polyglot: .NET (MSTest/xUnit/NUnit/TUnit), Python
@@ -21,10 +22,11 @@ license: MIT
2122
# Grade Tests
2223

2324
Grade a curated list of test methods and produce a compact, PR-comment-friendly
24-
report: one row per test method with a letter grade, a score band, and a
25-
one-line note explaining the grade. The skill **does not discover tests on its
26-
own** — the caller (typically a PR automation workflow or a human reviewer
27-
holding a specific list) provides the test methods to grade.
25+
report: one row per test method with a letter grade, a score band,
26+
pseudo-mutation resilience, a one-line note explaining the grade, and a
27+
concrete improvement for every grade below A. The skill **does not discover
28+
tests on its own** — the caller (typically a PR automation workflow or a human
29+
reviewer holding a specific list) provides the test methods to grade.
2830

2931
> **Language-specific guidance**: Call the `test-analysis-extensions` skill
3032
> to discover available extension files, then read the file matching the
@@ -71,7 +73,7 @@ that question with a one-row-per-test verdict that fits in a comment table.
7173
|-------|----------|-------------|
7274
| Test methods | Yes | A scope to grade. Provide one of: (a) an explicit list of test method names (fully-qualified, e.g. `Namespace.ClassName.TestMethodName`); (b) one or more file paths plus an explicit instruction to grade every test declared in those files; or (c) a diff hunk / PR identifier whose changed tests should be graded. File paths are recommended but optional when method names are unambiguous in the workspace. Ambiguous requests like *"grade my tests"* with no scope are rejected up-front (see Step 0); this skill is for curated input and does not auto-grade an entire workspace. |
7375
| Test bodies / spans | Recommended | The exact source lines for each test method. If omitted, read them from the listed files. |
74-
| Production code | No | The code under test, for judging whether assertions cover the meaningful behaviors. When unavailable, mark relevant findings as "Unverified" rather than guessing. |
76+
| Production code | Recommended | The code under test, used to judge meaningful assertions and perform pseudo-mutation analysis. Resolve it from the workspace when possible. When unavailable, render mutation resilience as `N/A`, explain that production code was unavailable in Notes, exclude that sub-grade from the weighted score, and do not guess. |
7577
| Diff context | No | When grading PR changes, the unified diff for each test method helps focus on what actually changed. |
7678

7779
### Step 0: Validate the input
@@ -113,6 +115,12 @@ For each entry in the input list:
113115
/ decorators / fixtures and any helper code that the test calls.
114116
3. If a method cannot be found, record it as `N/A — method not found` and
115117
continue. Never invent a body to grade.
118+
4. Trace the production entry point called by the test, including every helper
119+
and branch relevant to the behavior claimed by the test, even when its
120+
current input does not reach that branch. If the production code is not
121+
supplied, resolve it from the workspace using symbol references and call
122+
sites. Record production code as unavailable only after a reasonable lookup
123+
fails.
116124

117125
### Step 3: Score each test
118126

@@ -122,9 +130,10 @@ for hypothetical concerns (e.g., "could have more negative assertions")
122130
unless the production code clearly demands them and the production code is
123131
available.
124132

125-
#### Three sub-dimensions
133+
#### Four sub-dimensions
126134

127-
Compute three sub-grades (each A–F) that together drive the overall grade.
135+
Compute four sub-grades (each A–F) that together drive the overall grade.
136+
Pseudo-mutation may be `N/A` only when the production code cannot be resolved.
128137

129138
##### A. Assertion strength
130139

@@ -191,6 +200,9 @@ Examples (Critical/High and Medium counts → Anti-pattern sub-grade):
191200
- Always-true literal assertions (`Assert.IsTrue(true)`, `assert True`,
192201
`expect(true).toBe(true)`) → **F** (verifies nothing; also drives
193202
Assertion sub-grade to F)
203+
- All async assertions are neither awaited nor returned (for example,
204+
an `Assert.ThrowsAsync` task or `expect(promise).resolves` chain whose result
205+
is silently discarded) → F
194206
- Self-referential / tautological assertions on bound values
195207
(`Assert.AreEqual(x, x)`, `assert dto.name == dto.name`) → D
196208
- Commented-out assertions → D
@@ -234,58 +246,124 @@ Examples (Critical/High and Medium counts → Anti-pattern sub-grade):
234246
`dbg!`, `Write-Host`, `std::cout`); inconsistent naming versus siblings;
235247
leftover TODO comments. Mention in the note column but do not deduct.
236248

249+
##### D. Pseudo-mutation resilience
250+
251+
Evaluate whether **this individual test** would detect plausible defects in
252+
the production behavior it claims to verify. Do not give a test credit because
253+
another test kills the mutation.
254+
255+
Call the `test-gap-analysis` skill to load its canonical mutation catalog and
256+
calibration rules, then apply them at this skill's per-test scope:
257+
258+
1. Identify meaningful mutation points on every production path relevant to
259+
the behavior claimed by the test, including paths its current input does
260+
not exercise:
261+
- boundary changes (`<` ↔ `<=`, index or loop off-by-one);
262+
- Boolean and logic flips (`&&` ↔ `||`, negated conditions);
263+
- changed return values (`null`/`None`/`nil`, empty, zero, opposite Boolean);
264+
- removed exceptions, guards, or error propagation;
265+
- arithmetic changes (`+` ↔ `-`, sign or increment flips);
266+
- removed null/None/nil checks or coalescing.
267+
2. Classify each point against this test:
268+
- **Killed** — this test's inputs reach the point and its assertions would fail.
269+
- **Survived** — this test reaches the point but its assertions would still pass.
270+
- **No coverage** — the mutation is part of the behavior named by this test,
271+
but the test's inputs do not reach it.
272+
- **Equivalent** — the mutation cannot change observable behavior; exclude it.
273+
3. Judge only the behavior promised by the test name and setup. Do not penalize
274+
a focused test for unrelated branches that belong in separate tests.
275+
4. Skip trivial code such as simple getters, auto-properties, generated code,
276+
and boilerplate. Prefer risk-significant logic over mutation count.
277+
278+
Score the non-equivalent mutation points:
279+
280+
| Sub-grade | Pattern |
281+
|-----------|---------|
282+
| **A** | All meaningful mutation points for the claimed behavior are killed, or the claimed behavior contains no meaningful mutation point. |
283+
| **B** | The primary contract is protected; only one low-risk mutation survives. |
284+
| **C** | The central outcome is protected, but one or more meaningful secondary mutations survive or lack coverage. |
285+
| **D** | A high-risk mutation in the claimed behavior survives or lacks coverage, such as a boundary flip, removed validation, or wrong calculation. |
286+
| **F** | At least one meaningful mutation point exists, and the test would kill none of them. |
287+
| **N/A** | Production code cannot be resolved. Report as unverified and do not deduct. |
288+
289+
For the report, render mutation resilience as `killed/total killed` (for
290+
example, `3/4 killed`), `0/0 (no meaningful points)`, or `N/A`. Exclude
291+
Equivalent mutations from the total.
292+
237293
#### Combining sub-grades
238294

239295
Convert sub-grades to numeric points: A=4, B=3, C=2, D=1, F=0.
240296
- **Overall score band** = weighted average:
241-
`0.45 × Assertion + 0.30 × Anti-pattern + 0.25 × Structure`
297+
`0.35 × Assertion + 0.30 × Pseudo-mutation + 0.20 × Anti-pattern + 0.15 × Structure`
298+
- If Pseudo-mutation is `N/A`, omit it and renormalize the remaining weights
299+
to total 1. Do not lower a grade because production context is unavailable.
242300
- Map to letter:
243301
- ≥ 3.5 → **A** (band 90–100)
244302
- ≥ 2.8 → **B** (band 80–89)
245303
- ≥ 2.0 → **C** (band 70–79)
246304
- ≥ 1.2 → **D** (band 60–69)
247305
- < 1.2 → **F** (band 0–59)
248-
- The overall grade is **capped at the worst sub-grade** — if any sub-grade
249-
is **F**, the overall grade is **F**; if the worst sub-grade is **D**,
250-
the overall grade is at most **D**; and so on. A test that fails on any
251-
one dimension cannot earn a higher overall grade than that dimension.
306+
- Apply an overall ceiling only when the Anti-pattern catalog classifies an
307+
observed finding as **Critical**: a Critical finding labeled F forces the
308+
overall grade to F, and one labeled D caps it at D. Do not otherwise cap the
309+
weighted result at the worst sub-grade; the weights must remain meaningful.
252310

253311
Report the **letter grade** and the **score band** (not a single 0–100
254312
number). False precision invites bikeshedding; bands keep the conversation
255313
focused on the rubric.
256314

257-
### Step 4: Build the note
315+
### Step 4: Build the note and improvement
258316

259317
The note column is one short sentence (target ≤ 120 characters). State the
260318
single most important reason for the grade. Examples:
261319

262320
- A (90–100): `Clear AAA structure; equality + exception assertions on the public contract.`
263-
- B (80–89): `Good assertion variety, mildly long body — consider splitting into per-condition tests.`
321+
- B (80–89): `Primary contract is protected, but the upper-bound mutation survives.`
264322
- C (70–79): `Only checks IsNotNull on the result; no value verification.`
265323
- D (60–69): `Self-referential assertion: round-trip identity verifies plumbing, not transformation.`
266324
- F (0–59): `No assertions — test executes the method but never verifies anything.`
267325

268326
If a test gets A with no notable issues, the note may simply be
269327
`No issues found.` — do not invent weaknesses to justify the grade.
270328

329+
For every test below A, add a **How to improve** sentence (target ≤ 120
330+
characters) describing the smallest concrete change that addresses the
331+
grade-limiting issue:
332+
333+
- Name the assertion to add or strengthen and the observable value to check.
334+
- For a survived mutation, give the input and expected outcome that would kill
335+
it, such as `Add max+1 input and assert ArgumentOutOfRangeException.`
336+
- For structure or hygiene findings, name the specific extraction, split, or
337+
deterministic replacement to make.
338+
- Do not use vague advice such as `Add more assertions`, `Improve coverage`,
339+
or `Write better tests`.
340+
- Do not recommend unrelated scenarios merely to make a focused test broader.
341+
- For A-grade tests, render `—`; no improvement is required.
342+
271343
### Step 5: Report
272344

273345
Produce two sections.
274346

275347
#### 1. Summary
276348

277349
A short paragraph (2–4 sentences) covering: total tests graded, grade
278-
distribution, most common issue, and the single most important
279-
recommendation.
350+
distribution, the most common issue, and the single highest-leverage
351+
recommendation. Include the most important survived or uncovered mutation
352+
only when one exists. Otherwise state the applicable result without inventing
353+
a gap: all meaningful mutations were killed, no meaningful mutation points
354+
were found (`0/0`), or production code could not be resolved (`N/A`). In the
355+
latter two cases, lead with the dominant assertion, hygiene, or structure
356+
signal.
280357

281358
#### 2. Per-test table
282359

283360
```markdown
284-
| Test | Grade | Band | Notes |
285-
|------|-------|------|-------|
286-
| `Namespace.ClassName.Test_Method_Condition_Expected` | A | 90–100 | Clear AAA; equality + exception assertions. |
287-
| `Namespace.ClassName.Test_Other` | C | 70–79 | Only `IsNotNull` — no value verification. |
288-
| `Namespace.ClassName.Test_Old` | F | 0–59 | No assertions. |
361+
| Test | Grade | Band | Mutation | Notes | How to improve |
362+
|------|-------|------|----------|-------|----------------|
363+
| `Namespace.ClassName.Test_Method_Condition_Expected` | A | 90–100 | 4/4 killed | Clear AAA; assertions protect the public contract. | — |
364+
| `Namespace.ClassName.Test_UpperBound` | B | 80–89 | 2/3 killed | The inclusive upper-bound mutation survives. | Add `max + 1` input and assert rejection. |
365+
| `Namespace.ClassName.Test_Other` | C | 70–79 | 1/3 killed | Only `IsNotNull`; default-return mutations survive. | Assert the expected value and collection contents. |
366+
| `Namespace.ClassName.Test_Old` | F | 0–59 | 0/2 killed | No assertions; every mutation survives. | Assert the exact result produced by the arranged input. |
289367
```
290368

291369
**Caps and ordering**:
@@ -306,6 +384,14 @@ prefix each section with the language name and framework.
306384
`N/A — method not found`).
307385
- [ ] Every grade is justified by at least one observable signal in the
308386
captured body — no speculative deductions.
387+
- [ ] Production code was resolved where possible; unavailable code is
388+
reported as mutation `N/A` and omitted from scoring.
389+
- [ ] Every meaningful mutation point in the behavior claimed by each test is
390+
classified Killed / Survived / No coverage / Equivalent.
391+
- [ ] Equivalent mutations and unrelated production branches do not affect
392+
the mutation sub-grade.
393+
- [ ] Mutation resilience is evaluated per test; a mutation killed only by a
394+
different test does not receive credit.
309395
- [ ] Trivial-assertion tests are flagged only when the **only** assertion
310396
is trivial (a null check before a meaningful assertion is not trivial).
311397
- [ ] Exception-only tests are not penalized for low assertion count.
@@ -320,6 +406,8 @@ prefix each section with the language name and framework.
320406
JS/TS `expect(mock).toHaveBeenCalledWith(...)`.
321407
- [ ] Async test pitfalls (un-awaited `resolves`/`rejects`/`ThrowsAsync`,
322408
pytest-asyncio without `await`) drop the Assertion sub-grade to F.
409+
- [ ] Every test below A has one concrete, grade-targeted improvement; every
410+
A test uses `—`.
323411
- [ ] The summary leads with the highest-leverage observation, not a recap
324412
of the table.
325413

@@ -335,6 +423,10 @@ prefix each section with the language name and framework.
335423
| Flagging Go/Rust table-driven loops as conditional logic | They are idiomatic; do not deduct. |
336424
| Treating pytest bare `assert` or Go `if got != want { t.Error… }` as missing-framework | Both are canonical; count in the correct assertion category. |
337425
| Penalizing tests when production code is unavailable | Mark concerns about uncovered behaviors as `Unverified` and do not deduct. |
426+
| Giving mutation credit from another test | Evaluate whether the current test independently kills each relevant mutation. |
427+
| Penalizing a focused test for unrelated branches | Analyze only mutation points in the behavior promised by the test name and setup. |
428+
| Treating equivalent or trivial mutations as gaps | Exclude equivalent mutations, getters, generated code, and boilerplate. |
429+
| Giving vague improvement advice | Name the exact input, assertion, expected value, split, or deterministic replacement needed. |
338430
| Using a fake-precise score (e.g., 87/100) | Use the score band only — 90–100, 80–89, 70–79, 60–69, 0–59. |
339431
| Spilling a 500-row table into a PR comment | Apply the row cap from Step 5; collapse extras into `<details>`. |
340432
| Re-reporting an existing finding three times under different categories | Pick the most fitting category and report once. |

0 commit comments

Comments
 (0)