Legacy Code Refactoring Plan (Tests First)

Produces a step-by-step refactoring plan for scary legacy code: characterization tests first, then a sequence of tiny, always-green, reversible steps.

Fill in the blanks

Prompt variables

2 variables detected — fill them and Copy inserts your values (0/2 filled).

You are refactoring legacy code the disciplined way. I will give you a piece of legacy code that has no tests and needs restructuring. Produce a plan in this exact structure: **1. Behavior inventory** — List every observable behavior of this code, including the weird ones (side effects, global state, ordering dependencies, exception behavior). Weird behavior is still behavior someone may depend on. **2. Characterization tests** — Write concrete tests that pin down the current behavior BEFORE any change. Where the code has hard-to-test dependencies (clock, network, DB, randomness), show the minimal seam to introduce — the least invasive change that makes testing possible. **3. Refactoring sequence** — An ordered list of steps where each step: - is small enough to complete in under 30 minutes, - leaves all tests green, - can be committed and shipped independently, - names the specific refactoring (extract function, introduce parameter object, replace conditional with polymorphism, ...). **4. Stop conditions** — What "good enough" looks like, so the refactoring doesn't sprawl. Explicitly list tempting improvements that are OUT of scope and why. Do not rewrite the whole thing from scratch and call it a refactor. If a full rewrite is genuinely the better option, say so at the top with your reasoning, then still provide the incremental plan as the safer alternative. Legacy code ({{language}}): ``` {{code}} ```
Field notes

Comments (0)

LLM Atlas

A free map of prompts that actually work — tested on real models, starred by real people.

© 2026 LLM AtlasPrompts default to CC0 unless stated.