diff --git a/AGENTS.md b/AGENTS.md index 87ea08c..c8c7610 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -35,6 +35,7 @@ Never start a long-lived / blocking process such as `npm run watch`. It runs unt ## Read these - [CONTRIBUTING.md § Rules the tools don't enforce](./CONTRIBUTING.md#rules-the-tools-dont-enforce) — the constraints the linters don't catch; CI/review bounce these. **The most important section.** +- [CONTRIBUTING.md § Testing discipline (type-first)](./CONTRIBUTING.md#testing-discipline-type-first) — write the `expectTypeOf` (blue) before the `assert` (red); the types are the feature. - [CONTRIBUTING.md § Script prefix convention](./CONTRIBUTING.md#script-prefix-convention) — adding an `npm run` script? reuse an existing prefix or it doesn't belong. - [CONTRIBUTING.md § Commit messages](./CONTRIBUTING.md#commit-messages) — gitmoji + imperative + 50/72. - [CONTRIBUTING.md § Feedback tiers](./CONTRIBUTING.md#feedback-tiers) — what runs when and at what cost (`watch` / pre-commit / pre-push / `check` / `verify` / `fix` / `maintain` / CI). diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1a7d5b5..bcfd51d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -60,6 +60,17 @@ The tools are organized into a feedback ladder. Each tier catches different thin Run `npm run verify` — the one-shot correctness gate in the table above. Run `npm run maintain` only on a maintenance / update-deps branch. +## Testing discipline (type-first) + +For this library the types _are_ the feature — narrowing, `exhaustive()` returns, the `Matcher` contract — so a runtime-only test loop would verify the wrong thing. New behavior is written **type-first**, in a red/green/blue loop: + +1. **Blue** — write the compile-time expectation first (`expectTypeOf(...).toEqualTypeOf<…>()`) and let `npm run check:tsc` fail on the _type_. The type error is the spec you want to hit before the runtime logic exists. +2. **Red** — add the matching runtime assertion (`assert.*`) so `npm run test:unit` now fails on behavior. +3. **Green** — implement in `src/*.ts` until both the type check and the test pass. +4. **Refactor** — with the type system and the tests as the safety net, then `npm run verify` as the definition-of-done gate. + +This is why every test in the suite pairs an `expectTypeOf(...)` with an `assert.*` — keep them together. Blue-first is also enforced structurally: `npm test` runs `check:tsc` before the test runner, so a wrong type can never be papered over by a passing assertion. Per [AGENTS.md § Never do](./AGENTS.md#never-do), never reach green by suppressing the type system (`@ts-ignore`, `as` casts, `expectTypeOf` removed) — fix the types so both blue and red go green honestly. + ## Publishing workflow Publishing is CI-only by policy. Local `npm publish` is not supported.