phoebus_os/installer-rs/crates/phoebus-installer/tests/live_iso.rs
Phoebus fd23aa4890
Some checks are pending
ci / test (push) Waiting to run
fix(desktop): launch assistant and ready Snap on desktops
2026-10-01 09:08:49 -07:00

432 lines
17 KiB
Rust

//! Regression guards for the live ISO assembly and the installed defaults.
//!
//! These do not build an ISO; they pin the invariants that make the build
//! meaningful: the desktop payload is required and present in the package list,
//! the build fails clearly when it is missing, the live and installed login
//! configuration stay separate, and both session entries are shipped.
use std::path::{Path, PathBuf};
use phoebus_core::config::{DesktopProfile, InstallConfig};
use phoebus_core::system;
fn repo_root() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("../../..")
.canonicalize()
.expect("repo root")
}
fn read(rel: &str) -> String {
let path: PathBuf = repo_root().join(rel);
std::fs::read_to_string(&path).unwrap_or_else(|e| panic!("cannot read {}: {e}", path.display()))
}
#[test]
fn live_build_bundles_and_verifies_the_nvidia_payload() {
let list = read("installer/live/live-packages.list");
for required in [
"nvidia-driver",
"nvidia-kernel-dkms",
"firmware-nvidia-gsp",
"firmware-nvidia-graphics",
"libnvidia-egl-gbm1",
"libnvidia-egl-wayland1",
"linux-headers-amd64",
"dkms",
] {
assert!(
list.lines().any(|l| l.trim() == required),
"live package list is missing {required}"
);
}
let build = read("installer/live/build.sh");
// The signed non-free components are enabled for the NVIDIA packages.
assert!(build.contains("main,contrib,non-free,non-free-firmware"));
// The payload is verified on every build, including a cached rootfs, and a
// missing/mismatched component fails the build.
assert!(build.contains("--verify-live-nvidia"));
assert!(build.contains("--nvidia-version"));
assert!(build.contains("etc/phoebus/nvidia"));
// Module build happens for the exact live kernel in the hook.
let hook = read("installer/live/livefs-hook.sh");
assert!(hook.contains("dkms autoinstall"));
assert!(hook.contains("nvidia_drm"));
// The live kernel is pinned to Debian stable, where the 550 driver builds;
// testing's 7.2 kernel removed strncpy and breaks nvidia-kernel-dkms.
assert!(build.contains("trixie"));
assert!(build.contains("linux-kbuild-"));
assert!(build.contains("--setup-hook"));
// The live driver policy file the verifier requires is actually produced,
// and Debian's unconditional nouveau configuration is replaced so the
// explicit nouveau fallback can bind an unsupported GPU.
assert!(build.contains("etc/modprobe.d/phoebus-nvidia.conf"));
assert!(build.contains("nvidia-blacklists-nouveau.conf"));
assert!(build.contains("blacklist nouveau"));
// Nouveau blacklisting/module options no longer come solely from
// nvidia-kernel-common; its unconditional modules-load entry is removed in
// favour of the gated unit.
assert!(build.contains("nvidia-kernel-common"));
assert!(build.contains("modules-load.d/nvidia.conf"));
// A documented fail-safe entry disables NVIDIA for that boot, and marks the
// command line so the load script and unit both stand down.
assert!(build.contains("nomodeset"));
assert!(build.contains("phoebus.nvidia=off"));
assert!(build.contains("modprobe.blacklist=nvidia"));
}
#[test]
fn live_package_list_carries_the_desktop_stack() {
let list = read("installer/live/live-packages.list");
let entries: Vec<&str> = list
.lines()
.map(str::trim)
.filter(|l| !l.is_empty() && !l.starts_with('#'))
.collect();
for required in [
"quickshell",
"greetd",
"tuigreet",
// Mango is built from source, so its build dependencies must be present.
"libwlroots-0.20-dev",
"libscenefx-0.5-dev",
"meson",
// The installer and bookkeeping need these tools in the live image.
"cryptsetup-bin",
"btrfs-progs",
"flatpak",
] {
assert!(
entries.contains(&required),
"live package list is missing {required}"
);
}
}
#[test]
fn live_build_requires_the_desktop_and_fails_clearly() {
let build = read("installer/live/build.sh");
// The desktop compositor and shell must be verified before packing.
assert!(build.contains("usr/bin/mango"));
assert!(build.contains("usr/bin/dms"));
assert!(build.contains("quickshell"));
assert!(build.contains("phoebus-install.desktop"));
// Live autologin must be present in the live login config.
assert!(build.contains("initial_session"));
// The pinned releases are checksum-verified.
assert!(build.contains("releases.sha256"));
// The shared assets come from the installer, not a divergent copy.
assert!(build.contains("--emit-asset"));
}
#[test]
fn pinned_releases_are_checksummed() {
let pins = read("installer/live/releases.sha256");
assert!(pins.contains("dms-full-amd64.tar.gz"));
assert!(pins.contains("mango-0.17.2.tar.gz"));
// 64-hex digests.
for line in pins.lines() {
let line = line.trim();
if line.is_empty() || line.starts_with('#') {
continue;
}
let digest = line.split_whitespace().next().unwrap();
assert_eq!(digest.len(), 64, "not a sha256: {line}");
assert!(digest.chars().all(|c| c.is_ascii_hexdigit()));
assert!(
digest.chars().any(|c| c != '0'),
"placeholder digest: {line}"
);
}
}
#[test]
fn installed_login_is_authenticated_and_selects_mango_by_default() {
let config = system::greetd_config(system::default_session_command(DesktopProfile::Mango));
assert!(config.contains("--cmd /usr/local/bin/phoebus-session-mango"));
assert!(config.contains("--sessions /usr/share/wayland-sessions"));
assert!(
!config.contains("[initial_session]"),
"the installed system must require authentication"
);
}
#[test]
fn live_login_autologins_and_the_configs_are_separate() {
let live = system::desktop_asset("greetd-live").unwrap();
let installed = system::desktop_asset("greetd-installed").unwrap();
assert!(live.contains("[initial_session]"));
assert!(live.contains("user = \"phoebus\""));
assert!(!installed.contains("[initial_session]"));
// The live and installed configs must not be the same file content.
assert_ne!(live, installed);
}
#[test]
fn only_mango_session_entry_is_shipped() {
let mango = system::desktop_asset("wayland-session-mango").unwrap();
assert!(mango.contains("Exec=/usr/local/bin/phoebus-session-mango"));
assert!(system::desktop_asset("wayland-session-dwl").is_none());
assert!(system::desktop_asset("session-dwl").is_none());
}
#[test]
fn default_config_omits_to_mango_and_overrides_are_respected() {
assert_eq!(
InstallConfig::default().desktop.profile,
DesktopProfile::Mango
);
assert!(InstallConfig::default().desktop.flatpak);
for (value, expected) in [
("none", DesktopProfile::None),
("mango", DesktopProfile::Mango),
] {
let cfg = InstallConfig::from_legacy(&format!("DESKTOP_PROFILE='{value}'\n")).unwrap();
assert_eq!(cfg.desktop.profile, expected);
}
// Standalone dwl is obsolete and rejected.
assert!(InstallConfig::from_legacy("DESKTOP_PROFILE='dwl'\n").is_err());
}
#[test]
fn build_script_is_syntax_declared_shell() {
// A cheap guard that the checked-in script is still a bash script and not a
// stub: it must contain the mmdebstrap invocation and the ISO assembly.
let build = read("installer/live/build.sh");
assert!(build.starts_with("#!/usr/bin/env bash"));
assert!(build.contains("mmdebstrap"));
assert!(build.contains("xorriso"));
assert!(build.contains("mksquashfs"));
let _ = Path::new(".");
}
#[test]
fn live_build_installs_the_branded_launcher_and_marker() {
let build = read("installer/live/build.sh");
// The welcome/installer Quickshell configs and branding are part of the
// payload, and the live marker gates live-only autostart.
for needle in [
"etc/xdg/quickshell/phoebus-welcome",
"etc/xdg/quickshell/phoebus-install",
"phoebus-welcome",
"usr/share/phoebus/branding",
"etc/phoebus/live",
"brand-wallpaper",
"splash.png",
] {
assert!(build.contains(needle), "build.sh is missing {needle}");
}
// The live help text is shipped and read by the welcome window.
let help = read("installer/live/install-help.txt");
assert!(help.contains("ERASE"));
assert!(help.contains("LUKS2"));
}
#[test]
fn assets_include_the_welcome_launcher_and_branding() {
let welcome = system::desktop_asset("welcome").expect("welcome asset");
assert!(welcome.contains("quickshell --no-duplicate -c phoebus-welcome"));
// Duplicate installer sessions are prevented.
let install = system::desktop_asset("install").expect("install asset");
assert!(install.contains("quickshell --no-duplicate -c phoebus-install"));
assert!(install.contains("pgrep -f"));
// Branding assets are reachable through the same `--emit-asset` dispatch.
for name in [
"brand-emblem",
"brand-wordmark",
"brand-wallpaper",
"brand-tokens",
] {
assert!(system::desktop_asset(name).is_some(), "{name} missing");
}
}
#[test]
fn mango_session_selects_live_or_installed_welcome() {
// The installed launcher checks its per-user seen marker. Mango itself
// starts the launcher because this custom session does not run XDG autostart.
let script = system::desktop_asset("session-mango").unwrap();
assert!(script.contains("if [ -e /etc/phoebus/live ]"));
assert!(script.contains("elif [ -x /usr/local/bin/phoebus-welcome ]"));
assert!(system::INSTALLED_WELCOME_SCRIPT.contains("welcome-seen"));
}
#[test]
fn qml_theme_matches_the_backend_palette() {
let qml = read("installer/live/desktop/common/Theme.qml");
for token in [
phoebus_core::brand::PALETTE.charcoal,
phoebus_core::brand::PALETTE.surface,
phoebus_core::brand::PALETTE.border,
phoebus_core::brand::PALETTE.warm_white,
phoebus_core::brand::PALETTE.muted,
phoebus_core::brand::PALETTE.amber,
phoebus_core::brand::PALETTE.amber_deep,
phoebus_core::brand::PALETTE.success,
phoebus_core::brand::PALETTE.warning,
phoebus_core::brand::PALETTE.danger,
] {
assert!(
qml.contains(token),
"Theme.qml is missing brand token {token}"
);
}
// Dark is the default; a light mode exists and the selection persists.
assert!(qml.contains("themeMode"), "Theme.qml has no themeMode");
assert!(qml.contains("\"dark\""), "dark default missing");
assert!(qml.contains("isLight"), "light mode missing");
}
#[test]
fn assistant_theme_tokens_never_drift() {
// Every `Theme.<token>` referenced by the assistant must be defined in
// Theme.qml. This catches future renames on either side.
let theme = read("installer/live/desktop/common/Theme.qml");
let defined: std::collections::HashSet<String> = theme
.lines()
.filter_map(|l| {
let t = l.trim();
t.strip_prefix("readonly property")
.and_then(|r| r.split_whitespace().nth(1))
.map(|n| n.trim_end_matches(':').to_string())
})
.chain(["themeMode", "isLight"].into_iter().map(str::to_string))
// `property string themeMode` is not readonly; include it explicitly.
.chain(std::iter::once("themeMode".to_string()))
.collect();
// Also accept the plain `property` form.
let mut defined = defined;
for line in theme.lines() {
let t = line.trim();
if let Some(rest) = t.strip_prefix("property string") {
if let Some(name) = rest.split_whitespace().next() {
defined.insert(name.trim_end_matches(':').to_string());
}
}
if let Some(rest) = t.strip_prefix("property color") {
if let Some(name) = rest.split_whitespace().next() {
defined.insert(name.trim_end_matches(':').to_string());
}
}
if let Some(rest) = t.strip_prefix("property int") {
if let Some(name) = rest.split_whitespace().next() {
defined.insert(name.trim_end_matches(':').to_string());
}
}
if let Some(rest) = t.strip_prefix("property real") {
if let Some(name) = rest.split_whitespace().next() {
defined.insert(name.trim_end_matches(':').to_string());
}
}
}
let shell = read("installer/live/desktop/phoebus-assistant/shell.qml");
let mut used = std::collections::HashSet::new();
let mut start = 0;
while let Some(i) = shell[start..].find("Theme.") {
let abs = start + i + "Theme.".len();
let rest = &shell[abs..];
let end = rest
.find(|c: char| !c.is_alphanumeric() && c != '_')
.unwrap_or(rest.len());
used.insert(rest[..end].to_string());
start = abs + end;
}
// QtQuick Controls palette bindings (`palette.window` etc.) are not Theme
// tokens and are excluded by construction (they do not start with Theme.).
for token in used {
assert!(
defined.contains(&token),
"assistant uses undefined Theme.{token}"
);
}
}
#[test]
fn assistant_layout_fits_small_vm_windows() {
let shell = read("installer/live/desktop/phoebus-assistant/shell.qml");
// Quickshell FloatingWindow accepts implicit sizing, not minimumWidth or
// minimumHeight. The content and tab row scroll at smaller sizes.
assert!(shell.contains("implicitWidth: 820"));
assert!(shell.contains("implicitHeight: 640"));
assert!(!shell.contains("minimumWidth:"));
assert!(!shell.contains("minimumHeight:"));
assert!(
shell.contains("Flickable") || shell.contains("Flow") || shell.contains("ScrollView"),
"tab row never wraps or scrolls"
);
// Truthful connection: never "Connected" solely because the bridge
// started; a setup action and the real error are shown instead.
assert!(
shell.contains("aiConfigured") || shell.contains("ai_configured"),
"assistant never checks ai_configured"
);
assert!(
shell.contains("Setup required")
|| shell.contains("setup action")
|| shell.contains("Open Legacy Admin"),
"assistant shows no setup action when unconnected"
);
// Error cards must not expose approval controls: approval is gated on a
// reviewed plan id + digest (executePlan refuses without them).
assert!(
shell.contains("if (!data.plan_id || !data.digest)"),
"executePlan does not refuse errors without a plan id/digest"
);
assert!(
shell.contains("prepared") && shell.contains("state === \"prepared\""),
"approval is not gated on the prepared state"
);
// Long errors and plan details wrap or scroll.
assert!(
shell.contains("wrapMode: Text.Wrap"),
"long errors/plan details do not wrap"
);
}
#[test]
fn installer_help_is_available_to_the_gui() {
let help = read("installer/live/install-help.txt");
assert!(help.contains("deterministic `sys`"));
assert!(help.contains("installation medium"));
}
#[test]
fn welcome_primary_action_is_keyboard_reachable() {
let qml = read("installer/live/desktop/phoebus-welcome/shell.qml");
// The tiled window may not be focused at session start, so the launcher
// must request activation and force focus on the primary action; without
// this the focus ring (and Enter) never reach it.
assert!(
qml.contains("forceActiveFocus"),
"welcome never forces focus"
);
assert!(
qml.contains("requestActivate"),
"welcome never requests activation"
);
assert!(
qml.contains("id: installButton") || qml.contains("id: window"),
"welcome has no identifiable primary action"
);
// Regression: `FloatingWindow` has no `onActiveChanged`; using it makes the
// whole configuration fail to load.
assert!(
!qml.contains("onActiveChanged"),
"welcome uses a non-existent FloatingWindow signal"
);
}
#[test]
fn progress_cannot_be_abandoned_silently() {
let qml = read("installer/live/desktop/phoebus-install/shell.qml");
// Escape during the destructive stage must not close the frontend without
// an explanation.
assert!(
qml.contains("cannot be cancelled"),
"no truthful cancellation message"
);
assert!(
qml.contains("shell.phase === \"progress\""),
"the guard against closing mid-install is missing"
);
}