Legacy Code — Junior¶
Find the smallest observable behavior around the requested change. Run the existing tests, reproduce the current result, and add a characterization test that records it.
sequenceDiagram
Test->>Legacy: known input
Legacy-->>Test: current output
Note over Test: capture behavior before editing
Developer->>Legacy: minimal change
Test->>Legacy: old and new cases
Legacy-->>Test: verified behavior
Characterization tests do not declare existing behavior correct. They reveal accidental changes. Keep the production edit narrow and separate naming or extraction steps when possible.
Test yourself¶
- What does a characterization test prove?
- Which current “bug” might be a caller dependency?
- Why separate structural and behavioral edits?
- What is the smallest safe observation point?
Continue to middle.md.