* feat(#3028): responsive Markdown separators instead of fixed-width rules Stage banners, checkpoints, completion and error panels used fixed-width runs of box-drawing characters -- a 53-column heavy rule and a 62-column double-line box. Those runs are ordinary text to a Markdown-rendering host, so in a narrower pane they wrap and the border comes apart from the heading it framed. Shipped content now emits an ATX heading for a titled section and a blank-line-delimited --- for a break between sections, both of which adapt to the available width. The same convention is applied to the three code sites that built these strings at runtime: the UAT checkpoint renderer, the milestone-close audit report, and the TDD review checkpoint table. Removing the box also removes its only reason to exist -- the east-asian-width padding helpers that kept its right border aligned (checkpointBoxLine, displayWidth, isWideCodePoint, ZERO_WIDTH_MARK_RE, CHECKPOINT_BOX_WIDTH). RTL directional isolation is unchanged. The convention is specified in gsd-core/references/ui-brand.md and enforced across all shipped content by tests/responsive-separators.test.cjs. Refs #3028 * test(#3028): pin the heading form in checkpoint and audit-report assertions These suites asserted the exact box borders and the 62-column padded banner interior. With the box gone they assert the ### heading form, the --- break and the bolded instruction line, and each now carries a positive assertion that no box character remains -- which is what pins the fix rather than merely tolerating it. Language coverage is converted, not dropped: Japanese, Chinese, Korean, Hindi and Arabic all still assert their rendered banner, and the Arabic case still asserts the RTL directional isolates the box removal must not disturb. Adds a case for a banner longer than the old inner width, which previously produced a ragged border and now has none. Refs #3028 * chore(#3028): acknowledge execute-plan.md growth from the checkpoint display spec The checkpoint_protocol display spec described the drawn box; it now describes the heading, the --- break and the bolded action prompt, which costs 22 bytes (40111 -> 40133, 827 under the cap). Appended to the existing #3370 fragment rather than filed as a new one: a growth ack keys on the bare filename and #3370 already declares execute-plan.md, so a second source naming it would be a hard duplicate-key error. Same supersede-by-append route #3370 took for the spent #2652 fragment. Refs #3028 * docs(#3028): state the load-bearing half of the separator rule, and amend the zh-CN reference Review found three things. The rule as first written demanded a blank line above AND below every ---. Only the one above is load-bearing: it is what stops CommonMark reading the rule as a setext underline for the line above. The one below is cosmetic, because a thematic break is a leaf block. The rule now says that, with the reason, instead of asserting a stricter form the content does not keep. The zh-CN reference had received the mechanical box-to-heading swap but none of the prose behind it: it still claimed a 62-character checkpoint width and still listed --- among forbidden mixed banner styles, so it contradicted the convention it was translating. It now carries the separator section, the setext reasoning, the unconditional-vs-per-runtime rationale and a corrected anti-pattern list, in Chinese. The user guide asserted that a heading is not a degradation anywhere. That is an assertion, not a demonstration. It now says what was actually traded away in a plain terminal, points at the recorded rationale, and invites the report that would justify the capability flag instead. Refs #3028 * chore(#3028): backfill changeset PR number Refs #3028 --------- Co-authored-by: sim <sim@local>
329 lines
10 KiB
Markdown
329 lines
10 KiB
Markdown
<overview>
|
|
TDD is about design quality, not coverage metrics. The red-green-refactor cycle forces you to think about behavior before implementation, producing cleaner interfaces and more testable code.
|
|
|
|
**Principle:** If you can describe the behavior as `expect(fn(input)).toBe(output)` before writing `fn`, TDD improves the result.
|
|
|
|
**Key insight:** TDD work is fundamentally heavier than standard tasks—it requires 2-3 execution cycles (RED → GREEN → REFACTOR), each with file reads, test runs, and potential debugging. TDD features get dedicated plans to ensure full context is available throughout the cycle.
|
|
</overview>
|
|
|
|
<when_to_use_tdd>
|
|
## When TDD Improves Quality
|
|
|
|
**TDD candidates (create a TDD plan):**
|
|
- Business logic with defined inputs/outputs
|
|
- API endpoints with request/response contracts
|
|
- Data transformations, parsing, formatting
|
|
- Validation rules and constraints
|
|
- Algorithms with testable behavior
|
|
- State machines and workflows
|
|
- Utility functions with clear specifications
|
|
|
|
**Skip TDD (use standard plan with `type="auto"` tasks):**
|
|
- UI layout, styling, visual components
|
|
- Configuration changes
|
|
- Glue code connecting existing components
|
|
- One-off scripts and migrations
|
|
- Simple CRUD with no business logic
|
|
- Exploratory prototyping
|
|
|
|
**Heuristic:** Can you write `expect(fn(input)).toBe(output)` before writing `fn`?
|
|
→ Yes: Create a TDD plan
|
|
→ No: Use standard plan, add tests after if needed
|
|
</when_to_use_tdd>
|
|
|
|
<tdd_plan_structure>
|
|
## TDD Plan Structure
|
|
|
|
Each TDD plan implements **one feature** through the full RED-GREEN-REFACTOR cycle.
|
|
|
|
```markdown
|
|
---
|
|
phase: XX-name
|
|
plan: NN
|
|
type: tdd
|
|
---
|
|
|
|
<objective>
|
|
[What feature and why]
|
|
Purpose: [Design benefit of TDD for this feature]
|
|
Output: [Working, tested feature]
|
|
</objective>
|
|
|
|
<context>
|
|
@.planning/PROJECT.md
|
|
@.planning/ROADMAP.md
|
|
@relevant/source/files.ts
|
|
</context>
|
|
|
|
<feature>
|
|
<name>[Feature name]</name>
|
|
<files>[source file, test file]</files>
|
|
<behavior>
|
|
[Expected behavior in testable terms]
|
|
Cases: input → expected output
|
|
</behavior>
|
|
<implementation>[How to implement once tests pass]</implementation>
|
|
</feature>
|
|
|
|
<verification>
|
|
[Test command that proves feature works]
|
|
</verification>
|
|
|
|
<success_criteria>
|
|
- Failing test written and committed
|
|
- Implementation passes test
|
|
- Refactor complete (if needed)
|
|
- All 2-3 commits present
|
|
</success_criteria>
|
|
|
|
<output>
|
|
After completion, create SUMMARY.md with:
|
|
- RED: What test was written, why it failed
|
|
- GREEN: What implementation made it pass
|
|
- REFACTOR: What cleanup was done (if any)
|
|
- Commits: List of commits produced
|
|
</output>
|
|
```
|
|
|
|
**One feature per TDD plan.** If features are trivial enough to batch, they're trivial enough to skip TDD—use a standard plan and add tests after.
|
|
</tdd_plan_structure>
|
|
|
|
<execution_flow>
|
|
## Red-Green-Refactor Cycle
|
|
|
|
**RED - Write failing test:**
|
|
1. Create test file following project conventions
|
|
2. Write test describing expected behavior (from `<behavior>` element)
|
|
3. Run test - it MUST fail
|
|
4. If test passes: feature exists or test is wrong. Investigate.
|
|
5. Commit: `test({phase}-{plan}): add failing test for [feature]`
|
|
|
|
**GREEN - Implement to pass:**
|
|
1. Write minimal code to make test pass
|
|
2. No cleverness, no optimization - just make it work
|
|
3. Run test - it MUST pass
|
|
4. Commit: `feat({phase}-{plan}): implement [feature]`
|
|
|
|
**REFACTOR (if needed):**
|
|
1. Clean up implementation if obvious improvements exist
|
|
2. Run tests - MUST still pass
|
|
3. Only commit if changes made: `refactor({phase}-{plan}): clean up [feature]`
|
|
|
|
**Result:** Each TDD plan produces 2-3 atomic commits.
|
|
</execution_flow>
|
|
|
|
<test_quality>
|
|
## Good Tests vs Bad Tests
|
|
|
|
**Test behavior, not implementation:**
|
|
- Good: "returns formatted date string"
|
|
- Bad: "calls formatDate helper with correct params"
|
|
- Tests should survive refactors
|
|
|
|
**One concept per test:**
|
|
- Good: Separate tests for valid input, empty input, malformed input
|
|
- Bad: Single test checking all edge cases with multiple assertions
|
|
|
|
**Descriptive names:**
|
|
- Good: "should reject empty email", "returns null for invalid ID"
|
|
- Bad: "test1", "handles error", "works correctly"
|
|
|
|
**No implementation details:**
|
|
- Good: Test public API, observable behavior
|
|
- Bad: Mock internals, test private methods, assert on internal state
|
|
</test_quality>
|
|
|
|
<framework_setup>
|
|
## Test Framework Setup (If None Exists)
|
|
|
|
When executing a TDD plan but no test framework is configured, set it up as part of the RED phase:
|
|
|
|
**1. Detect project type:**
|
|
```bash
|
|
# JavaScript/TypeScript
|
|
if [ -f package.json ]; then echo "node"; fi
|
|
|
|
# Python
|
|
if [ -f requirements.txt ] || [ -f pyproject.toml ]; then echo "python"; fi
|
|
|
|
# Go
|
|
if [ -f go.mod ]; then echo "go"; fi
|
|
|
|
# Rust
|
|
if [ -f Cargo.toml ]; then echo "rust"; fi
|
|
```
|
|
|
|
**2. Install minimal framework:**
|
|
| Project | Framework | Install |
|
|
|---------|-----------|---------|
|
|
| Node.js | Jest | `npm install -D jest @types/jest ts-jest` |
|
|
| Node.js (Vite) | Vitest | `npm install -D vitest` |
|
|
| Python | pytest | `pip install pytest` |
|
|
| Go | testing | Built-in |
|
|
| Rust | cargo test | Built-in |
|
|
|
|
**3. Create config if needed:**
|
|
- Jest: `jest.config.js` with ts-jest preset
|
|
- Vitest: `vitest.config.ts` with test globals
|
|
- pytest: `pytest.ini` or `pyproject.toml` section
|
|
|
|
**4. Verify setup:**
|
|
```bash
|
|
# Run empty test suite - should pass with 0 tests
|
|
npm test # Node
|
|
pytest # Python
|
|
go test ./... # Go
|
|
cargo test # Rust
|
|
```
|
|
|
|
**5. Create first test file:**
|
|
Follow project conventions for test location:
|
|
- `*.test.ts` / `*.spec.ts` next to source
|
|
- `__tests__/` directory
|
|
- `tests/` directory at root
|
|
|
|
Framework setup is a one-time cost included in the first TDD plan's RED phase.
|
|
</framework_setup>
|
|
|
|
<error_handling>
|
|
## Error Handling
|
|
|
|
**Test doesn't fail in RED phase:**
|
|
- Feature may already exist - investigate
|
|
- Test may be wrong (not testing what you think)
|
|
- Fix before proceeding
|
|
|
|
**Test doesn't pass in GREEN phase:**
|
|
- Debug implementation
|
|
- Don't skip to refactor
|
|
- Keep iterating until green
|
|
|
|
**Tests fail in REFACTOR phase:**
|
|
- Undo refactor
|
|
- Commit was premature
|
|
- Refactor in smaller steps
|
|
|
|
**Unrelated tests break:**
|
|
- Stop and investigate
|
|
- May indicate coupling issue
|
|
- Fix before proceeding
|
|
</error_handling>
|
|
|
|
<commit_pattern>
|
|
## Commit Pattern for TDD Plans
|
|
|
|
TDD plans produce 2-3 atomic commits (one per phase):
|
|
|
|
```
|
|
test(08-02): add failing test for email validation
|
|
|
|
- Tests valid email formats accepted
|
|
- Tests invalid formats rejected
|
|
- Tests empty input handling
|
|
|
|
feat(08-02): implement email validation
|
|
|
|
- Regex pattern matches RFC 5322
|
|
- Returns boolean for validity
|
|
- Handles edge cases (empty, null)
|
|
|
|
refactor(08-02): extract regex to constant (optional)
|
|
|
|
- Moved pattern to EMAIL_REGEX constant
|
|
- No behavior changes
|
|
- Tests still pass
|
|
```
|
|
|
|
**Comparison with standard plans:**
|
|
- Standard plans: 1 commit per task, 2-4 commits per plan
|
|
- TDD plans: 2-3 commits for single feature
|
|
|
|
Both follow same format: `{type}({phase}-{plan}): {description}`
|
|
|
|
**Benefits:**
|
|
- Each commit independently revertable
|
|
- Git bisect works at commit level
|
|
- Clear history showing TDD discipline
|
|
- Consistent with overall commit strategy
|
|
</commit_pattern>
|
|
|
|
<gate_enforcement>
|
|
## Gate Enforcement Rules
|
|
|
|
When `workflow.tdd_mode` is enabled in config, the RED/GREEN/REFACTOR gate sequence is enforced for all `type: tdd` plans.
|
|
|
|
### Gate Definitions
|
|
|
|
| Gate | Required | Commit Pattern | Validation |
|
|
|------|----------|---------------|------------|
|
|
| RED | Yes | `test({phase}-{plan}): ...` | Test exists AND fails before implementation |
|
|
| GREEN | Yes | `feat({phase}-{plan}): ...` | Test passes after implementation |
|
|
| REFACTOR | No | `refactor({phase}-{plan}): ...` | Tests still pass after cleanup |
|
|
|
|
### Fail-Fast Rules
|
|
|
|
1. **Unexpected GREEN in RED phase:** If the test passes before any implementation code is written, STOP. The feature may already exist or the test is wrong. Investigate before proceeding.
|
|
2. **Missing RED commit:** If no `test(...)` commit precedes the `feat(...)` commit, the TDD discipline was violated. Flag in SUMMARY.md.
|
|
3. **REFACTOR breaks tests:** Undo the refactor immediately. Commit was premature — refactor in smaller steps.
|
|
|
|
### Executor Gate Validation
|
|
|
|
After completing a `type: tdd` plan, the executor validates the git log:
|
|
```bash
|
|
# Check for RED gate commit
|
|
git log --oneline --grep="^test(${PHASE}-${PLAN})" | head -1
|
|
# Check for GREEN gate commit
|
|
git log --oneline --grep="^feat(${PHASE}-${PLAN})" | head -1
|
|
# Check for optional REFACTOR gate commit
|
|
git log --oneline --grep="^refactor(${PHASE}-${PLAN})" | head -1
|
|
```
|
|
|
|
If RED or GREEN gate commits are missing, add a `## TDD Gate Compliance` section to SUMMARY.md with the violation details.
|
|
</gate_enforcement>
|
|
|
|
<end_of_phase_review>
|
|
## End-of-Phase TDD Review Checkpoint
|
|
|
|
When `workflow.tdd_mode` is enabled, the execute-phase orchestrator inserts a collaborative review checkpoint after all waves complete but before phase verification.
|
|
|
|
### Review Checkpoint Format
|
|
|
|
```
|
|
### TDD REVIEW — Phase {X}
|
|
|
|
TDD Plans: {count} | Gate violations: {count}
|
|
|
|
| Plan | RED | GREEN | REFACTOR | Status |
|
|
|------|-----|-------|----------|--------|
|
|
| {id} | ✓ | ✓ | ✓ | Pass |
|
|
| {id} | ✓ | ✗ | — | FAIL |
|
|
|
|
{If violations exist:}
|
|
⚠ Gate violations are advisory — review before advancing.
|
|
```
|
|
|
|
### What the Review Checks
|
|
|
|
1. **Gate sequence:** Each TDD plan has RED → GREEN commits in order
|
|
2. **Test quality:** RED phase tests fail for the right reason (not import errors or syntax)
|
|
3. **Minimal GREEN:** Implementation is minimal — no premature optimization in GREEN phase
|
|
4. **Refactor discipline:** If REFACTOR commit exists, tests still pass
|
|
|
|
This checkpoint is advisory — it does not block phase completion but surfaces TDD discipline issues for human review.
|
|
</end_of_phase_review>
|
|
|
|
<context_budget>
|
|
## Context Budget
|
|
|
|
TDD plans target **~40% context usage** (lower than standard plans' ~50%).
|
|
|
|
Why lower:
|
|
- RED phase: write test, run test, potentially debug why it didn't fail
|
|
- GREEN phase: implement, run test, potentially iterate on failures
|
|
- REFACTOR phase: modify code, run tests, verify no regressions
|
|
|
|
Each phase involves reading files, running commands, analyzing output. The back-and-forth is inherently heavier than linear task execution.
|
|
|
|
Single feature focus ensures full quality throughout the cycle.
|
|
</context_budget>
|