In plain words
Refactoring changes how code is organised without changing its behaviour, done safely in small steps, each covered by tests and shipped on its own, so any mistake is small and quick to trace.
Where you see it
Harbor's 1,800-line invoice module needs splitting before new tax rules arrive. Instead of one big rewrite, the team adds characterisation tests that pin down today's outputs, then moves one function at a time, each in its own pull request, with the tests green after every step.
What goes wrong
- Refactoring and changing behaviour in one go
When a pull request both moves code and changes the tax rule, a wrong total could come from either. Refactor first and merge, then change behaviour in a separate pull request.
- No tests to catch the slip
Without tests that cover current behaviour, a refactor is a hopeful rewrite. Write characterisation tests first, even for behaviour that looks wrong, and fix that later on purpose.
- Letting the agent tidy everything it touches
Asked to fix one bug, an agent may rename and reorganise a dozen files, and the diff becomes impossible to review. Ask for refactors as separate, named tasks with the scope stated.
What to tell your agent
Quick check
Sign in to earn +10 XP for itYour agent's pull request refactors Harbor's invoice module and also changes how discounts round. A total is now wrong. What should have been done differently?