Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/holger

xtask/tests/installer_iso_kvm.rs

//! **The crown proof** — the per-site holger installer ISO, mastered by the
//! verb from the DECLARED cell with `--param` values, boots under QEMU/OVMF,
//! installs to a blank disk, and the DISK carries the site's declarations:
//! the hub.conf on P3's filesystem, the product + site on the ESP's cmdline.
//!
//! Heavy and opt-in (a real KVM boot + the full composition):
//!
//! ```text
//! KORP_TEST_KERNEL=/path/to/bzImage cargo test -p xtask --test installer_iso_kvm -- --ignored --nocapture
//! ```
//!
//! One writer throughout, and this file is now the SMALL half of it: the ISO
//! comes from `cargo xtask installer-iso` (the verb under test — never a
//! test-private composition), and the whole boot→install→readback→row ceremony
//! is `korp_installer::isoproof` (the SHARED harness gunnar and korp drive with
//! their own payloads). What stays here is exactly what is HOLGER: the site
//! params, the declared cell, the expected cmdline and the expected P3 bytes.

use std::path::{Path, PathBuf};
use std::process::Command;
use std::time::Duration;

use korp_installer::isoproof::{
    appliance_component, DataFileExpectation, IsoInstallProof, KvmPreflight, FORM_ISO_KVM,
    INSTALL_OK,
};

/// The proof's own name — what a loud SKIP says instead of vanishing.
const PROOF: &str = "holger per-site install (iso-kvm)";

fn workspace_root() -> PathBuf {
    Path::new(env!("CARGO_MANIFEST_DIR"))
        .parent()
        .unwrap()
        .to_path_buf()
}

#[test]
#[ignore = "requires: KVM plus OVMF firmware and a test kernel (KORP_TEST_KERNEL) — the ISO is composed, booted under QEMU and read back off a real disk; no plain cargo test box has this rig"]
fn the_per_site_iso_installs_and_the_disk_carries_the_site() {
    let root = workspace_root();
    let Some(preflight) = KvmPreflight::detect(PROOF) else {
        return;
    };

    // ── the per-site hub declaration, in the ceremony's own dialect ──
    let scratch = root.join("target/installer-iso-kvm");
    let _ = std::fs::remove_dir_all(&scratch);
    std::fs::create_dir_all(&scratch).unwrap();
    let hub_conf = "\
[Interface]
Address = 10.77.0.7/16

[Peer]
PublicKey = HIgo9xNzJMWLKASShiTqIybxZ0U3wGLiUeJ1PKf8ykw=
Endpoint = 192.0.2.7:51820
AllowedIPs = 10.77.0.0/16
PersistentKeepalive = 25
";
    let hub_path = scratch.join("hub.conf");
    std::fs::write(&hub_path, hub_conf).unwrap();
    let ron_path = root.join("xtask/tests/fixtures/site-holger.ron");

    // ── the ISO, through THE VERB (the thing under test) ──
    let run = Command::new(env!("CARGO"))
        .args([
            "run",
            "--quiet",
            "--manifest-path",
            "xtask/Cargo.toml",
            "--",
            "installer-iso",
        ])
        .args(["--param", "site=kvmproof-1"])
        .arg("--param")
        .arg(format!("hub_conf=@{}", hub_path.display()))
        .arg("--param")
        .arg(format!("holger_ron=@{}", ron_path.display()))
        .current_dir(&root)
        .output()
        .expect("spawn installer-iso");
    assert!(
        run.status.success(),
        "installer-iso must master:\n--- stdout ---\n{}\n--- stderr ---\n{}",
        String::from_utf8_lossy(&run.stdout),
        String::from_utf8_lossy(&run.stderr)
    );
    let iso = root.join(".iso-out/holger-installer.iso");
    assert!(iso.is_file(), "the verb produced {}", iso.display());

    // ── the declared cell: the disk size + attachment shape, one writer ──
    let set = holger_build_space::build_variant_set().unwrap();
    let cell = set
        .installers
        .iter()
        .find(|i| i.name == "holger-installer")
        .unwrap();
    let disk_path = scratch.join("target.raw");
    let ron_bytes = std::fs::read(&ron_path).unwrap();

    // ── the SHARED ceremony, with holger's values as its inputs ──
    let installed = IsoInstallProof {
        product: "holger",
        check: "install_ok",
        iso: &iso,
        disk: &disk_path,
        disk_bytes: cell.target_disk_bytes(),
        disk_args: cell.kvm_disk_args(disk_path.to_str().unwrap()),
        workdir: &scratch,
        marker: INSTALL_OK,
        timeout: Duration::from_secs(180),
        // The volume door in action, narrated by the PID-1 itself.
        expect_serial: &["materialized off the ISO volume"],
        expect_cmdline: &[
            // the installed disk boots HOLGER…
            "korp.entry=holger",
            // …the site parameter reached the installed cmdline…
            "korp.site=kvmproof-1",
            // …the installed app is the raw partition…
            "korp.znippy=part:korp-rootfs",
            // …and R9: the declared cmd rides the installed cmdline — the
            // metal shape's answer to the container's cmd (the argv gap,
            // closed at the declaration).
            "korp.args=start,--config,/data/holger.ron",
        ],
        expect_data_files: &[
            // R9: the server declaration landed beside the identity — the file
            // the korp.args tail names, byte-for-byte.
            DataFileExpectation { path: "holger.ron", bytes: &ron_bytes },
            // The ceremony hub.conf on the durable home, verbatim.
            DataFileExpectation { path: "wg/hub.conf", bytes: hub_conf.as_bytes() },
        ],
        detail: "per-site ISO → KVM boot → INSTALL-OK; korp.entry/site/znippy on the installed ESP, hub.conf verbatim on P3",
    }
    .run(&preflight);

    // The rollup's `holger-appliance/iso-kvm` install_ok row was emitted by the
    // harness, after every assert above — never by this file, so no product can
    // spell the form as plain `iso` and let a KVM green pass for a metal one.
    assert!(
        installed.cmdline.contains("korp.entry=holger"),
        "the readback the harness returned is the installed cmdline: {}",
        installed.cmdline
    );

    // ── the row holger OWNS ──────────────────────────────────────────────
    //
    // The shared harness emits this coordinate too, and deliberately so: it is
    // the one writer of the FORM word, which is why no product can spell a KVM
    // green as if it were metal. But a coordinate assembled inside another
    // repo is a coordinate no scan of THIS repo can see — and the 2026-09-10
    // inventory proved what that costs: holger's `install_ok` came back
    // "declared, nothing emits it", and the nearest thing to an emitter was a
    // unit-test FIXTURE in edda. So the string is spelled out here, in the file
    // whose test earns it, and pinned to the shared rule on the line above so
    // the two spellings cannot drift apart.
    assert_eq!(
        appliance_component("holger", FORM_ISO_KVM),
        "holger-appliance/iso-kvm",
        "the coordinate this file spells IS the shared rule's — one form word, one writer"
    );
    nornir_testmatrix::functional_status(
        "holger-appliance/iso-kvm",
        "install_ok",
        installed.cmdline.contains("korp.entry=holger") && installed.cmdline.contains("korp.site=kvmproof-1"),
        "per-site ISO → KVM boot → INSTALL-OK; korp.entry/site/znippy read back off the installed ESP",
    );
}