Files
HamPack/tests/update.bats
T
David YoungandClaude Opus 5.5 4cb5ce25ff Stop creating a dialout group for Graywolf
Graywolf's setup created a dialout group, which nothing on Arch uses:
serial ports belong to uucp, and Graywolf's service runs as you, with
your groups. Machines that have the group keep it, in case anything else
uses it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 14:09:46 -07:00

154 lines
5.5 KiB
Bash

#!/usr/bin/env bats
#
# update.sh as run on first install (by install.sh) and on later updates
# (by CoreDesktop's `update`)
load helpers
setup() {
setup_fake_home
fake_coredesktop
# No apps to download or build; those scripts have their own tests
export HAMPACK_BINARIES_CONF="$BATS_TEST_TMPDIR/empty.conf"
export HAMPACK_COMPILE_CONF="$BATS_TEST_TMPDIR/empty.conf"
: > "$HAMPACK_BINARIES_CONF"
local data="$BATS_TEST_TMPDIR/uv-tools/not1mm/lib/python3.13/site-packages/not1mm/data"
mkdir -p "$data"
touch "$data/k6gte-not1mm.desktop"
export UV_TOOL_DIR="$BATS_TEST_TMPDIR/uv-tools"
stub uv '
case "$1 $2" in
"tool list") [ -f "$HOME/not1mm" ] && echo "not1mm v1.0" ;;
"tool install") touch "$HOME/not1mm" ;;
"tool dir") echo "$UV_TOOL_DIR" ;;
esac
exit 0'
}
@test "first install records only the packages and Flatpaks it installed" {
mark_installed cmake wine
run bash "$REPO/update.sh"
[ "$status" -eq 0 ]
[[ "$output" == *"HamPack updated."* ]]
# Everything on the list is installed now
local pkg
for pkg in $(all_hampack_packages); do [ -f "$FAKE_PACMAN_DB/$pkg" ]; done
# but what was there before isn't recorded as HamPack's
! grep -qx cmake "$HAMPACK_STATE/installed-packages"
! grep -qx wine "$HAMPACK_STATE/installed-packages"
grep -qx hamlib "$HAMPACK_STATE/installed-packages"
[ "$(wc -l < "$HAMPACK_STATE/installed-flatpaks")" -eq "$(all_hampack_flatpaks | wc -l)" ]
grep -qx "uv tool install not1mm" "$STUB_LOG"
[ -x "$HOME/.local/bin/hampackremove" ]
[ "$(readlink "$HOME/.local/bin/radio")" = "$REPO/radio" ]
"$HOME/.local/bin/radio" help | grep -q "Usage: radio"
}
@test "adds you to the uucp group once, and records it" {
run bash "$REPO/update.sh"
[ "$status" -eq 0 ]
[[ "$output" == *"Added you to the uucp group"*"Log out and back in"* ]]
grep -qx "usermod -aG uucp $USER" "$STUB_LOG"
grep -qx uucp "$HAMPACK_STATE/added-groups"
: > "$STUB_LOG"
run bash "$REPO/update.sh"
[[ "$output" != *"Added you to the uucp group"* ]]
! grep -q usermod "$STUB_LOG"
}
@test "doesn't claim the uucp group if you were already in it" {
echo uucp > "$FAKE_GROUPS"
run bash "$REPO/update.sh"
[ "$status" -eq 0 ]
! grep -q usermod "$STUB_LOG"
[ ! -e "$HAMPACK_STATE/added-groups" ]
}
@test "installs the CM108 udev rule once, and again when it changes" {
run bash "$REPO/update.sh"
[ "$status" -eq 0 ]
grep -qx "sudo install -m 644 $REPO/udev/70-hampack-cm108.rules $HAMPACK_UDEV_RULES_DIR/70-hampack-cm108.rules" "$STUB_LOG"
grep -qx "udevadm control --reload-rules" "$STUB_LOG"
grep -qx "udevadm trigger --subsystem-match=hidraw --action=change" "$STUB_LOG"
# Installed as it is now: nothing to do
mkdir -p "$HAMPACK_UDEV_RULES_DIR"
cp "$REPO/udev/70-hampack-cm108.rules" "$HAMPACK_UDEV_RULES_DIR/"
: > "$STUB_LOG"
run bash "$REPO/update.sh"
! grep -q "70-hampack-cm108" "$STUB_LOG"
echo "# older" >> "$HAMPACK_UDEV_RULES_DIR/70-hampack-cm108.rules"
run bash "$REPO/update.sh"
grep -q "^sudo install -m 644 .*70-hampack-cm108.rules" "$STUB_LOG"
}
@test "update leaves alone a radio command that isn't HamPack's" {
echo "theirs" > "$HOME/.local/bin/radio"
run bash "$REPO/update.sh"
[ "$status" -eq 0 ]
[[ "$output" == *"Not installing HamPack's radio command"* ]]
[ "$(cat "$HOME/.local/bin/radio")" = theirs ]
}
@test "a later update installs and records nothing new" {
bash "$REPO/update.sh"
cp "$HAMPACK_STATE/installed-packages" "$BATS_TEST_TMPDIR/before"
: > "$STUB_LOG"
run bash "$REPO/update.sh"
[ "$status" -eq 0 ]
! grep -q '^yay -S' "$STUB_LOG"
! grep -q '^flatpak install' "$STUB_LOG"
grep -qx "uv tool upgrade not1mm" "$STUB_LOG"
cmp "$HAMPACK_STATE/installed-packages" "$BATS_TEST_TMPDIR/before"
}
@test "an update after install from before records: existing packages aren't claimed" {
local pkg
for pkg in $(all_hampack_packages); do mark_installed "$pkg"; done
run bash "$REPO/update.sh"
[ "$status" -eq 0 ]
[ ! -s "$HAMPACK_STATE/installed-packages" ]
}
@test "update removes stale state from older HamPack versions" {
mkdir -p "$HAMPACK_STATE"
printf 'Kiwix-Desktop=2.75.1\nkiwix-desktop=2.5.1\nKiwix-Tools=3.8.2\n' > "$HAMPACK_STATE/.installed_versions"
mark_installed $(all_hampack_packages)
printf 'fldigi\nlibappindicator-gtk3\nzim-tools\nzimwriterfs\n' > "$HAMPACK_STATE/installed-packages"
touch "$HOME/.local/bin/hampackupdate"
run bash "$REPO/update.sh"
[ "$(cat "$HAMPACK_STATE/.installed_versions")" = "kiwix-desktop=2.5.1" ]
[ "$(cat "$HAMPACK_STATE/installed-packages")" = "$(printf 'fldigi\nlibappindicator\nzim-tools')" ]
[ ! -e "$HOME/.local/bin/hampackupdate" ]
grep -qx "sudo rm -f /etc/sudoers.d/hampack" "$STUB_LOG"
}
@test "graywolf's service is installed and enabled once graywolf is built" {
run bash "$REPO/update.sh"
! grep -q "graywolf.service" "$STUB_LOG"
touch "$HOME/.local/bin/graywolf"
chmod +x "$HOME/.local/bin/graywolf"
: > "$STUB_LOG"
run bash "$REPO/update.sh"
[ "$status" -eq 0 ]
grep -qx "sudo tee /etc/systemd/system/graywolf.service" "$STUB_LOG"
grep -qx "enable_services graywolf" "$STUB_LOG"
# It runs as you, with your groups: it needs no group of its own
! grep -q "groupadd" "$STUB_LOG"
}
@test "the graywolf web UI listens only on this machine" {
grep -q -- "-http 127.0.0.1:8080" "$REPO/systemd/graywolf.service"
}
@test "a failing step is reported and the rest still run" {
stub flatpak 'exit 1'
run bash "$REPO/update.sh"
[ "$status" -eq 1 ]
[[ "$output" == *"errors in: Installing Flatpak applications"* ]]
grep -qx "uv tool install not1mm" "$STUB_LOG"
}