From a8ca3ad5fbd17448b74ecc69f5057bc5767b1e3c Mon Sep 17 00:00:00 2001 From: Sisyphus Date: Sat, 3 Jan 2026 10:05:03 +0900 Subject: [PATCH] docs: add TDD section with RED-GREEN-REFACTOR cycle to AGENTS.md (#433) --- AGENTS.md | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/AGENTS.md b/AGENTS.md index 0bcc39e..90efb1a 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -39,6 +39,29 @@ oh-my-opencode/ | Config schema | `src/config/schema.ts` | Run `bun run build:schema` after | | Claude Code compat | `src/features/claude-code-*-loader/` | Command, skill, agent, mcp loaders | +## TDD (Test-Driven Development) + +**MANDATORY for new features and bug fixes.** Follow RED-GREEN-REFACTOR: + +``` +1. RED - Write failing test first (test MUST fail) +2. GREEN - Write MINIMAL code to pass (nothing more) +3. REFACTOR - Clean up while tests stay GREEN +4. REPEAT - Next test case +``` + +| Phase | Action | Verification | +|-------|--------|--------------| +| **RED** | Write test describing expected behavior | `bun test` → FAIL (expected) | +| **GREEN** | Implement minimum code to pass | `bun test` → PASS | +| **REFACTOR** | Improve code quality, remove duplication | `bun test` → PASS (must stay green) | + +**Rules:** +- NEVER write implementation before test +- NEVER delete failing tests to "pass" - fix the code +- One test at a time - don't batch +- Test file naming: `*.test.ts` alongside source + ## CONVENTIONS - **Bun only**: `bun run`, `bun test`, `bunx` (NEVER npm/npx) @@ -46,7 +69,7 @@ oh-my-opencode/ - **Build**: `bun build` (ESM) + `tsc --emitDeclarationOnly` - **Exports**: Barrel pattern in index.ts; explicit named exports for tools/hooks - **Naming**: kebab-case directories, createXXXHook/createXXXTool factories -- **Testing**: BDD comments `#given`, `#when`, `#then` (same as AAA) +- **Testing**: BDD comments `#given`, `#when`, `#then` (same as AAA); TDD workflow (RED-GREEN-REFACTOR) - **Temperature**: 0.1 for code agents, max 0.3 ## ANTI-PATTERNS