Strict Test-Driven Development enforcer with Red-Green-Refactor workflow automation. Auto-detects frameworks, validates semantic test failures, and blocks production code until tests fail properly...
Strict Red-Green-Refactor workflow enforcement with automated validation.
This skill acts as a TDD workflow state machine that enforces discipline through validators. It prevents common TDD anti-patterns and ensures proper test-first development.
# Start TDD for a new feature
/sc:tdd "add user password validation"
# TDD with specific framework
/sc:tdd payment-module --framework pytest
# Fast mode (skip full suite after green, run at end)
/sc:tdd api-endpoint --fast
# Allow snapshot tests
/sc:tdd ui-component --allow-snapshots
This skill enforces a 7-step Red-Green-Refactor cycle:
IDLE → RED_PENDING → RED_CONFIRMED → GREEN_PENDING →
GREEN_CONFIRMED → REFACTOR_PENDING → REFACTOR_COMPLETE → [cycle repeats]
Critical Rules:
When: User requests TDD workflow
Your Actions:
python .claude/skills/sc-tdd/scripts/framework_detector.py \
--detect-scope $(pwd) \
--json
python .claude/skills/sc-tdd/scripts/tdd_state_machine.py \
--scope-root <detected_scope> \
--init \
--json
python .claude/skills/sc-tdd/scripts/tdd_state_machine.py \
--scope-root <scope> \
--phase RED_PENDING \
--evidence "User requested: <feature_description>" \
--json
Output: Confirm initialization, explain RED phase rules to user
Rules:
pass, raise NotImplementedError, empty functions)Your Actions:
CRITICAL: You MUST run this validator before proceeding.
Command:
python .claude/skills/sc-tdd/scripts/validate_red.py \
--scope-root <scope> \
--json
Interpretation:
"allowed": true → Proceed to RED_CONFIRMED"allowed": false → STOP, show user reasons, ask them to fixCommon Blocking Reasons:
"Test failed but NOT with semantic assertion" - Compile error, need to fix test"Test PASSED (expected failure)" - Test not actually testing the feature"No changed test files found" - Forgot to write testIf Blocked: Show user the reasons array, artifacts.test_output, and ask them to address the issue. DO NOT propose production code until validator allows.
If Allowed: Store artifacts.intent_test information, transition state, proceed to GREEN phase.
Rules:
Your Actions:
python .claude/skills/sc-tdd/scripts/tdd_state_machine.py \
--scope-root <scope> \
--phase GREEN_PENDING \
--evidence "Implemented: <description>" \
--json
CRITICAL: You MUST run this validator before claiming success.
Command (standard):
python .claude/skills/sc-tdd/scripts/validate_green.py \
--scope-root <scope> \
--json
Command (fast mode, skips full suite):
python .claude/skills/sc-tdd/scripts/validate_green.py \
--scope-root <scope> \
--skip-full-suite \
--json
Interpretation:
"allowed": true → GREEN_CONFIRMED, proceed to refactor"allowed": false → STOP, implementation insufficientCommon Blocking Reasons:
"Intent test still FAILING" - Implementation didn't make test pass"Full test suite FAILED - REGRESSION DETECTED" - Broke existing testsIf Blocked: Show user the failure details, fix implementation, re-validate.
If Allowed: Celebrate! Test passes, no regressions. Ask user if they want to refactor or complete cycle.
Rules:
Your Actions:
Command:
python .claude/skills/sc-tdd/scripts/validate_green.py \
--scope-root <scope> \
--json
(Same validator, ensures tests still pass)
If Allowed: Cycle complete! Ask user:
| Flag | Type | Default | Description |
|---|---|---|---|
--framework |
string | auto | Test framework: auto, pytest, jest, vitest, go, cargo |
--fast |
bool | false | Skip full suite in GREEN, run only at feature completion |
--allow-snapshots |
bool | false | Allow snapshot tests as semantic failures |
--strict |
bool | false | No stubs allowed in RED (must be pure test-first) |
mcp__pal__codereview - Review test quality and implementationmcp__pal__debug - Investigate unexpected test failuresBlocked by validators:
Warned by validators:
Evaluated on:
Threshold: 70+ score required to mark feature complete
/sc:tdd "add password validation: minimum 8 characters"
# Workflow enforced:
# 1. Initialize state for current directory scope
# 2. User/Claude writes test_password_validation.py:
# def test_password_min_length():
# assert validate_password("short") == False
# assert validate_password("longenough") == True
# 3. Run validate_red.py → confirms test FAILS with AssertionError (no validate_password function)
# 4. Claude implements:
# def validate_password(password: str) -> bool:
# return len(password) >= 8
# 5. Run validate_green.py → confirms test PASSES, full suite GREEN
# 6. Ask user about refactoring
# 7. Feature complete or next cycle
/sc:tdd "fix: user deletion doesn't cascade to posts" --framework pytest
# Workflow:
# 1. Write test exposing bug (test fails showing cascade doesn't work)
# 2. Validate RED (confirms bug exists)
# 3. Fix cascade behavior
# 4. Validate GREEN (confirms bug fixed, no regressions)
cd backend/user-service
/sc:tdd "add email validation"
# Auto-detects:
# - scope_root: backend/user-service (nearest package.json)
# - framework: jest (from package.json devDependencies)
# - Runs tests only in this package scope
Solution:
--framework pytestCause: Compile error, import error, syntax error
Solution:
def my_function(): raise NotImplementedErrorSolution:
--fast mode for faster cyclesCause: More than one test file modified (TDD requires focus)
Solution:
If state file is lost or corrupted:
python tdd_state_machine.py --init --scope-root <path>"allowed" field in JSONVersion: 1.0.0 Last Updated: 2025-01-09 Maintainer: SuperClaude Framework