| name | stay-green |
| description | 2-gate TDD development workflow: Gate 1 is Red-Green-Refactor testing, Gate 2 is pre-commit quality checks. Use when implementing features, fixing bugs, or doing any development work. Ensures code is never committed without passing tests and quality checks. Do NOT use for bug-specific debugging (use bug-squashing-methodology). |
| metadata | {"author":"Geoff","version":"1.0.0"} |
Stay Green
Write tests first, then code. Never declare work finished until all checks pass.
Instructions
Gate 1: TDD (Red-Green-Refactor)
-
Red - Write a failing test describing the behavior you want
./scripts/test.sh --all
-
Green - Write just enough code to make the test pass
./scripts/test.sh --all
-
Refactor - Clean up while keeping tests green
./scripts/test.sh --all
Repeat for each small piece of functionality. Write tests incrementally, not all at once.
Gate 2: Pre-Commit Quality Checks
pre-commit run --all-files
When checks fail: read errors, fix issues, run again. Repeat until all green.
Quality checks include: formatting (Black + isort), linting (Ruff), type checking (MyPy), complexity (<=10 per function), security (Bandit), tests with coverage (>=90%), file hygiene.
Work is DONE when:
- All tests pass (Gate 1 complete)
- All pre-commit checks pass (Gate 2 complete)
No exceptions.
Examples
Example 1: Adding a New Function
def test_calculate_cost_from_impressions():
result = calculate_cost(impressions=1000, cpm=5.0)
assert result == 5.0
def calculate_cost(impressions: int, cpm: float) -> float:
return impressions * (cpm / 1000)
Example 2: Fixing a Formatting Failure
$ pre-commit run --all-files
black....Failed
$ ./scripts/format.sh --fix
$ pre-commit run --all-files
Troubleshooting
Error: Coverage below 90%
./scripts/test.sh --all --coverage
Error: Complexity above 10
./scripts/complexity.sh
Error: Type errors from MyPy
./scripts/typecheck.sh