Files
coredesktop/tests/cleanup.bats
T
davidandClaude Opus 5.5 54f9e12526
shellcheck / shellcheck (push) Failing after 17s
Log each install and update, and keep only the recent logs
Each run's output now goes to ~/.local/state/coredesktop/logs/, so what
failed can be read after the terminal is gone. In a terminal, update runs
itself under script(1), so everything it runs still sees a terminal, then
strips color codes and progress redraws from the log; otherwise it uses
tee. install.sh, usually piped into bash, uses tee, and runs configure
straight on the terminal, outside the log. Both name the log when
something fails. 95-cleanup.sh keeps the newest 10 update logs and 3
install logs.

The sudo keepalive loops no longer share the logged output, so their
sleep can't hold the log open after the run ends.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 11:00:31 -07:00

66 lines
2.1 KiB
Bash

#!/usr/bin/env bats
load test_helper
@test "95-cleanup removes -debug packages whose package is gone, and keeps the rest" {
# -Qqm lists the AUR packages; -Qq NAME prints what matches NAME, which for
# herdr is herdr-bin, as it provides herdr
stub pacman '
case "$1" in
-Qqm) printf "%s\n" asdf-vm-debug cliamp cliamp-debug herdr-bin herdr-debug ;;
-Qq) case "$2" in cliamp) echo cliamp ;; herdr) echo herdr-bin ;; *) exit 1 ;; esac ;;
esac'
stub sudo
stub flatpak
run bash "$REPO/updates.d/95-cleanup.sh" < /dev/null
[ "$status" -eq 0 ]
called sudo pacman -R --noconfirm asdf-vm-debug herdr-debug
}
@test "95-cleanup leaves -debug packages alone while their packages are installed" {
stub pacman '
case "$1" in
-Qqm) printf "%s\n" cliamp cliamp-debug ;;
-Qq) [ "$2" = cliamp ] && echo cliamp ;;
esac'
stub sudo
stub flatpak
run bash "$REPO/updates.d/95-cleanup.sh" < /dev/null
[ "$status" -eq 0 ]
[ -z "$(grep 'pacman -R ' "$STUB_LOG")" ]
}
@test "95-cleanup keeps the newest 10 update logs and 3 install logs" {
stub pacman
stub sudo
stub flatpak
logs="$HOME/.local/state/coredesktop/logs"
mkdir -p "$logs"
for day in 01 02 03 04 05 06 07 08 09 10 11 12; do
touch "$logs/update-2026-11-$day-120000.log" "$logs/install-2026-11-$day-120000.log"
done
touch "$logs/notes.txt"
run bash "$REPO/updates.d/95-cleanup.sh" < /dev/null
[ "$status" -eq 0 ]
[ "$(cd "$logs" && echo update-*)" = "$(printf 'update-2026-11-%s-120000.log ' 03 04 05 06 07 08 09 10 11 12 | sed 's/ $//')" ]
[ "$(cd "$logs" && echo install-*)" = "install-2026-11-10-120000.log install-2026-11-11-120000.log install-2026-11-12-120000.log" ]
[ -f "$logs/notes.txt" ]
}
@test "95-cleanup is fine with no logs or only a few" {
stub pacman
stub sudo
stub flatpak
run bash "$REPO/updates.d/95-cleanup.sh" < /dev/null
[ "$status" -eq 0 ]
mkdir -p "$HOME/.local/state/coredesktop/logs"
touch "$HOME/.local/state/coredesktop/logs/update-2026-11-01-120000.log"
run bash "$REPO/updates.d/95-cleanup.sh" < /dev/null
[ "$status" -eq 0 ]
[ -f "$HOME/.local/state/coredesktop/logs/update-2026-11-01-120000.log" ]
}