Files
davidandClaude Opus 5.5 a102e6fe0b
shellcheck / shellcheck (push) Successful in 11s
Check the machine before installing, and keep old shells' mise working
install.sh now stops early, with a clear message, if this isn't 64-bit
Arch, it's run as root, there's no internet, or sudo doesn't work.
system/preflight.sh then asks before going on with too little disk space
or / not on btrfs, and offers to switch another login screen to GDM and
PulseAudio to PipeWire. Keeping another login screen puts GDM in
services-off, so install and update stop failing to enable it; a
migration does the same on existing machines. It says nothing when all
is well, as refresh runs install.sh again.

Intel GPUs also get intel-media-driver for hardware video decoding, with
a migration for existing machines.

The mise migration links ~/.local/bin/mise to /usr/bin/mise instead of
deleting it, so shells opened before the update don't print an error at
every prompt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 08:25:46 -06:00

123 lines
3.3 KiB
Bash

#!/usr/bin/env bats
load test_helper
# A machine where all is well: lots of space, / on btrfs, GDM or no login
# screen yet, no PulseAudio. Tests change one thing each.
setup() {
common_setup
mkdir -p "$HOME/.local/share"
ln -s "$REPO" "$HOME/.local/share/coredesktop"
export FREE_KIB=$((200 * 1024 * 1024)) FSTYPE=btrfs DM="" INSTALLED=""
stub df 'printf "Avail\n%s\n" "$FREE_KIB"'
stub findmnt 'echo "$FSTYPE"'
stub readlink '[ -n "$DM" ] && echo "/usr/lib/systemd/system/$DM"'
stub pacman '
case "$1" in
-Qi) [[ " $INSTALLED " == *" $2 "* ]] ;;
-Qq) for p in $INSTALLED; do echo "$p"; done ;;
esac'
stub sudo
# No terminal unless a test gives answers
export COREDESKTOP_TTY="$BATS_TEST_TMPDIR/no-tty/tty"
}
answer() {
export COREDESKTOP_TTY="$BATS_TEST_TMPDIR/answer"
echo "$1" > "$COREDESKTOP_TTY"
}
already_installed() {
mkdir -p "$HOME/.local/state/coredesktop/migrations"
}
@test "preflight says nothing and changes nothing when all is well" {
run bash "$REPO/system/preflight.sh"
[ "$status" -eq 0 ]
[ -z "$output" ]
not_called sudo
}
@test "preflight stops on too little disk space unless told to go on" {
export FREE_KIB=$((30 * 1024 * 1024))
answer n
run bash "$REPO/system/preflight.sh"
[ "$status" -eq 1 ]
[[ "$output" == *"Only 30 GB is free"* ]]
answer y
run bash "$REPO/system/preflight.sh"
[ "$status" -eq 0 ]
}
@test "preflight needs less space on a machine that's already set up" {
export FREE_KIB=$((30 * 1024 * 1024))
already_installed
run bash "$REPO/system/preflight.sh"
[ "$status" -eq 0 ]
[ -z "$output" ]
}
@test "preflight warns once that / isn't btrfs, and goes on without a terminal" {
export FSTYPE=ext4
run bash "$REPO/system/preflight.sh"
[ "$status" -eq 0 ]
[[ "$output" == *"/ is on ext4, not btrfs"* ]]
already_installed
run bash "$REPO/system/preflight.sh"
[ "$status" -eq 0 ]
[ -z "$output" ]
}
@test "preflight switches another login screen to GDM when asked to" {
export DM=sddm.service
answer y
run bash "$REPO/system/preflight.sh"
[ "$status" -eq 0 ]
called sudo systemctl disable sddm.service
}
@test "preflight keeps another login screen, and update then leaves GDM off" {
export DM=sddm.service
answer n
run bash "$REPO/system/preflight.sh"
[ "$status" -eq 0 ]
not_called sudo
grep -qx "system gdm.service" "$HOME/.config/coredesktop/services-off"
# Not asked again
run bash "$REPO/system/preflight.sh"
[ -z "$output" ]
}
@test "preflight changes no login screen without a terminal to ask on" {
export DM=sddm.service
run bash "$REPO/system/preflight.sh"
[ "$status" -eq 0 ]
not_called sudo
}
@test "preflight replaces PulseAudio and its modules with PipeWire when asked to" {
export INSTALLED="pulseaudio pulseaudio-bluetooth"
answer y
run bash "$REPO/system/preflight.sh"
[ "$status" -eq 0 ]
called sudo pacman -R --noconfirm pulseaudio-bluetooth
called sudo pacman -S --needed --noconfirm --ask=4 pipewire pipewire-pulse pipewire-alsa wireplumber
}
@test "preflight keeps PulseAudio when told to, or without a terminal" {
export INSTALLED="pulseaudio"
answer n
run bash "$REPO/system/preflight.sh"
[ "$status" -eq 0 ]
[[ "$output" == *"Keeping PulseAudio."* ]]
not_called sudo
export COREDESKTOP_TTY="$BATS_TEST_TMPDIR/no-tty/tty"
run bash "$REPO/system/preflight.sh"
[ "$status" -eq 0 ]
not_called sudo
}