Implement a feature using Test-Driven Development (RED-GREEN-REFACTOR).
Module: $ARGUMENTS
TDD Workflow
Phase 1: RED — Write Failing Tests
- •Create test file at
packages/server/src/modules/<module>/__tests__/<feature>.test.ts - •Write test cases that describe the expected behavior:
- •Happy path
- •Edge cases
- •Error cases (domain errors)
- •Run
bun test <test-file>— confirm tests FAIL (this is expected)
Phase 2: GREEN — Implement Minimum Code
- •Write the minimum code to make all tests pass
- •Follow project conventions:
- •Domain entities: pure TypeScript, no Effect
- •Use cases:
Effect.gen(function* () { ... }) - •Ports:
Context.Taginterfaces - •Adapters:
Layer.effectimplementations
- •Run
bun test <test-file>— confirm all tests PASS
Phase 3: REFACTOR — Clean Up
- •Remove duplication
- •Improve naming
- •Ensure Clean Architecture compliance
- •Run
bun test <test-file>— confirm tests still PASS - •Run
bun tsc --noEmit— confirm no type errors
Testing Conventions
- •Use
bun:test(describe,it,expect) - •Test domain logic as pure functions (no Effect needed)
- •Test use cases with mock Layers:
Layer.succeed(MyPort, { ... }) - •Describe behavior, not implementation: "creates a character with valid stats"
- •See
.claude/rules/testing.mdfor full conventions
Output
After completing all phases, report:
- •Tests written (count)
- •Tests passing (count)
- •Files created/modified (list)