From b02813821b08d0d5d000dd9fda3e834f8cf9b380 Mon Sep 17 00:00:00 2001 From: Jeremy Daer Date: Mon, 3 Aug 2026 19:58:16 -0700 Subject: [PATCH] Stop a losing rm -rf race from failing a passing test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit update_nix_flake.bats builds a throwaway git repo per test, and under `bats -j` teardown's `rm -rf` intermittently fails with ENOTEMPTY on .git/objects. bats counts a failing teardown as a failing test, so a green assertion gets reported red — twice in six local bin/ci runs, landing on a different test name each time. ENOTEMPTY says the directory was not empty when rm reached it. It does not say what refilled it, and I have not established that, so the fix goes at the teardown rather than at a presumed cause: retry briefly, then give up quietly. Cleanup should not decide whether a test passed, and a leftover directory under TMPDIR is worth less than a signal people trust. --- e2e/update_nix_flake.bats | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/e2e/update_nix_flake.bats b/e2e/update_nix_flake.bats index a9793697..5140d782 100644 --- a/e2e/update_nix_flake.bats +++ b/e2e/update_nix_flake.bats @@ -38,7 +38,23 @@ NIXPKG } teardown() { - rm -rf "$WORK" + # Cleanup must not decide whether the test passed. Under `bats -j` these tests + # each build a throwaway git repo in $TMPDIR, and on macOS `rm -rf` + # intermittently fails with ENOTEMPTY on .git/objects. bats treats a failing + # teardown as a failing test, so a green assertion was reported red — twice in + # six local runs, landing on a different test name each time. + # + # ENOTEMPTY says the directory was not empty when rm reached it; it does not + # say what refilled it, and that has not been established. Hence a fix at the + # teardown rather than at a presumed cause: retry briefly, then give up + # quietly. A leftover directory under $TMPDIR is worth less than a trustworthy + # signal, and the assertions have already run either way. + for _ in 1 2 3; do + rm -rf "$WORK" 2>/dev/null && return 0 + sleep 0.1 + done + rm -rf "$WORK" 2>/dev/null || true + return 0 } # Emits a canned nix log plus the sentinel the script reads for exit status.