test(rust): replace the Bash parity test with golden plan tests
parity.rs compared the Rust plan to the Bash installer. The Bash tree is being retired, so pin the exact Rust plan and destructive preview to golden files instead (UPDATE_GOLDEN=1 to regenerate).
This commit is contained in:
parent
9bda0496fb
commit
4c59a1f3ad
5 changed files with 148 additions and 100 deletions
|
|
@ -56,8 +56,12 @@ RUSTFLAGS="-C target-feature=+crt-static" \
|
||||||
cargo build --release -p phoebus-installer --target x86_64-unknown-linux-gnu
|
cargo build --release -p phoebus-installer --target x86_64-unknown-linux-gnu
|
||||||
```
|
```
|
||||||
|
|
||||||
`rustfmt` and `clippy` are not available in the reference toolchain used for
|
Formatting and lints are part of the gate:
|
||||||
this milestone.
|
|
||||||
|
```sh
|
||||||
|
cargo fmt --all -- --check
|
||||||
|
cargo clippy --workspace --all-targets
|
||||||
|
```
|
||||||
|
|
||||||
## CLI
|
## CLI
|
||||||
|
|
||||||
|
|
@ -109,6 +113,9 @@ records *measured* compile times parsed from Portage's `emerge.log`
|
||||||
|
|
||||||
## Verification
|
## Verification
|
||||||
|
|
||||||
`crates/phoebus-installer/tests/parity.rs` compares the Bash and Rust plans for
|
`crates/phoebus-installer/tests/plan_golden.rs` pins the rendered plan and
|
||||||
the same configuration. The disposable VM harness in `../installer/tests/vm`
|
destructive preview to golden files under `tests/golden/` (regenerate with
|
||||||
drives the static binary through a full encrypted install and boot.
|
`UPDATE_GOLDEN=1`). `crates/phoebus-installer/tests/cli_coverage.rs` pins the
|
||||||
|
command-line surface to the reference Bash installer. The disposable VM harness
|
||||||
|
in `../installer/tests/vm` drives the static binary through a full encrypted
|
||||||
|
install and boot.
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
TARGET: /dev/vda
|
||||||
|
|
||||||
|
ALL DATA ON THIS DEVICE WILL BE DESTROYED.
|
||||||
|
This cannot be undone.
|
||||||
|
|
||||||
|
EFI (FAT32): 1024 MiB
|
||||||
|
LUKS2 (passphrase): remainder
|
||||||
|
btrfs:
|
||||||
|
@
|
||||||
|
@home
|
||||||
|
@var
|
||||||
|
@snapshots
|
||||||
|
@swap
|
||||||
|
|
||||||
|
Existing partitions on the target:
|
||||||
|
NAME SIZE TYPE
|
||||||
|
vda 30G disk
|
||||||
46
installer-rs/crates/phoebus-installer/tests/golden/plan.txt
Normal file
46
installer-rs/crates/phoebus-installer/tests/golden/plan.txt
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
Installation plan
|
||||||
|
=================
|
||||||
|
|
||||||
|
System:
|
||||||
|
Distribution : Phoebus OS
|
||||||
|
Architecture : x86_64
|
||||||
|
Init system : systemd
|
||||||
|
Firmware : unknown
|
||||||
|
|
||||||
|
Identity:
|
||||||
|
Hostname : paritybox
|
||||||
|
Keymap : us
|
||||||
|
Locale : en_US.UTF-8
|
||||||
|
Timezone : UTC
|
||||||
|
User : parityuser
|
||||||
|
|
||||||
|
Storage:
|
||||||
|
Target disk : /dev/vda
|
||||||
|
Partitioning : GPT (whole_disk)
|
||||||
|
Encryption : luks2
|
||||||
|
Filesystem : btrfs
|
||||||
|
|
||||||
|
Layout:
|
||||||
|
EFI System Partition (FAT32) 1024 MiB -> /efi
|
||||||
|
luks2 container remainder
|
||||||
|
btrfs
|
||||||
|
@
|
||||||
|
@home
|
||||||
|
@var
|
||||||
|
@snapshots
|
||||||
|
@swap
|
||||||
|
|
||||||
|
Boot and kernel:
|
||||||
|
Bootloader : systemd-boot (BLS entries)
|
||||||
|
Unified UKI : no (deferred; BLS used)
|
||||||
|
Kernel : sys-kernel/gentoo-kernel-bin (safe profile)
|
||||||
|
Keep kernels : 3
|
||||||
|
|
||||||
|
Software:
|
||||||
|
Package policy : balanced
|
||||||
|
Binary pkgs : yes
|
||||||
|
Accept license : @FREE @BINARY-REDISTRIBUTABLE
|
||||||
|
Desktop : dwl
|
||||||
|
Flatpak : no
|
||||||
|
Audio : pipewire
|
||||||
|
AI assistant : no
|
||||||
|
|
@ -1,95 +0,0 @@
|
||||||
//! 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<PathBuf> {
|
|
||||||
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}"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
73
installer-rs/crates/phoebus-installer/tests/plan_golden.rs
Normal file
73
installer-rs/crates/phoebus-installer/tests/plan_golden.rs
Normal file
|
|
@ -0,0 +1,73 @@
|
||||||
|
//! Golden-file tests for the Rust installation plan.
|
||||||
|
//!
|
||||||
|
//! These pin the exact human-readable plan and destructive preview for a fixed
|
||||||
|
//! configuration, replacing the Bash/Rust `parity.rs` comparison. Regenerate
|
||||||
|
//! with `UPDATE_GOLDEN=1 cargo test -p phoebus-installer --test plan_golden`
|
||||||
|
//! after an intentional plan change, then review the diff.
|
||||||
|
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use phoebus_core::{InstallConfig, InstallPlan};
|
||||||
|
|
||||||
|
const CONFIG: &str = "\
|
||||||
|
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";
|
||||||
|
|
||||||
|
fn sample_config() -> InstallConfig {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
let path = dir.path().join("golden.conf");
|
||||||
|
std::fs::write(&path, CONFIG).unwrap();
|
||||||
|
InstallConfig::load_from_path(&path).expect("load golden configuration")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn check_golden(name: &str, actual: &str) {
|
||||||
|
let path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
||||||
|
.join("tests/golden")
|
||||||
|
.join(name);
|
||||||
|
if std::env::var("UPDATE_GOLDEN").as_deref() == Ok("1") {
|
||||||
|
std::fs::create_dir_all(path.parent().unwrap()).unwrap();
|
||||||
|
std::fs::write(&path, actual).unwrap();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let expected = std::fs::read_to_string(&path)
|
||||||
|
.unwrap_or_else(|_| panic!("missing golden file {name}; run with UPDATE_GOLDEN=1"));
|
||||||
|
assert_eq!(actual, expected, "output drifted from tests/golden/{name}");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn plan_output_matches_golden() {
|
||||||
|
let config = sample_config();
|
||||||
|
let actual = InstallPlan::for_config(&config).render_human(&config, None);
|
||||||
|
check_golden("plan.txt", &actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn destructive_preview_matches_golden() {
|
||||||
|
let config = sample_config();
|
||||||
|
let actual = InstallPlan::for_config(&config)
|
||||||
|
.destructive_preview(&config, "NAME SIZE TYPE\nvda 30G disk");
|
||||||
|
check_golden("destructive-preview.txt", &actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn golden_config_is_valid_and_ordered() {
|
||||||
|
// Guard against a golden that silently stops exercising the real path.
|
||||||
|
let config = sample_config();
|
||||||
|
assert_eq!(config.system.hostname, "paritybox");
|
||||||
|
let steps = InstallPlan::for_config(&config).steps;
|
||||||
|
assert_eq!(steps.first().map(|s| s.name()), Some("storage_prepare"));
|
||||||
|
assert_eq!(steps.last().map(|s| s.name()), Some("finalize"));
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue