Overview
Refactoring fails when it changes behavior while intending to only improve structure, when it replaces one complexity with a different complexity, or when it's done without tests that verify the behavior before and after. A refactoring that passes "looks cleaner" but breaks a downstream consumer has made the code worse, not better. Safe refactoring is test-first, small-step, and behaviorally equivalent.
The Code Refactoring Framework identifies the specific code smell, applies the correct refactoring technique, and verifies behavioral equivalence at each step.