#!/usr/bin/env bats load test_helper # version runs from a fake checkout with fake git, uname, pacman and # checkupdates. The running kernel's modules never exist here, so the kernel # line always also says a newer one is installed. Sibling projects are real git # repositories: only git commands on the fake checkout are faked. setup() { common_setup CD="$HOME/.local/share/coredesktop" mkdir -p "$CD" cp "$REPO/version" "$REPO/utils.sh" "$REPO/sibling" "$CD/" export CD REAL_GIT REAL_GIT="$(command -v git)" stub git '[ "$2" = "$CD" ] || exec "$REAL_GIT" "$@" case "$3" in rev-parse) exit 0 ;; log) echo "2026.10.31 (6bc4fdc)" ;; fetch) exit 1 ;; esac' stub uname 'echo "${KERNEL:-9.9.1-arch1-1}"' # pacman -Q : the versions in $INSTALLED, "name version" per line. # pacman -Sl federated: $FEDERATED's names, as installed from that repo. # pacman -Qlq : a GNOME Shell extension's files for $EXTENSION_PKG. stub pacman 'case "$1" in -Sl) [ "$2" = federated ] && [ -n "$FEDERATED" ] || exit 1 for name in $FEDERATED; do echo "federated $name $(grep "^$name " <<< "$INSTALLED" | cut -d" " -f2) [installed]" done ;; -Qlq) [ "$2" = "$EXTENSION_PKG" ] || exit 1 printf "%s\n" /usr/share/gnome-shell/ /usr/share/gnome-shell/extensions/ \ /usr/share/gnome-shell/extensions/menu@example.com/ \ /usr/share/gnome-shell/extensions/menu@example.com/extension.js ;; *) grep "^$2 " <<< "$INSTALLED" || exit 1 ;; esac' # This user's GNOME Shell started $SHELL_AGE seconds ago, if it's set, with # the extensions in $ENABLED turned on stub pgrep '[ -n "$SHELL_AGE" ] && echo 4242 || exit 1' stub ps 'echo " $SHELL_AGE"' stub gsettings 'echo "$ENABLED"' export FEDERATED="" EXTENSION_PKG="" SHELL_AGE="" ENABLED="@as []" export PACMAN_LOCAL_DB="$BATS_TEST_TMPDIR/local" stub checkupdates 'printf "%s" "$PENDING"; [ -n "$PENDING" ] || exit 2' export INSTALLED="mesa 1:26.2.6-1" PENDING="" # The mirror synced $SYNCED_HOURS ago (an hour by default) export MIRRORLIST="$BATS_TEST_TMPDIR/mirrorlist" SYNCED_HOURS=1 echo 'Server = https://mirror.example/archlinux/$repo/os/$arch' > "$MIRRORLIST" stub curl 'echo "$(( $(date +%s) - SYNCED_HOURS * 3600 ))"' } @test "version shows the kernel and Mesa, with nothing newer to install" { run bash "$CD/version" [ "$status" -eq 0 ] [[ "$output" == *"CoreDesktop 2026.10.31 (6bc4fdc)"* ]] [[ "$output" == *"Kernel 9.9.1-arch1-1 (newer kernel installed, reboot to use it)"$'\n'* ]] [[ "$output" == *"Video driver Mesa 26.2.6"$'\n'* ]] [[ "$output" != *"is available"* ]] [[ "$output" != *"mirror"* ]] } @test "version suggests update for a newer kernel and video driver" { export PENDING=$'linux 9.9.1.arch1-1 -> 9.9.2.arch1-1\nmesa 1:26.2.6-1 -> 1:26.3.0-1\n' run bash "$CD/version" [ "$status" -eq 0 ] [[ "$output" == *"Kernel 9.9.1-arch1-1"*", 9.9.2 is available (run update)"* ]] [[ "$output" == *"Video driver Mesa 26.2.6, 26.3.0 is available (run update)"* ]] } @test "version shows NVIDIA's driver over Mesa, and ignores a rebuild of the same version" { export INSTALLED=$'mesa 1:26.2.6-1\nnvidia-utils 615.78.08-1' export PENDING=$'nvidia-utils 615.78.08-1 -> 615.78.08-2\n' run bash "$CD/version" [ "$status" -eq 0 ] [[ "$output" == *"Video driver NVIDIA 615.78.08"$'\n'* ]] [[ "$output" != *"is available"* ]] } @test "version checks the kernel package that's running, e.g. linux-lts" { export KERNEL=6.12.50-1-lts export PENDING=$'linux 9.9.1.arch1-1 -> 9.9.2.arch1-1\nlinux-lts 6.12.50-1 -> 6.12.51-1\n' run bash "$CD/version" [ "$status" -eq 0 ] [[ "$output" == *"6.12.51 is available"* ]] [[ "$output" != *"9.9.2"* ]] } @test "version leaves out what's available when it can't check" { rm "$STUB_BIN/checkupdates" stub checkupdates 'exit 1' export PENDING=$'linux 9.9.1.arch1-1 -> 9.9.2.arch1-1\n' run bash "$CD/version" [ "$status" -eq 0 ] [[ "$output" == *"Kernel 9.9.1-arch1-1"* ]] [[ "$output" != *"is available"* ]] } @test "version warns when the package mirror is behind Arch" { export SYNCED_HOURS=73 run bash "$CD/version" [ "$status" -eq 0 ] [[ "$output" == *"Your package mirror (https://mirror.example/archlinux) last synced with Arch 3 days ago"* ]] [[ "$output" == *"Run update"* ]] } @test "version doesn't warn about a mirror it can't reach" { rm "$STUB_BIN/curl" stub curl 'exit 7' run bash "$CD/version" [ "$status" -eq 0 ] [[ "$output" != *"mirror"* ]] } # installed_at PACKAGE-VERSION SECONDS_AGO: pacman's record of when it was installed installed_at() { mkdir -p "$PACMAN_LOCAL_DB/$1" printf '%%NAME%%\nx\n\n%%INSTALLDATE%%\n%s\n\n' "$(( $(date +%s) - $2 ))" > "$PACMAN_LOCAL_DB/$1/desc" } @test "version leaves out federated packages when none are installed" { run bash "$CD/version" [ "$status" -eq 0 ] [[ "$output" != *"Federated"* ]] } @test "version lists federated packages, with newer builds, even a rebuild" { export INSTALLED=$'mesa 1:26.2.6-1\nfederated-calendar 52.alpha.r1-1\ngnome-shell-extension-coredesktop 1:1.0.r3.g9e514eb-1' export FEDERATED="federated-calendar gnome-shell-extension-coredesktop" export PENDING=$'gnome-shell-extension-coredesktop 1:1.0.r3.g9e514eb-1 -> 1:1.0.r3.g9e514eb-2\n' run bash "$CD/version" [ "$status" -eq 0 ] [[ "$output" == *"Federated packages"$'\n'" federated-calendar 52.alpha.r1-1"$'\n'* ]] [[ "$output" == *" gnome-shell-extension-coredesktop 1.0.r3.g9e514eb-1, 1.0.r3.g9e514eb-2 is available (run update)"* ]] } @test "version says when it couldn't check federated packages for a newer build" { rm "$STUB_BIN/checkupdates" stub checkupdates 'exit 1' export INSTALLED=$'mesa 1:26.2.6-1\nfederated-calendar 52.alpha.r1-1' export FEDERATED="federated-calendar" run bash "$CD/version" [ "$status" -eq 0 ] [[ "$output" == *" federated-calendar 52.alpha.r1-1, couldn't check for a newer version"* ]] } @test "version says to log out to use an extension upgraded since login" { export INSTALLED=$'mesa 1:26.2.6-1\ngnome-shell-extension-coredesktop 1.0.r4-1' export FEDERATED="gnome-shell-extension-coredesktop" EXTENSION_PKG="gnome-shell-extension-coredesktop" export SHELL_AGE=3600 ENABLED="['other@example.com', 'menu@example.com']" installed_at gnome-shell-extension-coredesktop-1.0.r4-1 60 run bash "$CD/version" [ "$status" -eq 0 ] [[ "$output" == *" gnome-shell-extension-coredesktop 1.0.r4-1 (newer version installed, log out and back in to use it)" ]] } @test "version doesn't say to log out for an extension installed before login, or turned off" { export INSTALLED=$'mesa 1:26.2.6-1\ngnome-shell-extension-coredesktop 1.0.r4-1' export FEDERATED="gnome-shell-extension-coredesktop" EXTENSION_PKG="gnome-shell-extension-coredesktop" export SHELL_AGE=3600 ENABLED="['menu@example.com']" installed_at gnome-shell-extension-coredesktop-1.0.r4-1 7200 run bash "$CD/version" [ "$status" -eq 0 ] [[ "$output" != *"log out"* ]] installed_at gnome-shell-extension-coredesktop-1.0.r4-1 60 export ENABLED="['other@example.com']" run bash "$CD/version" [ "$status" -eq 0 ] [[ "$output" != *"log out"* ]] # Nor when GNOME Shell isn't running, e.g. over ssh export ENABLED="['menu@example.com']" SHELL_AGE="" run bash "$CD/version" [ "$status" -eq 0 ] [[ "$output" != *"log out"* ]] } # sibling_repo NAME: a sibling at v1.0.0 whose origin has a newer v1.1.0 sibling_repo() { export GIT_AUTHOR_NAME=Test GIT_AUTHOR_EMAIL=test@example.com export GIT_COMMITTER_NAME=Test GIT_COMMITTER_EMAIL=test@example.com local origin="$BATS_TEST_TMPDIR/origins/$1" git init -q -b main "$origin" echo 'echo "$PWD" >> "$HOME/updated"' > "$origin/update.sh" git -C "$origin" add -A git -C "$origin" commit -qm first git -C "$origin" tag v1.0.0 git clone -q "$origin" "$HOME/.local/share/siblings/$1" git -C "$origin" commit -q --allow-empty -m second git -C "$origin" tag v1.1.0 } @test "version leaves out sibling projects when none are installed" { run bash "$CD/version" [ "$status" -eq 0 ] [[ "$output" != *"Sibling"* ]] } @test "version lists sibling projects, and doesn't ask to update without a terminal" { sibling_repo tools run bash "$CD/version" < /dev/null [ "$status" -eq 0 ] [[ "$output" == *"Sibling projects"$'\n'" tools v1.0.0, v1.1.0 is available"* ]] [[ "$output" != *"Update tools"* ]] [ ! -f "$HOME/updated" ] } @test "version updates the sibling projects the user says yes to" { sibling_repo keep sibling_repo tools run script -qec "bash '$CD/version'" /dev/null <<< $'n\ny' [ "$status" -eq 0 ] [[ "$output" == *"Update keep to v1.1.0? [y/N]"* ]] [[ "$output" == *"tools is at v1.1.0."* ]] [ "$(cat "$HOME/updated")" = "$HOME/.local/share/siblings/tools" ] } @test "version shows a spinner on a terminal while it checks, and clears it" { run script -qec "bash '$CD/version'" /dev/null < /dev/null [ "$status" -eq 0 ] [[ "$output" == *"Checking for updates..."* ]] # Cleared, and the cursor shown again, before the results are printed [[ "$output" == *$'\r\e[K\e[?25hCoreDesktop 2026.10.31'* ]] } @test "version shows no spinner when its output isn't a terminal" { run bash "$CD/version" [ "$status" -eq 0 ] [[ "$output" != *"Checking"* ]] [[ "$output" != *$'\e[?25l'* ]] }