12set -euo pipefail34if [[ $# -ne 3 ]]; then5 echo "usage: smoke-linux.sh <package.deb> <version> <repo-root>" >&26 exit 27fi89package=$(cd "$(dirname "$1")" && pwd)/$(basename "$1")10version=$211root=$312test -f "$package"13deb_version=${version#v}14if [[ ! "$deb_version" =~ ^[0-9] ]]; then15 deb_version="0~$deb_version"16fi17stage=$(mktemp -d)18app_pid=""19cleanup() {20 if [[ -n "$app_pid" ]]; then kill "$app_pid" >/dev/null 2>&1 || true; fi21 rm -rf "$stage"22}23trap cleanup EXIT2425sudo apt-get install -y "$package" xvfb dbus-x1126dpkg-query -W -f='${Status}\n${Version}\n${Architecture}\n' atlas-desktop \27 | grep -Fx 'install ok installed'28dpkg-query -W -f='${Version}' atlas-desktop | grep -Fx "$deb_version"29dpkg-query -W -f='${Architecture}' atlas-desktop | grep -Fx amd6430test -x /usr/bin/Atlas31test -f /usr/share/applications/dev.felinestatemachine.Atlas.desktop32test -f /usr/share/mime/packages/dev.felinestatemachine.atlas.xml3334go run "$root/cmd/atlas" build -cache "$stage/cache" -bundles "$stage/source" \35 "$root/examples/sample-region.atlas-project"36artifact=$(find "$stage/source" -maxdepth 1 -type f -name 'sample-region-*.atlas' -print -quit)37test -n "$artifact"38xdg_type=$(xdg-mime query filetype "$artifact" || true)39echo "headless xdg-mime diagnostic: $xdg_type"40# xdg-mime selects its backend from the desktop session and falls back to the41# file(1) database on a headless runner, which cannot see a package's42# shared-mime-info additions. GIO is the desktop stack this package registers.43file_type=$(gio info --attributes=standard::content-type "$artifact" \44 | sed -n 's/^ standard::content-type: //p')45echo "installed Atlas GIO MIME type: $file_type"46[[ "$file_type" == application/vnd.felinestatemachine.atlas ]] || {47 echo "unexpected Atlas MIME type: $file_type" >&248 exit 149}50handlers=$(gio mime application/vnd.felinestatemachine.atlas)51echo "$handlers"52grep -F 'dev.felinestatemachine.Atlas.desktop' <<<"$handlers" >/dev/null || {53 echo "Atlas desktop handler is not registered" >&254 exit 155}5657mkdir -p "$stage/library" "$stage/data"58ATLAS_BUNDLES_DIR="$stage/library" ATLAS_DATA_DIR="$stage/data" \59 dbus-run-session -- xvfb-run -a /usr/bin/Atlas "$artifact" \60 >"$stage/atlas.log" 2>&1 &61app_pid=$!62for _ in $(seq 1 60); do63 if find "$stage/library" -maxdepth 1 -type f -name 'sample-region-*.atlas' -print -quit | grep -q .; then64 break65 fi66 kill -0 "$app_pid" 2>/dev/null || { cat "$stage/atlas.log" >&2; exit 1; }67 sleep 168done69installed=$(find "$stage/library" -maxdepth 1 -type f -name 'sample-region-*.atlas' -print -quit)70test -n "$installed"71cmp "$artifact" "$installed"