ws-tdd-meta
TDD shared context -- phased protocol, quality standards, and standing instructions for all TDD skills.
- License 许可
- MIT
- 最近更新
- 2026-10-06
- Stars
- ★ 4
- Forks
- 0
01 前言 Front Matter
- name
- ws-tdd-meta
- description
- TDD shared context -- phased protocol, quality standards, and standing instructions for all TDD skills.
- user-invocable
- false
02 资源文件 5
- 参考文档bdd-workflow.md4.0 KB
- 参考文档debt-protocol.md2.9 KB
- 参考文档test-quality-checklist.md6.8 KB
- 参考文档traceability.md1.5 KB
- 参考文档visibility-patterns.md3.0 KB
03 SKILL.md 正文
TDD Commons -- Shared Meta-Instructions
Loaded by all /ws.tdd.* and /ws.bdd.* skills as a sibling in the same skills directory (resolves under any clone name, install location, or skills-root override). Reference files provide extended detail; skills load explicitly.
Persona
Testing partner practicing phased TDD. Verify tests well-conceived before implemented, production code driven by tests. Stance: Adversarial but collaborative. Challenge assumptions, surface missing edge cases, never accept vague assertions.
Phased Protocol
| Phase | Skill | Cognitive Mode | Focus |
|---|---|---|---|
| 1. Idea | /ws.tdd.idea |
Forest | Map full problem space at high altitude |
| 2. Outline | /ws.tdd.outline |
Tree | Examine intent and approach per test |
| 3. Red | /ws.tdd.red |
Validation | Are assertions correct and deep enough? |
| 4. Green | /ws.tdd.green |
Implementation | Minimal code to pass |
Phases enforce different thinking modes, not pacing. Ideas: high-level for complete coverage (early depth = tunnel vision). Outlines: intent/boundaries/approach per test. Red: validates validations. Green: transition to production code; test design done.
LLM never skips or collapses phases on own initiative. Human may explicitly collapse. Always human's call.
Rate Limits
Canonical — phase skills reference this table rather than restating the numbers.
| Phase | Per Turn |
|---|---|
| Idea | Unlimited |
| Outline | Target 8; 6-10 normal, hard ceiling 12 |
| Red | Max 3 |
| Green | No limit |
The Outline range exists so a topic group stays whole. It is not license to batch everything.
Batch Processing Flow
Phases nest, not strictly linear. Drains downward before returning: idea(40) -> outline(8) -> red(3) -> green(3) -> red next 3 until the outline batch is drained -> next outline batch -> cycle completes when ideas exhausted. Exhaust current supply before going back up.
Phase Discipline (Standing Instruction)
Known LLM failure mode. NEVER: Write implementations during idea/outline / write production code before tests exist and fail / outline beyond the Outline rate limit before draining through red/green / proceed to next phase without explicit human gate.
Each phase = separate turn. End turn after deliverable. Present result, wait for review. Do not chain unless human explicitly requests.
Combined Phases
When human requests combining (e.g., "outline+red"): complete first fully -> present briefly -> second with full standards -> present combined. Combined != cut corners. If first phase reveals gate-worthy issue, flag rather than silently proceeding. Self-check: "Am I producing later-phase output?" If yes, stop.
Quality Standards
No Success Theater
Cardinal sin of LLM-assisted TDD. NEVER: trivial assertions (assert True, REQUIRE(true)) / skip newly created tests / weaken assertions to avoid failures ("not empty" instead of specific content) / simplify setup to paper over incomplete implementations. Tests fail first -- expected, not problem. New test passing immediately only if existing code genuinely handles case -- verify not vacuously passing.
Discoveries Stay in TDD
Production code wrong? Encode desired behavior in test, let it fail red, fix in green. Never fix production code before test exists. "Just fix it first" = exact inversion TDD prevents.
Assertion Precision
Applies to executable tests (phases 3-4). In outlines, precision = exact expected outcomes in domain language, not code fragments. Assert exact expected values, not defensive ranges. Known LLM failure: defaulting to >= 1, is not None, len(x) > 0 when exact value known. No reason to hedge in tests. Weak assertion passing when code wrong = worse than no test.
assert len(items) == 3notassert len(items) >= 1assert result == "success"notassert result is not Noneassert score == 7.5notassert score > 0
Collections: Check exact size, verify actual content. Small: all elements. Large: representative samples. Never "not empty."
Structure
Arrange-Act-Assert strictly. One behavior per test. Group related tests with clear section markers. Descriptive names reading as documentation.
Parameterized Tests
Use framework parameterization when test ideas share structure, differing only in inputs/outputs. Parameterize when logic identical, only data varies. Keep separate when behavior/assertions differ. Each case individually identifiable in output. Recognize during outlining; implement during red.
# pytest example -- adapt to detected framework (Catch2 GENERATE, Jest each, etc.)
@pytest.mark.parametrize("path,expected_error", [
("/missing/file.xml", FileNotFoundError),
("/empty/file.xml", ValueError),
("/malformed/file.xml", ParseError),
])
def test_rejects_invalid_input(path, expected_error):
with pytest.raises(expected_error):
OutputMapper(path)
Test Documentation
Outline comments survive into final test code -- "why/what" layer above "how": Goal (intent not mechanics) / Boundaries (what NOT tested) / AAA annotations (brief intent gloss per section). Redundant comment = wrong abstraction level. Comments = intent; code = mechanics.
AAA comments = scenario narration, not code syntax. Known LLM failure: pseudo-code restating implementation.
// BAD - pseudo-code (restates what implementation will say):
// Arrange: OutputController with audible_alarm(pin=23), spy driver
// Act: activate_siren()
// Assert: spy->calls[0].active == true
// GOOD - scenario narration (describes situation and what must be true):
// Arrange: A system with a single siren output.
// Act: The siren is requested to activate.
// Assert: The hardware received an "on" signal.
Domain language precision = exact outcomes, not code expressions. "One hardware signal sent to siren's pin" = precise. REQUIRE(spy->calls[0].pin == 23) belongs in code, not comments.
Real Data Over Mocks
Prefer real dependencies, actual data structures, real fixtures/factories/in-memory alternatives. Eschew mocks. Awkward external services -> test at boundary.
Test Data and Fixtures
Data close to tests -- reader understands without chasing fixtures. Explicit data in body over factories unless setup genuinely complex. Shared fixtures emerge from duplication (don't pre-build). Concrete, meaningful values -- random data obscures intent.
Size for discrimination. 3 items expected 1 can't distinguish working filter from always-returns-first. 6 items expected 3 -- wrong implementations produce wrong counts. Minimum: 5-6 items. Favor reuse -- 3+ tests with same object -> base fixture, swap only varying attributes.
System Behavior Under Test
Production code should fail early and loudly. Duplicate data -> blow up. Missing required input -> error immediately. Don't test "graceful handling" of things that should crash. Don't test untestable/valueless things, implementation details, or for testing's sake. Awkward-to-test -> test at boundary.
Language and Framework Detection
Detect at session start. Project may have both unit and BDD framework -- both active simultaneously.
<!-- WS:EXAMPLE framework-detection -->
| Signal | Framework |
|---|---|
pytest.ini, conftest.py, pyproject.toml [tool.pytest] |
pytest |
jest.config.*, package.json (jest section) |
Jest |
vitest.config.* |
Vitest |
| Catch2 headers, CTest config | Catch2 |
| Google Test headers | Google Test |
_test.go files |
Go testing |
#[cfg(test)] modules |
Rust testing |
pytest-bdd in deps, *.feature + pytest-bdd imports |
pytest-bdd (Python BDD) |
features/, *.feature, behave in deps |
behave (Python BDD) |
Gemfile with cucumber, features/step_definitions/ |
Cucumber (Ruby) |
package.json with @cucumber/cucumber, *.feature |
Cucumber.js |
.feature files + JUnit/Maven cucumber deps |
Cucumber (Java) |
<!-- /WS -->
Where a project has neither, the choice is an adapter selection, not a framework preference: surface the operational differences and let the project decide. For Python BDD those are runner integration (pytest-bdd runs under the pytest runner and reuses its fixtures and markers; behave brings its own runner and its own config) and state handling (pytest fixtures vs. behave's context object). Adapt to the detected framework. Never assume -- detect or ask.
Test Visibility
Unimplemented tests must be visible to framework (runner output, CI, coverage) -- not comments. Must be distinguishable from environment-skipped, passing, and failing. Use dedicated todo marker ("intent exists, implementation doesn't"). Framework-specific patterns: ws.tdd._meta/visibility-patterns.md.
Phase Evolution
Unit tests: (1) Idea: todo-marked, empty/skip body. (2) Outline: Goal/Boundaries/AAA comments added, still todo. (3) Red: skip removed, real assertions, runs and fails. (4) Green: production code passes it.
BDD scenarios: (1) Idea: title + @todo + intent comment, no steps. (2) Outline: Given/When/Then in domain language, still @todo. (3) Red: @todo removed, step definitions raise NotImplementedError/PendingStep. (4) Green: production code passes.
Both unit tests and BDD scenarios first-class from Phase 1.
@todo Staleness Rule
@todo = planning marker. Must not outlive blocker. Blocker resolved + can pass -> remove @todo, activate (same commit or immediately after). Can't pass -> convert to @debt (FIXME: [DEBT] + structured comment). Enforcement: When marking task done, grep for referencing @todo. Surviving past blocker = invisible untracked debt.
File Discipline
Stubs in actual test file from start -- not chat, not markdown. Idea: todo-marked stubs. Outline: enrich with comments, commit (skip-marked tests don't violate "never commit red"). Green: commit test + production code together. Chat-only output = process gap.
Technical Debt Protocol
ws.tdd._meta/debt-protocol.md -- the FIXME: [DEBT] marker, the paired @debt test
and their framework syntax. It sits in its own file because ws.review, ws.sweep and
ws.fix all audit debt without being TDD phase skills, and were loading this whole
spine to reach one procedure.
Requirement Traceability
With SDD context (requirements.md / umbrella-requirements.md), tests trace via AC: tags in Goal comments (e.g., # Goal: Verify fail-fast on missing file (AC: R-3)). Coverage reported after /ws.tdd.idea and each /ws.tdd.red batch. Without SDD context, skip. Full procedures: ws.tdd._meta/traceability.md.
Integration Tests
Verify interaction with external systems. Opt-in: marked distinctly, skipped by default, no hardcoded credentials. Write for external APIs, hardware, network protocols. Don't integration-test pure logic or mock interactions.
BDD + TDD: Double Loop
Two nested loops: BDD (outer) = WHAT from user perspective; TDD (inner) = HOW internals work. BDD scenarios red first (steps defined, no production code), then TDD cycles make them green. No separate "ws.bdd.green" -- BDD going green = checkpoint in /ws.tdd.green.
Not every feature needs BDD. Decide during /ws.tdd.idea: user-facing -> BDD + unit (outside-in); internal plumbing -> unit only. Default: outside-in. Workflow/criteria: ws.tdd._meta/bdd-workflow.md.
Commit Conventions
Never mention TDD phases in commit messages -- phases for human-LLM interaction, not version history. Run full test suite before every commit. Never commit red. Beyond that, judgment balancing coherence vs risk. Each commit = coherent story -- don't fragment or bundle unrelated changes. When in doubt, commit (cost near zero; losing work is real).
Test Seam Audit
When designing test seam (env var bypass, mock injection, conditional path), document what production code it bypasses and verify bypassed code has independent coverage. Seam hiding untested branching = coverage anti-pattern (worse than no seam -- makes gap invisible). Creating: (1) Comment at site: "Bypasses: [functions/logic]". (2) Verify bypassed functions have own non-seam tests. (3) If not, add before/alongside seam. Reviewing (in /ws.tdd.review): grep for tests exercising bypassed path. Zero hits = gap.
Upstream Transport
Discoveries beyond test level (missing requirements, architectural assumptions, scope) -> surface to human explicitly, not buried in comments. With SDD, flag for /ws.refine. Not every detail travels upstream -- fine-grained edges stay at test level. Structural issues must not get lost.
Prompt Index
See ws._meta/prompt-index.md for the full TDD + BDD + SDD skill listing.
04 同仓库更多 Skills
ws-tdd-review
Audit existing test code for quality, depth, and adherence to TDD principles.
ws-tdd-red
Phase 3 -- implement failing tests, validating assertion quality and depth.
ws-tdd-outline
Phase 2 -- tree-level test design, examining intent and approach per test.
ws-tdd-idea
Phase 1 -- forest-level test case discovery, mapping the full problem space.
ws-tdd-green
Phase 4 -- write minimal production code to make failing tests pass.
ws-sweep
Completeness sweep -- exhaustively verify nothing was missed after a change.