`hampackcheck packages` (and so the weekly `make check-packages`) now asks Flathub's API for each Flatpak's permissions, and fails if its devices don't include all, without which it can't see /dev/ttyUSB0 to control a radio itself, or if Flathub can't say. WSJT-X and QLog both have it. radio configure doesn't need it: it points them at rigctld over the network. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
246 lines
8.3 KiB
Bash
246 lines
8.3 KiB
Bash
#!/usr/bin/env bats
|
|
|
|
load helpers
|
|
|
|
# curl, git and pacman are stubbed: GitHub releases, tags, HEADs, Last-Modified
|
|
# dates, the AUR and Flathub all answer from files in $FAKE_NET
|
|
setup() {
|
|
setup_fake_home
|
|
export FAKE_NET="$BATS_TEST_TMPDIR/net"
|
|
mkdir -p "$FAKE_NET"
|
|
export HAMPACK_BINARIES_CONF="$BATS_TEST_TMPDIR/binaries.conf"
|
|
export HAMPACK_COMPILE_CONF="$BATS_TEST_TMPDIR/compile.conf"
|
|
export HAMPACK_PACKAGES_CONF="$BATS_TEST_TMPDIR/packages.conf"
|
|
: > "$HAMPACK_BINARIES_CONF"
|
|
: > "$HAMPACK_COMPILE_CONF"
|
|
|
|
stub curl '
|
|
url=""; for a in "$@"; do case "$a" in https://*) url="$a" ;; esac; done
|
|
case "$url" in
|
|
https://api.github.com/repos/*/releases/latest)
|
|
f="$FAKE_NET/release-$(echo "$url" | cut -d/ -f5-6 | tr / _)"
|
|
[ -f "$f" ] || exit 22
|
|
echo "{\"tag_name\": \"$(cat "$f")\"}" ;;
|
|
https://aur.archlinux.org/*)
|
|
[ -f "$FAKE_NET/aur-down" ] && exit 7
|
|
printf "{\"results\":["; sep=""
|
|
for a in "$@"; do
|
|
case "$a" in "arg[]="*)
|
|
p="${a#arg[]=}"
|
|
grep -qxF "$p" "$FAKE_NET/aur" 2>/dev/null && { printf "%s{\"Name\":\"%s\"}" "$sep" "$p"; sep=,; } ;;
|
|
esac
|
|
done
|
|
echo "]}" ;;
|
|
https://flathub.org/api/v2/summary/*)
|
|
f="$FAKE_NET/summary-${url##*/}"
|
|
[ -f "$f" ] || exit 22
|
|
cat "$f" ;;
|
|
https://flathub.org/*)
|
|
grep -qxF "${url##*/}" "$FAKE_NET/flathub" 2>/dev/null && echo 200 || echo 404 ;;
|
|
*)
|
|
f="$FAKE_NET/modified-${url##*/}"
|
|
[ -f "$f" ] || exit 22
|
|
printf "HTTP/1.1 200 OK\r\nLast-Modified: %s\r\n" "$(cat "$f")" ;;
|
|
esac'
|
|
|
|
stub git '
|
|
[ "$1" = ls-remote ] || exit 1
|
|
if [ "$2" = --tags ]; then cat "$FAKE_NET/tags-${4##*/}" 2>/dev/null
|
|
else f="$FAKE_NET/head-${2##*/}"; [ -f "$f" ] && printf "%s\tHEAD\n" "$(cat "$f")"
|
|
fi; exit 0'
|
|
|
|
# Repo packages, groups, and names only provided by another package
|
|
stub pacman '
|
|
case "$1" in
|
|
-Si) grep -qxF "$2" "$FAKE_NET/repo" 2>/dev/null ;;
|
|
-Sg) grep -qxF "$2" "$FAKE_NET/groups" 2>/dev/null ;;
|
|
-Sddp) grep "^$4=" "$FAKE_NET/provides" 2>/dev/null | cut -d= -f2 | grep . ;;
|
|
*) exit 1 ;;
|
|
esac'
|
|
}
|
|
|
|
# A Flatpak on Flathub, with these devices: flathub_app ID [DEVICES...]
|
|
flathub_app() {
|
|
local id="$1"
|
|
shift
|
|
echo "$id" >> "$FAKE_NET/flathub"
|
|
jq -n --args '{metadata: {permissions: {devices: $ARGS.positional, shared: ["network"]}}}' "$@" > "$FAKE_NET/summary-$id"
|
|
}
|
|
|
|
tags() { local repo="$1"; shift; printf 'abc\trefs/tags/%s\n' "$@" > "$FAKE_NET/tags-$repo"; }
|
|
|
|
packages_conf() {
|
|
printf 'UTILITIES=(\n%s\n)\nAPPLICATIONS=(\n%s\n)\nFLATPAKS=(\n%s\n)\n' "$1" "$2" "$3" > "$HAMPACK_PACKAGES_CONF"
|
|
}
|
|
|
|
@test "hampackcheck: binaries are compared with their latest GitHub release" {
|
|
cat > "$HAMPACK_BINARIES_CONF" << 'EOF'
|
|
[old]
|
|
version=1.0
|
|
url=https://github.com/me/old/releases/download/v1.0/old
|
|
sha256=x
|
|
[current]
|
|
version=2.0
|
|
url=https://github.com/me/current/releases/download/v2.0/current
|
|
sha256=x
|
|
[offline]
|
|
version=1.0
|
|
url=https://github.com/me/offline/releases/download/1.0/offline
|
|
sha256=x
|
|
[elsewhere]
|
|
version=1.0
|
|
url=https://example.com/files/elsewhere
|
|
EOF
|
|
echo v1.1 > "$FAKE_NET/release-me_old"
|
|
echo v2.0 > "$FAKE_NET/release-me_current"
|
|
run "$REPO/hampackcheck" versions
|
|
[ "$status" -eq 0 ]
|
|
[[ "$output" =~ old\ +pinned=1.0\ +latest=1.1\ +\*\*\ UPDATE\ AVAILABLE ]]
|
|
[[ "$output" =~ current\ +up\ to\ date\ \(2.0\) ]]
|
|
[[ "$output" =~ offline\ +pinned=1.0\ +\(GitHub\ API\ unavailable\) ]]
|
|
[[ "$output" == *"manual check: https://example.com/files"* ]]
|
|
[[ "$output" == *"elsewhere has no sha256="* ]]
|
|
}
|
|
|
|
@test "hampackcheck: a binary pinned to a commit is compared with upstream HEAD" {
|
|
cat > "$HAMPACK_BINARIES_CONF" << 'EOF'
|
|
[script]
|
|
version=aaaa
|
|
url=https://raw.githubusercontent.com/me/script/aaaa/script.py
|
|
sha256=x
|
|
EOF
|
|
echo bbbb > "$FAKE_NET/head-script"
|
|
run "$REPO/hampackcheck" versions
|
|
[[ "$output" =~ script\ +pinned=aaaa\ +latest=bbbb ]]
|
|
}
|
|
|
|
@test "hampackcheck: built apps use the newest plain version tag, not pre-releases" {
|
|
cat > "$HAMPACK_COMPILE_CONF" << 'EOF'
|
|
[app]
|
|
version=1.9
|
|
git=https://example.com/app
|
|
EOF
|
|
tags app v1.9 v1.10 v2.0-beta1 nightly 1.2
|
|
run "$REPO/hampackcheck" versions
|
|
[[ "$output" =~ app\ +pinned=1.9\ +latest=1.10\ +\*\*\ UPDATE ]]
|
|
}
|
|
|
|
@test "hampackcheck: a built app shows its name= rather than its section" {
|
|
printf '[app-improved]\nname=App\nversion=1.0\ngit=https://example.com/app\n' > "$HAMPACK_COMPILE_CONF"
|
|
tags app 1.0
|
|
run "$REPO/hampackcheck" versions
|
|
[[ "$output" =~ App\ +up\ to\ date ]]
|
|
[[ "$output" != *app-improved* ]]
|
|
}
|
|
|
|
@test "hampackcheck: an untagged repo pinned with ref= is compared with HEAD" {
|
|
cat > "$HAMPACK_COMPILE_CONF" << 'EOF'
|
|
[same]
|
|
version=1.0
|
|
git=https://example.com/same
|
|
ref=1111111111
|
|
[moved]
|
|
version=1.0
|
|
git=https://example.com/moved
|
|
ref=1111111111
|
|
EOF
|
|
echo 1111111111 > "$FAKE_NET/head-same"
|
|
echo 2222222222 > "$FAKE_NET/head-moved"
|
|
run "$REPO/hampackcheck" versions
|
|
[[ "$output" =~ same\ +up\ to\ date ]]
|
|
[[ "$output" =~ moved\ +pinned=1.0\ +latest=HEAD\ 2222222222 ]]
|
|
}
|
|
|
|
@test "hampackcheck: an archive versioned by date is compared with its Last-Modified date" {
|
|
cat > "$HAMPACK_COMPILE_CONF" << 'EOF'
|
|
[dated]
|
|
version=2026-01-01
|
|
wget=https://example.com/dated.zip
|
|
[numbered]
|
|
version=3.0
|
|
wget=https://example.com/numbered.zip
|
|
EOF
|
|
echo "Fri, 06 Mar 2026 12:00:00 GMT" > "$FAKE_NET/modified-dated.zip"
|
|
run "$REPO/hampackcheck" versions
|
|
[[ "$output" =~ dated\ +pinned=2026-01-01\ +latest=2026-03-06 ]]
|
|
[[ "$output" == *"manual check: https://example.com"* ]]
|
|
}
|
|
|
|
@test "hampackcheck: versions alone doesn't check packages" {
|
|
run "$REPO/hampackcheck" versions
|
|
[ "$status" -eq 0 ]
|
|
[[ "$output" != *packages.conf* ]]
|
|
}
|
|
|
|
@test "hampackcheck: packages in the repos, groups, the AUR and Flathub all pass" {
|
|
packages_conf "repo-pkg
|
|
a-group # with a comment" "aur-pkg" "org.example.App"
|
|
echo repo-pkg > "$FAKE_NET/repo"
|
|
echo a-group > "$FAKE_NET/groups"
|
|
echo aur-pkg > "$FAKE_NET/aur"
|
|
flathub_app org.example.App all
|
|
run "$REPO/hampackcheck" packages
|
|
[ "$status" -eq 0 ]
|
|
[[ "$output" == *"org.example.App can open serial ports (devices=all)"* ]]
|
|
[[ "$output" == *"3 packages, 2 in the repos"* ]]
|
|
[[ "$output" == *"aur-pkg is on the AUR"* ]]
|
|
[[ "$output" == *"org.example.App is on Flathub"* ]]
|
|
[[ "$output" != *MISSING* ]]
|
|
}
|
|
|
|
@test "hampackcheck: a misspelt package or Flatpak fails the check" {
|
|
packages_conf "repo-pkg
|
|
repo-pgk" "aur-pkg" "org.example.Ap"
|
|
echo repo-pkg > "$FAKE_NET/repo"
|
|
echo aur-pkg > "$FAKE_NET/aur"
|
|
run "$REPO/hampackcheck" packages
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" == *"repo-pgk is in neither the repos nor the AUR ** MISSING **"* ]]
|
|
[[ "$output" == *"org.example.Ap is not on Flathub ** MISSING **"* ]]
|
|
[[ "$output" != *"repo-pkg is"* ]]
|
|
}
|
|
|
|
@test "hampackcheck: a Flatpak that can't open serial ports fails the check" {
|
|
packages_conf "" "" "org.example.Dri
|
|
org.example.None
|
|
org.example.Unknown"
|
|
flathub_app org.example.Dri dri
|
|
flathub_app org.example.None
|
|
echo org.example.Unknown >> "$FAKE_NET/flathub"
|
|
run "$REPO/hampackcheck" packages
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" == *"org.example.Dri can't open serial ports: its devices are \"dri\", not all ** NO SERIAL PORTS **"* ]]
|
|
[[ "$output" == *"org.example.None can't open serial ports: its devices are \"none\", not all"* ]]
|
|
[[ "$output" == *"org.example.Unknown's permissions couldn't be checked"* ]]
|
|
}
|
|
|
|
@test "hampackcheck: a name only provided by another package passes, with a note" {
|
|
packages_conf "old-name" "" ""
|
|
echo "old-name=new-name" > "$FAKE_NET/provides"
|
|
run "$REPO/hampackcheck" packages
|
|
[ "$status" -eq 0 ]
|
|
[[ "$output" == *"old-name is provided by new-name"* ]]
|
|
}
|
|
|
|
@test "hampackcheck: if the AUR can't be reached, the check fails rather than passing" {
|
|
packages_conf "aur-pkg" "" ""
|
|
touch "$FAKE_NET/aur-down"
|
|
run "$REPO/hampackcheck" packages
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" == *"The AUR couldn't be reached, so these weren't checked: aur-pkg"* ]]
|
|
}
|
|
|
|
@test "hampackcheck: with everything in the repos, the AUR isn't asked" {
|
|
packages_conf "repo-pkg" "" ""
|
|
echo repo-pkg > "$FAKE_NET/repo"
|
|
touch "$FAKE_NET/aur-down"
|
|
run "$REPO/hampackcheck" packages
|
|
[ "$status" -eq 0 ]
|
|
}
|
|
|
|
@test "hampackcheck: an unknown argument prints the usage" {
|
|
run "$REPO/hampackcheck" everything
|
|
[ "$status" -eq 2 ]
|
|
[[ "$output" == Usage:* ]]
|
|
}
|