Add a weekly report of the wrong edits gstack's tests fail to catch (GST-3386) (#4652)

A new weekly Mutation report plants small wrong edits in the five `lib/`
files with the most landings in the last 30 days and lists the edits no
test caught.

Why: agents write most of our code and tests, and a green suite only
means something if the tests reject plausible wrong code; this trial
measures where they don't.

Nothing to do: it runs Saturdays on main, is never a required check, and
never blocks a merge.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
This commit is contained in:
Garry Tanandcapy-ai[bot] authored and GitHub committed 2026-11-22 04:06:55 +00:00
1 parent 6484fd58ae
commit 6963fa8089
7 files changed
+368 -1

No files matched your search

+23
View File
@@ -1139,6 +1139,29 @@ machine swap, in this order:
plus ten minutes has passed, so set `UBI_TTL_HOURS` above the expected
duration and name that duration in the thread before launching.
## Mutation report
A weekly, report-only trial of mutation testing. It checks whether gstack's tests reject plausible wrong code in the files agents change most. `.github/workflows/mutation-report.yml` runs every Saturday at 06:00 UTC, or on demand through workflow_dispatch, on `ubicloud-standard-16`. It is not a required check, never runs on pull requests, and never blocks a merge.
`scripts/mutation-report.ts` does the work:
1. It picks the five `lib/**/*.ts` files (not tests) with the most landings on main in the last 30 days (`git log --first-parent`), from the job's full-history checkout. A file that no test imports is listed as `no tests`, and a file Stryker finds nothing to mutate in (a data-only file) as `no mutants`; in both cases the next file takes its place.
2. For each file it selects the test files that import it directly. If none do, it falls back to the transitive importers from `lib/pregate/import-graph.ts`. At most 20 run, and the report shows "20 of N" when it caps them.
3. **Positive control.** The selected tests must first pass on the unedited file; if they don't, the file is reported as `failed`. Then the script prepends `throw new Error('mutation-report positive control')` to the file and runs the same tests, which must fail with that message. If they don't, the tests reach the file only through a spawned process, and every mutant would be a false survivor. The file is then reported as `control survived` and not mutated.
4. It runs StrykerJS with the community Bun runner, using per-test coverage and `ignoreStatic`, within a 55-minute budget per file that also covers the two test runs before it (at most 10 minutes each). Stryker runs under `timeout`, which kills its whole process group at the budget, and the script then restores the tree with `git checkout -- .`. A file that runs out of budget is reported as `unfinished`. The report is rewritten after every file, so a job that hits its own limit still leaves the finished files.
5. It writes a table (killed, survived, no coverage, timeout, mutation score) and up to 15 survivors per file, each with its line, mutator and replacement. The table goes to the step summary, and the Markdown, JSON and per-file Stryker reports go to the `mutation-report` artifact.
Stryker (`@stryker-mutator/core`) and `@hughescr/stryker-bun-runner` are both Apache-2.0. They are installed at the exact versions in `STRYKER_PACKAGES` into the runner's temp directory with `--ignore-scripts`, so `package.json` and `bun.lock` don't change. Their own dependencies aren't locked.
Stryker has to edit files in place, because its sandbox copy fails on this repo's symlinked directories (`EISDIR` on `connect-chrome`). The script therefore refuses a dirty tree, requires `--throwaway-checkout`, and must never run in a checkout you work in. If a run is killed, it can leave a mutated file behind: run `git checkout -- .` and remove `.stryker-tmp`. To run it locally, use a scratch worktree:
```bash
git worktree add /tmp/mut origin/main && cd /tmp/mut && bun install
npm install --prefix /tmp/stryker --no-save --ignore-scripts @stryker-mutator/core@10.1.1 @hughescr/stryker-bun-runner@1.6.0
bun --no-env-file --config=/dev/null scripts/mutation-report.ts --throwaway-checkout --files 1 \
--stryker-dir /tmp/stryker --out-dir /tmp/mutation-out
```
## Cloud sandboxes (Vercel / Conductor cloud workspaces)
Syscall-supervised sandboxes need environment setup before `bun run test` can