Pin a Characterization Suite Before You Accept the First Refactor Diff
说明与用途
构建和维护特征化套件可确保重构更改不会悄悄破坏现有业务合同。
问题
Refactoring a large, poorly tested module with an AI agent can silently break business‑critical contracts because the changes are not validated against real fixtures.
结果
After implementing the workflow, refactor commits no longer introduce hidden regressions; all observable outputs are pinned to real fixtures and verified by CI.
工作流
- Wrap the current public entry point and record outputs from production‑shaped fixtures using a helper script.
- Run the recording command on the untouched revision to ensure stability; if it fails, fix flaky behavior first.
- Promote each recording into a test that asserts the output matches the golden file.
- Add the tests to CI so that any refactor must pass them before merging.
- Iterate: record new cases as needed and keep the suite up to date.
- Use the suite as the merge gate to prevent accidental contract drift.
证据
Record from production-shaped fixtures, not from synthetic rows invented to make the function look pure.
If the second command fails on an untouched revision, you do not yet have a characterization suite.
- 记录日期: 2026-09-21T00:15:23.270Z