Make the bug executable before touching production code, so the fix is proven, not claimed.
在修改生产代码之前,先让 Bug 变得可执行,从而证明修复有效,而不是仅声称已修复。
Steps
步骤
Pin down the bug: expected behavior, actual behavior, the code path, and the smallest way to reproduce it.
Find the nearest existing test style for that code path. Use it. Do not build a new harness just for this.
Write the smallest test that would have caught the bug. It checks intended behavior, not the current implementation.
Run it. Show the output. It must fail, and fail for the bug, not for a typo or missing import. If not, fix the test first.
Make the smallest production change that gives the intended behavior without breaking nearby contracts.
Run the new test and the surrounding suite. Show the output.
If a clean test is impractical (heavy setup, brittle mocks, production-only state), use the closest runnable check instead: a script, a repro command or a log check. Say why you skipped the test.