//! Bash/Rust plan parity. //! //! Runs the same configuration through the reference Bash `--plan` and the //! Rust `--plan` and checks that the semantically important facts agree. //! Formatting is allowed to differ; behavior is not. use std::path::PathBuf; use std::process::Command; fn bash_installer() -> Option { let path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../installer/bin/ai-installer"); if path.is_file() { Some(path) } else { None } } fn write_config(dir: &std::path::Path) -> PathBuf { let path = dir.join("parity.conf"); let text = "\ HOSTNAME='paritybox'\n\ USERNAME='parityuser'\n\ LOCALE='en_US.UTF-8'\n\ TIMEZONE='UTC'\n\ KEYMAP='us'\n\ TARGET_DISK='/dev/vda'\n\ EFI_SIZE_MIB='1024'\n\ FILESYSTEM='btrfs'\n\ ENCRYPTION='luks2'\n\ COMPRESS='zstd:3'\n\ KERNEL_PROFILE='safe'\n\ KERNEL_CONSOLE='console=tty0'\n\ PACKAGE_POLICY='balanced'\n\ DESKTOP_PROFILE='dwl'\n\ BTRFS_SUBVOLS='@ @home @var @snapshots @swap'\n"; std::fs::write(&path, text).unwrap(); path } #[test] fn rust_plan_matches_bash_plan_on_key_facts() { let Some(bash) = bash_installer() else { eprintln!("skipping: reference Bash installer not found"); return; }; let dir = tempfile::tempdir().unwrap(); let config = write_config(dir.path()); let bash_out = Command::new("bash") .arg(&bash) .arg("--config") .arg(&config) .arg("--plan") .output() .expect("run bash installer"); if !bash_out.status.success() { eprintln!("skipping: Bash installer could not run"); return; } let bash_text = String::from_utf8_lossy(&bash_out.stdout).to_string(); let rust_out = Command::new(env!("CARGO_BIN_EXE_phoebus-installer")) .arg("--config") .arg(&config) .arg("--plan") .output() .expect("run rust installer"); assert!(rust_out.status.success()); let rust_text = String::from_utf8_lossy(&rust_out.stdout).to_string(); // Facts both renderings must agree on. for fact in [ "paritybox", "parityuser", "en_US.UTF-8", "UTC", "/dev/vda", "luks2", "btrfs", "@snapshots", "sys-kernel/gentoo-kernel-bin", "balanced", "dwl", ] { assert!( bash_text.contains(fact), "Bash plan missing `{fact}`:\n{bash_text}" ); assert!( rust_text.contains(fact), "Rust plan missing `{fact}`:\n{rust_text}" ); } }