phoebus_os/installer/tests/vm/sys-acceptance.sh
Phoebus f9e39925b4 feat(install): AI-first sys install workflow
Implement the shared installation workflow (ADR 0013). sys install, sys ask
install and the explicit backend flags all use one path: identify -> evidence
-> AI investigation -> deterministic validation/effects -> review -> approval
-> execute -> verify -> history.

- phoebus-ai::install: bounded, multi-turn investigation. The model may request
  typed read-only evidence (discover_candidates, inspect_candidate,
  check_backend, inspect_installation), ask one bounded question about intent,
  and must return a structured InstallProposal. Turn/request/size limits and
  repeated-request detection bound it; a rejected proposal is revised.
- phoebus-core: add the four read-only investigation actions and strict
  validators; add a transaction id; backend/kind wire names now match as_str.
- phoebus-executor::install: resolve_explicit (no model, no fallback),
  resolve_deterministic and resolve_with_ai; validate_proposal re-resolves the
  candidate against real metadata, rejects fabrication/ambiguity/staleness/
  duplicates, maps it to the existing broker action, and binds approval to a
  digest; revalidate + verify_installed. chooser gains per-lane friendly-name
  resolution and structured evidence.
- transaction::begin/finish record an in-progress transaction before mutation.
- sys: --portage/--flatpak/--nix/--snap/--appimage/--ebuild (mutually
  exclusive) bypass the model; an unqualified install consults the model and,
  with none, prints the deterministic selection and installs nothing.
- The installer persists /etc/phoebus/install.toml; sys loads it and adds free
  space, Wayland, usable lanes, saved preferences and recovery capability to
  the bounded facts.
- Docs: ADR 0013, docs/SYS.md install sections and cases 23-31, CHANGELOG,
  STATUS, HANDOFF, ROADMAP. New live-VM workflow check script.

Host gates pass: fmt, clippy (no new warnings), workspace tests, make test.
VM: verified the workflow CLI and read-only investigation on the reference
LiveGUI ISO; a full target install journey is running (see HANDOFF).
2026-09-23 20:30:13 -07:00

160 lines
6.7 KiB
Bash
Executable file

#!/bin/bash
# Guest-side `sys` acceptance matrix for a booted, installed Phoebus system.
#
# Runs the deterministic phrase path and the typed JSON path, plus failure
# cases, and prints one machine-readable line per case. Read-only by default;
# set SYS_ACCEPTANCE_MUTATE=1 to also exercise install/remove/service/snapshot
# on a disposable VM only. Never run the mutate group on a physical host.
#
# The driver matches `===SYS-ACC-(START|END)===` and `CASE <id> <PASS|FAIL>`.
set -uo pipefail
SYS="${SYS_BIN:-/usr/local/bin/sys}"
[[ -x "$SYS" ]] || SYS=/tmp/sys
MUTATE="${SYS_ACCEPTANCE_MUTATE:-0}"
WORK="$(mktemp -d)"
trap 'rm -rf "$WORK"' EXIT
PASS=0
FAIL=0
report() {
# report <id> <PASS|FAIL> <detail>
printf 'CASE %s %s %s\n' "$1" "$2" "$3"
if [[ "$2" == PASS ]]; then PASS=$((PASS + 1)); else FAIL=$((FAIL + 1)); fi
}
# run_expect_zero <id> <args...>
run_expect_zero() {
local id="$1"; shift
if "$SYS" "$@" >"$WORK/$id.out" 2>"$WORK/$id.err"; then
report "$id" PASS "$(head -c 200 "$WORK/$id.out" | tr '\n' ' ')"
else
report "$id" FAIL "rc=$? stderr=$(head -c 200 "$WORK/$id.err" | tr '\n' ' ')"
fi
}
# run_expect_nonzero <id> <needle> <args...>
run_expect_nonzero() {
local id="$1" needle="$2"; shift 2
"$SYS" "$@" >"$WORK/$id.out" 2>"$WORK/$id.err"
local rc=$?
if [[ $rc -ne 0 ]] && grep -qi -- "$needle" "$WORK/$id.err" "$WORK/$id.out"; then
report "$id" PASS "rejected: $(head -c 160 "$WORK/$id.err" | tr '\n' ' ')"
else
report "$id" FAIL "rc=$rc expected nonzero and '$needle'"
fi
}
# json_nonzero <id> <needle> <json>
json_nonzero() {
local id="$1" needle="$2" json="$3"
"$SYS" --action "$json" >"$WORK/$id.out" 2>"$WORK/$id.err"
local rc=$?
if [[ $rc -ne 0 ]] && grep -qi -- "$needle" "$WORK/$id.err" "$WORK/$id.out"; then
report "$id" PASS "rejected: $(head -c 160 "$WORK/$id.err" | tr '\n' ' ')"
else
report "$id" FAIL "rc=$rc expected nonzero and '$needle'"
fi
}
echo "===SYS-ACC-START==="
echo "sys-acceptance: SYS=$SYS MUTATE=$MUTATE"
"$SYS" --version 2>&1 | head -1
# --- Read-only deterministic and JSON paths -------------------------------
run_expect_zero identity --version
run_expect_zero history history
run_expect_zero appimage-empty --root / appimage list
run_expect_zero ebuild-empty --root / ebuilds
# --- Failure cases ---------------------------------------------------------
run_expect_nonzero invalid-natural "could not parse" -- install --color=n
run_expect_nonzero unknown-phrase "unsupported instruction" frobnicate
json_nonzero unknown-action "invalid action" '{"action":"run_shell","command":"rm -rf /"}'
json_nonzero unknown-field "invalid action" '{"action":"history","x":1}'
json_nonzero option-operand "invalid action" '{"action":"install_package","atom":"-C"}'
json_nonzero bad-snap-name "invalid" '{"action":"snap_install","name":"Bad Name"}'
json_nonzero bad-appimage-hash "SHA-256" '{"action":"appimage_acquire","name":"x","url":"https://e/x","sha256":"00"}'
json_nonzero ebuild-traversal "invalid" '{"action":"custom_ebuild_prepare","atom":"../../x","version":"1","rationale":"r","ebuild":"EAPI=8"}'
# --- Offline / model-free behaviour ---------------------------------------
if [[ "$(id -u)" -ne 0 ]]; then
run_expect_nonzero nonroot-mutation "root" --action '{"action":"set_package_preference","name":"firefox","backend":"flatpak"}'
fi
# With no provider, `ask` must fall back deterministically and exit nonzero.
PHOEBUS_AI_PROVIDER= PHOEBUS_AI_BACKEND=direct \
run_expect_nonzero ask-offline "no AI provider" ask "install vim"
# --- Choosing a source (never invents a candidate) ------------------------
"$SYS" --root / choose unused-package-xyz >"$WORK/choose.out" 2>"$WORK/choose.err"
if grep -q "Selected package:" "$WORK/choose.out"; then
report choose PASS "selection: $(grep -m1 'Selected package:' "$WORK/choose.out")"
elif grep -qi "no compatible\|no AI provider" "$WORK/choose.err"; then
report choose PASS "no candidate: $(head -c 160 "$WORK/choose.err" | tr '\n' ' ')"
else
report choose FAIL "unexpected output: $(head -c 200 "$WORK/choose.err")"
fi
# --- AI-first installation workflow (read-only cases) ---------------------
# Conflicting backend flags must be rejected by the CLI.
"$SYS" install firefox --flatpak --nix >"$WORK/conflict.out" 2>"$WORK/conflict.err"
if [[ $? -ne 0 ]] && grep -qi "cannot be used with\|conflict\|not allowed" "$WORK/conflict.err"; then
report install-flag-conflict PASS "rejected"
else
report install-flag-conflict FAIL "$(head -c 160 "$WORK/conflict.err")"
fi
# A backend flag without an install is refused.
"$SYS" --flatpak history >"$WORK/flag.out" 2>"$WORK/flag.err"
if [[ $? -ne 0 ]] && grep -q "only apply to" "$WORK/flag.err"; then
report install-flag-alone PASS "refused"
else
report install-flag-alone FAIL "$(head -c 160 "$WORK/flag.err")"
fi
# An unqualified install with no provider must offer the explicit commands and
# install nothing.
PHOEBUS_AI_PROVIDER= PHOEBUS_AI_BACKEND=direct \
"$SYS" install unused-package-xyz >"$WORK/noai.out" 2>"$WORK/noai.err"
if [[ $? -ne 0 ]] && grep -q -- "--flatpak" "$WORK/noai.err"; then
report install-no-model-offer PASS "no model: deterministic offer shown"
else
report install-no-model-offer FAIL "$(head -c 200 "$WORK/noai.err")"
fi
# Read-only investigation returns structured evidence.
"$SYS" --action '{"action":"check_backend","backend":"flatpak"}' >"$WORK/be.out" 2>"$WORK/be.err"
if grep -q '"backend"' "$WORK/be.out"; then
report investigate-check-backend PASS "$(head -c 120 "$WORK/be.out" | tr '\n' ' ')"
else
report investigate-check-backend FAIL "$(head -c 160 "$WORK/be.err")"
fi
# --- Optional mutating group (disposable VM only) -------------------------
if [[ "$MUTATE" == "1" ]]; then
PKG="${SYS_ACCEPTANCE_PACKAGE:-app-misc/hello}"
if "$SYS" -y install "$PKG" >"$WORK/install.out" 2>&1; then
if emerge --pretend --quiet "$PKG" >/dev/null 2>&1; then
report mutate-install PASS "installed $PKG"
else
report mutate-install FAIL "install reported ok but system does not know $PKG"
fi
else
report mutate-install FAIL "sys install failed: $(head -c 160 "$WORK/install.out")"
fi
if "$SYS" -y remove "$PKG" >"$WORK/remove.out" 2>&1; then
report mutate-remove PASS "removed $PKG"
else
report mutate-remove FAIL "sys remove failed: $(head -c 160 "$WORK/remove.out")"
fi
"$SYS" history >"$WORK/hist.out" 2>&1
if grep -q "$PKG" "$WORK/hist.out"; then
report mutate-history PASS "transaction recorded"
else
report mutate-history FAIL "install/removal missing from history"
fi
fi
echo "===SYS-ACC-END=== SUMMARY PASS=$PASS FAIL=$FAIL"
[[ "$FAIL" -eq 0 ]]