phoebus_os/installer-rs/crates/phoebus-installer/tests/cli_coverage.rs
Phoebus b4a6b5df80
Some checks are pending
ci / test (push) Waiting to run
feat(nvidia): hardware-driven driver policy, installed integration and live payload
- resolve the NVIDIA branch and kernel-module flavor from PCI device IDs
  (Turing+ open modules; Maxwell/Pascal/Volta proprietary, masked below 595;
  Fermi/Kepler fall back to nouveau, reported; unknown IDs reported)
- capture pci_id/pci_address in the probe; drive VIDEO_CARDS, package.use,
  package.accept_keywords, package.mask, modprobe.d and dracut from the plan,
  preserving hybrid Intel/AMD
- add the nvidia_drivers install stage (after the kernel, before boot) that
  emerges the driver, regenerates the initramfs, records /etc/phoebus/nvidia and
  fails the install on failure; sys update rebuilds modules and the initramfs
- refuse AI changes to x11-drivers/nvidia-drivers
- live ISO: signed non-free components, stable-kernel pin (testing 7.2 breaks
  the 550 driver), DKMS build for the exact kernel, gated pre-greetd load,
  fail-safe entry, gpu-report, and a --verify-live-nvidia build gate that runs
  on cached rootfs builds and fails on any missing component
- docs: ADR 0012, STATUS/CHANGELOG/HANDOFF, live README
- also carries the pending OpenCode model-variant/streaming changes and fixes
  the GUI bridge install thread join that could hang
2026-09-22 21:53:28 -07:00

168 lines
5.7 KiB
Rust

//! Coverage of the reference Bash installer's command-line surface.
//!
//! Every mode and flag accepted by the reference Bash installer (see
//! `docs/BASH-MIGRATION.md`) must have a Rust equivalent, or be explicitly
//! recorded as intentionally dropped. The test inspects `--help` so it never
//! executes an installation or bootstraps OpenCode.
use std::path::PathBuf;
use std::process::Command;
/// Flags that must be present in the Rust CLI.
const REQUIRED_FLAGS: &[&str] = &[
"--config",
"--plan",
"--dry-run",
"--install",
"--yes",
"--luks-passphrase-file",
"--user-password-file",
"--root-password-file",
"--bootstrap-opencode",
];
/// Bash-only surface that is intentionally not ported, with the rationale so a
/// future session knows the omission was deliberate.
const INTENTIONALLY_DROPPED: &[(&str, &str)] = &[
(
"--backend",
"an alias for --plan; the Rust CLI has a single deterministic backend",
),
(
"--ui",
"UI_BACKEND only selected a dialog/whiptail variant; ratatui needs none",
),
("-y", "clap provides the short form of --yes"),
("--version", "clap provides -V/--version"),
("--help", "clap provides -h/--help"),
];
fn help_text() -> String {
let out = Command::new(env!("CARGO_BIN_EXE_phoebus-installer"))
.arg("--help")
.output()
.expect("run phoebus-installer --help");
assert!(out.status.success(), "`--help` must succeed");
String::from_utf8_lossy(&out.stdout).into_owned()
}
fn manifest_path() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("resources/opencode.manifest")
}
#[test]
fn every_bash_cli_mode_has_a_rust_flag() {
let help = help_text();
for flag in REQUIRED_FLAGS {
assert!(help.contains(flag), "Rust CLI is missing `{flag}`:\n{help}");
}
// The dropped surface is recorded in code, not silently forgotten.
for (flag, _reason) in INTENTIONALLY_DROPPED {
let _ = flag;
}
}
#[test]
fn verify_live_nvidia_accepts_a_complete_payload_and_rejects_an_incomplete_one() {
fn touch(path: &std::path::Path) {
std::fs::create_dir_all(path.parent().unwrap()).unwrap();
std::fs::write(path, b"x").unwrap();
}
fn complete(root: &std::path::Path) {
let kver = "6.16.7-amd64";
touch(&root.join(format!("boot/vmlinuz-{kver}")));
let modules = root.join(format!("lib/modules/{kver}"));
std::fs::create_dir_all(&modules).unwrap();
std::fs::write(modules.join("modules.dep"), b"").unwrap();
for m in ["nvidia", "nvidia_modeset", "nvidia_uvm", "nvidia_drm"] {
touch(&modules.join(format!("updates/dkms/{m}.ko")));
}
for lib in [
"libnvidia-glcore.so.550",
"libGLX_nvidia.so.0",
"libnvidia-egl-gbm.so.1",
"libnvidia-egl-wayland.so.1",
] {
touch(&root.join("usr/lib/x86_64-linux-gnu").join(lib));
}
touch(&root.join("usr/bin/nvidia-smi"));
touch(&root.join("usr/share/egl/egl_external_platform.d/15_nvidia_gbm.json"));
touch(&root.join("usr/share/egl/egl_external_platform.d/10_nvidia_wayland.json"));
touch(&root.join("usr/lib/firmware/nvidia/550.163.01/gsp.bin"));
touch(&root.join("usr/local/bin/phoebus-nvidia-load"));
let blacklist = root.join("etc/modprobe.d/nvidia-blacklists-nouveau.conf");
std::fs::create_dir_all(blacklist.parent().unwrap()).unwrap();
std::fs::write(&blacklist, b"blacklist nouveau\n").unwrap();
}
let run = |root: &std::path::Path| {
Command::new(env!("CARGO_BIN_EXE_phoebus-installer"))
.arg("--verify-live-nvidia")
.arg(root)
.args([
"--nvidia-version",
"550.163.01",
"--nvidia-flavor",
"proprietary",
])
.output()
.expect("run --verify-live-nvidia")
};
let dir = tempfile::tempdir().unwrap();
complete(dir.path());
let out = run(dir.path());
assert!(
out.status.success(),
"{}",
String::from_utf8_lossy(&out.stderr)
);
let record = std::fs::read_to_string(dir.path().join("etc/phoebus/nvidia")).unwrap();
assert!(record.contains("driver_version=550.163.01"));
assert!(record.contains("kernel_version=6.16.7-amd64"));
let broken = tempfile::tempdir().unwrap();
complete(broken.path());
std::fs::remove_file(broken.path().join("usr/bin/nvidia-smi")).unwrap();
let out = run(broken.path());
assert!(
!out.status.success(),
"a missing component must fail the gate"
);
assert_eq!(out.status.code(), Some(1));
}
#[test]
fn relocated_opencode_manifest_is_pinned_and_complete() {
let path = manifest_path();
assert!(path.is_file(), "missing {}", path.display());
let text = std::fs::read_to_string(&path).expect("read opencode manifest");
let version = text
.lines()
.find_map(|line| line.strip_prefix("VERSION="))
.expect("manifest pins a VERSION");
assert!(version.starts_with('v'), "unexpected version `{version}`");
for key in ["x86_64.url", "x86_64.sha256", "x86_64.binary"] {
assert!(text.contains(key), "manifest is missing `{key}`");
}
let sha = text
.lines()
.find_map(|line| line.strip_prefix("x86_64.sha256="))
.expect("x86_64 checksum");
assert_eq!(
sha.len(),
64,
"x86_64 checksum must be a SHA-256 hex digest"
);
assert!(
sha.chars().all(|c| c.is_ascii_hexdigit()),
"x86_64 checksum must be hex"
);
assert!(
sha.chars().any(|c| c != '0'),
"x86_64 checksum must not be a placeholder"
);
}