Files
coredesktop/tests/version.bats
T
davidandClaude Opus 5.5 ee7451600b
shellcheck / shellcheck (push) Failing after 19s
Show sibling projects' versions, and let version update them
A sibling's version is its latest git tag (v1.4.0, or v1.4.0+3 for commits
after it), or, without tags, its commit's date and short hash, like
CoreDesktop's own. The version shown as available is that of the newest
commit on the default branch, which is what update installs.

sibling list shows each sibling's version. sibling check fetches every
sibling at once and shows which have a newer version, and sibling update
[name...] updates the named siblings or all of them. 71-siblings.sh now
runs sibling update, so update and version share one way of updating.

version lists the installed siblings with any newer version and, when run
in a terminal, asks for each one whether to update it now. version --check
and the update notification still only look at CoreDesktop.

The sibling skill docs describe how to release a version by tagging it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 10:26:51 -07:00

136 lines
4.9 KiB
Bash

#!/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 <package>: the versions in $INSTALLED, "name version" per line
stub pacman 'grep "^$2 " <<< "$INSTALLED" || exit 1'
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"* ]]
}
# 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" ]
}