Codex 為既有程式補測試:鎖住現有行為、專攻邊界、零行為改動
讓 Codex 為一段沒有測試的既有程式碼補上特徵化測試(characterization tests):先讀懂並記錄它『現在實際的行為』(含 bug 也照鎖),系統性覆蓋正常路徑+邊界+錯誤路徑,且絕對不修改被測程式。
替沒測試的舊程式補測試網。重點不是『它該怎樣』而是『它現在實際怎樣』——把當前行為(含怪癖)鎖成測試,專打 null/空/邊界/錯誤路徑,一行都不准改原始碼。之後你才敢放心重構。
[ Log in to see the full prompt ]Sign up free to see the full prompt, copy it, save it, and join the discussion. Free content unlocks on login; Pro content is a separate subscription.
何時用:接手 legacy code、準備重構前、或某模組『不敢動因為沒測試』時。為何有效:特徵化測試的精髓是『鎖現狀、不鎖理想』——很多 AI 會自作主張寫『它應該回傳 X』結果測試一跑就紅。這個 prompt 三度強調『assert 實際輸出、不是你以為的輸出』,連 bug 都照鎖(加 NOTE 註解留給人決定),並硬性禁止改被測程式+要求貼測試通過輸出。如此產出的測試網才真的能在你重構時抓回歸。技巧:在 Codex 用 workspace-write 沙箱讓它能實際跑 code 取得真值再 assert;它最後會列『故意沒覆蓋的缺口』和『疑似 bug(沒修)』,這兩份清單本身就很有價值。
// src/pricing.test.ts — characterization tests for calcTax() test('applies 5% for standard rate', () => expect(calcTax(100,'std')).toBe(105)) test('returns input unchanged for unknown rate code', () => expect(calcTax(100,'???')).toBe(100)) // NOTE: current behavior may be a bug — locked for now test('negative amount yields negative tax (not clamped)', () => expect(calcTax(-100,'std')).toBe(-105)) test('throws on null amount', () => expect(() => calcTax(null,'std')).toThrow(TypeError)) $ vitest run src/pricing.test.ts ✓ 4 passed Suspected bugs (not fixed): 負數金額未夾零、未知 rate code 靜默回傳原值不報錯。 Coverage gaps left: 未測 currency rounding(需 i18n 環境、另案處理)。
Suno Engineer's Mindset: 4 Steps to a Song That Doesn't Sound Like AI
A studio engineer's breakdown of Suno's fatal weaknesses (fried vocals, high-frequency artifacts), plus a 4-step DAW workflow and a Suno Studio cleanup prompt.
5 Claude Weekly Workflows That Stuck After 6 Months
Proposal generator / meeting processor / content repurposer / Friday review / shutdown reset — out of 40 I tried, only these 5 survived, each saving 30+ minutes per run.