phoebus_os/installer/tests/vm/rollback-guest.sh
Phoebus 297f3201ff
Some checks are pending
ci / test (push) Waiting to run
feat(sys): hardware-aware lane selection and new lanes
Replace the fixed category routing (ADR 0006) with a shared, inspectable,
hardware- and preference-aware selection policy over resolved candidates from
Portage (source/binary/vendor), Nix, Flatpak, Snap, AppImage and the Phoebus
overlay. The policy keeps base components under Portage, separates hard
constraints from preferences, honours and persists explicit choices, errors
instead of silently switching lanes, and reuses an already-installed lane.

- phoebus-core::selection: the pure policy (16 tests: base-system, low-memory
  vs high-core, sandbox requirement, GPU/arch/storage rejection, explicit
  preference, unavailable backend, reproducibility, render).
- phoebus-executor::chooser: resolves real metadata and hardware facts.
- phoebus-executor::{snap,appimage,ebuild}: new lanes. Snap detects daemon and
  confinement and installs app-containers/snapd through Portage; AppImage
  adopts images with a pinned SHA-256, checks the ELF architecture without
  executing, integrates a desktop entry and preserves user data on removal; the
  custom ebuild overlay binds approval to the ebuild content digest and builds
  through Portage's sandbox.
- Typed actions choose_package / set_package_preference / snap_* / appimage_* /
  custom_ebuild_* with strict validators; the assistant prompt and schema are
  reconciled (no category routing; custom ebuilds are untrusted).
- Installed sys: the installer locates the trusted static binary, copies it to
  /usr/local/bin/sys and proves it runs in the target chroot before the
  recovery snapshot, failing closed if absent; the VM harness fetches sys.
- docs/SYS.md: command/action reference and acceptance matrix; ADR 0006 revised.

Host gates pass: fmt, clippy (no new warnings), workspace tests, make test,
release and static sys builds. VM lane journeys remain pending (see HANDOFF).
2026-09-23 18:35:26 -07:00

63 lines
2.5 KiB
Bash
Executable file

#!/bin/bash
# Guest-side rollback acceptance for the disposable VM.
#
# Fetched and run by `serial-driver.py rollback` inside an already-installed
# Phoebus system. It establishes a known-good package/root state, creates a
# recovery point through the supported `sys` interface, introduces a
# controlled, reversible mutation, runs the real `sys undo` path and powers
# off. The host then boots the disk detached and verifies the restored state.
#
# `sys` is installed into the target by the installer; fall back to the host
# copy only if it is somehow absent (see docs/HANDOFF.md). This exercises the
# real installed command path, not a mock.
set -uo pipefail
SERVE="${SERVE_URL:-http://10.0.2.2:8000}"
if [[ -n "${SYS_BIN:-}" ]]; then
SYS="$SYS_BIN"
elif [[ -x /usr/local/bin/sys ]]; then
SYS=/usr/local/bin/sys
else
SYS=/tmp/sys
fi
USER_NAME="${USERNAME:-phoebus}"
WORK=/tmp/phoebus-rollback
mkdir -p "$WORK"
pkg_fingerprint() {
# The package database, not a marker file: a rollback must restore it.
find /var/db/pkg -mindepth 2 -maxdepth 2 -type d 2>/dev/null \
| sort | sha256sum | awk '{print $1}'
}
# 1. Establish and record a known-good root/package state. The /home marker
# proves user data survives (it is not part of the snapshotted subvolumes).
KERNEL="$(uname -r)"
HOME_MARKER="rollback-marker-$$-$KERNEL"
printf '%s\n' "$HOME_MARKER" > "/home/$USER_NAME/rollback-marker.txt"
PKGS_BEFORE="$(pkg_fingerprint)"
echo "===ROLLBACK-KNOWN-GOOD pkgs=$PKGS_BEFORE kernel=$KERNEL home=$HOME_MARKER==="
# 2. Create the recovery point through the supported interface.
"$SYS" -y snapshot "rollback acceptance" > "$WORK/snapshot.out" 2>&1
SNAP_ID="$(sed -n 's/^protective snapshot: //p' "$WORK/snapshot.out" | tail -1)"
echo "===ROLLBACK-SNAPSHOT id=$SNAP_ID==="
# 3. Controlled, reversible update failure. A small package install is a real
# update: it changes both the root subvolume and /var/db/pkg, and a snapshot
# can restore it. A root marker proves the root generation too.
printf 'broken by rollback acceptance\n' > /etc/phoebus/rollback-broken.txt 2>/dev/null || true
"$SYS" -y install app-editors/nano > "$WORK/break.out" 2>&1
echo "===ROLLBACK-BROKEN pkgs=$(pkg_fingerprint)==="
# 4. Invoke the real sys undo path.
"$SYS" -y undo > "$WORK/undo.out" 2>&1
RC=$?
echo "===ROLLBACK-UNDO rc=$RC==="
"$SYS" rollback status > "$WORK/status.out" 2>&1 || true
sed -n '1,40p' "$WORK/status.out"
echo "===ROLLBACK-DONE==="
sync
sudo -n poweroff -f || poweroff -f
echo "===POWEROFF==="