Characterize the Mess First, Then Make One Safe Change
Описание и применение
Пошаговый процесс документирования текущего поведения модуля и создания тестов‑характеризаций, чтобы безопасно рефакторить без нарушения контрактов.
Задача
A small helper module contains hidden state, silent fallbacks, and inconsistent rounding, causing callers to rely on undocumented behavior that unit tests miss.
Результат
The workflow ensures that refactoring a messy helper does not alter existing contracts by first documenting current behavior and then making incremental changes.
Рабочий процесс
- 1. Search repository for all
quoteTotal(call sites and record arguments. - 2. Note hidden coupling such as
setLoyaltyand tests that don't reset it. - 3. Capture one production-shaped input per call site, including missing flags.
- 4. Write an inventory table before writing tests.
- 5. Create characterization tests that assert current results, naming tests after observed behavior.
- 6. Use
afterEachto reset global loyalty state. - 7. Refactor only one small change at a time, guided by the characterization tests.
Доказательства
Characterization tests exist for that gap between a green suite and the behavior callers already shipped.
Global loyalty state leaks across tests when a file forgets to reset it after a run.
- Дата записи: 2026-09-11T14:15:54.646Z