refactor-safely

Plan behavior-preserving legacy code refactoring with characterization tests and incremental patterns.

Updated Sep 10, 2026
One-click install
npx skills add https://github.com/serpro-workshop-fortaleza/sifap-modernization-paula --skill refactor-safely-serpro-workshop-fortaleza
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactor-safely
Source: https://github.com/serpro-workshop-fortaleza/sifap-modernization-paula/tree/main/.github/skills/refactor-safely
Command: npx skills add https://github.com/serpro-workshop-fortaleza/sifap-modernization-paula --skill refactor-safely-serpro-workshop-fortaleza

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Refactoring legacy code without tests is risky: a single change can silently alter behavior in a critical flow. This Skill provides a disciplined workflow for changing legacy code safely, ensuring every transformation preserves observable behavior and remains reversible. ## Core Features & Use Cases - Characterization Tests First: Guides you to lock in current behavior (including quirks and preserved bugs) with golden-file or snapshot tests before touching any code. - Proven Refactoring Patterns: Applies the Strangler Fig pattern for system migrations, the Mikado Method for discovering prerequisites, and Branch by Abstraction for swapping implementations without long-lived branches. - Structured Refactoring Plan: Produces a plan template with safety net, ordered reversible steps, Mikado prerequisites, and one behavior-preserving commit per step. - Use Case: When extracting a payment service from a 29-year-old monolith, use this Skill to characterize the existing behavior, place a facade in front of the legacy code, and migrate traffic incrementally until the old path reaches zero. ## Quick Start Ask the AI to create a safe refactoring plan for extracting a service from legacy code using characterization tests and the Strangler Fig pattern.

Frequently Asked Questions about refactor-safely

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I refactor legacy code that has no tests?

Write characterization tests first that capture the current behavior, including quirks and edge cases, before making any change. Then apply one behavior-preserving transformation at a time, keeping tests green after each step and reverting immediately if they fail.

What is the Strangler Fig pattern for legacy migration?

The Strangler Fig pattern places a facade in front of the old system, routes a small slice of traffic to the new implementation, and grows the new system incrementally. The old implementation is deleted only when its traffic reaches zero.

What is the difference between refactoring and rewriting code?

Refactoring preserves observable behavior with proof from tests, while rewriting changes behavior. If you cannot demonstrate behavior preservation through characterization tests, the change is a rewrite and carries different risk.

When should I use the Mikado Method for refactoring?

Use the Mikado Method when a goal change fails due to hidden dependencies. Attempt the goal, record failures as prerequisites, revert, resolve prerequisites recursively from the leaves, and reach the original goal last.

Why should refactoring commits be separated from behavior changes?

Separating refactoring commits from behavior-changing commits keeps reviews focused and preserves git bisect usefulness. Mixed commits make it impossible to identify which change introduced a regression.