From 35fd5e07e4a2554f62ed350b9d193a255901ce02 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 21 Sep 2026 19:22:54 +0000 Subject: publish-apk: cap the backups it creates Four publishes in one evening left 448MB of .bak copies of a 112MB APK, in a public web directory. A backup policy with no retention becomes the problem it was guarding against. Keeps the two most recent, configurable with --keep. Prunes before copying, so a failed publish doesn't skip the pruning as well. The first version of the test gave all four fixture backups the same mtime, so 'ls -t' ordered them arbitrarily and 'keeps the most recent' proved nothing -- it only failed because the arbitrary order happened to go the wrong way. Worth recording: a test that passes for the wrong reason is the same class of problem as the dead code these guards exist to catch. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_018AwnALZL6bD4VBtATDVv3B --- test/run-tests.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'test') diff --git a/test/run-tests.sh b/test/run-tests.sh index 415ecc3..0e655d0 100755 --- a/test/run-tests.sh +++ b/test/run-tests.sh @@ -292,5 +292,31 @@ else ok "accepts a real multi-entry APK (no SIGPIPE from the zip check)" fi +# 24. Backups are full copies of a large file in a public directory; without a cap they +# become the problem they were guarding against. +pubdir="$tmproot/pubdir"; mkdir -p "$pubdir" +cp "$realapk" "$pubdir/keep.apk" +# Distinct mtimes matter: an earlier version of this test gave all four the same time, so +# `ls -t` ordered them arbitrarily and the assertion proved nothing. +hour=1 +for stamp in 20260101-0100 20260101-0200 20260101-0300 20260101-0400; do + printf 'old' > "$pubdir/keep.apk.$stamp.bak" + touch -d "2026-01-01 0$hour:00:00" "$pubdir/keep.apk.$stamp.bak" + hour=$((hour + 1)) +done +out=$("$BIN/publish-apk" "$realapk" keep.apk --host "$(hostname)" --dir "$pubdir" --keep 2 2>&1) +remaining=$(ls "$pubdir"/keep.apk.*.bak 2>/dev/null | wc -l) +# 2 kept from before, plus the one this run made. +if [ "$remaining" -le 3 ]; then + ok "prunes old backups instead of accumulating them" +else + bad "backup pruning" "$remaining backups remain" +fi +if [ -f "$pubdir/keep.apk.20260101-0400.bak" ]; then + ok "keeps the most recent backups" +else + bad "pruning kept the wrong ones" "newest backup was deleted" +fi + printf '\n=== summary: %d passed, %d failed ===\n' "$pass" "$fail" [ "$fail" -eq 0 ] -- cgit v1.2.3