installer

This commit is contained in:
2026-09-22 08:18:02 -03:00
parent 2a0a793f19
commit dee899d86f
36 changed files with 521 additions and 13 deletions

52
rig/ctrl/hosttest.sh Executable file
View File

@@ -0,0 +1,52 @@
#!/usr/bin/env bash
# Replay host fixtures: run `deps.sh detect all` against a stand-in machine and check
# what it must (and must not) say. No docker, no network, no root.
# Usage: hosttest.sh [FIXTURE_DIR...] default: tests/hosts/* exits 1 on a mismatch
# A fixture is root/ (the files detect reads), expect.txt (+ must appear, - must not,
# exit N), and an optional env (KEY=value lines). `deps.sh snapshot` writes one.
# Notes: docs/notes/installer-testing.md
set -uo pipefail
cd "$(dirname "$0")"
dirs=("$@")
if [ ${#dirs[@]} -eq 0 ]; then dirs=(../tests/hosts/*/); fi
rc=0 passed=0 failed=0
for d in "${dirs[@]}"; do
d="${d%/}"
if [ ! -f "$d/expect.txt" ]; then
echo " FAIL $d: no expect.txt — not a host fixture" >&2
rc=1; failed=$((failed + 1)); continue
fi
# Only the fixture's own settings: the caller's HOST_ROOT, MEMINFO or UNAME_S
# must not leak into a replay.
run=(env -u HOST_ROOT -u MEMINFO -u OVERCOMMIT_FILE -u UNAME_S)
if [ -d "$d/root" ]; then run+=(HOST_ROOT="$(cd "$d/root" && pwd)"); fi
if [ -f "$d/env" ]; then
while IFS= read -r kv; do run+=("$kv"); done < <(grep -vE '^[[:space:]]*(#|$)' "$d/env")
fi
out=$("${run[@]}" bash ./deps.sh detect all 2>&1)
code=$?
bad=""
want_exit=0
while IFS= read -r line; do
case "$line" in
'+ '*) grep -qF -- "${line#+ }" <<< "$out" || bad+=$'\n'" missing: ${line#+ }" ;;
'- '*) grep -qF -- "${line#- }" <<< "$out" && bad+=$'\n'" present: ${line#- }" ;;
'exit '*) want_exit="${line#exit }" ;;
esac
done < <(grep -vE '^[[:space:]]*(#|$)' "$d/expect.txt")
if [ "$code" != "$want_exit" ]; then bad+=$'\n'" exit: $code, wanted $want_exit"; fi
if [ -z "$bad" ]; then
printf ' ok %s\n' "$(basename "$d")"
passed=$((passed + 1))
else
printf ' FAIL %s%s\n' "$(basename "$d")" "$bad"
rc=1; failed=$((failed + 1))
fi
done
printf '%d host fixture(s) as expected, %d not\n' "$passed" "$failed"
exit "$rc"