From ecc
Triggers legacy TDD workflow shim delegating to tdd-workflow skill: RED (write failing tests), GREEN (minimal passing code), REFACTOR with explicit checkpoints.
npx claudepluginhub jevonthompsonx/todo.tsx# TDD Command (Legacy Shim) Use this only if you still invoke `/tdd`. The maintained workflow lives in `skills/tdd-workflow/SKILL.md`. ## Canonical Surface - Prefer the `tdd-workflow` skill directly. - Keep this file only as a compatibility entry point. ## Arguments `$ARGUMENTS` ## Delegation Apply the `tdd-workflow` skill. - Stay strict on RED -> GREEN -> REFACTOR. - Keep tests first, coverage explicit, and checkpoint evidence clear. - Use the skill as the maintained TDD body instead of duplicating the playbook here. }) bash npm test lib/liquidity.test.ts FAIL lib/liquidity.test.ts...
/tddEnforces test-driven development workflow: scaffolds interfaces, generates failing tests first, implements minimal passing code, refactors, and ensures 80%+ coverage.
/tddEnforces TDD workflow: scaffolds interfaces, generates failing tests first, implements minimal passing code, refactors, and verifies 80%+ coverage.
/tddEnforces TDD workflow: scaffolds interfaces, generates failing tests first, implements minimal passing code, refactors, and verifies 80%+ coverage.
/tddEnforces test-driven development: scaffolds interfaces, generates failing tests first, implements minimal passing code, refactors, and verifies 80%+ coverage.
/tddEnforces TDD cycle: scaffolds interfaces, writes failing tests (RED), implements minimal passing code (GREEN), refactors while tests pass, verifies 80%+ coverage.
/tddGenerates tests for source files, analyzes coverage gaps, and validates test quality in TDD workflows. Supports generate, coverage, and validate subcommands.
Share bugs, ideas, or general feedback.
Use this only if you still invoke /tdd. The maintained workflow lives in skills/tdd-workflow/SKILL.md.
tdd-workflow skill directly.$ARGUMENTS
Apply the tdd-workflow skill.
## Step 3: Run Tests - Verify FAIL
```bash
npm test lib/liquidity.test.ts
FAIL lib/liquidity.test.ts
✕ should return high score for liquid market (2 ms)
Error: Not implemented
1 test failed, 0 passed
PASS: Tests fail as expected. Ready to implement.
// lib/liquidity.ts
export function calculateLiquidityScore(market: MarketData): number {
// Handle zero volume edge case
if (market.totalVolume === 0) {
return 0
}
// Calculate component scores (0-100 scale)
const volumeScore = Math.min(market.totalVolume / 1000, 100)
const spreadScore = Math.max(100 - (market.bidAskSpread * 1000), 0)
const traderScore = Math.min(market.activeTraders / 10, 100)
// Recent activity bonus
const hoursSinceLastTrade = (Date.now() - market.lastTradeTime.getTime()) / (1000 * 60 * 60)
const recencyScore = Math.max(100 - (hoursSinceLastTrade * 10), 0)
// Weighted average
const score = (
volumeScore * 0.4 +
spreadScore * 0.3 +
traderScore * 0.2 +
recencyScore * 0.1
)
return Math.min(Math.max(score, 0), 100) // Clamp to 0-100
}
npm test lib/liquidity.test.ts
PASS lib/liquidity.test.ts
✓ should return high score for liquid market (3 ms)
✓ should return low score for illiquid market (2 ms)
✓ should handle edge case: zero volume (1 ms)
3 tests passed
PASS: All tests passing!
// lib/liquidity.ts - Refactored with constants and better readability
const WEIGHTS = {
VOLUME: 0.4,
SPREAD: 0.3,
TRADERS: 0.2,
RECENCY: 0.1,
} as const
const SCALE_FACTORS = {
VOLUME: 1000,
SPREAD: 1000,
TRADERS: 10,
RECENCY_PENALTY: 10,
} as const
function clamp(value: number, min: number, max: number): number {
return Math.min(Math.max(value, min), max)
}
export function calculateLiquidityScore(market: MarketData): number {
if (market.totalVolume === 0) return 0
const volumeScore = Math.min(market.totalVolume / SCALE_FACTORS.VOLUME, 100)
const spreadScore = clamp(100 - (market.bidAskSpread * SCALE_FACTORS.SPREAD), 0, 100)
const traderScore = Math.min(market.activeTraders / SCALE_FACTORS.TRADERS, 100)
const hoursSinceLastTrade = (Date.now() - market.lastTradeTime.getTime()) / (1000 * 60 * 60)
const recencyScore = clamp(100 - (hoursSinceLastTrade * SCALE_FACTORS.RECENCY_PENALTY), 0, 100)
const weightedScore =
volumeScore * WEIGHTS.VOLUME +
spreadScore * WEIGHTS.SPREAD +
traderScore * WEIGHTS.TRADERS +
recencyScore * WEIGHTS.RECENCY
return clamp(weightedScore, 0, 100)
}
npm test lib/liquidity.test.ts
PASS lib/liquidity.test.ts
✓ should return high score for liquid market (3 ms)
✓ should return low score for illiquid market (2 ms)
✓ should handle edge case: zero volume (1 ms)
3 tests passed
PASS: Refactoring complete, tests still passing!
npm test -- --coverage lib/liquidity.test.ts
File | % Stmts | % Branch | % Funcs | % Lines
---------------|---------|----------|---------|--------
liquidity.ts | 100 | 100 | 100 | 100
Coverage: 100% PASS: (Target: 80%)
PASS: TDD session complete!
## TDD Best Practices
**DO:**
- PASS: Write the test FIRST, before any implementation
- PASS: Run tests and verify they FAIL before implementing
- PASS: Write minimal code to make tests pass
- PASS: Refactor only after tests are green
- PASS: Add edge cases and error scenarios
- PASS: Aim for 80%+ coverage (100% for critical code)
**DON'T:**
- FAIL: Write implementation before tests
- FAIL: Skip running tests after each change
- FAIL: Write too much code at once
- FAIL: Ignore failing tests
- FAIL: Test implementation details (test behavior)
- FAIL: Mock everything (prefer integration tests)
## Test Types to Include
**Unit Tests** (Function-level):
- Happy path scenarios
- Edge cases (empty, null, max values)
- Error conditions
- Boundary values
**Integration Tests** (Component-level):
- API endpoints
- Database operations
- External service calls
- React components with hooks
**E2E Tests** (use `/e2e` command):
- Critical user flows
- Multi-step processes
- Full stack integration
## Coverage Requirements
- **80% minimum** for all code
- **100% required** for:
- Financial calculations
- Authentication logic
- Security-critical code
- Core business logic
## Important Notes
**MANDATORY**: Tests must be written BEFORE implementation. The TDD cycle is:
1. **RED** - Write failing test
2. **GREEN** - Implement to pass
3. **REFACTOR** - Improve code
Never skip the RED phase. Never write code before tests.
## Integration with Other Commands
- Use `/plan` first to understand what to build
- Use `/tdd` to implement with tests
- Use `/build-fix` if build errors occur
- Use `/code-review` to review implementation
- Use `/test-coverage` to verify coverage
## Related Agents
This command invokes the `tdd-guide` agent provided by ECC.
The related `tdd-workflow` skill is also bundled with ECC.
For manual installs, the source files live at:
- `agents/tdd-guide.md`
- `skills/tdd-workflow/SKILL.md`