From workflow-skills
Execute the red/green TDD workflow: detect test command, capture baseline, write failing tests (RED), confirm failure, implement minimum code (GREEN), confirm all tests pass. Invoke with /red-green-tdd when the user wants to follow a disciplined test-driven development cycle. Do NOT auto-trigger on general test writing requests.
npx claudepluginhub arosenkranz/claude-code-config --plugin workflow-skillsThis skill uses the workspace's default tool permissions.
Enforce the test-driven development ceremony: write failing tests first, verify they fail, then implement the minimum code to make them pass. The value of TDD is in the sequence; skipping RED verification defeats the purpose.
Compares coding agents like Claude Code and Aider on custom YAML-defined codebase tasks using git worktrees, measuring pass rate, cost, time, and consistency.
Designs and optimizes AI agent action spaces, tool definitions, observation formats, error recovery, and context for higher task completion rates.
Designs, implements, and audits WCAG 2.2 AA accessible UIs for Web (ARIA/HTML5), iOS (SwiftUI traits), and Android (Compose semantics). Audits code for compliance gaps.
Enforce the test-driven development ceremony: write failing tests first, verify they fail, then implement the minimum code to make them pass. The value of TDD is in the sequence; skipping RED verification defeats the purpose.
Supported ecosystems (v1): JavaScript/TypeScript (npm/yarn/pnpm/bun + Jest/Vitest) and Python (pytest/tox).
For test patterns (AAA structure, mocking, fixtures), see the automating-tests skill. This skill handles the ceremony, not the patterns.
Detect the test command. Check in this order:
package.json scripts for test, test:unit, test:watchpytest.ini, pyproject.toml [tool.pytest.ini_options], or setup.cfg [tool:pytest]Makefile for a test targettox.ini for a tox configurationIf still ambiguous, ask: "What command runs your tests?" Do NOT guess.
Run the full suite NOW and record baseline failures. Only regressions introduced during this session are blockers. Pre-existing failures are noted and excluded from GREEN phase blocking criteria.
State: "Baseline captured. [N] tests passing, [M] failing pre-existing."
Before writing any tests, confirm:
Ask if unclear. Do not infer scope from filenames alone.
Write tests according to the scenario type:
New module or function (does not exist yet):
Import the symbol that will be created. This guarantees an ImportError (Python) or Cannot find module / ReferenceError (JS/TS), which is the correct RED state for brand-new code.
# Python: import the not-yet-existing module
from mymodule import new_function # will raise ImportError
def test_new_function_happy_path():
assert new_function(2, 3) == 5
// TypeScript: import the not-yet-existing export
import { newFunction } from './new-function'; // will fail at compile/runtime
describe('newFunction', () => {
it('returns sum of two numbers', () => {
expect(newFunction(2, 3)).toBe(5);
});
});
Bug fix or refactor (code already exists): Write an assertion against the current broken behavior or the expected correct behavior that currently fails. Do not write tests that already pass.
Run the test suite and examine the output.
Required before continuing:
ImportError, ModuleNotFoundError, Cannot find module, or similarIf new tests already pass: STOP. Do not proceed. Investigate:
If the failure reason is wrong (e.g., a syntax error in the test file, not the import error expected): Fix the test, re-run to confirm the correct RED state, then continue.
After verifying RED, state explicitly:
"RED confirmed. [N] new tests failing as expected ([describe failure reason]). Ready to begin GREEN phase. Proceeding..."
Do not skip this statement. It is the explicit phase boundary.
Write only the code needed to make the failing tests pass. Do not add functionality not covered by a test. Do not refactor while implementing.
Create the module/function/class at the expected import path if doing new code.
Run the complete test suite (not just the new tests). Compare against the baseline:
If a test fails during GREEN because the spec was wrong (the implementation reveals the test assertion is incorrect):
This loop preserves the TDD contract: tests define the spec, and spec changes are explicit.
When all new tests pass and no new regressions exist:
"GREEN confirmed. [N] new tests passing. No new regressions. Implementation complete."
Ask the user: "Would you like to refactor now that the tests are green?"
If yes:
Refactoring does not change behavior. If a refactor causes a test to fail, the refactor changed behavior and must be reconsidered.
| Situation | Response |
|---|---|
| No test command found | Ask. Do not guess or invent a command. |
| New tests pass before RED | STOP. Investigate before continuing. |
| Wrong failure reason in RED | Fix test, re-run, confirm correct RED state. |
| Existing tests break during GREEN | Compare to baseline. Only new regressions block. |
| User wants to skip RED verification | Decline. Explain: "Verifying RED is what distinguishes TDD from test-after. Without it, tests may not actually be testing the implementation." |
| User wants to write tests after implementation | Explain the trade-off: tests written after may inadvertently mirror the implementation's shape rather than the spec's intent. Offer to retrofit: stub out the implementation to verify tests fail, then restore it. |
| Ambiguous test runner | Always ask. Running the wrong test command produces unreliable results. |
| Import resolves to wrong module | Check __init__.py (Python) or index.ts exports. Trace the import path before concluding. |
| Phase | Action | Success Condition |
|---|---|---|
| PREFLIGHT | Detect test command; run full suite; record baseline | Test command confirmed; baseline count recorded |
| RED | Clarify scope; write tests; run suite | New tests fail for expected reason |
| RED gate | State "RED confirmed" explicitly | Phase boundary acknowledged |
| GREEN | Implement minimum code; run full suite | All new tests pass; no new regressions |
| GREEN gate | State "GREEN confirmed" explicitly | Implementation complete |
| REFACTOR | One change; run tests; revert on failure | All tests still pass after each change |