Soundness corpus: the bug classes that pass every gate and fail at run time, as a CI ratchet #109

Merged
sionzee merged 2 commits from soundness-corpus into main 2026-11-21 11:11:50 +01:00
Owner

Until now, programs that pass every static gate and still fail at run time were found by hand, one probe at a time. This makes the count mechanical and turns it into a gate, so closing a hole shows up in a diff and reopening one fails CI.

What it is

scripts/soundness/ holds 31 known bug classes. Each is a small program generator with a one-line statement of what goes wrong and a runtime oracle. Every program is checked the way the adoption guide sets a project up (tsc strict with strict-lib, safe-ts check --deny-warnings with the idiomatic rules and the packs, oxlint with the preset). The ones that pass run in Node, and the oracle says whether they went wrong: threw, changed data they only borrowed, or returned a wrong result.

scripts/soundness/escaping.txt lists the classes that escape today, one per line. npm run test:soundness fails when that list is wrong in either direction:

  • a class escapes that isn't listed: a regression;
  • a listed class no longer escapes: remove the line, like an unused @ts-expect-error.

Today 29 of 31 escape. The run takes about a second and is a step in the test workflow and in npm test.

It is not a fuzzer and does not claim to be: the generators are hand-written, with random names and constants only, so it measures the classes written down and cannot find new ones.

From the prototype

The corpus started as a 920-line prototype reporting 32 classes. Reviewing each program changed the list:

  • Four random-* classes were duplicates of others and are merged.
  • One was an artefact: a function changing its own local through a closure it called itself.
  • try-return-unawaited-promise did not escape for the reason it claimed. The checker follows that case; what escaped was Promise.reject(new Error()), now its own class.
  • Three classes the prototype's seed never produced are now written on every run.
  • A crash counts only when the checker saw no failure at all: each crashing program has a caller file that must pass too.

Also in this PR

notes/prototypes/ keeps two experiments from the same work, each with a README stating its status. Neither runs in CI.

  • Proofs that a nominal, invariant Mut<T> with mut(x) at call sites closes six zero-cast crashes under tsc. That design is approved and will be built separately.
  • An experiment with TypeScript 7's native API as a type oracle. It depends on typescript/unstable/* and is not a planned dependency.

How it was checked

  • The gate passes on main and gives the same class set for 34 seeds.
  • Each failure path was exercised: an unlisted class, a listed class that stopped escaping, an unknown id, an unsorted list, and a checker that fails to run (the run stops with exit 2 and does not count everything as passing).
  • Run against a build that reports Promise.reject, it fails naming promise-reject-untracked and the finding that rejected it, as intended.

Created with Claude Opus 5.5 (implementation) and Claude Fable 5.2 (review, and the division-by-zero class) in Claude Code.

Until now, programs that pass every static gate and still fail at run time were found by hand, one probe at a time. This makes the count mechanical and turns it into a gate, so closing a hole shows up in a diff and reopening one fails CI. ## What it is `scripts/soundness/` holds 31 known bug classes. Each is a small program generator with a one-line statement of what goes wrong and a runtime oracle. Every program is checked the way the adoption guide sets a project up (`tsc` strict with strict-lib, `safe-ts check --deny-warnings` with the idiomatic rules and the packs, oxlint with the preset). The ones that pass run in Node, and the oracle says whether they went wrong: threw, changed data they only borrowed, or returned a wrong result. `scripts/soundness/escaping.txt` lists the classes that escape today, one per line. `npm run test:soundness` fails when that list is wrong in either direction: - a class escapes that isn't listed: a regression; - a listed class no longer escapes: remove the line, like an unused `@ts-expect-error`. Today 29 of 31 escape. The run takes about a second and is a step in the test workflow and in `npm test`. It is not a fuzzer and does not claim to be: the generators are hand-written, with random names and constants only, so it measures the classes written down and cannot find new ones. ## From the prototype The corpus started as a 920-line prototype reporting 32 classes. Reviewing each program changed the list: - Four `random-*` classes were duplicates of others and are merged. - One was an artefact: a function changing its own local through a closure it called itself. - `try-return-unawaited-promise` did not escape for the reason it claimed. The checker follows that case; what escaped was `Promise.reject(new Error())`, now its own class. - Three classes the prototype's seed never produced are now written on every run. - A crash counts only when the checker saw no failure at all: each crashing program has a caller file that must pass too. ## Also in this PR `notes/prototypes/` keeps two experiments from the same work, each with a README stating its status. Neither runs in CI. - Proofs that a nominal, invariant `Mut<T>` with `mut(x)` at call sites closes six zero-cast crashes under `tsc`. That design is approved and will be built separately. - An experiment with TypeScript 7's native API as a type oracle. It depends on `typescript/unstable/*` and is not a planned dependency. ## How it was checked - The gate passes on `main` and gives the same class set for 34 seeds. - Each failure path was exercised: an unlisted class, a listed class that stopped escaping, an unknown id, an unsorted list, and a checker that fails to run (the run stops with exit 2 and does not count everything as passing). - Run against a build that reports `Promise.reject`, it fails naming `promise-reject-untracked` and the finding that rejected it, as intended. Created with Claude Opus 5.5 (implementation) and Claude Fable 5.2 (review, and the division-by-zero class) in Claude Code.
An agent aims at "the checker passes", so a program that passes the static gates and fails at
run time is a bug SAFE-TS lets through. Until now those were found by hand. The corpus makes the
count a gate: scripts/soundness/escaping.txt lists the classes that escape today, and
`npm run test:soundness` (also in CI and `npm test`) fails when the classes that escape differ
from the list in either direction. A class escaping that isn't listed is a regression; a listed
class that no longer escapes must come off the list, like an unused @ts-expect-error. So closing
a class shows up in a diff, and reopening one fails CI.

It is not a fuzzer: each class is a hand-written generator with small variations (names, sizes,
constants), in scripts/soundness/classes/, with a one-line statement and the oracle that shows
it. Every run writes every variant, so the set doesn't depend on the seed. Programs are checked
in the setup docs/guide/adoption.md documents (strict + strict-lib, `safe-ts check
--deny-warnings` with idiomatic rules and the packs, oxlint with the preset) and run in Node
with the loader. A crash counts only if the checker saw no failure: a caller file invoking
run() at top level must pass too. About a second.

From the prototype's 32 classes: 28 escape. Dropped as artefacts the oracles reported where the
rules permit it (0 / 0 is NaN, a number; a Mut captured by a closure the owner calls itself),
merged duplicates (the random-* classes, getter + method mutation of a borrowed receiver), and
split try-return: the checker tracks it, `Promise.reject` is what escaped. Three classes the
prototype's seed never produced now escape every run.

The prototypes it came with move to notes/prototypes/, marked as such: the nominal Mut<T>
proofs (approved, built separately) and the TypeScript 7 native API type-oracle experiment.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Soundness corpus: count division by zero
All checks were successful
Benchmarks / bench (pull_request) Successful in 3m54s
Tests / test (pull_request) Successful in 10m24s
013d698ea1
The first cut dropped it because `NaN` is a `number`, so no declared type is
broken. The output is still wrong (`"NaN%"`, an average of nothing shown as
`NaN`), `number-parse-nan` already treats `NaN` from parsing as a bug, and a
check of divisors is planned. The class uses a divisor that is always 0, so it
does not depend on the seed.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
sionzee deleted branch soundness-corpus 2026-11-21 11:11:50 +01:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Evobug/Safe-Ts!109
No description provided.