From 914139abb1198dec43574d6096d2d02311a49698 Mon Sep 17 00:00:00 2001 From: Baiheng Xie <874256269@qq.com> Date: Wed, 4 Feb 2026 15:48:30 +0800 Subject: [PATCH 1/2] feat: add guide for test-driven development workflow with agent orchestration --- .claude/commands/tdd.md | 82 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 .claude/commands/tdd.md diff --git a/.claude/commands/tdd.md b/.claude/commands/tdd.md new file mode 100644 index 0000000..d0dcbd3 --- /dev/null +++ b/.claude/commands/tdd.md @@ -0,0 +1,82 @@ +Guide test-driven development through RED → GREEN → REFACTOR cycle with agent orchestration. + +Reference `pytest-patterns` skill for testing conventions. + +Task: $ARGUMENTS + +## Workflow + +### Phase 1: RED (Write Failing Test) + +1. **Understand requirement** from task description +2. **Find test location**: + - Search existing tests in `tests/` directory + - Match structure: `src/foo/bar.py` → `tests/foo/test_bar.py` +3. **Write test that fails**: + - Test behavior, not implementation + - Use descriptive test names + - Follow `pytest-patterns` conventions +4. **Run test to verify failure**: + ```bash + uv run pytest path/to/test_file.py::test_name -v + ``` + +### Phase 2: GREEN (Minimal Implementation) + +**For complex implementations** (multi-file changes, architectural decisions, unclear scope): +- Use the `planner` agent to create implementation plan +- Follow the plan to implement minimal code + +**For simple implementations** (single function, obvious change): +- Implement minimal code directly + +**Verify test passes**: +```bash +uv run pytest path/to/test_file.py::test_name -v +``` + +### Phase 3: REFACTOR (Improve Code) + +1. **Use `refactor-cleaner` agent** to identify: + - Dead code to remove + - Duplicated logic to consolidate + - Cleanup opportunities + +2. **Apply refactorings** while keeping tests green: + ```bash + uv run pytest path/to/test_file.py -v + ``` + +3. **Verify coverage**: + ```bash + uv run pytest path/to/test_file.py --cov=src/module/being/tested --cov-report=term-missing + ``` + +### Phase 4: REVIEW (Quality Check) + +**Use `code-reviewer` agent** to verify: +- Security concerns +- Code quality +- Test coverage adequacy +- Adherence to project patterns + +## Agent Usage + +- **planner**: Complex implementations in GREEN phase +- **refactor-cleaner**: Cleanup in REFACTOR phase +- **code-reviewer**: Final quality check in REVIEW phase + +## Guidelines + +- One behavior per test +- Self-contained test setup +- Clear assertion messages with context +- Tests < 1 second (mark slow tests with `@pytest.mark.integration`) +- Create test/implementation files following project structure if they don't exist + +## Output + +- Show test run results +- Report coverage percentage +- Indicate active phase (RED/GREEN/REFACTOR/REVIEW) +- Show agent outputs when used From 1c897a17fddb5ab5775c8ab983d627b62e2cf7f8 Mon Sep 17 00:00:00 2001 From: Baiheng Xie <874256269@qq.com> Date: Wed, 4 Feb 2026 15:53:48 +0800 Subject: [PATCH 2/2] refactor: split verbose command --- .claude/commands/tdd.md | 81 +--------------------------- .claude/skills/tdd-workflow/SKILL.md | 68 +++++++++++++++++++++++ 2 files changed, 70 insertions(+), 79 deletions(-) create mode 100644 .claude/skills/tdd-workflow/SKILL.md diff --git a/.claude/commands/tdd.md b/.claude/commands/tdd.md index d0dcbd3..1d96907 100644 --- a/.claude/commands/tdd.md +++ b/.claude/commands/tdd.md @@ -1,82 +1,5 @@ -Guide test-driven development through RED → GREEN → REFACTOR cycle with agent orchestration. +Guide test-driven development through RED → GREEN → REFACTOR → REVIEW cycle. -Reference `pytest-patterns` skill for testing conventions. +Reference `pytest-patterns` and `tdd-workflow` skills. Use `planner` agent for complex implementations, `refactor-cleaner` agent for cleanup, `code-reviewer` agent for final review. Task: $ARGUMENTS - -## Workflow - -### Phase 1: RED (Write Failing Test) - -1. **Understand requirement** from task description -2. **Find test location**: - - Search existing tests in `tests/` directory - - Match structure: `src/foo/bar.py` → `tests/foo/test_bar.py` -3. **Write test that fails**: - - Test behavior, not implementation - - Use descriptive test names - - Follow `pytest-patterns` conventions -4. **Run test to verify failure**: - ```bash - uv run pytest path/to/test_file.py::test_name -v - ``` - -### Phase 2: GREEN (Minimal Implementation) - -**For complex implementations** (multi-file changes, architectural decisions, unclear scope): -- Use the `planner` agent to create implementation plan -- Follow the plan to implement minimal code - -**For simple implementations** (single function, obvious change): -- Implement minimal code directly - -**Verify test passes**: -```bash -uv run pytest path/to/test_file.py::test_name -v -``` - -### Phase 3: REFACTOR (Improve Code) - -1. **Use `refactor-cleaner` agent** to identify: - - Dead code to remove - - Duplicated logic to consolidate - - Cleanup opportunities - -2. **Apply refactorings** while keeping tests green: - ```bash - uv run pytest path/to/test_file.py -v - ``` - -3. **Verify coverage**: - ```bash - uv run pytest path/to/test_file.py --cov=src/module/being/tested --cov-report=term-missing - ``` - -### Phase 4: REVIEW (Quality Check) - -**Use `code-reviewer` agent** to verify: -- Security concerns -- Code quality -- Test coverage adequacy -- Adherence to project patterns - -## Agent Usage - -- **planner**: Complex implementations in GREEN phase -- **refactor-cleaner**: Cleanup in REFACTOR phase -- **code-reviewer**: Final quality check in REVIEW phase - -## Guidelines - -- One behavior per test -- Self-contained test setup -- Clear assertion messages with context -- Tests < 1 second (mark slow tests with `@pytest.mark.integration`) -- Create test/implementation files following project structure if they don't exist - -## Output - -- Show test run results -- Report coverage percentage -- Indicate active phase (RED/GREEN/REFACTOR/REVIEW) -- Show agent outputs when used diff --git a/.claude/skills/tdd-workflow/SKILL.md b/.claude/skills/tdd-workflow/SKILL.md new file mode 100644 index 0000000..995f365 --- /dev/null +++ b/.claude/skills/tdd-workflow/SKILL.md @@ -0,0 +1,68 @@ +--- +name: tdd-workflow +description: TDD cycle phases (RED → GREEN → REFACTOR → REVIEW) and agent orchestration +--- + +# TDD Workflow + +## Phases + +### Phase 1: RED (Write Failing Test) + +1. **Understand requirement** from task description +2. **Find test location**: + - Search existing tests in `tests/` directory + - Match structure: `src/server/auth.py` → `tests/server/test_auth.py` +3. **Write test that fails**: + - Test behavior, not implementation + - Use descriptive test names + - Follow `pytest-patterns` conventions +4. **Run test to verify failure**: + ```bash + uv run pytest path/to/test_file.py::test_name -v + ``` + +### Phase 2: GREEN (Minimal Implementation) + +**For complex implementations** (multi-file changes, architectural decisions, unclear scope): +- Use the `planner` agent to create implementation plan +- Follow the plan to implement minimal code + +**For simple implementations** (single function, obvious change): +- Implement minimal code directly + +**Verify test passes**: +```bash +uv run pytest path/to/test_file.py::test_name -v +``` + +### Phase 3: REFACTOR (Improve Code) + +1. **Use `refactor-cleaner` agent** to identify: + - Dead code to remove + - Duplicated logic to consolidate + - Cleanup opportunities + +2. **Apply refactorings** while keeping tests green: + ```bash + uv run pytest path/to/test_file.py -v + ``` + +3. **Verify coverage**: + ```bash + uv run pytest path/to/test_file.py --cov=src/module/being/tested --cov-report=term-missing + ``` + +### Phase 4: REVIEW (Quality Check) + +**Use `code-reviewer` agent** to verify: +- Security concerns +- Code quality +- Test coverage adequacy +- Adherence to project patterns + +## Agent Orchestration + +- **planner**: Complex implementations in GREEN phase +- **refactor-cleaner**: Cleanup in REFACTOR phase +- **code-reviewer**: Final quality check in REVIEW phase