From cc10x
Guides TDD implementation with RED-GREEN-REFACTOR cycle, false-RED detection, vertical slicing, and code generation patterns. Loaded by component-builder and bug-investigator.
How this skill is triggered — by the user, by Claude, or both
Slash command
/cc10x:buildingThis skill is limited to the following tools:
The summary Claude sees in its skill listing — used to decide when to auto-load this skill
**Iron Law:** NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST.
Iron Law: NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST.
| Word | Means | Replaces |
|---|---|---|
| red | Failing test (behavioral, not error) | "write a test that fails because the feature is missing" |
| green | Passing test after minimal code | "write just enough code to make the test pass" |
| tight | Fast, deterministic, sub-second feedback loop | "build a quick repro that runs fast and is reliable" |
| deep | Module with small interface, lots hidden inside | "well-abstracted module that hides complexity" |
| shallow | Module with interface as complex as implementation | "thin wrapper that adds complexity without hiding any" |
| seam | Place where a test can attach to exercise real behavior | "test insertion point at a module boundary" |
references/testing-patterns.md — test structure, isolation, namingreferences/test-data-and-mocks.md — mock discipline, test data factoriesreferences/integration-and-live-proof.md — integration test guidance, live verificationCI=true npm test, npx vitest run (NOT npx vitest), CI=true npx jesttimeout 60s npx vitest run if uncertain about CI=truepgrep -f "vitest|jest" || echo "Clean". Kill if found.Write one failing test for the current slice. Run it. Exit 1 = RED achieved.
False-RED guard (CRITICAL): Exit 1 from import/syntax/collection ERROR is NOT a real RED. A genuine RED is a behavioral failure ("X is not a function", "expected 3, received undefined"). Record the observed failure reason verbatim. Fix the harness and re-run if false-RED.
Write the minimum code to pass the test. No extra features, no abstractions for hypothetical futures. No unrelated test breakage. If existing tests break, fix the code not the tests.
Improve code quality while keeping tests green. If tests fail during refactor, revert. Re-run after every refactor step.
Safety-Check Guard (MANDATORY): Never simplify away a safety check during refactoring. Safety checks include:
If a safety check seems unnecessary, verify with a test that proves it's dead code before removing. "Looks redundant" is not sufficient evidence.
Build in thin vertical slices that cross all layers: UI → API → logic → data → test. A horizontal slice (all UI, then all API, then all logic) defers integration risk to the end and produces untestable layers. Each slice should be independently verifiable and shippable.
Before writing code: read 2-3 existing similar components in the repo. Match naming, file structure, export style, test patterns. Follow the project's conventions — don't introduce a new pattern when an existing one works.
LSP before writing: Use LSP to find definitions, references, and type information before writing code that interfaces with existing modules.
If the build scope grows beyond the approved phase — new files not in the plan, new dependencies, API contract changes — emit SCOPE_INCREASES: ["new scope item"] in the contract. The router decides whether to escalate to a full BUILD (with planner + reviewer) or approve the expansion.
Decision Checkpoints (return FAIL when triggered):
| Trigger | Action |
|---|---|
| Changing >3 files not in plan | FAIL with extra files named |
| Choosing between 2+ valid patterns | FAIL with competing options |
| Breaking existing API contract | FAIL with impacted callers |
| Adding dependency not in plan | FAIL with dependency name |
| Touching a later planned phase early | FAIL with skipped phase |
Write minimal diffs. A bug fix doesn't need surrounding cleanup. A one-shot operation doesn't need a helper. Don't add error handling, fallbacks, or validation for scenarios that cannot happen. Trust internal code and framework guarantees. Only validate at system boundaries.
| Excuse | Reality |
|---|---|
| "Too simple to test" | Simple code breaks. Test takes 30 seconds. |
| "I'll write tests after" | "After" never comes. Write the test first — it IS the spec. |
| "It's just a refactor" | Refactors break things. Run the tests before AND after. |
| "The existing tests cover this" | Then your new test will pass immediately — that's a false RED. |
| "I manually tested it" | Manual testing doesn't survive the next refactor or CI run. |
| "Adding tests would slow down delivery" | Debugging untested code takes longer than writing the test. |
| "The framework handles this" | Verify with a test. Framework guarantees have edge cases. |
A tautological test recomputes the expected value the same way the code does — it passes by construction and can never disagree.
// BAD — tautological: recomputes expected value using same logic
const expected = items.reduce((sum, x) => sum + x.value, 0);
expect(calculateTotal(items)).toBe(expected);
// GOOD — expected value comes from an independent source of truth
expect(calculateTotal([{value: 10}, {value: 20}, {value: 30}])).toBe(60);
Rule: Expected values must come from a known-good literal, a worked example, or the spec — never from re-running the same algorithm the code uses.
If coverage-thresholds.json exists, run coverage and compare. Below thresholds → FAIL. If no thresholds file, skip coverage check.
If tests are hard to write, the code is hard to test — fix the code, not the test. Pure functions are easy to test. Side effects are hard. Isolate side effects at boundaries; keep core logic pure.
Behavioral focus: Test what the function DOES, not how it's implemented. "returns the sum" not "calls add() then format()". Implementation tests break on refactor; behavioral tests survive.
Pure HTML/CSS/JS exception: If no test runner exists, TDD evidence may use manual browser verification. Set TDD_RED_EXIT=1, TDD_GREEN_EXIT=0 with manual check evidence.
npx claudepluginhub romiluz13/cc10x --plugin cc10xEnforces the RED-GREEN-REFACTOR loop: write a failing test, see it fail, then minimal code to pass, then refactor. Use when starting new features or bugfixes.
Enforces red-green-refactor TDD cycle with configurable strictness (strict/recommended/off). Use before writing implementation code for any feature or bugfix.
Enforces RED-GREEN-REFACTOR TDD cycle: write a failing test first, then minimal code to pass, then refactor. Use when implementing features or fixing bugs during the implement phase.