From 0adcfaa5c7e479e9c433b92836a5548a19168e05 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 13 Sep 2026 10:59:31 -0500 Subject: fix(test): keep each failed install attempt's log The retry loop refetched the guest's newest install log after every failed attempt, so `test-logs/` only ever held the last one. When a retry followed a pacstrap stall, the saved log showed the retry's "Disk in use" and the stall behind it was gone. Each failed attempt's log now lands in `test-logs/-install-attempt.log`. --- tests/unit/test_test_install.bats | 42 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'tests') diff --git a/tests/unit/test_test_install.bats b/tests/unit/test_test_install.bats index 52ea037..3fb7c19 100644 --- a/tests/unit/test_test_install.bats +++ b/tests/unit/test_test_install.bats @@ -14,6 +14,48 @@ setup() { source "${BATS_TEST_DIRNAME}/../../scripts/test-install.sh" } +############################# +# save_attempt_log +############################# +# The retry loop refetches the guest's newest /tmp/archangel-*.log on +# every failed attempt, so a retried install used to keep only the last +# attempt's log — the failure that triggered the retry was gone by the +# time anyone read test-logs/. save_attempt_log keeps each one. + +# Normal: a failed attempt's log lands under its own attempt-numbered name. +@test "save_attempt_log writes the attempt's log under an attempt-numbered name" { + local dir="$BATS_TEST_TMPDIR/logs" + mkdir -p "$dir" + run save_attempt_log "$dir" zfs-encrypt 1 $'line one\nline two' + [ "$status" -eq 0 ] + [ -f "$dir/zfs-encrypt-install-attempt1.log" ] + [ "$(cat "$dir/zfs-encrypt-install-attempt1.log")" = $'line one\nline two' ] +} + +# Boundary: an empty capture still writes a file, so "attempt ran, log +# was empty" stays distinguishable from "attempt never happened". +@test "save_attempt_log writes an empty file for an empty capture" { + local dir="$BATS_TEST_TMPDIR/logs" + mkdir -p "$dir" + run save_attempt_log "$dir" mirror 2 "" + [ "$status" -eq 0 ] + [ -f "$dir/mirror-install-attempt2.log" ] + [ ! -s "$dir/mirror-install-attempt2.log" ] +} + +# Error: an unwritable log dir fails the save without aborting the caller. +@test "save_attempt_log returns non-zero when the log dir is unwritable" { + [ "$EUID" -ne 0 ] || skip "running as root" + local dir="$BATS_TEST_TMPDIR/logs" + mkdir -p "$dir" + chmod 000 "$dir" + run save_attempt_log "$dir" mirror 1 "content" + chmod 755 "$dir" + [ "$status" -eq 1 ] + [ -z "$output" ] + [ ! -f "$dir/mirror-install-attempt1.log" ] +} + ############################# # is_transient_install_failure ############################# -- cgit v1.2.3