summaryrefslogtreecommitdiff
path: root/scripts/testing/cleanup-tests.sh
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2025-11-13 23:26:21 -0600
committerCraig Jennings <c@cjennings.net>2025-11-13 23:26:21 -0600
commit2e10a8856d0bdd4c8f77c53320221ad1b8deaa13 (patch)
tree95832c3b74fc523fe9d8319e25c5ea5bf1d40433 /scripts/testing/cleanup-tests.sh
parentfd9cce59993556400b635256d712a65d87f5d72d (diff)
fix(archsetup): implement critical bug fixes and test improvements
This commit addresses several high-priority bugs and enhances the testing infrastructure: **Bug Fixes:** 1. Add root permission check at script start to fail fast with clear error message 2. Disable debug package installation by adding --nodebug flag to all yay calls 3. Replace unsafe `git pull --force` with safe rm + fresh clone to prevent data loss 4. Add geoclue package with correct systemd service configuration for geolocation 5. Add completion marker for reliable automated test detection **Testing Infrastructure:** - Add comprehensive VM-based testing framework in scripts/testing/ - Fix test script pgrep infinite loop using grep bracket self-exclusion pattern - Add network diagnostics and pre-flight checks - Support snapshot-based testing for reproducible test runs **Package Management:** - Remove anki (build hangs 98+ minutes) - Remove adwaita-color-schemes (CMake build issues) Test Results: 0 errors, 1,363 packages installed in 40 minutes 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'scripts/testing/cleanup-tests.sh')
-rwxr-xr-xscripts/testing/cleanup-tests.sh171
1 files changed, 171 insertions, 0 deletions
diff --git a/scripts/testing/cleanup-tests.sh b/scripts/testing/cleanup-tests.sh
new file mode 100755
index 0000000..e4289a7
--- /dev/null
+++ b/scripts/testing/cleanup-tests.sh
@@ -0,0 +1,171 @@
+#!/bin/bash
+# Clean up old test VMs and artifacts
+# Author: Craig Jennings <craigmartinjennings@gmail.com>
+# License: GNU GPLv3
+
+set -e
+
+# Get script directory
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
+
+# Source utilities
+source "$SCRIPT_DIR/lib/logging.sh"
+source "$SCRIPT_DIR/lib/vm-utils.sh"
+
+# Parse arguments
+KEEP_LAST=5
+FORCE=false
+
+while [[ $# -gt 0 ]]; do
+ case $1 in
+ --keep)
+ KEEP_LAST="$2"
+ shift 2
+ ;;
+ --force)
+ FORCE=true
+ shift
+ ;;
+ *)
+ echo "Usage: $0 [--keep N] [--force]"
+ echo " --keep N Keep last N test results (default: 5)"
+ echo " --force Skip confirmation prompts"
+ exit 1
+ ;;
+ esac
+done
+
+# Initialize logging
+LOGFILE="/tmp/cleanup-tests-$(date +'%Y%m%d-%H%M%S').log"
+init_logging "$LOGFILE"
+
+section "Cleaning Up Test Artifacts"
+
+# Find all test VMs
+step "Finding test VMs"
+TEST_VMS=$(virsh --connect qemu:///system list --all | grep "archsetup-test-" | awk '{print $2}' || true)
+
+if [ -z "$TEST_VMS" ]; then
+ info "No test VMs found"
+else
+ VM_COUNT=$(echo "$TEST_VMS" | wc -l)
+ info "Found $VM_COUNT test VM(s)"
+
+ if ! $FORCE; then
+ echo ""
+ echo "$TEST_VMS"
+ echo ""
+ read -p "Destroy these VMs? [y/N] " -n 1 -r
+ echo ""
+ if [[ ! $REPLY =~ ^[Yy]$ ]]; then
+ info "Skipping VM cleanup"
+ else
+ for vm in $TEST_VMS; do
+ step "Destroying VM: $vm"
+ if vm_is_running "$vm"; then
+ virsh --connect qemu:///system destroy "$vm" >> "$LOGFILE" 2>&1
+ fi
+ virsh --connect qemu:///system undefine "$vm" --nvram >> "$LOGFILE" 2>&1 || true
+ success "VM destroyed: $vm"
+ done
+ fi
+ else
+ for vm in $TEST_VMS; do
+ step "Destroying VM: $vm"
+ if vm_is_running "$vm"; then
+ virsh --connect qemu:///system destroy "$vm" >> "$LOGFILE" 2>&1
+ fi
+ virsh --connect qemu:///system undefine "$vm" --nvram >> "$LOGFILE" 2>&1 || true
+ success "VM destroyed: $vm"
+ done
+ fi
+fi
+
+# Clean up test disk images
+section "Cleaning Up Disk Images"
+
+step "Finding test disk images"
+if [ -d "$PROJECT_ROOT/vm-images" ]; then
+ TEST_DISKS=$(find "$PROJECT_ROOT/vm-images" -name "archsetup-test-*.qcow2" 2>/dev/null || true)
+
+ if [ -z "$TEST_DISKS" ]; then
+ info "No test disk images found"
+ else
+ DISK_COUNT=$(echo "$TEST_DISKS" | wc -l)
+ DISK_SIZE=$(du -ch $TEST_DISKS | tail -1 | awk '{print $1}')
+ info "Found $DISK_COUNT test disk image(s) totaling $DISK_SIZE"
+
+ if ! $FORCE; then
+ echo ""
+ echo "$TEST_DISKS"
+ echo ""
+ read -p "Delete these disk images? [y/N] " -n 1 -r
+ echo ""
+ if [[ ! $REPLY =~ ^[Yy]$ ]]; then
+ info "Skipping disk cleanup"
+ else
+ echo "$TEST_DISKS" | while read disk; do
+ rm -f "$disk"
+ done
+ success "Test disk images deleted"
+ fi
+ else
+ echo "$TEST_DISKS" | while read disk; do
+ rm -f "$disk"
+ done
+ success "Test disk images deleted"
+ fi
+ fi
+fi
+
+# Clean up old test results
+section "Cleaning Up Test Results"
+
+if [ ! -d "$PROJECT_ROOT/test-results" ]; then
+ info "No test results directory"
+else
+ step "Finding test result directories"
+ TEST_RESULTS=$(find "$PROJECT_ROOT/test-results" -maxdepth 1 -type d -name "20*" 2>/dev/null | sort -r || true)
+
+ if [ -z "$TEST_RESULTS" ]; then
+ info "No test results found"
+ else
+ RESULT_COUNT=$(echo "$TEST_RESULTS" | wc -l)
+ info "Found $RESULT_COUNT test result directory(ies)"
+
+ if [ $RESULT_COUNT -le $KEEP_LAST ]; then
+ info "Keeping all results (count <= $KEEP_LAST)"
+ else
+ TO_DELETE=$(echo "$TEST_RESULTS" | tail -n +$((KEEP_LAST + 1)))
+ DELETE_COUNT=$(echo "$TO_DELETE" | wc -l)
+ info "Keeping last $KEEP_LAST, deleting $DELETE_COUNT old result(s)"
+
+ if ! $FORCE; then
+ echo ""
+ echo "Will delete:"
+ echo "$TO_DELETE"
+ echo ""
+ read -p "Delete these test results? [y/N] " -n 1 -r
+ echo ""
+ if [[ ! $REPLY =~ ^[Yy]$ ]]; then
+ info "Skipping results cleanup"
+ else
+ echo "$TO_DELETE" | while read dir; do
+ rm -rf "$dir"
+ done
+ success "Old test results deleted"
+ fi
+ else
+ echo "$TO_DELETE" | while read dir; do
+ rm -rf "$dir"
+ done
+ success "Old test results deleted"
+ fi
+ fi
+ fi
+fi
+
+section "Cleanup Complete"
+
+info "Log file: $LOGFILE"