Safe Legacy Code Modernization with Golden Master Tests
Safely modernize fragile legacy codebases using Martin Fowler refactoring patterns and characterization tests.
Refactor legacy, untested, or deeply nested code using characterization tests (Golden Master) to guarantee zero behavioral regressions.
Execution Workflow Procedure
Ordered steps the coding agent executes when performing this skill.
Build Characterization Test Safety Net
Write characterization tests that capture the current exact output behavior across wide input matrices before modifying production code.
De-Nest and Apply Guard Clauses
Flatten deep conditional nesting with early returns and guard clauses without changing execution semantics.
Apply Micro-Refactorings
Execute small atomic refactorings (Extract Method, Parameter Object, Strategy Pattern) running characterization tests after each step.
Introduce Strict Types and Pure Functions
Replace magic numbers and mutable variables with strict types, constants, and pure deterministic functions.
Agent Safety Guardrails & Anti-Hallucination Rules
- DO NOT alter business behavior or fix unrelated bugs in the same refactoring pull request.
- DO NOT modify legacy code without a passing characterization test harness.
Expected Output Format
Characterization tests and step-by-step refactored code.
Domain Verification Checks
Example Agent Invocations
Install / Configure This Skill
# Place in .cursorrules or create .cursor/rules/safe-legacy-code-refactor.mdc # Trigger: Whenever you perform safe legacy code modernization with golden master tests --- name: safe-legacy-code-refactor description: Modernize legacy code safely using characterization tests and atomic Martin Fowler refactoring steps. version: 1.2.0 compatibility: [Cursor, Claude Code, Cline, Roo Code, Antigravity] --- # Safe Legacy Code Modernization with Golden Master Tests ## Objective Refactor complex legacy code without introducing regressions by creating characterization tests first and applying atomic refactoring steps. ## Workflow 1. **Characterization Tests**: Write Golden Master tests capturing current outputs across diverse inputs. 2. **Flatten & Guard**: Eliminate nested if-statements using early return guard clauses. 3. **Atomic Refactoring**: Extract methods and introduce design patterns (Strategy, Factory) while keeping tests green.
Need a quick one-time prompt for chat?
Try the Legacy Code Safe Refactoring with Characterization Tests — a lightweight version designed for 1-click copying directly into Claude, ChatGPT, or Cursor chat.
SprintKit Workflow Integrations
Complementary tools and checklists to pair with this agent workflow.
Related Agent Skills
Explore related procedural workflows in this discipline.
God Class & Monolithic Method Decomposition (SOLID)
Decompose monolithic 1,000+ line classes into Single Responsibility components using SOLID design patterns.
Comprehensive Unit Test Suite Generation (AAA Pattern)
Generate mutation-tested unit tests with Arrange-Act-Assert structure, boundary cases, and proper mock boundaries.
Strict TypeScript Type Safety & Soundness Audit
Audit TypeScript code for type safety, type narrowing, generics, mutation traps, and runtime boundary validation.