2026-10-17

Characterization tests before the rewrite

Feathers' definition of legacy code, plus a 1M-token output window: generate characterization tests, lock the baseline, gate the rewrite.


First posted on LinkedIn, October 17, 2026.

---

In Working Effectively with Legacy Code, Michael Feathers defined legacy code as simply code without tests. After my post earlier this week on how a 1M-token output decode window changes legacy modernization, one of the sharpest pushbacks in the thread called out the ultimate production reality: I'd still gate any one-shot rewrite behind characterization tests. That hits the Catch-22 of enterprise modernization.

No rewrite ships without characterization tests that pin down existing behavior—including the undocumented quirks and load-bearing bugs that downstream systems secretly rely on. But if a 20-year-old module has 15,000 lines of tangled control flow and 0% test coverage, how do you get those characterization tests in the first place?

Generating that characterization suite is actually the single best use case for the 1M decode window, before you ever rewrite a line of legacy code. In production, this happens in three passes:

1 — Generate the Safety Net

Legacy code usually starts at 0% test coverage. On a 128K cap, a model burns 40K+ tokens just reasoning through the tangled control flow and quickly runs out of output budget—leaving you with shallow happy-path coverage and lazy placeholder tests. With a 1M window, the model maps every conditional branch in its thinking phase and emits hundreds of edge-case characterization tests in one unbroken pass.

2 — Lock the Baseline (Run Against Legacy First)

You execute that generated suite against the live legacy system first to record and lock actual golden-master outputs—never trusting an LLM to guess what a 20-year-old routine actually returns on a leap year or null record.

3 — The Gated Rewrite

Once the characterization suite is green on the legacy code, you run the atomic module rewrite in a single pass and gate the merge on passing 100% of those pinned tests. A 1M-long decode window doesn't replace the characterization gate. It solves the cold-start problem of generating a complete test harness for an untested monolith.

If you want to go deeper on this pattern, watch Michael Feathers' talk Legacy Code and AI Coding Assistants, where he explores how AI fits directly into his characterization-testing workflow for safely untangling untested legacy systems.