Skip to prompt
Back to marketplace

coding · PromptZap Team

Refactor Without Breaking

Contract-first refactoring: baseline the observable behavior, flag risky spots, write missing tests first — so 'improved' never means 'silently changed'.

Prompt text

Refactor [file/function] to improve [readability / performance / testability — pick one primary goal], with a hard constraint: behavior must not change.

Before touching code:
1. List the current observable behaviors/contracts (inputs → outputs, side effects, error cases) so we have a baseline
2. Propose the refactor plan and explain what changes and what explicitly does NOT change
3. Flag anything where you can't be 100% sure behavior is preserved — call those out as risky rather than silently "improving" them

After refactoring, list what tests I should run (or write) to confirm the baseline behaviors from step 1 still hold. If no tests exist for this code, write them first, before refactoring, so we have a safety net.