| 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/check-backend.sh --test
frontend/WavelengthWatch/run-tests-individually.sh
-
Green - Write just enough code to make the test pass
-
Refactor - Clean up while keeping tests green
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:
- Backend: Ruff lint + format, Mypy type checking, pytest, bandit security
- Frontend: SwiftFormat formatting
- File hygiene (trailing whitespace, EOF, YAML/JSON/TOML validity)
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 Backend Endpoint
def test_get_phase_returns_expected_fields():
response = client.get("/api/v1/phases/1")
assert response.status_code == 200
assert "name" in response.json()
Example 2: Adding a SwiftUI View
@Test func phaseCard_displaysTitle() {
let card = PhaseCardView(phase: .mock)
#expect(card.title == "Rising")
}
Troubleshooting
Error: Frontend tests fail with simulator issues
frontend/WavelengthWatch/run-tests-individually.sh
Error: Backend type errors from Mypy
scripts/check-backend.sh --type
scripts/check-backend.sh