Files
coredesktop/tests/pacman-guard.bats
T
davidandClaude Opus 5.5 9dc5eb193d
shellcheck / shellcheck (push) Failing after 19s
Add upgrade safeguards, hardware setup, sign-in options and Taildrop from Omarchy
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>
2026-11-16 12:08:06 -07:00

93 lines
2.9 KiB
Bash

#!/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
}