#!/usr/bin/env bash # Smoke tests for scripts/dev-setup/bluefin.sh. # # Runs locally on the EDIT host without any bluefin/bootc prereqs — # exercises the shell logic via bash -n (parse) and the --help / --check # argument paths, which must not require sudo or rpm-ostree on the caller. # # Usage: # bash scripts/dev-setup/test_bluefin.sh # run all tests # bash scripts/dev-setup/test_bluefin.sh -v # verbose # # Exit codes: # 0 all tests passed # 1 at least one test failed # # Wired into CI via `./run verify` → scripts/run/verify.sh once that lands. set -uo pipefail REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" BLUEFIN="$REPO_ROOT/scripts/dev-setup/bluefin.sh" GREEN='\033[0;32m' RED='\033[0;31m' DIM='\033[2m' NC='\033[0m' pass_count=0 fail_count=0 fail_names=() _verbose=false for a in "$@"; do case "$a" in -v|--verbose) _verbose=true ;; esac done run_test() { local name="$1"; shift if "$@" >/tmp/bluefin-test-stdout.log 2>/tmp/bluefin-test-stderr.log; then pass_count=$((pass_count + 1)) echo -e " ${GREEN}PASS${NC} $name" else fail_count=$((fail_count + 1)) fail_names+=("$name") echo -e " ${RED}FAIL${NC} $name" if [ "$_verbose" = "true" ]; then echo -e "${DIM}--- stdout ---${NC}" cat /tmp/bluefin-test-stdout.log echo -e "${DIM}--- stderr ---${NC}" cat /tmp/bluefin-test-stderr.log fi fi } echo "scripts/dev-setup/bluefin.sh — smoke tests" # 1. Script exists and is executable test_script_exists() { test -x "$BLUEFIN" } run_test "bluefin.sh exists + executable" test_script_exists # 2. Shell parses cleanly (no syntax errors) test_parses_cleanly() { bash -n "$BLUEFIN" } run_test "bash -n passes (shell syntax valid)" test_parses_cleanly # 3. --help works and mentions --check test_help_mentions_check() { local out out="$("$BLUEFIN" --help 2>&1)" || return 1 grep -q -- '--check' <<< "$out" } run_test "--help output mentions --check" test_help_mentions_check # 4. Unknown arg exits nonzero test_unknown_arg_rejected() { if "$BLUEFIN" --not-a-real-flag >/dev/null 2>&1; then return 1 # unexpected success fi return 0 } run_test "unknown argument exits nonzero" test_unknown_arg_rejected # 5. On non-bluefin hosts (EDIT host is macOS / non-rpm-ostree Linux), # running without --check must exit 2 because rpm-ostree is absent. # This guards the "don't try to install on hosts that don't support it". test_non_rpm_ostree_host_refuses_install() { if command -v rpm-ostree >/dev/null 2>&1; then # On a bluefin host, this test is a no-op — the install path is # legitimate here. Skip by returning success. echo "[skip] running on an rpm-ostree host; install path is valid here" return 0 fi # On non-rpm-ostree hosts, invoking bluefin.sh without --check should # immediately fail with exit 2 (per the preconditions block). "$BLUEFIN" >/dev/null 2>&1 local rc=$? # Exit 2 is the expected "unsupported host" signal. [ $rc -eq 2 ] } run_test "non-rpm-ostree host refuses install with exit 2" test_non_rpm_ostree_host_refuses_install # 6. REQUIRED_PACKAGES list is defined and non-empty (catches refactor # accidentally emptying the manifest). Parse the array literal # directly from the file text — sourcing the script is unsafe because # it exits on help/check/unknown paths. test_required_packages_non_empty() { # Count non-blank, non-comment lines between `REQUIRED_PACKAGES=(` and # the matching `)`. local n n="$(awk '/^REQUIRED_PACKAGES=\(/{f=1;next} f && /^\)/{exit} f && NF && $0 !~ /^[[:space:]]*#/{c++} END{print c+0}' "$BLUEFIN")" [ -n "$n" ] && [ "$n" -ge 3 ] } run_test "REQUIRED_PACKAGES defines >= 3 entries" test_required_packages_non_empty # 7. REQUIRED_PACKAGES contains the three canonical entries test_required_packages_includes_canonical() { grep -q 'weston' "$BLUEFIN" || return 1 grep -q 'vulkan-tools' "$BLUEFIN" || return 1 grep -q 'mesa-vulkan-drivers' "$BLUEFIN" || return 1 } run_test "REQUIRED_PACKAGES lists weston + vulkan-tools + mesa-vulkan-drivers" \ test_required_packages_includes_canonical # ── Summary ───────────────────────────────────────────────────────── echo "" if [ $fail_count -eq 0 ]; then echo -e "${GREEN}All $pass_count tests passed.${NC}" exit 0 else echo -e "${RED}$fail_count test(s) failed:${NC}" for n in "${fail_names[@]}"; do echo -e " ${RED}×${NC} $n" done echo "" echo "Re-run with -v for stdout/stderr:" echo " bash $0 -v" exit 1 fi