<!-- textlint-disable ja-technical-writing/no-exclamation-question-mark -->
Implements BDD tests using append-first principle and RED-GREEN-REFACTOR cycle.
/plugin marketplace add aglabo/deckrd/plugin install bdd-coder@deckrdReference this template when implementing tests for bdd-coder tasks.
# BDD Implementation Task
## Task Summary
[Brief description of feature/functionality to implement]
## Requirements
- [Requirement 1]
- [Requirement 2]
- [Requirement 3]
## Implementation Rules
### Append-First Principle
- **First assertion**: Create NEW test case (new describe block)
- **Second and subsequent assertions**: MUST append to existing test
- **Forbidden**: Creating new test block for same Given/When context
- **Reason**: Preserve Given/When semantic context
- **How**: Use `it.each([...])` or add expects to same it block
- **Exception**: Create new test ONLY if Given/When differs, intent changes, or naming becomes unnatural
- **All phases**: This rule applies during implementation AND refactoring
### Assertion Granularity
- One assertion per test case (separate it blocks OR it.each rows)
- Group related assertions (same Given/When) via it.each parameterization
- Each failure must point to one assertion clearly
### RED-GREEN-REFACTOR Cycle
1. **RED**: Write failing test (test code only, NO implementation)
2. **GREEN**: Write minimal implementation to pass test
3. **REFACTOR**: Improve test and code while keeping tests GREEN
## Coverage Categories
Identify assertions across these categories:
- **Normal**: Happy path with valid inputs
- **Invalid**: Type mismatches, null/undefined, wrong formats, out-of-range values
- **Edge cases**: Boundary values, empty collections, special characters
Example breakdown for function `getRawOSPlatform(runtime)`:
- Normal: Windows, macOS, Linux runtime values
- Invalid: number, null, undefined, wrong string values
- Edge: empty string, whitespace, mixed-case strings
## Test Structure Example (TypeScript/Vitest)
```typescript
describe('Given: runtime parameter provided', () => {
describe('When: checking normal values', () => {
describe('Then: Task T01-02 - Detect platform from runtime', () => {
// Append-first pattern: it.each for grouped assertions
it.each<[string, PlatformType]>([
['windows', 'windows'], // Normal case 1
['macos', 'darwin'], // Normal case 2
['linux', 'linux'], // Normal case 3
])('Should: return %s for %s runtime', (input, expected) => {
const result = getRawOSPlatform(input as AGRuntimeType);
expect(result).toBe(expected);
});
});
});
describe('When: checking invalid values', () => {
describe('Then: Task T01-02 - Detect platform from runtime', () => {
// Separate Then block for different When context
it.each<[unknown]>([
[null], // Invalid case 1
[undefined], // Invalid case 2
[123], // Invalid case 3
['invalid'], // Invalid case 4
])('Should: return undefined for invalid input %s', (input) => {
const result = getRawOSPlatform(input as unknown as AGRuntimeType);
expect(result).toBeUndefined();
});
});
});
});
```
Before Starting:
During Implementation:
After All Assertions:
Splitting Tests:
it.each into separate it() blocks if it improves failure clarityit.each([case1, case2, case3]) → three it() under same describeTechnical Debt:
For complete workflow details, see:
<!-- textlint-disable -->.claude/agents/bdd-coder.mdUse this agent when analyzing conversation transcripts to find behaviors worth preventing with hooks. Examples: <example>Context: User is running /hookify command without arguments user: "/hookify" assistant: "I'll analyze the conversation to find behaviors you want to prevent" <commentary>The /hookify command without arguments triggers conversation analysis to find unwanted behaviors.</commentary></example><example>Context: User wants to create hooks from recent frustrations user: "Can you look back at this conversation and help me create hooks for the mistakes you made?" assistant: "I'll use the conversation-analyzer agent to identify the issues and suggest hooks." <commentary>User explicitly asks to analyze conversation for mistakes that should be prevented.</commentary></example>