Skip to content

date: 2026-06-13 tags: [testing, mutation, committed-fixtures, file-io] status: active graduated_to:

A test that deletes a committed file must restore it in finally, not a trailing statement

Symptomharness-dashboard/data/harness-config.json (a committed input) went missing from the branch, and a WIP git add -A then committed its deletion.

Root causeExportHarnessConfigTest deleted the committed file, ran the export, asserted, then restored it as the last statement. Under pest --mutate, a mutation that breaks the export makes assertSuccessful() throw before the restore runs, leaving the file deleted on disk — and any later git add -A commits that deletion.

Fix — capture the original first, then wrap delete→assert in try { … } finally { File::put($default, $original); }. See tests/Feature/ExportHarnessConfigTest.php:29 (PR #499).

Guard — convention: any test that deletes or mutates a committed file restores it in a finally, never a trailing statement — an assertion (and especially mutation testing) can short-circuit the restore. Candidate for .claude/rules/testing.md if it recurs.