Skip to content
13 changes: 8 additions & 5 deletions .agents/skills/test-health-push/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ Call it `EPIC` below: `origin/epic/<epic number>-test-health`.
TH shards --profile push --base EPIC --count <workers x 2> --tag e<epic number> --out <shard dir>
```

Each shard is a list of files inside one package, weighted by cost, so every
package with work gets at least one and the count is a target. Shards are
Each shard is a list of files inside one group, weighted by cost, so every
group with work gets at least one and the count is a target. A group is a large
package, or `small`: the packages with few test files share shards and batches
rather than each opening a pull request of its own. Shards are
disjoint by construction, and the ledger's claims keep two workers on one shard
from colliding.

Expand All @@ -70,8 +72,8 @@ own worktree. A worker's whole brief is:

Do not give a worker any audit guidance of your own. The `push` profile in
`scripts/test-health/config.json` already changes what scale requires: no file
budget per run, longer claims, and a batch that is ripe only when its shard is
exhausted.
budget per run, longer claims, and a batch that is ripe only when its group
has nothing left to audit.

When a worker finishes, start the next shard. A worker that stops early leaves
its claims to expire; start its shard again and the new worker continues the
Expand Down Expand Up @@ -144,7 +146,8 @@ squashes.
runs get; say so, and do not claim more.
- Close the epic when its pull request has merged and main's own run is green.
The recurring run continues from the ledger: everything audited here is
already marked, so it picks up only new, changed and dropped files.
already marked, so it picks up only new, changed, dropped and unfinished
files.

## When to stop early

Expand Down
51 changes: 39 additions & 12 deletions .agents/skills/test-health/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ description: Audit a batch of brain-kit's automated tests in depth and fix the w
# Keep the tests healthy

One invocation is **one run**. A run audits a few clusters of related tests
inside one package, commits each proven fix to that package's batch branch,
lands the batch when it is ripe, and records what it did. Coverage of the whole
inside one group, commits each proven fix to that group's batch branch, lands
the batch when it is ripe, and records what it did. A group is a package of its
own, or `small`: the packages with few test files, which share one batch. A
cluster always stays inside one package. Coverage of the whole
suite comes from running this again and again: the planner picks different
files every time and reaches all of them eventually.

Expand Down Expand Up @@ -45,7 +47,7 @@ start: a run reads a great deal, and most of it can be avoided.
- `capabilities.browserRunner: false`: add `--bun-only` to `plan`.
- `capabilities.mayLand: false`: audit, but skip step 6.
2. **Plan.** `TH plan`. It claims the files it gives you. Note `runId`,
`runDir`, `package`, `batch` and `clusters`.
`runDir`, `group`, `batch` and `clusters`, each with its `package`.
- `throttled` is set: too much is waiting to land. Go to step 6, then record
the run with `--outcome throttled`.
- `clusters` is empty: go to step 6, then record `--outcome nothing-to-do`.
Expand All @@ -69,6 +71,21 @@ start: a run reads a great deal, and most of it can be avoided.
budget you were given is spent (45 minutes if none was given). A cluster you
did not finish is simply not recorded; its claim expires.

**Proof outlasts the budget.** A fix you have already written is proven even
when that runs past the budget, by up to `proofOverrunMinutes` in
`scripts/test-health/config.json`, before you take any new cluster. When a
brief lists findings deferred by an earlier audit, resume them first: apply
the prepared patch it names (`git apply <patch>`) and run its proof before
anything else in that cluster. If the proof still cannot finish, keep the
fix for the next run instead of losing it:

```sh
git diff -- <files> > <runDir>/wip-<n>.patch && git checkout -- <files>
```

defer the finding with `deferredFor: "proof"`, and pass
`--wip <runDir>/wip-<n>.patch` to `record cluster`.

1. `TH brief --run <runId> --cluster <n>` (Markdown). Read every member
file completely, and the source it exercises. Read context files only to
judge overlap.
Expand All @@ -88,15 +105,17 @@ start: a run reads a great deal, and most of it can be avoided.
`TH validate <runDir>/cluster-<n>.json --run <runId>` until it is `ok`.
A problem it reports is a missing proof, not a formatting chore.
7. If you changed anything, commit exactly this cluster's files, with the
trailer from the brief as the last line of the message:
trailer from the brief as the last line of the message and the cluster's
package from the brief in the subject:

```sh
git add <changed test files>
git commit -m "test(<package>): <what the cluster's fixes do>" -m "Test-Health: <runId>#<n>"
```

8. `TH record cluster --run <runId> --cluster <n> --worksheet <runDir>/cluster-<n>.json`,
adding `--commit HEAD` when you committed.
adding `--commit HEAD` when you committed and `--wip <patch>` when you
kept an unproven fix.

5. **Push** the batch branch: `git push -u origin <batch.branch>`. Do not open
a pull request here.
Expand All @@ -109,8 +128,8 @@ start: a run reads a great deal, and most of it can be avoided.
read that smell's rule in the authoring guide. If the rule would not have
prevented what you saw, sharpen it or add the example, in the batch. If the
smell is mechanical, file an issue proposing a lint check.
9. Report in a few lines: package, clusters audited, findings by status, what
landed, and anything a human must decide.
9. Report in a few lines: group and packages, clusters audited, findings by
status, what landed, and anything a human must decide.

| Order | Lens | Reference |
| --- | --- | --- |
Expand All @@ -133,8 +152,15 @@ test and agree something is wrong.
| The signal is fine in context (the weak matcher is the whole claim, the timer is a failure cap) | `none` | `accepted`, with the reason in the note |
| You can fix it inside this cluster's member files, and can produce the proof the reference names | the fixing action | `fixed` |
| The fix needs product code, a timeout or deadline, shard or selection rules, a workflow, or a test file outside this cluster | `file-issue` | `filed`, with the issue number |
| The file is context (another package), or you ran out of budget, or the proof would not come out | the action you would take | `deferred` |
| An open issue on the file is assigned to someone | comment your evidence on the issue | `deferred` |
| You ran out of budget before writing the fix | the action you would take | `deferred`, `deferredFor: "budget"` |
| The fix is written, but its proof would not come out within the overrun | the action you would take | `deferred`, `deferredFor: "proof"`, with the fix kept through `--wip` |
| The file is context (another package) | the action you would take | `deferred`, `deferredFor: "context"` |
| An open issue on the file is assigned to someone | comment your evidence on the issue | `deferred`, `deferredFor: "assigned"` |
| An open failure issue did not reproduce | comment what you ran on the issue | `deferred`, `deferredFor: "unreproduced"` |

`budget` and `proof` leave the work unfinished: the file stays in the
rotation (in the worst-first queue it ranks ahead of a never-audited file with
the same score), and the next run's brief lists these findings and the patch. Every other reason marks the file audited.

When two actions fit, take the smaller one. Strengthening an assertion beats
rewriting a test; rewriting beats removing it.
Expand Down Expand Up @@ -198,16 +224,17 @@ TH signals <file...>
TH measure <file...> [--runs <n>] [--shuffle] [--together] [--stress] --out <file>
TH mutate --test <file> [--name "<case>"] --expect "<failure text>" --from-worktree <path...> --out <file>
TH validate <worksheet> --run <runId>
TH record cluster --run <runId> --cluster <n> --worksheet <file> [--commit <sha>]
TH record cluster --run <runId> --cluster <n> --worksheet <file> [--commit <sha>] [--wip <patch>]
TH record run --run <runId> --outcome completed|throttled|blocked|nothing-to-do|failed --agent <label>
TH record batch --batch <id> --event pr|attempt|dropped|landed|abandoned [--pr <n>] [--commit <sha>] [--merge-sha <sha>] [--reason "<text>"]
TH batch status
TH batch verify --base <ref> [--head <ref>]
TH report [--publish]
```

Tunable values (cluster size, files per run, when a batch is ripe, how many
may land per day) live in `scripts/test-health/config.json`, not here.
Tunable values (cluster size, files per run, when a package counts as small,
how long proof may outlast the budget, when a batch is ripe, how many may land
per day) live in `scripts/test-health/config.json`, not here.

When a command, limit or path in this skill turns out wrong, fix it in the
batch that found it.
4 changes: 2 additions & 2 deletions .agents/skills/test-health/references/failure-issues.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ If the brief lists no issue for a file, the verdict for this lens is

| Verdict | Issue unassigned | Issue assigned to someone |
| --- | --- | --- |
| `test-fault` | Fix the test under the lens that names the cause (usually [non-determinism](nondeterminism.md)); the finding is `fixed` with that lens's proof. Comment the cause and the proof on the issue. | Comment your evidence. Finding `deferred`. |
| `test-fault` | Fix the test under the lens that names the cause (usually [non-determinism](nondeterminism.md)); the finding is `fixed` with that lens's proof. Comment the cause and the proof on the issue. | Comment your evidence. Finding `deferred`, `deferredFor: "assigned"`. |
| `product-fault` | Leave the test exactly as it is. Comment the evidence. Make sure a `type: fix` issue exists for the defect, filing one if not. Finding `filed`. | Same, without filing a duplicate. |
| `unreproduced` | Comment what you ran: command, commit, run count, conditions, result. Keep `needs: repro`. Finding `deferred`. | Same. |
| `unreproduced` | Comment what you ran: command, commit, run count, conditions, result. Keep `needs: repro`. Finding `deferred`, `deferredFor: "unreproduced"`. | Same. |

Record the finding under this lens (`failure-issues`) with the smell that is
your verdict. When you also fix the cause, the action is the fixing action
Expand Down
20 changes: 12 additions & 8 deletions .agents/skills/test-health/references/landing.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Landing a batch

A batch is one branch of audited commits inside one package. Hosted proof for a
test change is priced by the packages it touches, not by the number of files,
so a batch lands as **one pull request**, when it is ripe, and never one pull
A batch is one branch of audited commits inside one group: one package, or
`small`, the packages with few test files together. Hosted proof for a test
change is priced by the packages it touches, not by the number of files, so a
batch lands as **one pull request**, when it is ripe, and never one pull
request per cluster.

Land only the batch that `bun scripts/test-health.ts batch status` names in
Expand Down Expand Up @@ -55,23 +56,26 @@ changeset only if `check:pr` asks for one.

**The batch's own issue.** File one issue for the batch before opening its
pull request, with the GitHub skill: title `<package>: test-health batch
<batch id>`, a body that names each fixed finding (file, smell, one line on
what was wrong), labels `type: test` and the package's `area:` label, and
the release milestone. The pull request closes it. Merging into `main`
<batch id>` (`tests: test-health batch <batch id>` for a `small` batch), a
body that names each fixed finding (file, smell, one line on what was wrong),
labels `type: test` and the `area:` label of every package the batch changed,
and the release milestone. The pull request closes it. Merging into `main`
needs at least one delivered issue (`--issues` in step 4), and most batches
resolve no failure issue of their own.

Then open the pull request as a draft, against the branch that `batch.base`
names:

- Title: `test(<package>): test-health batch <batch id>`.
- Title: `test(<package>): test-health batch <batch id>`; for a `small` batch,
which may change several packages, `test: test-health batch <batch id>`.
- Body: `Closes #N` for the batch's own issue; what the batch does in numbers
(clusters, files changed, findings fixed by lens, tests removed with their
obligation maps, mutations killed), the gate's `stats`, `Closes #N` or
`Refs #N` for each failure issue it resolves or advances, and the
`check:pr` receipt block. Use the repository template. Screen the text as
the GitHub skill requires.
- Labels: `type: test` and the package's `area:` label.
- Labels: `type: test` and the `area:` label of every package the batch
changed.

Record it: `TH record batch --batch <id> --event pr --pr <number>`.

Expand Down
35 changes: 32 additions & 3 deletions .agents/skills/test-health/references/worksheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ prose. The brief ends with a skeleton to start from; its lens verdicts say
`split`, `deflake`, `speed-up`, `unskip`, `cleanup`, `file-issue`, `none`.
- `status` is `fixed`, `filed`, `deferred` or `accepted`.
- `note` is one sentence: what was wrong, and what you did or why you left it.
- `deferredFor` is required on a `deferred` finding and allowed on no other:
`budget` (no time to write the fix), `proof` (the fix is written, its proof
did not finish), `assigned` (an issue's owner has it), `unreproduced` (an
open failure issue did not reproduce) or `context` (the finding is on a
context file). `budget` and `proof` keep the file in the rotation: the next
run plans it again and its brief lists the finding. The others mark the
file audited.
- `evidence` paths are relative to the run directory.

## Evidence a fixed finding must carry
Expand Down Expand Up @@ -110,8 +117,8 @@ When a title is missing from your declarations, the message quotes it:
copy it from there. If you did not mean to remove it, you have just been
stopped from losing a test; restore it.

A context file's finding can never be `fixed`: defer it, and its own package's
run will pick it up.
A context file's finding can never be `fixed`: defer it with
`deferredFor: "context"`, and its own package's run will pick it up.

## Validating and recording

Expand All @@ -134,11 +141,33 @@ bun scripts/test-health.ts record cluster --run <runId> --cluster <n> --workshee
| `N test(s) disappeared without being declared: "..."` | A test is gone that no fixed finding names; declare it or restore it |
| `N executed case(s) fewer than before, and the findings declare M` | Fewer cases run than you declared: a table or loop shrank, or a test is no longer collected |
| `measurements.before and measurements.after must both measure it` | A Bun test file changed and one of the two measurements does not cover it |
| `a deferred finding says why in deferredFor` | A `deferred` finding has no reason, or one not in the list above |

`record cluster` refuses a worksheet that does not validate, a member whose
content changed without `--commit`, a commit whose message lacks the cluster's
`Test-Health:` trailer, and a change that loses a test no finding declared. Record a clean cluster too: that is what
marks its files as audited.

Do not edit a worksheet to match a result you did not get. If the proof will
not come out, the finding is `deferred`.
not come out, the finding is `deferred` with `deferredFor: "proof"`.

## Keeping an unproven fix

Before you defer for `proof`, prove the fix past your time budget, by up to
`proofOverrunMinutes` in `config.json`, as the skill's step 4 says; and when a
brief names a patch from an earlier audit, apply it and prove it before
anything else in that cluster. A fix whose proof still did not finish is kept on the ledger, so a later run on any
machine resumes it instead of rediscovering it. Save it as a patch, restore the
files so the cluster records nothing as changed, and pass the patch to
`record cluster`:

```sh
git diff -- <files> > <runDir>/wip-<n>.patch && git checkout -- <files>
bun scripts/test-health.ts record cluster --run <runId> --cluster <n> --worksheet <runDir>/cluster-<n>.json --wip <runDir>/wip-<n>.patch
```

The ledger stores it as `wip/<runId>-<n>.patch`. It refuses a patch larger than
`wipMaxBytes` in `config.json`, one without a `diff --git` header, and one that
touches any path a batch could not land: only test code and test support. The
next brief for the file copies the patch into that run's directory and names
it.
23 changes: 19 additions & 4 deletions docs/decisions/test-health.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
The automated tests are kept in shape by a recurring, scripted audit rather
than by occasional clean-up epics. One skill
([test-health](../../.agents/skills/test-health/SKILL.md)) audits a few related
test files in depth per run, proves each fix, lands the fixes in per-package
batches and records what it did. A second skill
test files in depth per run, proves each fix, lands the fixes in batches of
one package, or of the small packages together, and records what it did. A second skill
([test-health-push](../../.agents/skills/test-health-push/SKILL.md)) runs the
same audit over the whole suite at once. This record covers the rulings the
maintainer made on 2026-11-10 while the two were designed, the alternatives
Expand Down Expand Up @@ -37,12 +37,27 @@ follows is in [ci-utility.md](ci-utility.md) and
`scripts/test-health.ts`, so a cheaper model and a stronger one produce
comparable records. The agent's own contribution is recorded only in
enumerated fields.
- **A batch stays inside one package and lands as one pull request.** Hosted
- **A batch stays inside one group and lands as one pull request.** Hosted
proof for a test edit is priced by the workspaces it touches, not by the
number of files (`const packageCode`, `scripts/ci-plan.ts:355-356`): any path
under a package's `tests/` selects that package and its reverse dependants.
One changed test in a package costs the same confirmation as thirty, so
small pull requests are the most expensive way to land this work.
small pull requests are the most expensive way to land this work. A large
package is a group of its own. **Small packages share one group, `small`**
(ruled on #3854): a package with at most `smallPackageFiles` test files can
only ever land a few changed files, and the first such batch, all ten files
of `common` audited for a five-line change, still took a lane slot and a
15-job main run. One pull request across several small packages pays the
union of their closures once, where one per package pays each closure and a
lane slot apiece. A cluster still stays inside one package.
- **Deferred work is unfinished work.** A finding deferred because the run ran
out of budget, or because a written fix could not be proven in time, leaves
its file in the rotation instead of marking it audited for the re-audit
window (#3852). The slowest and flakiest files, whose proof takes longest,
are the ones the audit exists for, and they are the ones a time budget
defers. A run may outlast its budget to prove a fix it already wrote, and a
fix that still cannot be proven is kept on the ledger as a patch for the next
run.
- **The ledger lives on its own ref.** What was audited, claimed, batched and
landed is an append-only record on `refs/heads/brain-test-health`. It is the
rotation's memory and the only source of the metrics. A progress log does not
Expand Down
Loading
Loading