#!/usr/bin/env bash # ka-build test suite — dry-run paths only. # # Phase-1 deliverable per issue #34. The full makepkg path is exercised # manually on boltzmann (parity test against the most recent hand-built # linux-fresnel-fourier pkg); not in this suite because: # - Needs real ssh to boltzmann + ~30 min build wall time # - Hermetic sandbox would need a mock marfrit-publish-arch on hertz # Future-work: add a `--mock-build-host` flag + fixture builder so this # can run in CI. # # What this suite covers: # - Argument parsing + required-host check # - manifest.yaml read + package.name / build_host.primary extraction # - Refuses if manifest.lock missing (ka-promote not run) # - Refuses if PKGBUILD missing # - Refuses on patch drift between kernel-agent and marfrit-packages # - Happy-path dry-run on fresnel (all 6 patches match) set -euo pipefail repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" packages_repo="${PACKAGES_REPO_FOR_TESTS:-${HOME}/src/marfrit-packages}" pass=0 fail=0 results=() note() { printf ' %s\n' "$*"; } ok() { results+=("PASS $1"); pass=$((pass+1)); note "PASS"; } ko() { results+=("FAIL $1: $2"); fail=$((fail+1)); note "FAIL: $2"; } # Reset build/ before running so we exercise the "no manifest.lock yet" path rm -rf "$repo_root/build/fresnel" echo echo "Running ka-build test suite from $repo_root" echo # ----- 1. requires host arg ----- echo "::: requires host arg" set +e out=$("$repo_root/bin/ka-build" 2>&1) rc=$? set -e if [ "$rc" -eq 2 ] && echo "$out" | grep -q "host is required"; then ok "requires host arg"; else ko "requires host arg" "exit=$rc out=$out"; fi # ----- 2. unknown flag ----- echo "::: unknown flag rejected" set +e out=$("$repo_root/bin/ka-build" fresnel --nonsense 2>&1) rc=$? set -e if [ "$rc" -ne 0 ] && echo "$out" | grep -q "unknown flag"; then ok "unknown flag rejected"; else ko "unknown flag rejected" "exit=$rc out=$out"; fi # ----- 3. refuses if manifest.lock missing ----- echo "::: refuses if manifest.lock missing (ka-promote not run)" set +e out=$("$repo_root/bin/ka-build" fresnel --dry-run --packages-repo "$packages_repo" 2>&1) rc=$? set -e if [ "$rc" -eq 2 ] && echo "$out" | grep -q "no manifest.lock"; then ok "refuses no-lock"; else ko "refuses no-lock" "exit=$rc out=$out"; fi # Now run ka-promote so the rest can proceed "$repo_root/bin/ka-promote" fresnel >/dev/null # ----- 4. refuses if PKGBUILD missing ----- echo "::: refuses if PKGBUILD missing (--packages-repo wrong)" set +e out=$("$repo_root/bin/ka-build" fresnel --dry-run --packages-repo /tmp/non-existent-mp 2>&1) rc=$? set -e if [ "$rc" -eq 2 ]; then ok "refuses bad packages-repo"; else ko "refuses bad packages-repo" "exit=$rc out=$out"; fi # ----- 5. happy-path dry-run ----- echo "::: happy-path dry-run (fresnel, real packages-repo)" if [ ! -f "$packages_repo/arch/linux-fresnel-fourier/PKGBUILD" ]; then note "SKIP: $packages_repo/arch/linux-fresnel-fourier/PKGBUILD not present" results+=("SKIP happy-path dry-run (PKGBUILD missing locally)") else set +e out=$("$repo_root/bin/ka-build" fresnel --dry-run --packages-repo "$packages_repo" 2>&1) rc=$? set -e if [ "$rc" -eq 0 ] && echo "$out" | grep -q "patches OK (6 files)"; then ok "happy-path dry-run"; else ko "happy-path dry-run" "exit=$rc out=$out"; fi fi # ----- 6. patch drift detection ----- echo "::: patch drift detection (mutate a copied patch, expect exit 3)" if [ ! -d "$packages_repo/arch/linux-fresnel-fourier" ]; then note "SKIP: $packages_repo/arch/linux-fresnel-fourier not present" results+=("SKIP patch drift detection") else sandbox=$(mktemp -d -t ka-build-drift.XXXXXX) cp -r "$packages_repo/arch/linux-fresnel-fourier" "$sandbox/linux-fresnel-fourier" mkdir -p "$sandbox/arch" mv "$sandbox/linux-fresnel-fourier" "$sandbox/arch/linux-fresnel-fourier" # Mutate one patch so its sha256 differs from manifest.lock's recorded sha echo "drift" >> "$sandbox/arch/linux-fresnel-fourier/0001-arm64-dts-rk3399-pinebook-pro-add-OC-OPP-tables-1704-2184.patch" set +e out=$("$repo_root/bin/ka-build" fresnel --dry-run --packages-repo "$sandbox" 2>&1) rc=$? set -e rm -rf "$sandbox" if [ "$rc" -eq 3 ] && echo "$out" | grep -q "DRIFT:"; then ok "patch drift detection"; else ko "patch drift detection" "exit=$rc out=$out"; fi fi echo echo "====================" printf '%s\n' "${results[@]}" echo "====================" echo "passed: $pass" echo "failed: $fail" [ "$fail" -eq 0 ] || exit 1