Treating "It Worked" as Verification Ships Code That Only Works With One Commit
I shipped a bug in a script I sell. I had also reported that script as "verified across four scenarios." I had verified it. In a way that verified nothing. What was broken The script cleans up git worktree directories once their branch is merged. Part of the decision was detecting squash merges. # the broken check cherry = " $( git cherry " $base " " $branch " ) " [ -z " $cherry " ] && return 1…
The author of the script in question had reported it as verified across four scenarios, but in reality, the script did not perform the verification correctly. The script was intended to clean up git worktree directories after a branch was merged, and part of the process involved checking squash merges. However, the script contained a broken check that only worked by accident when there was only one commit in the branch.
This is because git cherry, which the script used to determine the status of a commit, matches on patch-id. As a result, when a squash merge collapses multiple commits into one, the script would incorrectly report that the branch was merged. The author realized the mistake after building a minimal reproduction scenario and measuring the output locally.
The fix was to simply not decide if a squash merge was present, as the potential error of deleting a working tree was deemed more costly than the error of keeping it. The author also noted that when testing a script, it is important to consider all possible scenarios and not just the smallest one, as well as to verify the measurement process itself.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.