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

nordisk/monetize

crates/monetize-build-thing/tests/declaration.rs

//! The declaration holds: nornir-build-thing's laws, the bijection, the
//! committed emission, the sibling list against the real reach, and the owner
//! ruling of 2026-09-25 — no row carries a plugin, not even as an edge.

use monetize_build_thing::{declared, MonetizeBuildThing, COMMERCIAL, ORIGINAL};
use nornir_build_thing::plugin::BuildThing;
use nornir_build_thing::variant::BuildVariantSet;

#[test]
fn the_conformance_gate_holds() {
    nornir_build_thing::laws::assert_bijective(&MonetizeBuildThing);
}

#[test]
fn every_row_validates_and_each_group_has_one_default() {
    let set = declared();
    for v in &set.variants {
        set.validate(v)
            .unwrap_or_else(|e| panic!("variant `{}`: {e:#}", v.name));
        set.validate_kind(v)
            .unwrap_or_else(|e| panic!("variant `{}`: {e:#}", v.name));
        set.validate_shape(v)
            .unwrap_or_else(|e| panic!("variant `{}`: {e:#}", v.name));
    }
    assert!(
        set.check_defaults().is_empty(),
        "{:?}",
        set.check_defaults()
    );
}

/// OWNER RULING 2026-09-25: monetize's Build Thing carries NO plugin, and neither delivery names
/// a private checkout; plugins are signed guests built in monetize-impl and taken in at runtime.
/// v2.0 P2 12.6 (A25 2.6): the standalone `monetize-server` rows went (no estate runs a
/// monetize); the ONE box's program, monetize-admin, is the server of both deliveries.
#[test]
fn no_delivery_carries_a_plugin() {
    let set = declared();
    assert_eq!(set.suites(), [ORIGINAL, COMMERCIAL]);
    assert!(
        set.require("monetize-server").is_err()
            && set.require("monetize-server-commercial").is_err(),
        "the standalone server rows went"
    );
    let one = set.require("monetize-admin").expect("declared");
    assert_eq!(one.suites, [ORIGINAL, COMMERCIAL]);
    assert!(one.is_default, "the ONE box's program is the server");
    for v in &set.variants {
        assert!(
            v.edges.is_empty(),
            "`{}` carries a plugin edge: {:?}",
            v.name,
            v.edges
        );
    }
    assert!(
        one.command_line()
            .contains("--target x86_64-unknown-linux-musl"),
        "{}",
        one.command_line()
    );
    let toml = monetize_build_thing::emitted_toml().expect("emit");
    assert!(
        !toml.contains("monetize-impl/") && !toml.contains("[build.variant.edges"),
        "{toml}"
    );
}

/// The measured failure the edges caused: with them, the declaration refused to
/// load on a box whose `monetize-impl` checkout declares no build space. Now
/// it validates with NO donor resolvable at all.
#[test]
fn the_declaration_loads_with_no_private_checkout_anywhere() {
    // The ONE donor is public and declared: the monetize-admin medium boots
    // tunnr's kernel (the checkout beside this one). No private checkout.
    let root = monetize_build_thing::repo_root();
    declared()
        .validate_edges_with("monetize", &|repo: &str| match repo {
            "tunnr" => Ok(root.parent().expect("a parent").join("tunnr")),
            other => anyhow::bail!("no checkout named {other} may be needed"),
        })
        .expect("the declaration needs no private donor");
    let committed = BuildVariantSet::discover(&root)
        .expect("read")
        .expect("a build space");
    assert_eq!(committed, declared());
}

#[test]
fn the_emission_reads_back_to_the_same_set() {
    let toml = monetize_build_thing::emitted_toml().expect("emit");
    assert_eq!(
        BuildVariantSet::from_toml_str(&toml).expect("read back"),
        declared()
    );
}

#[test]
fn the_committed_file_is_the_codes_emission() {
    monetize_build_thing::require_committed_is_emitted(&monetize_build_thing::repo_root())
        .expect("the committed description is stale");
}

#[test]
fn the_declared_siblings_cover_the_reach() {
    let root = monetize_build_thing::repo_root();
    let reach = nornir_build_thing::cargo_container::sibling_closure(&root);
    if reach.is_empty() {
        eprintln!("skipping: no siblings beside {}", root.display());
        return;
    }
    let declared: Vec<String> = declared().toolchain.expect("toolchain").siblings;
    let missing: Vec<&String> = reach.iter().filter(|s| !declared.contains(s)).collect();
    assert!(
        missing.is_empty(),
        "undeclared siblings {missing:?}; reach = {reach:?}"
    );
}

/// **holger's rule 1, held here: nothing monetize builds reaches a gunnar
/// checkout** (2026-09-28). holger builds from this repo (its front links
/// `monetize-front` and `monetize-server`), so a `../gunnar` path anywhere in
/// this tree — it was `products/gunnar`'s dev-dependency on
/// `gunnar-monetize-guest` — made holger's Build Thing mount ../gunnar and made
/// `cargo metadata` of this workspace refuse without one. Three measures, none
/// may name `gunnar*`: the declared siblings; every path dependency any
/// manifest in this tree names, scanned lexically the way the forge's
/// pre-flight and `sibling_closure` read it (nested workspaces included); and
/// the checkouts `cargo metadata --locked` of the workspace actually loads,
/// which must also be covered by the declaration.
#[test]
fn nothing_monetize_builds_reaches_a_gunnar_checkout() {
    use nornir_build_thing::cargo_container::{escaping_path_deps, metadata_sibling_closure};
    let is_gunnar = |s: &str| s.starts_with("gunnar");
    let declared: Vec<String> = declared().toolchain.expect("toolchain").siblings;
    assert!(
        !declared.iter().any(|s| is_gunnar(s)),
        "declared siblings name gunnar: {declared:?}"
    );

    let root = monetize_build_thing::repo_root();
    let parent = root.parent().expect("a checkout parent").to_path_buf();
    let lexical: Vec<String> = escaping_path_deps(&root)
        .into_iter()
        .filter(|(_, _, resolved)| {
            resolved
                .strip_prefix(&parent)
                .ok()
                .and_then(|r| r.components().next())
                .and_then(|c| c.as_os_str().to_str())
                .is_some_and(is_gunnar)
        })
        .map(|(m, dep, r)| format!("{} → {dep} ({})", m.display(), r.display()))
        .collect();
    assert!(
        lexical.is_empty(),
        "a manifest in monetize reaches a gunnar checkout: {lexical:?}"
    );

    if !parent.join("edda").is_dir() {
        eprintln!(
            "skipping the cargo-metadata half: no siblings beside {}",
            root.display()
        );
        return;
    }
    let loaded = metadata_sibling_closure(&root.join("Cargo.toml"), &parent)
        .expect("cargo metadata --locked of the monetize workspace loads with no gunnar checkout");
    assert!(
        !loaded.iter().any(|s| is_gunnar(s)),
        "the workspace loads gunnar: {loaded:?}"
    );
    let own = root
        .file_name()
        .and_then(|n| n.to_str())
        .unwrap_or("monetize")
        .to_string();
    let undeclared: Vec<&String> = loaded
        .iter()
        .filter(|s| **s != own && !declared.contains(s))
        .collect();
    assert!(
        undeclared.is_empty(),
        "the workspace loads undeclared siblings {undeclared:?}; loaded = {loaded:?}"
    );
}

#[test]
fn the_manifest_names_repo_and_source() {
    let m = MonetizeBuildThing.manifest();
    assert_eq!(m.repo, "monetize");
    assert_eq!(m.source_crate, "monetize-build-thing");
    assert_eq!(m.abi, nornir_build_thing::plugin::ABI_VERSION);
}

/// **The operator console is built by the Build Thing, not by host trunk**
/// (2026-09-28: nothing in the install path ran trunk, so no estate carried
/// monetize's UI at all). The BFF is a musl row in both deliveries, never its
/// role's default; the browser bundle is a wasm row claimed by the
/// `[[build.web_app]]` of the same name, landing in `crates/monetize-ui-web/dist`
/// from the page trunk already reads.
#[test]
fn the_console_is_two_rows_and_its_bundle_is_a_web_app() {
    let set = declared();
    let bff = set.require("monetize-ui-server").expect("declared");
    assert_eq!(bff.suites, [ORIGINAL, COMMERCIAL]);
    assert!(
        !bff.is_default,
        "the server is its role's default, not the console"
    );
    assert!(
        bff.command_line().contains("-p monetize-ui-server")
            && bff
                .command_line()
                .contains("--target x86_64-unknown-linux-musl"),
        "{}",
        bff.command_line()
    );
    let web = set.require("monetize-ui-web").expect("declared");
    assert!(
        web.command_line()
            .contains("--target wasm32-unknown-unknown"),
        "{}",
        web.command_line()
    );
    let apps = monetize_build_thing::web_apps();
    assert_eq!(apps.len(), 1);
    assert_eq!(
        (
            apps[0].name.as_str(),
            apps[0].out_dir.as_str(),
            apps[0].index.as_str()
        ),
        (
            "monetize-ui-web",
            "crates/monetize-ui-web/dist",
            "crates/monetize-ui-web/index.html"
        )
    );
    for a in &apps {
        set.validate_web_app(a)
            .unwrap_or_else(|e| panic!("{}: {e:#}", a.name));
    }
    assert!(
        monetize_build_thing::repo_root()
            .join(&apps[0].index)
            .is_file(),
        "the page the web app assembles from exists"
    );
    // The bundle's bindgen is the one the web-app step links: the lock pins it.
    let lock = std::fs::read_to_string(monetize_build_thing::repo_root().join("Cargo.lock"))
        .expect("root lock");
    assert!(lock.contains("name = \"wasm-bindgen\"\nversion = \"0.2.128\""), "the root lock must pin wasm-bindgen 0.2.128, the version nornir-build-thing's web-app step links");
}

/// **The monetize-admin appliance** (owner 2026-09-28): its program is built
/// by manifest dir (its own workspace), static musl, in both deliveries, never
/// a default; its medium boots it as PID 1 on tunnr's kernel with gunnar's front
/// medium's kernel rows exactly (one donor fragment for every front).
#[test]
fn the_admin_box_is_a_program_and_a_medium_on_the_fronts_kernel() {
    let set = declared();
    let prog = set.require("monetize-admin").expect("declared");
    assert_eq!(prog.manifest_dir.as_deref(), Some("crates/monetize-admin"));
    assert_eq!(prog.target.as_deref(), Some("x86_64-unknown-linux-musl"));
    assert!(
        prog.is_default,
        "the ONE box's program is the server of its deliveries (v2.0 P2 12.6)"
    );
    let medium = set
        .installers
        .iter()
        .find(|i| i.name == "monetize-admin-installer")
        .expect("the medium");
    assert_eq!(medium.variant, "monetize-admin");
    assert!(
        medium
            .boot_params
            .iter()
            .any(|p| p == "korp.entry=monetize-admin"),
        "{:?}",
        medium.boot_params
    );
    let donor = medium.kernel_donor.as_ref().expect("a donor");
    assert_eq!(
        (donor.repo.as_str(), donor.kernel.as_str()),
        ("tunnr", "tunnr-kernel")
    );
    let mut symbols: Vec<String> = medium
        .requires
        .iter()
        .map(|r| format!("{:?}", r.what))
        .collect();
    symbols.sort();
    for s in [
        "CONFIG_TUN",
        "CONFIG_PARAVIRT_CLOCK",
        "CONFIG_HOTPLUG_PCI_PCIE",
        "CONFIG_INET",
    ] {
        assert!(
            symbols.iter().any(|x| x.contains(&format!("\"{s}\""))),
            "{s}: {symbols:?}"
        );
    }
    assert_eq!(
        medium.requires.len(),
        15,
        "gunnar-front-installer-metered's fifteen kernel rows"
    );
    for p in ["pairing_seed", "reinstall", "install_then", "log_udp"] {
        assert!(medium.params.iter().any(|x| x.name == p), "{p}");
    }
    assert_eq!(
        medium
            .params
            .iter()
            .find(|x| x.name == "pairing_seed")
            .unwrap()
            .staged_file,
        "pairing/seed.toml"
    );
}

/// i54a run9 (2026-10-11): the mock ONE box answered an enrolment `[attach-clock]`
/// 7 199 015 ms off — a guest with no kvmclock (TCG) boots on the CMOS, and the
/// cloud's CMOS runs two hours ahead. The ONE box has no front to follow, so it
/// keeps its own clock (estate-clock, the fronts' rule) from the sources its
/// medium names: `clock` rides the cmdline as `korp.env.ESTATE_CLOCK`.
#[test]
fn the_admin_box_keeps_its_own_clock_from_its_mediums_sources() {
    let set = declared();
    let medium = set
        .installers
        .iter()
        .find(|i| i.name == "monetize-admin-installer")
        .expect("the medium");
    let clock = medium
        .params
        .iter()
        .find(|x| x.name == "clock")
        .expect("a `clock` parameter");
    assert_eq!(clock.boot_param, "korp.env.ESTATE_CLOCK");
    assert!(
        !clock.required,
        "unset is `not configured`, never a refusal to compose"
    );
    let manifest = std::fs::read_to_string(
        monetize_build_thing::repo_root().join("crates/monetize-admin/Cargo.toml"),
    )
    .expect("the admin's manifest");
    let line = manifest
        .lines()
        .find(|l| l.starts_with("estate-clock"))
        .expect("monetize-admin links estate-clock");
    for f in ["\"fetch\"", "\"adjust\""] {
        assert!(line.contains(f), "estate-clock needs {f}: {line}");
    }
}