- Home
- Skills
- Testing & Debugging
- TDD Loop: Red-Green-Refactor in Verified Baby Steps
Works with the AI Agents you already use
TDD Loop: Red-Green-Refactor in Verified Baby Steps
- **Green**: minimum code to pass, whole suite run every cycle, tests never bent to fit the code.
Free
TDD Loop: Red-Green-Refactor in Verified Baby Steps
Example session with this skill installed
Use TDD to add shipping cost calculation to our checkout (TypeScript + Vitest): base 4.90 € up to 1 kg, +1.20 € per extra kg, free from 50 €, international uses a zone table.
- Read your context and instructions
- Compiled the tdd loop
Setup
Detected Vitest 2, src/**/*.spec.ts, builders in test/builders.ts. Baseline: 84 tests green.
Test list
- empty order costs 0
- 1 kg domestic costs 4.90
- 3 kg domestic costs 7.30
- 1.5 kg rounds up to next kg (discovered)
- order ≥ 50 € ships free
- exactly 50 € ships free (boundary)
- international uses zone table
- unknown country throws UnsupportedDestinationError
- negative weight rejected
Cycles
✅ #1 empty order costs 0 - red (expected undefined to be 0) → green → refactor (85 tests, 0.6s)
✅ #2 1 kg domestic 4.90 - hard-coded return 4.9
✅ #3 3 kg domestic 7.30 - triangulation forced the formula BASE + max(0, kg-1) * PER_KG
✅ #4 1.5 kg rounds up - new item found during #3; Math.ceil
✅ #5/#6 free shipping ≥ 50 € incl. boundary - first attempt used >; boundary test caught it
✅ #7 zone table - extracted ZONES constant in refactor step
✅ #8 unknown country throws typed error
✅ #9 negative weight rejected
export function calculateShipping({ total, weightKg, country }: Order): number {
if (weightKg < 0) throw new RangeError('weightKg must be >= 0')
if (weightKg === 0) return 0
if (total >= FREE_FROM) return 0
const zone = zoneFor(country) // throws UnsupportedDestinationError
return round2(zone.base + Math.max(0, Math.ceil(weightKg) - 1) * zone.perKg)
}
Done
- 9 new tests, suite 93/93 green (0.9s), no
.only/skips tsc --noEmitand eslint clean- Commits: 9 cycles as
test:/feat:/refactor:
Question: should free shipping also apply to international orders? Currently yes - add a test if you want it domestic-only.
Connects securely to your tools. The creator never sees your data.
About this skill
Stop letting your agent write code first and "tests" later
Agents love to write 300 lines of code and then tests that just confirm what the code does. TDD Loop enforces real test-driven development, so every line exists because a test needed it.
What it does
- Setup: detects your test framework, runner, naming and mocking conventions; runs the suite to get a green baseline.
- Test list as the plan: turns the request into small behaviours ordered from degenerate case to happy path, boundaries and errors.
- Red: one behaviour-focused test at a time, and it must fail for the expected reason (not an import error).
- Green: minimum code to pass, whole suite run every cycle, tests never bent to fit the code.
- Refactor: clean code and tests with everything green.
- Progress log per cycle, optional commit per cycle (
test:/feat:/refactor:). - Bug-fix mode: reproduce with a failing test, minimal fix, root cause in 1-2 lines, regression guard kept.
- Quality rules: deterministic tests (fake clock, no real network), mocks only at boundaries, fakes over deep mocks, baby steps with revert when a cycle grows too big.
- Done means done: list empty, suite green, no
.only/skipped tests, lint and typecheck clean.
Includes
- SKILL.md workflow
- references/test-list.md - how to order behaviours, with an example
- references/test-quality.md - good tests in TS/Python, smells and fixes, test doubles, runner commands for 7 ecosystems
Works with Claude Code, Codex, Cursor, Copilot, Gemini CLI and any SKILL.md-compatible agent.
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Testing & Debugging.
Cycles exceeding 10 minutes trigger a revert to smaller steps. Deep mocking of the unit under test is avoided. Requires an existing test runner configuration.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
This skill has been used 10 times.
Trust & safety
Security scan
Security scan passed 10 days ago
- Free with an Agensi account
- Software
- vitest
Node.jsjest
Permissions
No special permissions declared or detected