Implement minimal code to make failing tests pass (GREEN phase of TDD). Write just enough code to pass tests, no more. Use after red-phase when tests are failing.
/plugin marketplace add foolishimp/ai_sdlc_method/plugin install aisdlc-methodology@aisdlcThis skill is limited to using the following tools:
Skill Type: Actuator (TDD Workflow) Purpose: Write minimal code to make failing tests pass (GREEN phase) Prerequisites:
You are in the GREEN phase of TDD (RED → GREEN → REFACTOR).
Your goal is to write MINIMAL code to make the failing tests pass.
Key principle: Write the simplest code that works. Do NOT over-engineer. Refactoring comes later.
Read the test file to understand:
Example:
# tests/auth/test_login.py shows we need:
- login(email: str, password: str) -> LoginResult
- LoginResult with fields: success, user, error
- Email validation (BR-001)
- Password length validation (BR-002)
- Account lockout logic (BR-003)
Follow project conventions:
Python:
tests/auth/test_login.py → src/auth/login.py
tests/services/test_payment.py → src/services/payment.py
TypeScript:
src/auth/login.test.ts → src/auth/login.ts
src/services/payment.test.ts → src/services/payment.ts
Java:
src/test/java/auth/LoginTest.java → src/main/java/auth/Login.java
Write the simplest code that makes tests pass:
# src/auth/login.py
# Implements: <REQ-ID>
# Business Rules: BR-001, BR-002, BR-003
import re
from dataclasses import dataclass
from typing import Optional
from datetime import datetime, timedelta
@dataclass
class LoginResult:
success: bool
user: Optional['User'] = None
error: Optional[str] = None
class User:
def __init__(self, email: str, password_hash: str):
self.email = email
self.password_hash = password_hash
self.failed_attempts = 0
self.locked_until: Optional[datetime] = None
def check_password(self, password: str) -> bool:
# Simplified: In real code, use bcrypt
return self.password_hash == hash_password(password)
# Implements: <REQ-ID>
def login(email: str, password: str) -> LoginResult:
# Implements: BR-001 (email validation)
if not validate_email(email):
return LoginResult(success=False, error="Invalid email format")
# Implements: BR-002 (password minimum length)
if len(password) < 12:
return LoginResult(success=False, error="Password must be at least 12 characters")
# Get user from database (simplified)
user = get_user_by_email(email)
if not user:
return LoginResult(success=False, error="User not found")
# Implements: BR-003 (account lockout)
if user.locked_until and datetime.now() < user.locked_until:
return LoginResult(success=False, error="Account locked. Try again in 15 minutes")
# Check password
if not user.check_password(password):
user.failed_attempts += 1
# Implements: BR-003 (lock after 3 attempts)
if user.failed_attempts >= 3:
user.locked_until = datetime.now() + timedelta(minutes=15)
return LoginResult(success=False, error="Invalid password")
# Success - reset failed attempts
user.failed_attempts = 0
user.locked_until = None
return LoginResult(success=True, user=user)
# Implements: BR-001 (email validation)
def validate_email(email: str) -> bool:
pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
return re.match(pattern, email) is not None
def hash_password(password: str) -> str:
# Simplified: In real code, use bcrypt
return str(hash(password))
def get_user_by_email(email: str) -> Optional[User]:
# Simplified: In real code, query database
# For now, return mock user for testing
return User(email, hash_password("SecurePass123!"))
Key implementation principles:
Run the test suite:
# Python
pytest tests/auth/test_login.py -v
# TypeScript/JavaScript
npm test src/auth/login.test.ts
# Java
mvn test -Dtest=LoginTest
Expected output:
tests/auth/test_login.py::test_login_with_valid_credentials PASSED ✓
tests/auth/test_login.py::test_login_fails_with_invalid_email PASSED ✓
tests/auth/test_login.py::test_login_fails_with_short_password PASSED ✓
tests/auth/test_login.py::test_account_locked_after_3_failed_attempts PASSED ✓
4 tests passed in 0.12s
✅ All tests PASSING! This is what we want in GREEN phase.
⚠️ If tests still FAIL: Fix implementation and retry until all tests pass.
Check coverage:
# Python
pytest --cov=src/auth tests/auth/test_login.py --cov-report=term-missing
# TypeScript
npm test -- --coverage
# Java
mvn test jacoco:report
Expected: Coverage should be high (aim for 80%+ overall, 100% for critical paths).
Create commit with implementation:
git add src/auth/login.py
git commit -m "GREEN: Implement <REQ-ID>
Implement user login functionality with email/password.
Implements:
- <REQ-ID>: User login
- BR-001: Email validation (regex pattern)
- BR-002: Password minimum 12 characters
- BR-003: Account lockout after 3 failed attempts (15min)
Tests: 4 tests passing ✓
Coverage: 95%
"
Commit message format:
GREEN:When you complete the GREEN phase, show:
[GREEN Phase - <REQ-ID>]
Implementation: src/auth/login.py
Code Created:
✓ LoginResult dataclass
✓ User class
✓ login() function (<REQ-ID>)
✓ validate_email() function (BR-001)
✓ hash_password() helper
✓ get_user_by_email() helper
Business Rules Implemented:
✓ BR-001: Email validation (regex)
✓ BR-002: Password minimum 12 characters
✓ BR-003: Account lockout after 3 attempts
Running tests...
tests/auth/test_login.py::test_login_with_valid_credentials PASSED ✓
tests/auth/test_login.py::test_login_fails_with_invalid_email PASSED ✓
tests/auth/test_login.py::test_login_fails_with_short_password PASSED ✓
tests/auth/test_login.py::test_account_locked_after_3_failed_attempts PASSED ✓
Result: 4/4 tests PASSING ✓ (GREEN phase)
Coverage: 95% (38/40 lines covered)
Commit: GREEN: Implement <REQ-ID>
✅ GREEN Phase Complete!
Next: Invoke refactor-phase skill to improve code quality
Before invoking this skill, ensure:
If prerequisites not met:
red-phase skill firstAfter GREEN phase completes:
refactor-phase skill to improve code quality and eliminate tech debt# First implementation (naive, but works)
def login(email: str, password: str) -> LoginResult:
if email == "user@example.com" and password == "SecurePass123!":
return LoginResult(success=True)
return LoginResult(success=False)
Then improve to handle more cases until all tests pass.
Implement code to pass one test at a time:
test_login_with_valid_credentials passtest_login_fails_with_invalid_email passtest_login_fails_with_short_password passtest_account_locked_after_3_failed_attempts passStart with hard-coded values, then generalize:
# Step 1: Hard-coded (passes one test)
def validate_email(email: str) -> bool:
return email == "user@example.com"
# Step 2: Generalize (passes all tests)
def validate_email(email: str) -> bool:
pattern = r'^[a-zA-Z0-9._%+-]+@...'
return re.match(pattern, email) is not None
❌ Over-engineering: Don't add features not tested ❌ Premature optimization: Don't optimize before refactor phase ❌ Perfect code: Don't worry about code quality yet (refactor phase handles this) ❌ Skipping tests: All tests must pass before moving to refactor ❌ Adding untested code: Every line should be tested
✅ Do this instead:
Why minimal implementation?
GREEN phase mantra: "Make it work, then make it right"
Homeostasis Goal:
desired_state:
tests_passing: true
all_requirements_implemented: true
code_coverage: >= 80%
"Excellence or nothing" 🔥
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code, generative art, algorithmic art, flow fields, or particle systems. Create original algorithmic art rather than copying existing artists' work to avoid copyright violations.
Applies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.
Create beautiful visual art in .png and .pdf documents using design philosophy. You should use this skill when the user asks to create a poster, piece of art, design, or other static piece. Create original visual designs, never copying existing artists' work to avoid copyright violations.