phoebus_os/installer/tests/test_regressions.sh
Phoebus 38214ea9e7 chore: import Phoebus OS installer and Rust migration
Initial public import of the proven Bash installer (installer/) and the production Rust workspace (installer-rs/). The reference ISO, build output and local agent transcripts are gitignored.

Verified: installer/tests/run_tests.sh and cargo test --workspace both pass.
2026-09-20 02:07:33 -07:00

104 lines
4.6 KiB
Bash

#!/usr/bin/env bash
# shellcheck shell=bash
#
# Regression tests for bugs found during the first real VM installation.
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
TEST_NAME="test_regressions"
phoebus_test_setup
# --- kernel cmdline: encrypted root must use rd.luks.name=<uuid>=<name> -----
config_set ENCRYPTION "luks2"
config_set LUKS_NAME "cryptroot"
FS_ROOT_PART="/dev/fake"
blkid() { printf '%s\n' "00000000-1111-2222-3333-444444444444"; }
root="$STATE_DIR/target"
mkdir -p "$root"
kernel_write_cmdline "$root"
cmdline="$(cat "$root/etc/kernel/cmdline")"
assert_contains "$cmdline" "rd.luks.name=00000000-1111-2222-3333-444444444444=cryptroot" \
"cmdline names the LUKS mapper"
assert_contains "$cmdline" "root=/dev/mapper/cryptroot" "cmdline root is the mapper"
assert_not_contains "$cmdline" "rd.luks.uuid=" "cmdline does not use un-named rd.luks.uuid"
# --- install.conf must declare every generator (it replaces the default) ----
boot_write_install_conf "$root"
iconf="$(cat "$root/etc/kernel/install.conf")"
assert_contains "$iconf" "layout=bls" "install.conf uses BLS layout"
assert_contains "$iconf" "initrd_generator=dracut" "install.conf sets initrd generator"
assert_contains "$iconf" "uki_generator=none" "install.conf disables UKI for BLS"
# dracut must be forced to include crypt/btrfs for the encrypted root
boot_write_dracut_conf "$root"
dconf="$(cat "$root/etc/dracut.conf.d/10-phoebus.conf")"
assert_contains "$dconf" "add_dracutmodules" "dracut config adds modules"
assert_contains "$dconf" "crypt" "dracut includes crypt"
assert_contains "$dconf" "btrfs" "dracut includes btrfs"
# --- fstab must be generated after the stage3 extraction --------------------
plan_generate
sig="" fgi="" pci=""
for i in "${!PLAN_STEPS[@]}"; do
case "${PLAN_STEPS[$i]}" in
stage_install) sig="$i" ;;
fstab_generate) fgi="$i" ;;
portage_configure) pci="$i" ;;
esac
done
assert_success "fstab_generate is a plan step" test -n "$fgi"
assert_success "stage_install precedes fstab_generate" test "$sig" -lt "$fgi"
assert_success "fstab_generate precedes portage_configure" test "$fgi" -lt "$pci"
__fn_contains() { declare -f "$1" | grep -q "$2"; }
assert_failure "storage stage does not generate fstab" \
__fn_contains install_stage_storage filesystem_generate_fstab
assert_success "fstab stage generates fstab" \
__fn_contains install_stage_fstab filesystem_generate_fstab
assert_success "fstab stage creates /var/tmp" \
__fn_contains install_stage_fstab "/var/tmp"
# --- chroot commands set TMPDIR (systemd kernel-install requires it) --------
assert_success "portage_chroot sets TMPDIR" \
__fn_contains portage_chroot "TMPDIR=/tmp"
assert_success "portage_chroot_stdin sets TMPDIR" \
__fn_contains portage_chroot_stdin "TMPDIR=/tmp"
# --- initial cmdline includes the configured console ------------------------
config_set KERNEL_CONSOLE "console=tty0 console=ttyS0,115200"
kernel_write_cmdline "$root"
assert_contains "$(cat "$root/etc/kernel/cmdline")" "console=ttyS0,115200" \
"cmdline includes configured console"
config_set KERNEL_CONSOLE "console=tty0"
# --- base packages must include the storage userspace needed by dracut ------
basepkgs="$(portage_base_packages)"
assert_contains "$basepkgs" "sys-fs/cryptsetup" "base packages include cryptsetup"
assert_contains "$basepkgs" "sys-fs/btrfs-progs" "base packages include btrfs-progs"
# --- systemd must be built with cryptsetup for the initramfs ---------------
pkgroot="$STATE_DIR/pkgroot"
mkdir -p "$pkgroot/etc/portage"
config_set DESKTOP_PROFILE "dwl"
portage_write_package_files "$pkgroot"
pupkg="$(cat "$pkgroot/etc/portage/package.use/phoebus")"
assert_contains "$pupkg" "sys-apps/systemd boot policykit cryptsetup" \
"systemd built with boot/policykit/cryptsetup"
assert_contains "$pupkg" "sys-kernel/installkernel" "installkernel policy present"
assert_contains "$pupkg" "x11-libs/cairo X" "desktop enables cairo X for GTK3"
config_set DESKTOP_PROFILE "none"
# --- fstab must mount @swap so the swapfile can be activated ----------------
FS_EFI_PART="/dev/fake-efi"
FS_ROOT_SOURCE="/dev/fake-root"
mkdir -p "$root/etc"
filesystem_generate_fstab "$root"
fstab="$(cat "$root/etc/fstab")"
assert_contains "$fstab" "subvol=@swap" "fstab mounts @swap subvolume"
assert_contains "$fstab" "/swap/swapfile" "fstab enables the swapfile"
# --- secrets never reach the log -------------------------------------------
secret_register "topsecretvalue123"
run_cmd "secret test" /bin/true "topsecretvalue123" >/dev/null 2>&1
logtext="$(cat "$PHOEBUS_LOG_FILE")"
assert_not_contains "$logtext" "topsecretvalue123" "secret is scrubbed from the log"
phoebus_test_report