Use when modifying, removing, or refactoring code that lacks test coverage. Emphasizes the danger of untested changes and the RGR workflow to add characterization tests before modifications.
View on GitHubSelect agents to install to:
npx add-skill https://github.com/TheBushidoCollective/han/blob/main/core/skills/legacy-code-safety/SKILL.md -a claude-code --skill legacy-code-safetyInstallation paths:
.claude/skills/legacy-code-safety/# Legacy Code Safety > "Changing untested code is like performing surgery blindfolded." ## DANGER: The Risk of Modifying Untested Code **Modifying code without tests is one of the HIGHEST-RISK activities in software development.** When you change untested code: - You CANNOT know what behaviors you're breaking - You have NO safety net to catch mistakes - You're relying on hope instead of evidence - You're creating technical debt on top of technical debt **In dynamically-typed languages (Python, JavaScript, Ruby, PHP), this risk is EXPONENTIALLY higher:** - No compiler to catch type errors - No static analysis to verify correctness - Tests are your ONLY safety mechanism - Runtime is when you discover your mistakes ## The Golden Rule **NEVER modify untested code without adding tests first.** If code lacks tests: 1. STOP 2. Add characterization tests 3. Verify tests pass 4. THEN make your changes ## The RGR Workflow for Legacy Code This is NOT standard TDD. This is **characterization testing** - capturing current behavior before changing it. ### Standard TDD (New Features) 1. RED: Write failing test for NEW behavior 2. GREEN: Implement to make test pass 3. REFACTOR: Clean up implementation ### Legacy Code RGR (Existing Code) 1. RED: Write test that SHOULD pass (captures current behavior) 2. GREEN: Verify it passes (confirms you captured reality correctly) 3. REFACTOR: NOW you can safely modify with a safety net ### The Critical Difference **TDD:** You know what the behavior SHOULD be, write test for ideal **Legacy RGR:** You DON'T know all behaviors, capture what EXISTS ### Why "RED" for Passing Tests? The "RED" step means "you're in the red zone" - working with dangerous untested code. Even though you expect the test to pass, you're at risk until you have that passing test as proof. ## Characterization Testing Process ### Step 1: Identify All Behaviors Before writing tests, understand what the code currently does: ```typescript // Legacy funct