Add upgrade safeguards, hardware setup, sign-in options and Taildrop from Omarchy
shellcheck / shellcheck (push) Failing after 19s

Adapted from Omarchy (github.com/omacom/omarchy) for Arch with GNOME:

- A pacman hook stops a full upgrade run without update (pacman -Syu,
  yay -Syu), which would skip the snapshot and update's checks. update
  and install.sh set COREDESKTOP_ALLOW_PACMAN=1, which the hook finds on
  pacman or any process above it; you can set it too.
- When the Arch upgrade stops on files no package owns, update lists
  them and asks to move them to /var/lib/coredesktop/replaced and try
  again, putting back what the retry didn't replace. When packages
  conflict, it runs pacman again so you can choose.
- update and install keep the computer from sleeping until they finish.
- system/hardware.sh (install, and a migration): the Wi-Fi country from
  the time zone, thermald and intel-lpmd on Intel laptops, and Wi-Fi 6
  on Intel BE200/BE211 cards, whose driver gets Wi-Fi 7 wrong.
- configure security-key and configure fingerprint: touch a FIDO2 key
  or a finger instead of typing your password for sudo and polkit,
  falling back to the password. Each shows only when the hardware is
  there. The fingerprint skips to the password with the lid shut.
- webapp: put a website in the app grid as its own app window.
- Taildrop: Files' Scripts > Send with Tailscale, and a user service
  that saves files sent here to Downloads, started when configure
  tailscale joins.
- A NetworkManager dispatcher script pauses a Tailscale exit node while
  you sign in to a captive portal, and resumes it once online.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 12:08:06 -07:00
co-authored by Claude Opus 5.5
parent 5d7db2cdc8
commit 9dc5eb193d
32 changed files with 1809 additions and 9 deletions
+114
View File
@@ -0,0 +1,114 @@
#!/usr/bin/env bats
load test_helper
# system/hardware.sh on a fake machine under $HARDWARE_ROOT, with fake pacman,
# yay, sudo and systemctl
setup() {
common_setup
export COREDESKTOP="$REPO"
export HARDWARE_ROOT="$BATS_TEST_TMPDIR/root"
R="$HARDWARE_ROOT"
mkdir -p "$R/sys/class/ieee80211" "$R/sys/class/power_supply" "$R/sys/bus/pci/devices" \
"$R/proc" "$R/etc/conf.d" "$R/usr/share/zoneinfo/Europe"
printf '# Countries\nUS\t+404251-0740023\tAmerica/New_York\nDE\t+5230+01322\tEurope/Berlin\n' \
> "$R/usr/share/zoneinfo/zone.tab"
touch "$R/usr/share/zoneinfo/Europe/Berlin"
ln -s "$R/usr/share/zoneinfo/Europe/Berlin" "$R/etc/localtime"
printf '#WIRELESS_REGDOM="DE"\n#WIRELESS_REGDOM="US"\n' > "$R/etc/conf.d/wireless-regdom"
cpu AuthenticAMD 25 33
stub pacman 'exit 1'
stub yay
stub sudo '"$@"'
stub systemctl '[ "$1" != is-enabled ]'
}
cpu() {
printf 'processor\t: 0\nvendor_id\t: %s\ncpu family\t: %s\nmodel\t\t: %s\n' "$1" "$2" "$3" > "$R/proc/cpuinfo"
}
wifi() { mkdir -p "$R/sys/class/ieee80211/phy0"; }
battery() { mkdir -p "$R/sys/class/power_supply/BAT0"; }
pci() {
mkdir -p "$R/sys/bus/pci/devices/$1"
echo "0x$2" > "$R/sys/bus/pci/devices/$1/vendor"
echo "0x$3" > "$R/sys/bus/pci/devices/$1/device"
}
@test "hardware.sh sets the Wi-Fi country from the time zone" {
wifi
run bash "$REPO/system/hardware.sh"
[ "$status" -eq 0 ]
called yay -S --noconfirm --answerdiff=None --answeredit=None --answerclean=None wireless-regdb
grep -qx 'WIRELESS_REGDOM="DE"' "$R/etc/conf.d/wireless-regdom"
}
@test "hardware.sh leaves a Wi-Fi country that's set" {
wifi
echo 'WIRELESS_REGDOM="FR"' >> "$R/etc/conf.d/wireless-regdom"
run bash "$REPO/system/hardware.sh"
[ "$status" -eq 0 ]
[ "$(grep -c '^WIRELESS_REGDOM' "$R/etc/conf.d/wireless-regdom")" -eq 1 ]
}
@test "hardware.sh says so when the time zone has no country" {
wifi
ln -sfn "$R/usr/share/zoneinfo/UTC" "$R/etc/localtime"
run bash "$REPO/system/hardware.sh"
[ "$status" -eq 0 ]
[[ "$output" == *"Couldn't tell the country"* ]]
refute grep -q '^WIRELESS_REGDOM' "$R/etc/conf.d/wireless-regdom"
}
@test "hardware.sh does nothing for Wi-Fi without it" {
run bash "$REPO/system/hardware.sh"
[ "$status" -eq 0 ]
not_called yay
refute grep -q '^WIRELESS_REGDOM' "$R/etc/conf.d/wireless-regdom"
}
@test "hardware.sh runs thermald and intel-lpmd on a newer Intel laptop" {
battery
cpu GenuineIntel 6 170
run bash "$REPO/system/hardware.sh"
[ "$status" -eq 0 ]
called yay -S --noconfirm --answerdiff=None --answeredit=None --answerclean=None thermald
called yay -S --noconfirm --answerdiff=None --answeredit=None --answerclean=None intel-lpmd
called systemctl enable thermald.service
called systemctl enable intel_lpmd.service
}
@test "hardware.sh runs only thermald on an older Intel laptop" {
battery
cpu GenuineIntel 6 142
run bash "$REPO/system/hardware.sh"
[ "$status" -eq 0 ]
called systemctl enable thermald.service
uncalled systemctl enable intel_lpmd.service
}
@test "hardware.sh leaves Intel desktops and AMD laptops alone" {
cpu GenuineIntel 6 170
run bash "$REPO/system/hardware.sh"
not_called systemctl
battery
cpu AuthenticAMD 25 33
run bash "$REPO/system/hardware.sh"
not_called systemctl
}
@test "hardware.sh turns off Wi-Fi 7 on an Intel BE200" {
pci 0000:00:14.3 8086 272b
run bash "$REPO/system/hardware.sh"
[ "$status" -eq 0 ]
grep -qx 'options iwlwifi disable_11be=Y' "$R/etc/modprobe.d/iwlwifi-disable-eht.conf"
}
@test "hardware.sh leaves other Wi-Fi cards on Wi-Fi 7" {
pci 0000:00:14.3 8086 7e40
run bash "$REPO/system/hardware.sh"
[ "$status" -eq 0 ]
[ ! -e "$R/etc/modprobe.d/iwlwifi-disable-eht.conf" ]
}
+92
View File
@@ -0,0 +1,92 @@
#!/usr/bin/env bats
load test_helper
# system/pacman-guard reads a fake /proc: process $1's command line and
# environment, and its parent
setup() {
common_setup
export PACMAN_GUARD_PROC="$BATS_TEST_TMPDIR/proc"
export PACMAN_GUARD_PID=300
}
# process PID PARENT "ARGS..." [ENV...]
process() {
local dir="$PACMAN_GUARD_PROC/$1"
mkdir -p "$dir"
# shellcheck disable=SC2086
printf '%s\0' $3 > "$dir/cmdline"
printf 'Name:\tx\nPPid:\t%s\n' "$2" > "$dir/status"
if (( $# > 3 )); then printf '%s\0' "${@:4}"; fi > "$dir/environ"
}
# pacman 300, started by sudo 200, started by a shell 100
processes() {
process 300 200 "$1" PATH=/usr/bin
process 200 100 "sudo $1" "${@:2}"
process 100 1 "bash" HOME=/home/me
}
@test "the guard stops pacman -Syu" {
processes "pacman -Syu"
run bash "$REPO/system/pacman-guard"
[ "$status" -eq 1 ]
[[ "$output" == *"COREDESKTOP_ALLOW_PACMAN=1 sudo pacman -Syu"* ]]
}
@test "the guard stops every spelling of a full upgrade" {
for args in "pacman -Su" "pacman -Syyu --noconfirm" "pacman -S -u" "pacman --sync --sysupgrade" "pacman -Suu"; do
rm -rf "$PACMAN_GUARD_PROC"
processes "$args"
run bash "$REPO/system/pacman-guard"
[ "$status" -eq 1 ]
done
}
@test "the guard lets installs, removals and partial syncs through" {
for args in "pacman -S git" "pacman -Sy git" "pacman -U /tmp/x.pkg.tar.zst" "pacman -Rns git" "pacman -D --asexplicit git" "pacman -S -- -u"; do
rm -rf "$PACMAN_GUARD_PROC"
processes "$args"
run bash "$REPO/system/pacman-guard"
[ "$status" -eq 0 ]
done
}
@test "the guard lets update's upgrade through: sudo still has the variable" {
processes "pacman -Su --noconfirm" COREDESKTOP_ALLOW_PACMAN=1
run bash "$REPO/system/pacman-guard"
[ "$status" -eq 0 ]
}
@test "the guard lets an upgrade through when any ancestor has the variable" {
process 300 200 "pacman -Su" PATH=/usr/bin
process 200 150 "sudo pacman -Su"
process 150 100 "yay -Syu"
process 100 1 "bash" COREDESKTOP_ALLOW_PACMAN=1
run bash "$REPO/system/pacman-guard"
[ "$status" -eq 0 ]
}
@test "the guard isn't fooled by a variable with another value" {
processes "pacman -Syu" COREDESKTOP_ALLOW_PACMAN=0 XCOREDESKTOP_ALLOW_PACMAN=1
run bash "$REPO/system/pacman-guard"
[ "$status" -eq 1 ]
}
@test "pacman-guard.sh installs the guard and its hook once" {
export PACMAN_GUARD_ROOT="$BATS_TEST_TMPDIR/root"
export COREDESKTOP="$REPO"
stub sudo '"$@"'
run bash "$REPO/system/pacman-guard.sh"
[ "$status" -eq 0 ]
cmp "$REPO/system/pacman-guard" "$PACMAN_GUARD_ROOT/usr/local/lib/coredesktop/pacman-guard"
[ -x "$PACMAN_GUARD_ROOT/usr/local/lib/coredesktop/pacman-guard" ]
grep -qx 'Exec = /usr/local/lib/coredesktop/pacman-guard' "$PACMAN_GUARD_ROOT/etc/pacman.d/hooks/00-coredesktop-guard.hook"
grep -qx 'AbortOnFail' "$PACMAN_GUARD_ROOT/etc/pacman.d/hooks/00-coredesktop-guard.hook"
: > "$STUB_LOG"
run bash "$REPO/system/pacman-guard.sh"
[ "$status" -eq 0 ]
not_called sudo
}
+202
View File
@@ -0,0 +1,202 @@
#!/usr/bin/env bats
load test_helper
# configure.d/lib/pam.sh and the security key and fingerprint items, on PAM
# files in the test's own directories, with a fake sudo
setup() {
common_setup
export COREDESKTOP="$REPO"
export PAM_DIR="$BATS_TEST_TMPDIR/pam.d"
export PAM_VENDOR_DIR="$BATS_TEST_TMPDIR/vendor/pam.d"
mkdir -p "$PAM_DIR" "$PAM_VENDOR_DIR"
printf '#%%PAM-1.0\nauth\t\tinclude\t\tsystem-auth\naccount\t\tinclude\t\tsystem-auth\nsession\t\tinclude\t\tsystem-auth\n' \
> "$PAM_DIR/sudo"
printf '#%%PAM-1.0\n\nauth include system-auth\naccount include system-auth\n' \
> "$PAM_VENDOR_DIR/polkit-1"
stub sudo '"$@"'
export USER=me
}
@test "pam_add puts the lines before the first auth line, once" {
source "$REPO/configure.d/lib/pam.sh"
pam_add sudo pam_test.so "auth sufficient pam_test.so a" "auth sufficient pam_other.so"
pam_add sudo pam_test.so "auth sufficient pam_test.so a"
[ "$(sed -n 2p "$PAM_DIR/sudo")" = "auth sufficient pam_test.so a" ]
[ "$(sed -n 3p "$PAM_DIR/sudo")" = "auth sufficient pam_other.so" ]
[[ "$(sed -n 4p "$PAM_DIR/sudo")" == auth*system-auth ]]
[ "$(grep -c pam_test.so "$PAM_DIR/sudo")" -eq 1 ]
}
@test "pam_add copies a vendor PAM file before changing it" {
source "$REPO/configure.d/lib/pam.sh"
pam_add polkit-1 pam_test.so "auth sufficient pam_test.so"
pam_has polkit-1 pam_test.so
refute grep -q pam_test.so "$PAM_VENDOR_DIR/polkit-1"
grep -q '^account include system-auth$' "$PAM_DIR/polkit-1"
}
@test "pam_has ignores commented-out lines" {
source "$REPO/configure.d/lib/pam.sh"
echo "#auth sufficient pam_test.so" >> "$PAM_DIR/sudo"
refute pam_has sudo pam_test.so
}
@test "pam_remove takes out only the matching lines" {
source "$REPO/configure.d/lib/pam.sh"
local before
before="$(cat "$PAM_DIR/sudo")"
pam_add sudo pam_test.so "auth sufficient pam_test.so"
pam_remove sudo 'pam_test\.so'
[ "$(cat "$PAM_DIR/sudo")" = "$before" ]
}
@test "pam_add fails on a PAM file that doesn't exist anywhere" {
source "$REPO/configure.d/lib/pam.sh"
run pam_add nothing pam_test.so "auth sufficient pam_test.so"
[ "$status" -eq 1 ]
}
# --- Security key ------------------------------------------------------------
key_setup() {
export U2F_MAPPINGS="$BATS_TEST_TMPDIR/u2f_mappings"
export HIDRAW="$BATS_TEST_TMPDIR/hidraw"
mkdir -p "$HIDRAW/hidraw0/device"
# A keyboard's report descriptor: usage page 1
printf '\x05\x01\x09\x06\xa1\x01' > "$HIDRAW/hidraw0/device/report_descriptor"
source "$REPO/configure.d/70-security-key.sh"
stub pacman
stub fido2-token 'echo "/dev/hidraw1: vendor=0x1050, product=0x0407 (Yubico YubiKey OTP+FIDO+CCID)"'
stub pamu2fcfg 'echo ":KEY1"'
}
@test "the security key item shows only when a key is plugged in or set up" {
key_setup
refute is_installed
mkdir -p "$HIDRAW/hidraw1/device"
printf '\x06\xd0\xf1\x09\x01\xa1\x01' > "$HIDRAW/hidraw1/device/report_descriptor"
is_installed
}
@test "setting up a security key registers it and adds it to sudo and polkit" {
key_setup
run run_configure
[ "$status" -eq 0 ]
[ "$(cat "$U2F_MAPPINGS")" = "me:KEY1" ]
grep -q "pam_u2f.so cue origin=pam://coredesktop appid=pam://coredesktop authfile=$U2F_MAPPINGS" "$PAM_DIR/sudo"
pam_has polkit-1 pam_u2f.so
is_configured
}
@test "a second key goes on the same line" {
key_setup
echo "other:KEYX" > "$U2F_MAPPINGS"
run run_configure
stub pamu2fcfg 'echo ":KEY2"'
run run_configure <<< 1
[ "$status" -eq 0 ]
[ "$(cat "$U2F_MAPPINGS")" = "$(printf 'other:KEYX\nme:KEY1:KEY2')" ]
[ "$(grep -c pam_u2f.so "$PAM_DIR/sudo")" -eq 1 ]
}
@test "stopping security keys takes them out of PAM and removes your keys" {
key_setup
echo "other:KEYX" > "$U2F_MAPPINGS"
run run_configure
run run_configure <<< 2
[ "$status" -eq 0 ]
refute pam_has sudo pam_u2f.so
refute pam_has polkit-1 pam_u2f.so
[ "$(cat "$U2F_MAPPINGS")" = "other:KEYX" ]
}
@test "setting up a security key fails without one plugged in, changing nothing" {
key_setup
stub fido2-token
run run_configure
[ "$status" -eq 1 ]
[[ "$output" == *"No security key found"* ]]
refute pam_has sudo pam_u2f.so
[ ! -e "$U2F_MAPPINGS" ]
}
# --- Fingerprint -------------------------------------------------------------
fingerprint_setup() {
export USB_DEVICES="$BATS_TEST_TMPDIR/usb"
export LID_CLOSED="$BATS_TEST_TMPDIR/lid-closed"
mkdir -p "$USB_DEVICES"
source "$REPO/configure.d/71-fingerprint.sh"
stub pacman
stub fprintd-list 'if [ -e "$BATS_TEST_TMPDIR/enrolled" ]; then echo "Fingerprints for user me on Goodix:"; echo " - #0: right-index-finger"; else echo "User me has no fingers enrolled for Goodix."; fi'
stub fprintd-enroll 'touch "$BATS_TEST_TMPDIR/enrolled"'
}
# usb_device NAME VENDOR [PRODUCT] [DRIVER]
usb_device() {
local dir="$USB_DEVICES/$1"
mkdir -p "$dir/$1:1.0"
echo "$2" > "$dir/idVendor"
[ -n "$3" ] && echo "$3" > "$dir/product"
if [ -n "$4" ]; then
mkdir -p "$BATS_TEST_TMPDIR/drivers/$4"
ln -s "$BATS_TEST_TMPDIR/drivers/$4" "$dir/$1:1.0/driver"
fi
return 0
}
@test "the fingerprint item finds readers by name or by vendor" {
fingerprint_setup
refute is_installed
usb_device 1-1 046d "USB Keyboard" usbhid
refute is_installed
usb_device 1-2 04f3 "ELAN:ARM-M4"
is_installed
rm -rf "${USB_DEVICES:?}"/*
usb_device 1-3 27c6
is_installed
}
@test "the fingerprint item doesn't take a reader vendor's touchpad for a reader" {
fingerprint_setup
usb_device 1-1 06cb "" usbhid
refute is_installed
# libusb's claim, while fprintd uses the reader
usb_device 1-2 06cb "" usbfs
is_installed
}
@test "setting up the fingerprint enrolls a finger and adds it to sudo and polkit" {
fingerprint_setup
usb_device 1-1 27c6
run run_configure
[ "$status" -eq 0 ]
called fprintd-enroll me
[ -x "$LID_CLOSED" ]
# The lid check comes right before pam_fprintd, so its success=1 skips it
[ "$(grep -A1 "pam_exec.so quiet $LID_CLOSED" "$PAM_DIR/sudo" | tail -n 1 | awk '{ print $3 }')" = pam_fprintd.so ]
pam_has polkit-1 pam_fprintd.so
is_configured
}
@test "setting up the fingerprint doesn't enroll again a finger enrolled in Settings" {
fingerprint_setup
touch "$BATS_TEST_TMPDIR/enrolled"
run run_configure
[ "$status" -eq 0 ]
not_called fprintd-enroll
pam_has sudo pam_fprintd.so
}
@test "stopping the fingerprint takes it and the lid check out of PAM" {
fingerprint_setup
local before
before="$(cat "$PAM_DIR/sudo")"
run run_configure
run run_configure <<< 1
[ "$status" -eq 0 ]
[ "$(cat "$PAM_DIR/sudo")" = "$before" ]
refute grep -q lid-closed "$PAM_DIR/polkit-1"
}
+94
View File
@@ -0,0 +1,94 @@
#!/usr/bin/env bats
load test_helper
# Taildrop: Files' "Send with Tailscale" script, and the captive portal helper,
# with a fake tailscale
setup() {
common_setup
stub notify-send
echo one > "$BATS_TEST_TMPDIR/one.txt"
echo two > "$BATS_TEST_TMPDIR/two.txt"
mkdir "$BATS_TEST_TMPDIR/folder"
stub tailscale 'if [ "$3" = --targets ]; then printf "100.64.0.2\tlaptop\n100.64.0.3\tdesktop\n"; fi'
stub zenity 'echo 100.64.0.3'
}
@test "Send with Tailscale sends the chosen files to the chosen computer" {
NAUTILUS_SCRIPT_SELECTED_FILE_PATHS="$BATS_TEST_TMPDIR/one.txt"$'\n'"$BATS_TEST_TMPDIR/folder"$'\n'"$BATS_TEST_TMPDIR/two.txt"$'\n' \
run bash "$REPO/system/send-with-tailscale"
[ "$status" -eq 0 ]
called tailscale file cp --update-interval=0 -- "$BATS_TEST_TMPDIR/one.txt" "$BATS_TEST_TMPDIR/two.txt" 100.64.0.3:
grep -q '^notify-send .*Sent to desktop 2 files$' "$STUB_LOG"
}
@test "Send with Tailscale does nothing when the choice is cancelled" {
stub zenity 'exit 1'
run bash "$REPO/system/send-with-tailscale" "$BATS_TEST_TMPDIR/one.txt"
[ "$status" -eq 0 ]
uncalled tailscale file cp --update-interval=0 -- "$BATS_TEST_TMPDIR/one.txt" 100.64.0.3:
}
@test "Send with Tailscale says when no computer can take files" {
stub tailscale
run bash "$REPO/system/send-with-tailscale" "$BATS_TEST_TMPDIR/one.txt"
[ "$status" -eq 1 ]
grep -q '^notify-send .*No computer to send to' "$STUB_LOG"
not_called zenity
}
@test "Send with Tailscale says when sending fails" {
stub tailscale 'if [ "$3" = --targets ]; then printf "100.64.0.3\tdesktop\n"; else echo "no route"; exit 1; fi'
run bash "$REPO/system/send-with-tailscale" "$BATS_TEST_TMPDIR/one.txt"
[ "$status" -eq 1 ]
grep -q "^notify-send .*Couldn't send to desktop no route$" "$STUB_LOG"
}
# --- Captive portal ----------------------------------------------------------
portal_setup() {
export CAPTIVE_PORTAL_STATE="$BATS_TEST_TMPDIR/paused"
export EXIT_NODE="${EXIT_NODE-100.64.0.9/32}"
stub logger
stub tailscale 'if [ "$1" = status ]; then
if [ -n "$EXIT_NODE" ]; then echo "{\"ExitNodeStatus\": {\"TailscaleIPs\": [\"$EXIT_NODE\"]}}"; else echo "{}"; fi
fi'
}
@test "at a captive portal, the exit node is paused, and comes back once online" {
portal_setup
CONNECTIVITY_STATE=PORTAL run bash "$REPO/system/captive-portal" wlan0 connectivity-change
[ "$status" -eq 0 ]
called tailscale set --exit-node=
[ "$(cat "$CAPTIVE_PORTAL_STATE")" = 100.64.0.9 ]
EXIT_NODE="" CONNECTIVITY_STATE=FULL run bash "$REPO/system/captive-portal" wlan0 connectivity-change
[ "$status" -eq 0 ]
called tailscale set --exit-node=100.64.0.9
[ ! -e "$CAPTIVE_PORTAL_STATE" ]
}
@test "a captive portal changes nothing without an exit node" {
EXIT_NODE="" portal_setup
CONNECTIVITY_STATE=PORTAL run bash "$REPO/system/captive-portal" wlan0 connectivity-change
CONNECTIVITY_STATE=FULL run bash "$REPO/system/captive-portal" wlan0 connectivity-change
uncalled tailscale set --exit-node=
[ ! -e "$CAPTIVE_PORTAL_STATE" ]
}
@test "an exit node chosen while at the portal is left alone" {
portal_setup
echo 100.64.0.9 > "$CAPTIVE_PORTAL_STATE"
EXIT_NODE=100.64.0.7/32 CONNECTIVITY_STATE=FULL run bash "$REPO/system/captive-portal" wlan0 connectivity-change
[ "$status" -eq 0 ]
refute grep -q '^tailscale set' "$STUB_LOG"
[ ! -e "$CAPTIVE_PORTAL_STATE" ]
}
@test "the captive portal helper ignores other events" {
portal_setup
CONNECTIVITY_STATE=PORTAL run bash "$REPO/system/captive-portal" wlan0 up
[ "$status" -eq 0 ]
not_called tailscale
}
+6
View File
@@ -53,3 +53,9 @@ not_called() {
uncalled() {
! called "$@"
}
# refute COMMAND...: true if COMMAND fails. Use it instead of "! COMMAND",
# which doesn't fail a test (see uncalled).
refute() {
! "$@"
}
+25 -2
View File
@@ -11,7 +11,7 @@ setup() {
CD="$HOME/.local/share/coredesktop"
mkdir -p "$CD/updates.d" "$HOME/.local/bin"
cp "$REPO/update" "$CD/update"
for script in refresh sibling version configure audit report; do
for script in refresh sibling version configure audit report webapp; do
echo '#!/bin/bash' > "$CD/$script"
done
@@ -25,6 +25,8 @@ setup() {
# Let go of bats' output pipes so the sudo keepalive's leftover sleep
# doesn't keep the test waiting
stub sleep 'exec > /dev/null 2>&1 3>&-; exec /usr/bin/sleep "$@"'
# Not the real one: it would ask logind to keep this computer awake
stub systemd-inhibit
}
# hook NAME BODY: add updates.d/NAME.sh with BODY as its run_update
@@ -51,11 +53,32 @@ ran() {
[[ "$output" == *"Done."* ]]
called git -C "$CD" pull --ff-only
ran a b
for script in update refresh sibling version configure audit report; do
for script in update refresh sibling version configure audit report webapp; do
[ -x "$HOME/.local/bin/$script" ]
done
}
@test "update keeps the computer awake while it runs" {
hook 10-a 'echo a >> "$RAN"'
run "$CD/update"
[ "$status" -eq 0 ]
# In the background, so give it a moment
for _ in 1 2 3 4 5 6 7 8 9 10; do
grep -q '^systemd-inhibit ' "$STUB_LOG" && break
/usr/bin/sleep 0.1
done
grep -q '^systemd-inhibit --what=sleep:idle .* --mode=block tail --pid=[0-9]* -f /dev/null$' "$STUB_LOG"
}
@test "update's hooks may upgrade past the pacman guard" {
hook 10-a 'echo "$COREDESKTOP_ALLOW_PACMAN" >> "$RAN"'
run "$CD/update"
[ "$status" -eq 0 ]
ran 1
}
@test "update pulls only once, before re-running its new copy" {
hook 10-a 'echo a >> "$RAN"'
+93
View File
@@ -321,3 +321,96 @@ LIST
[ "$status" -ne 0 ]
not_called curl
}
# --- unowned_conflicts, move_aside, put_back ---------------------------------
# A pacman -Su log that stopped on conflicting files: one line per path given
conflict_log() {
LOG="$BATS_TEST_TMPDIR/pacman.log"
{
echo ":: Proceed with installation? [Y/n] "
echo "(2/2) checking for file conflicts [######] 100%"
echo "error: failed to commit transaction (conflicting files)"
for line in "$@"; do printf '%s\r\n' "$line"; done
echo "Errors occurred, no packages were upgraded."
} > "$LOG"
}
@test "unowned_conflicts lists the files no package owns" {
source "$REPO/utils.sh"
stub pacman 'exit 1'
conflict_log "python-foo: /usr/lib/python3.13/site-packages/foo/__init__.py exists in filesystem" \
"python-foo: /usr/lib/python3.13/site-packages/foo exists in filesystem" \
"bar: /usr/bin/bar exists in filesystem"
run unowned_conflicts "$LOG"
[ "$status" -eq 0 ]
[ "$output" = "$(printf '%s\n' /usr/bin/bar /usr/lib/python3.13/site-packages/foo \
/usr/lib/python3.13/site-packages/foo/__init__.py)" ]
}
@test "unowned_conflicts gives up when a package owns a conflicting file" {
source "$REPO/utils.sh"
stub pacman 'exit 1'
conflict_log "foo: /usr/bin/foo exists in filesystem" \
"foo: /usr/bin/bar exists in filesystem (owned by bar)"
run unowned_conflicts "$LOG"
[ "$status" -eq 1 ]
[ -z "$output" ]
}
@test "unowned_conflicts gives up when pacman finds an owner now" {
source "$REPO/utils.sh"
stub pacman '[ "$2" = /usr/bin/foo ]'
conflict_log "foo: /usr/bin/foo exists in filesystem"
run unowned_conflicts "$LOG"
[ "$status" -eq 1 ]
}
@test "unowned_conflicts finds nothing in other failures" {
source "$REPO/utils.sh"
stub pacman 'exit 1'
LOG="$BATS_TEST_TMPDIR/pacman.log"
printf 'error: failed to prepare transaction (could not satisfy dependencies)\n' > "$LOG"
run unowned_conflicts "$LOG"
[ "$status" -eq 1 ]
run unowned_conflicts "$BATS_TEST_TMPDIR/missing.log"
[ "$status" -eq 1 ]
}
@test "move_aside moves files and folders under REPLACED_DIR, and put_back returns them" {
source "$REPO/utils.sh"
stub sudo '"$@"'
REPLACED_DIR="$BATS_TEST_TMPDIR/replaced"
local file="$BATS_TEST_TMPDIR/usr/bin/foo" dir="$BATS_TEST_TMPDIR/usr/lib/foo"
mkdir -p "$dir" "$(dirname "$file")"
echo old > "$file"
echo x > "$dir/x"
run move_aside "$file" "$dir"
[ "$status" -eq 0 ]
[ ! -e "$file" ] && [ ! -e "$dir" ]
[ "$(cat "$REPLACED_DIR$file")" = old ]
[ -f "$REPLACED_DIR$dir/x" ]
# The upgrade installed its own foo, but not the folder
echo new > "$file"
run put_back "$file" "$dir"
[ "$status" -eq 0 ]
[ "$(cat "$file")" = new ]
[ -f "$dir/x" ]
[ "$(cat "$REPLACED_DIR$file")" = old ]
}
@test "move_aside keeps what an earlier move left in REPLACED_DIR" {
source "$REPO/utils.sh"
stub sudo '"$@"'
REPLACED_DIR="$BATS_TEST_TMPDIR/replaced"
local file="$BATS_TEST_TMPDIR/usr/bin/foo"
mkdir -p "$(dirname "$file")"
echo first > "$file"
move_aside "$file"
echo second > "$file"
move_aside "$file"
[ "$(cat "$REPLACED_DIR$file")" = second ]
[ "$(cat "$REPLACED_DIR$file.~1~")" = first ]
}
+88
View File
@@ -0,0 +1,88 @@
#!/usr/bin/env bats
load test_helper
setup() {
common_setup
export XDG_DATA_HOME="$HOME/.local/share"
export XDG_DATA_DIRS="$BATS_TEST_TMPDIR/share"
APPS="$XDG_DATA_HOME/applications"
mkdir -p "$XDG_DATA_DIRS/applications"
printf '[Desktop Entry]\nExec=test-chromium %%U\n' > "$XDG_DATA_DIRS/applications/helium.desktop"
printf '[Desktop Entry]\nExec=/usr/lib/firefox/firefox %%u\n' > "$XDG_DATA_DIRS/applications/firefox.desktop"
stub xdg-settings 'echo "${DEFAULT_BROWSER:-helium.desktop}"'
export WEBAPP_BROWSERS="test-chromium"
stub test-chromium
stub xdg-open
stub update-desktop-database
stub gtk-update-icon-cache
# No icon to be had
stub curl 'exit 22'
}
@test "webapp add makes a launcher that opens the site as an app" {
run bash "$REPO/webapp" add "Nextcloud" https://nextcloud.example.com/apps/files
[ "$status" -eq 0 ]
local file="$APPS/webapp-nextcloud.desktop"
grep -qx 'Name=Nextcloud' "$file"
grep -qx "Exec=\"$HOME/.local/bin/webapp\" open \"https://nextcloud.example.com/apps/files\"" "$file"
grep -qx 'StartupWMClass=chrome-nextcloud.example.com__apps_files-Default' "$file"
grep -qx 'Icon=applications-internet' "$file"
}
@test "webapp add quotes a URL's special characters for the launcher" {
run bash "$REPO/webapp" add "Search" 'https://example.com/?q=a%20b&x=$y'
[ "$status" -eq 0 ]
grep -qxF 'Exec="'"$HOME"'/.local/bin/webapp" open "https://example.com/?q=a%%20b&x=\\$y"' "$APPS/webapp-search.desktop"
}
@test "webapp add refuses addresses that aren't http(s)" {
for url in "javascript:alert(1)" "file:///etc/passwd" "example.com" "https://a b"; do
run bash "$REPO/webapp" add "Bad" "$url"
[ "$status" -eq 1 ]
done
[ ! -e "$APPS/webapp-bad.desktop" ]
}
@test "webapp add takes an icon from a file" {
# A 1x1 PNG
base64 -d > "$BATS_TEST_TMPDIR/icon.png" <<< \
iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR4nGNgYGD4DwABBAEAwS2OUAAAAABJRU5ErkJggg==
run bash "$REPO/webapp" add "My App" https://app.example.com "$BATS_TEST_TMPDIR/icon.png"
[ "$status" -eq 0 ]
local icon="$XDG_DATA_HOME/icons/hicolor/256x256/apps/webapp-my-app.png"
[ -f "$icon" ]
grep -qx "Icon=$icon" "$APPS/webapp-my-app.desktop"
}
@test "webapp list and remove handle only web apps" {
bash "$REPO/webapp" add "Nextcloud" https://nextcloud.example.com
printf '[Desktop Entry]\nName=Other\n' > "$APPS/webapp-other.desktop"
run bash "$REPO/webapp" list
[[ "$output" == "Nextcloud"*"https://nextcloud.example.com" ]]
run bash "$REPO/webapp" remove Other
[ "$status" -eq 1 ]
[ -f "$APPS/webapp-other.desktop" ]
run bash "$REPO/webapp" remove Nextcloud
[ "$status" -eq 0 ]
[ ! -e "$APPS/webapp-nextcloud.desktop" ]
}
@test "webapp open uses the default browser when it's Chromium-based" {
run bash "$REPO/webapp" open https://example.com
[ "$status" -eq 0 ]
called test-chromium --app=https://example.com
}
@test "webapp open falls back to an installed Chromium-based browser" {
DEFAULT_BROWSER=firefox.desktop run bash "$REPO/webapp" open https://example.com
[ "$status" -eq 0 ]
called test-chromium --app=https://example.com
}
@test "webapp open uses the browser when there's no Chromium-based one" {
rm "$STUB_BIN/test-chromium"
DEFAULT_BROWSER=firefox.desktop run bash "$REPO/webapp" open https://example.com
[ "$status" -eq 0 ]
called xdg-open https://example.com
}