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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
155 changes: 155 additions & 0 deletions .agents/skills/test-health-push/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
---
name: test-health-push
description: Run one dedicated push that takes the whole brain-kit test suite through the test-health audit in parallel and lands the result as a single pull request from an integration branch. Use only when explicitly asked for a full test-health pass or push; the recurring run is the test-health skill, and this skill adds nothing to how a test is audited.
disable-model-invocation: true
---

# One full pass of the test suite

This skill is **only about scale**. How a cluster is chosen, audited, proven,
recorded, gated and landed is [the test-health skill](../test-health/SKILL.md)
and its scripts, unchanged. When the approach is tuned, it is tuned there, and
this skill inherits it. If you find yourself writing an instruction here about
what makes a test good or bad, it belongs in the other skill.

What this adds: one integration branch as the base, disjoint shards so many
workers can run at once, an integrator that merges their batches, a shake-out
of the combined result, and one landing on `main`.

A push request authorizes everything a test-health run authorizes, plus
creating the integration branch and its epic issue, starting the workers, and
the final merge to `main`. Loading this skill does not start a push.

Write `TH` for `bun scripts/test-health.ts`.

## Before starting

- `TH doctor` is `ok` and `capabilities.mayLand` is true.
- The regular skill has already landed at least one batch on `main` through its
own path. A push repeats whatever the regular run does several hundred
times; a flaw in it is repeated as often.
- You were given, or have chosen and stated: a cut-off time, and the number of
workers. Local test runs are the bottleneck, and heavy ones queue behind host
admission, so more workers than half the machine's CPUs only wait.

## 1. The epic and its branch

File one epic issue for the push with the GitHub skill: the outcome (every test
file audited once at its current content, fixes landed as one pull request),
the cut-off, and that what is unfinished at the cut-off returns to the
recurring run. Then create the branch from current `main`:

```sh
git fetch origin
git push origin origin/main:refs/heads/epic/<epic number>-test-health
```

Call it `EPIC` below: `origin/epic/<epic number>-test-health`.

## 2. Shards

```sh
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
disjoint by construction, and the ledger's claims keep two workers on one shard
from colliding.

## 3. Workers

Start one worker per shard, at most the chosen number at a time, each in its
own worktree. A worker's whole brief is:

> Use the `test-health` skill. Pass `--profile push --base EPIC --shard <shard file>`
> to every `plan`, and add `--bun-only` if `doctor` reports no browser runner.
> Repeat runs until `plan` returns no clusters or the cut-off passes. Then land
> your batch as the skill's landing reference describes for a base that is not
> `main`, and report its pull request number, head and state.

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.

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
same batch.

## 4. Integrating

One integrator, which is you, merges the workers' pull requests into `EPIC`,
**one at a time**, each only after its own hosted proof passed on its current
head, exactly as the landing reference says. After each merge, the open worker
branches merge `EPIC` in before their next confirmation.

Record each as the landing reference says (`--event landed`). A worker whose
batch cannot land abandons it (`--event abandoned`); its files return to the
recurring run.

## 5. Shake-out

When the last batch is merged or the cut-off has passed, run the exhaustive
proof on the combined branch, twice, without holding the main lane:

```sh
gh workflow run ci.yml --ref epic/<epic number>-test-health
```

For every test that fails in either run and whose file a batch changed:
restore that cluster's member files from `main` on the epic branch, commit, and
withdraw its audit, so the recurring run takes it up again:

```sh
git checkout origin/main -- <the cluster's member files>
git commit -m "revert: drop <runId>#<n> after the shake-out" -m "Test-Health: <runId>#<n>"
TH record void --run <runId> --cluster <n> --reason "<the failure>"
```

A failure in a file no batch changed is an existing flake: find or file its
issue and carry on. Repeat the exhaustive run after any drop, until two
consecutive runs agree.

## 6. One landing on main

```sh
git fetch origin && git merge --no-edit origin/main # on the epic branch; a merge commit
TH batch verify --base origin/main --head HEAD --net-only
bun run check:pr --base origin/main
```

`--net-only` checks the whole diff (test code only, no proof-system change, no
new skip or retry, no test removed without its recorded obligation map) and
skips the per-commit trail, which each batch already passed before it was
squashed into `EPIC`.

Open one pull request from the epic branch to `main`, with the push's numbers
from `TH report` and the two shake-out run links as its off-main evidence. Land
it under the main reservation as a **merge commit**, so each batch stays one
revertable commit: acquire and renew the lease, mark the pull request ready,
wait for that run's `proof`, merge with `gh pr merge --merge --match-head-commit`,
and release the lease. The reservation commands are in
[CI and merge](../work-issue/references/ci-and-merge.md), "Reservation before
expensive confirmation"; do not use `integrate.ts confirm` here, because it
squashes.

## 7. Afterwards

- `TH report --publish`, and put its coverage and landing figures on the epic.
- For a before-and-after of the suite's cost, compare the last nightly
exhaustive run before the push with the shake-out runs, using
`bun scripts/ci-timings.ts collect --run <run id>`. They differ only by the
push's test changes, which is as close to a controlled comparison as hosted
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.

## When to stop early

- Main turns red: workers keep auditing, nothing merges to `main`, and step 6
waits.
- The first two worker batches both fail their gate or their proof for the same
reason: stop the push. That is a flaw in the regular skill; fix it there and
start again.
6 changes: 6 additions & 0 deletions .agents/skills/test-health-push/agents/openai.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
interface:
display_name: "One full pass of brain-kit's tests"
short_description: "Fan the test-health audit out over the whole suite and land it as one pull request"
default_prompt: "Use $test-health-push to run one dedicated push: shard the suite, run test-health workers against an integration branch, shake the result out and land it on main as one pull request."
policy:
allow_implicit_invocation: false
209 changes: 209 additions & 0 deletions .agents/skills/test-health/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
---
name: test-health
description: Audit a batch of brain-kit's automated tests in depth and fix the worst of them - tests that cannot fail, overlap between tiers, non-determinism, open failure issues, slow tests, tests that do not run, wrong tiers and poor hygiene - with scripted selection, proof and metrics. Use for a recurring test-health run, or when asked to audit or improve the existing tests; not for writing tests for a feature, and not for fixing a red main.
---

# 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
suite comes from running this again and again: the planner picks different
files every time and reaches all of them eventually.

`scripts/test-health.ts` decides everything that can be decided mechanically:
what to audit, what the static signals are, how a test behaves over repeated
runs, whether a mutation is killed, whether your worksheet may be recorded and
whether a batch may land. You supply the judgment in between. **Nobody reads
these changes before they merge.** The worksheet's evidence and the batch gate
are the review, so never work around them, and when you are unsure, do not
change the test.

A run request authorizes: changes to test code, commits and pushes to
`test-health/*` branches, one pull request per batch and its merge through the
repository's normal path, issue filing and comments under the GitHub skill, and
writes to the test-health ledger. It does not authorize anything in
[the rules that do not bend](#rules-that-do-not-bend).

Read [the authoring guide](../../../docs/process/test-authoring.md) first: it is
what you audit against. Use [the GitHub skill](../github/SKILL.md) for every
issue you file or comment on.

## The run

Write `TH` for `bun scripts/test-health.ts`. Pass the caller's `--profile`,
`--base`, `--shard` and `--batch` to `plan` if you were given them; otherwise
pass none. Read [spending few tokens](#spending-few-tokens) once before you
start: a run reads a great deal, and most of it can be avoided.

1. **Preflight.** `bun run test:skills > /tmp/test-skills.log 2>&1; echo "exit $?"`,
then `TH doctor`.
- The tooling's own tests fail: stop, and report the failing lines of the
log. Do not audit with a broken tool. This tier gates only this skill; it
is not product proof and blocks nothing else.
- `ok: false`: stop and report the failed check.
- `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`.
- `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`.
3. **Check out the batch branch in its own worktree**, and run everything else
from there.

```sh
git fetch origin
# batch.isNew is true:
git worktree add <dir> -b <batch.branch> <batch.base>
# batch.isNew is false:
git worktree add <dir> <batch.branch> && git -C <dir> merge --no-edit <batch.base>
cd <dir> && bun install --frozen-lockfile
```

4. **Audit each cluster, in order.** Stop taking new clusters when the time
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.

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.
2. Baseline, one command per runner (`bun` files together, `visual` files
together): `TH measure <files> --shuffle --together --out <runDir>/baseline-<n>.json`.
Browser files take minutes per run; give them `--runs 2` and no `--shuffle`.
3. Walk the eight lenses in the order of the table below, one reference at a
time. Give every member a verdict for every lens and write a finding for
each problem.
4. Decide each finding with [the decision table](#deciding-a-finding), then
fix and prove the ones you fix. The reference says which proof.
5. If you changed any file, measure the changed files again:
`TH measure <changed files> --out <runDir>/after-<n>.json`. The baseline
and this file are how the recorder proves no test was lost.
6. Write the worksheet to `<runDir>/cluster-<n>.json`
([format](references/worksheet.md)) and run
`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:

```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.

5. **Push** the batch branch: `git push -u origin <batch.branch>`. Do not open
a pull request here.
6. **Land a ripe batch.** `TH batch status`. If `land` names a batch, follow
[landing](references/landing.md) for that batch. Otherwise nothing lands
this run.
7. **Record the run**: `TH record run --run <runId> --outcome completed --agent <your model name>`,
then `TH report --publish`.
8. **Feed the guide.** If this run fixed the same smell three or more times,
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.

| Order | Lens | Reference |
| --- | --- | --- |
| 1 | `cannot-fail` | [cannot-fail.md](references/cannot-fail.md) |
| 2 | `overlap` | [overlap.md](references/overlap.md) |
| 3 | `nondeterminism` | [nondeterminism.md](references/nondeterminism.md) |
| 4 | `failure-issues` | [failure-issues.md](references/failure-issues.md) |
| 5 | `cost` | [cost.md](references/cost.md) |
| 6 | `not-running` | [running-tier-hygiene.md](references/running-tier-hygiene.md) |
| 7 | `tier-and-doubles` | [running-tier-hygiene.md](references/running-tier-hygiene.md) |
| 8 | `hygiene` | [running-tier-hygiene.md](references/running-tier-hygiene.md) |

## Deciding a finding

A scanner signal is a lead. It becomes a finding only when you have read the
test and agree something is wrong.

| What you found | Action | Status |
| --- | --- | --- |
| 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` |

When two actions fit, take the smaller one. Strengthening an assertion beats
rewriting a test; rewriting beats removing it.

## Rules that do not bend

- **Test code only.** A product defect is filed as a `type: fix` issue and the
finding is `filed`. The batch gate refuses any other path.
- **Never hide a test.** No `skip`, `todo`, `only`, `retry` or conditional
skip, and no raised or added timeout or deadline. The gate refuses each.
- **Never weaken an assertion to get green**, and never delete a test because
it fails.
- **Take assertions away only with an obligation map**: every assertion of the
removed, merged or moved test mapped to the test that still makes it, plus a
killed mutation on that retained owner.
- **No test disappears unannounced.** Every test title that is gone after your
change must be named in a fixed finding, as a removal or as a rename, and a
file's count of executed cases may fall only by the number you declared. The
recorder and the batch gate both check it, by name and by count, so a test
dropped by accident stops the cluster instead of landing.
- **A test that fails in your baseline is not yours to "fix" by editing its
expectation.** Find out whether the test or the product is wrong
([failure issues](references/failure-issues.md)).
- **Leave no mutation behind.** `TH mutate` reverts its own; run
`git status --short` before each commit and commit only test files.
- **Stay inside your cluster.** Member files only. A helper shared with other
tests is changed only when every user of it is a member.
- **Never rerun a failed CI job**, and never raise a deadline to absorb load.
- **Fixtures use the Odysseus world** and the pinned date `2026-07-12`; no real
names anywhere.

## Spending few tokens

- **Every `TH` command prints one line of JSON** with what the next step needs,
and writes the detail to a file. Do not print those files: `validate` and
`record` read the receipts and measurements themselves. Add `--full` only
when the one line leaves a question open.
- **The brief replaces searching.** It gives the signal lines, costs, issues
and neighbours for a cluster; do not rerun `signals` or grep for what it
already lists.
- **Read each member file once**, whole. Re-read only the lines you changed.
- **Send long output to a file** and read its end:

```sh
bun install --frozen-lockfile > <runDir>/install.log 2>&1; echo "exit $?"; tail -n 5 <runDir>/install.log
```

- **Write git, gh and test commands plainly.** Where `rtk` is installed, its
hook compresses their output without being asked. Never prefix a command
with `rtk proxy` or `rtk bypass`: both switch the compression off.
- **Do not pipe `gh` JSON through `jq` in the shell.** `TH plan`, `TH brief`
and `TH batch status` already fetch and reduce what a run needs from GitHub.

## Commands

```sh
TH doctor
TH plan [--profile cron|push] [--base <ref>] [--package <name>] [--shard <file>] [--batch <id>] [--bun-only] [--dry-run]
TH brief --run <runId> --cluster <n> [--json]
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 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.

When a command, limit or path in this skill turns out wrong, fix it in the
batch that found it.
4 changes: 4 additions & 0 deletions .agents/skills/test-health/agents/openai.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
interface:
display_name: "Keep brain-kit's tests healthy"
short_description: "Audit one batch of tests in depth, fix and prove the worst, land ripe batches"
default_prompt: "Use $test-health to do one test-health run: plan, audit each cluster through every lens, record the worksheets, land a ripe batch if there is one, and record the run."
Loading
Loading