feat(tdd): add seam-based test-driven development skill
- Add skills/tdd/SKILL.md (40 lines) with intent-scoped triggers, a Step 1 fast-exit gate for trivial edits, zero-ceremony execution on established seams, and red-green vertical slice loops. - Add skills/tdd/references/seams-and-mocking.md and test-quality.md covering boundary-only mocking, schema-safe fixtures, non-tautological assertions, and authoritative conflict reconciliation. - Register tdd in install.sh and README.md. Adapted from Matt Pocock's tdd skill (github.com/mattpocock/skills), extended with cross-stack fixture rules and state-reconciliation lessons. Rationale: Scoping description to explicit testing intent plus a Step 1 applicability check prevents unsolicited TDD ceremony on trivial fixes while keeping seam and anti-tautology rules reachable by subagents.
This commit is contained in:
1 parent
d866b602b8
commit
f43146bb18
5 files changed
+124
-1
No files matched your search
@@ -79,6 +79,7 @@ Every skill features an explicit **"Your call"** checkpoint where the agent paus
|
||||
| **[`nix-devshell`](skills/nix-devshell/SKILL.md)** | `/nix-devshell` | Authors, extends, validates, and troubleshoots project Nix development shells from repository evidence. | 75 lines |
|
||||
| **[`verify-slice`](skills/verify-slice/SKILL.md)** | `/verify-slice` | Runs risk-proportional verification and PR review across behavioral, state, security, ergonomic, and regression perspectives using falsifiable assertions. | 37 lines |
|
||||
| **[`code-review`](skills/code-review/SKILL.md)** | `/code-review` | Inspects diffs across four isolated axes: Spec & Scope, Standards & Smells, Seam & Test Integrity, and Defensive Invariants. | 42 lines |
|
||||
| **[`tdd`](skills/tdd/SKILL.md)** | `/tdd` | Guides red-green test-driven development through public interface seams, boundary-only mocking, and non-tautological assertions. | 40 lines |
|
||||
|
||||
### Vault Extensions (`extensions/`)
|
||||
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ while [[ $# -gt 0 ]]; do
|
||||
done
|
||||
|
||||
# Active skills to install
|
||||
ACTIVE_PORTABLE_SKILLS=(build-skill code-review diagnose document git-commit inspect-flake-update journal-builder nix-devshell practice reconcile-docs verify-slice)
|
||||
ACTIVE_PORTABLE_SKILLS=(build-skill code-review diagnose document git-commit inspect-flake-update journal-builder nix-devshell practice reconcile-docs tdd verify-slice)
|
||||
ACTIVE_EXTENSION_SKILLS=(draft-curation commit-logger)
|
||||
|
||||
# Legacy / deprecated skills to clean up or back up if found in target
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
---
|
||||
name: tdd
|
||||
description: >-
|
||||
Guides test-driven development through public interface seams using red-green
|
||||
vertical slices, boundary-only mocking, and non-tautological assertions. Use
|
||||
when the user types /tdd, asks for test-first implementation, requests a
|
||||
failing reproduction test for a bug, or writes unit and integration tests. Do
|
||||
not use for trivial fixes, styling, copy, declarative configuration, or
|
||||
routine edits where test-first was not requested.
|
||||
---
|
||||
|
||||
# Test-Driven Development
|
||||
|
||||
## Use when
|
||||
- `/tdd`, or explicit requests for test-first implementation, red-green loops, or bug reproduction tests.
|
||||
- Authoring or refactoring unit and integration tests around behavioral contracts.
|
||||
- Not for trivial two-line fixes, copy, styling, declarative config, or pure wiring: edit directly instead.
|
||||
- Not for pre-merge diff inspection (`code-review`) or live browser/deployment QA (`verify-slice`).
|
||||
|
||||
## Steps
|
||||
1. **Check applicability.** Confirm the task introduces or changes observable logic at a testable boundary. If the change is trivial (typo, styling, static config, pure wiring) and `/tdd` was not explicitly requested, skip this skill and apply the change directly. Read project domain docs (`GLOSSARY.md` or local ADRs) if present so test and interface names match domain terms.
|
||||
2. **Establish the public seam.** Identify the public interface where callers observe behavior without reaching into internals (see [seams-and-mocking](references/seams-and-mocking.md)). If the seam already exists and is unambiguous (such as adding a regression test to an established endpoint or function), proceed directly. Pause to confirm with the human owner only when introducing a new public interface, choosing between multiple candidate seams, or introducing test doubles.
|
||||
3. **Write one failing tracer bullet (Red).** Write a focused test at the agreed seam describing *what* capability or invariant holds, not *how* internals work (see [test-quality](references/test-quality.md)). Derive expected values from an independent source of truth (known literals, worked domain examples, specification rules), never by mirroring the implementation's formula.
|
||||
4. **Verify observable failure.** Run the targeted test command and confirm the test fails for the expected behavioral reason, not a syntax, import, or fixture setup error.
|
||||
5. **Write the minimal implementation (Green).** Write only enough production code to make the failing test pass. Avoid speculative abstractions or untested branches.
|
||||
6. **Cover negative, conflict, and boundary cases.** Once the happy-path slice passes, run additional red-to-green cycles for material failure modes (invalid inputs, conflict states such as `409`, timeouts, or state reconciliation invariants). Batch independent table-driven cases only after a vertical slice establishes the real contract.
|
||||
7. **Clean up and hand off.** Remove duplication and clarify names while keeping the suite green, or defer broader structural cleanup to `code-review`.
|
||||
|
||||
## Your call
|
||||
- **New seams and mock boundaries**: approve proposed public seams and any external mocks vs. real lightweight fixtures (such as an in-memory or temporary test database) before test authoring begins on new interfaces.
|
||||
- **Coverage depth**: decide when edge-case and negative-path slices are sufficient for the risk level of the change.
|
||||
|
||||
## Done when
|
||||
- Every targeted test was observed failing for the expected reason before passing, all tests verify public seams without tautological assertions, and the relevant test suite passes cleanly.
|
||||
|
||||
## Hands off to
|
||||
- `code-review`: to inspect the resulting diff, code smells, defensive invariants, and test seam integrity.
|
||||
- `verify-slice`: when the slice also needs live runtime, browser DOM, or multi-service verification.
|
||||
- `diagnose`: when an unexpected test or fixture failure needs root-cause investigation.
|
||||
- `git-commit`: to commit cohesive vertical slices.
|
||||
@@ -0,0 +1,39 @@
|
||||
# Public Seams and Boundary Mocking
|
||||
|
||||
Reference for `tdd`. Defines how to pick the test boundary, when to use real fixtures versus mocks, and how to shape interfaces so tests survive refactors.
|
||||
|
||||
Derived and adapted from Matt Pocock's `tdd` skill (`github.com/mattpocock/skills`), extended with cross-stack fixture and schema-integrity rules.
|
||||
|
||||
## 1. Choosing the Public Seam
|
||||
|
||||
A **seam** is the public interface where callers observe behavior without reaching into internal functions, private fields, or module wiring.
|
||||
|
||||
When proposing a new seam to the human owner, state two things in one line:
|
||||
- **What it catches**: the behavioral contract verified through this boundary.
|
||||
- **What it misses**: the outer integration layer left to `verify-slice` or higher-level tests.
|
||||
|
||||
| Stack | Typical Public Seam | Avoid Testing Directly |
|
||||
| :--- | :--- | :--- |
|
||||
| **Python API (FastAPI)** | HTTP route contract via `TestClient` / `AsyncClient` or domain service entrypoint | Private helper functions, ORM query-builder internals |
|
||||
| **TypeScript UI** | Rendered component DOM + user events + typed API client boundary | Internal component state variables, private render helpers |
|
||||
| **Rust CLI / Crate** | Public crate functions/traits or CLI command execution (`assert_cmd`) | Private module helpers, internal buffer representations |
|
||||
|
||||
## 2. Where to Mock (System Boundaries Only)
|
||||
|
||||
Mock or fake **external boundaries you do not control**:
|
||||
- Third-party network services (payments, email, external webhooks, OAuth providers).
|
||||
- Wall-clock time, timers, and randomness.
|
||||
- External OS or hardware effects outside deterministic test control.
|
||||
|
||||
Prefer **real lightweight fixtures** over mocks whenever practical:
|
||||
- Temporary or in-memory databases initialized through the real schema/migrations rather than mocked ORM sessions.
|
||||
- Temporary directories (`tmp_path` in `pytest`, `tempfile::TempDir` in Rust) rather than mocked filesystem calls.
|
||||
- Typed domain builders or service calls to seed state. Never maintain ad-hoc raw SQL seed strings that bypass migrations and silently drift from the real schema.
|
||||
|
||||
Never mock **collaborators you own**:
|
||||
- Internal modules, domain services, formatters, or validators within the same codebase. If mocking an internal module feels necessary, the interface boundary is in the wrong place.
|
||||
|
||||
## 3. Shaping Interfaces for Clean Boundary Doubles
|
||||
|
||||
1. **Inject external dependencies explicitly**: Pass clocks, HTTP adapters, or external clients into functions/constructors rather than instantiating globals or reading environment variables inside domain logic.
|
||||
2. **Use operation-specific adapter methods**: Prefer typed boundary methods (`api.getSession(id)`, `api.checkInAttendee(id)`) over a single generic `fetch(url, options)` mock. Operation-specific methods let each test stub one explicit response without reimplementing URL routing conditionals inside test setup.
|
||||
@@ -0,0 +1,43 @@
|
||||
# Test Quality and Anti-Patterns
|
||||
|
||||
Reference for `tdd`. Keeps red-to-green cycles anchored to observable behavior, independent truth, and real failure semantics.
|
||||
|
||||
Derived and adapted from Matt Pocock's `tdd` skill (`github.com/mattpocock/skills`), combined with empirical state-reconciliation and input-safety lessons.
|
||||
|
||||
## 1. Four Test Anti-Patterns to Reject
|
||||
|
||||
### A. Implementation-Coupled Tests
|
||||
- **Smell**: Asserting `toHaveBeenCalledWith` on internal helpers, testing private functions, or verifying state through a side channel (raw table query) when a public read interface exists.
|
||||
- **Tell**: The test breaks during an internal refactor even though caller-observable behavior is unchanged.
|
||||
- **Fix**: Act through the public write seam and assert through the public read seam or rendered output.
|
||||
|
||||
### B. Tautological Assertions
|
||||
- **Smell**: Recomputing the expected value with the same logic as production code, asserting a constant equals itself, or mocking a boundary to return `X` and only asserting `result == X`.
|
||||
- **Tell**: A bug in the formula or contract would change both the code and the expected expression identically, keeping the test green.
|
||||
- **Fix**: Use concrete literals, worked domain examples, or specification tables as an independent source of truth.
|
||||
|
||||
```python
|
||||
# BAD: Recomputes expected value using the same arithmetic
|
||||
def test_calculate_total():
|
||||
items = [Item(price=10), Item(price=5)]
|
||||
assert calculate_total(items) == sum(i.price for i in items)
|
||||
|
||||
# GOOD: Independent literal from worked example
|
||||
def test_calculate_total_sums_item_prices():
|
||||
assert calculate_total([Item(price=10), Item(price=5)]) == 15
|
||||
```
|
||||
|
||||
### C. Optimistic Local-State Illusions
|
||||
- **Smell**: Testing conflict or error recovery (such as HTTP `409 Conflict`) by asserting only that the clicked row changed locally, ignoring sibling records or aggregate counters that changed out-of-band on the server.
|
||||
- **Fix**: Simulate authoritative server state where multiple records diverged out-of-band, and assert that both item state and aggregate counters reconcile with the authoritative read.
|
||||
|
||||
### D. Premature Horizontal Batching
|
||||
- **Smell**: Writing twenty parameterized tests upfront against an imagined interface before one vertical slice works end-to-end.
|
||||
- **Fix**: Drive one tracer-bullet test from Red to Green first so the real contract settles. Once the vertical slice works, batch independent boundary/edge cases (`pytest.mark.parametrize`, `test.each`, Rust table slices) where they clarify the contract without padding test count.
|
||||
|
||||
## 2. Negative and Defensive Slices Worth Adding
|
||||
|
||||
After the primary capability turns green, add focused red-to-green tests for the failure modes present in the slice:
|
||||
- **Conflict and retry paths**: Duplicate submissions, `409` responses, network errors, and idempotent retries.
|
||||
- **Untrusted input boundaries**: Special characters or HTML payloads (`<img src=x onerror=...>`) rendered safely as literal text rather than executable markup.
|
||||
- **Empty and boundary values**: Zero items, maximum capacity limits, missing optional fields, and unauthorized callers.
|
||||
Reference in new issue
Block a user