📝 Document type-first (red/green/blue) testing discipline
New behavior is written type-first: the expectTypeOf (blue) comes before the assert (red), since for a pattern-matching library the types are the feature. Adds a CONTRIBUTING.md section and a discoverability pointer in AGENTS.md's "Read these" index. Human-facing rationale lives in CONTRIBUTING.md; AGENTS.md only links it so agents and reviewers don't diverge.
This commit is contained in:
1 parent
49a78f3683
commit
464789b385
2 files changed
+12
No files matched your search
@@ -35,6 +35,7 @@ Never start a long-lived / blocking process such as `npm run watch`. It runs unt
|
|||||||
## Read these
|
## 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 § 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 § 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 § 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).
|
- [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).
|
||||||
|
|||||||
@@ -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.
|
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<T>` 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 workflow
|
||||||
|
|
||||||
Publishing is CI-only by policy. Local `npm publish` is not supported.
|
Publishing is CI-only by policy. Local `npm publish` is not supported.
|
||||||
|
|||||||
Reference in new issue
Block a user