Characterisation tests: the safety net for legacy code
Characterisation tests capture what the system actually does before you change it, so refactoring is checked against reality. You record real inputs and the outputs the legacy code produces today, including its quirks, and turn them into automated tests that fail the moment a change alters behaviour someone depends on.