mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-04-02 23:23:31 +08:00
232 lines
5.7 KiB
Markdown
232 lines
5.7 KiB
Markdown
---
|
|
description: Legacy slash-entry shim for the tdd-workflow skill. Prefer the skill directly.
|
|
---
|
|
|
|
# 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.
|
|
})
|
|
```
|
|
|
|
## 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.
|
|
|
|
## Step 4: Implement Minimal Code (GREEN)
|
|
|
|
```typescript
|
|
// 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
|
|
}
|
|
```
|
|
|
|
## Step 5: Run Tests - Verify PASS
|
|
|
|
```bash
|
|
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!
|
|
|
|
## Step 6: Refactor (IMPROVE)
|
|
|
|
```typescript
|
|
// 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)
|
|
}
|
|
```
|
|
|
|
## Step 7: Verify Tests Still Pass
|
|
|
|
```bash
|
|
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!
|
|
|
|
## Step 8: Check Coverage
|
|
|
|
```bash
|
|
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`
|