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

nordisk/holger

xtask/tests/the_shared_pieces_are_not_copied.rs

//! **Holger carries no copy of a piece the estate shares** (P4a, 2026-10-25; A28 §4, L12).
//!
//! Five mechanisms Holger and Gunnar both carried moved into shared crates, Holger first:
//!
//! | piece | shared home | Holger's copy, gone |
//! |---|---|---|
//! | the box pump (key, Report/Orders/Ask, the order check, the Fleet client, the jera round) | monetize `monetize-estate-side::pump` | holger-fleet `puller.rs`, `duty.rs`, `grpc.rs`, `key.rs`, `config.rs` |
//! | the SoldEstate client (`unhex32`, `from_status`, `blocking`, the signed calls) | monetize `monetize-estate-side::sold_door` | holger-estate-front `shop_door.rs`'s client half |
//! | the update step (`on_trial`, `decide`, `wait_confirmed`, `staged_of`, `step`) | Skidbladnir `nordisk-pairing::frontside::update` | holger-estate-front `update.rs` |
//! | the metadata seed reader | Skidbladnir `nordisk-pairing::seed::metadata` | server/cli `metadata_seed.rs` and its `#[path]` includes |
//! | the guardian's building blocks (`order`, `wait`, `recharge`, `restate`, `heard`, `word`) | monetize `monetize-product::guardian::steps` | holger-monetize-guest `guardian.rs`'s helpers |
//!
//! These read the tree only: no sibling, no network.

use std::path::{Path, PathBuf};

fn root() -> PathBuf {
    Path::new(env!("CARGO_MANIFEST_DIR"))
        .parent()
        .expect("xtask has a parent")
        .to_path_buf()
}

fn text(rel: &str) -> String {
    std::fs::read_to_string(root().join(rel)).unwrap_or_else(|e| panic!("{rel}: {e}"))
}

/// The Rust files under `dir`, recursively.
fn rust_files(dir: &Path) -> Vec<PathBuf> {
    let mut out = Vec::new();
    for e in std::fs::read_dir(dir)
        .unwrap_or_else(|e| panic!("{}: {e}", dir.display()))
        .flatten()
    {
        let p = e.path();
        if p.is_dir() {
            out.extend(rust_files(&p));
        } else if p.extension().is_some_and(|x| x == "rs") {
            out.push(p);
        }
    }
    out
}

#[test]
fn the_box_pump_is_the_shared_crates() {
    for gone in ["puller.rs", "duty.rs", "grpc.rs", "key.rs", "config.rs"] {
        assert!(
            !root().join("estate/holger-fleet/src").join(gone).exists(),
            "estate/holger-fleet/src/{gone} is the shared pump's (monetize-estate-side::pump)"
        );
    }
    assert!(
        text("estate/holger-fleet/Cargo.toml").contains("monetize-estate-side"),
        "holger-fleet runs on monetize-estate-side"
    );
    assert!(text("estate/holger-fleet/src/lib.rs")
        .contains("pub use monetize_estate_side::pump::{config, duty, grpc, key, puller};"));
    assert!(
        text(".cargo/estate-siblings.toml").contains(
            "monetize-estate-side = { path = \"../monetize/crates/monetize-estate-side\" }"
        ),
        "the sibling patch reaches it"
    );
}

#[test]
fn the_fronts_soldestate_client_and_update_step_are_the_shared_crates() {
    let door = text("holger-estate-front/src/shop_door.rs");
    for gone in [
        "fn unhex32",
        "fn from_status",
        "fn blocking",
        "fn signed(",
        "SoldEstateClient",
    ] {
        assert!(
            !door.contains(gone),
            "shop_door.rs still carries `{gone}`: it is monetize-estate-side::sold_door's"
        );
    }
    assert!(door.contains("pub use monetize_estate_side::sold_door::*;"));
    let update = text("holger-estate-front/src/update.rs");
    for gone in [
        "fn on_trial",
        "fn decide",
        "fn wait_confirmed",
        "fn staged_of",
        "fn step(",
    ] {
        assert!(
            !update.contains(gone),
            "update.rs still carries `{gone}`: it is nordisk-pairing::frontside::update's"
        );
    }
    assert!(update.contains("pub use nordisk_pairing::frontside::update::*;"));
}

#[test]
fn the_seed_reader_is_nordisk_pairings_and_no_front_file_is_a_path_include_of_it() {
    assert!(
        !root().join("server/cli/src/metadata_seed.rs").exists(),
        "the metadata seed reader is nordisk-pairing::seed::metadata"
    );
    for dir in ["holger-estate-front", "server/cli"] {
        for f in rust_files(&root().join(dir)) {
            let t = std::fs::read_to_string(&f).unwrap();
            assert!(
                !t.contains("metadata_seed.rs\"]"),
                "{} includes the old seed reader by #[path]",
                f.display()
            );
        }
    }
    assert!(
        text("holger-estate-front/src/main.rs").contains("nordisk_pairing::seed::metadata::read")
    );
    assert!(text("server/cli/src/paired.rs").contains("nordisk_pairing::seed::metadata::read"));
}

#[test]
fn the_guests_guardian_builds_its_plans_from_the_shared_steps() {
    let g = text("crates/holger-monetize-guest/src/guardian.rs");
    for gone in [
        "fn order(",
        "fn wait(",
        "fn recharge(",
        "fn restate(",
        "fn heard(",
        "fn word<",
        "pub const HEARD_WITHIN_MS: u64",
    ] {
        assert!(!g.contains(gone), "the guest's guardian still carries `{gone}`: it is monetize-product::guardian::steps's");
    }
    assert!(g.contains("monetize_product_guest::guardian::steps::"));
}

/// P4c (A28 M11): **the sign-in-again mail goes through the ONE shared sender**, monetize's
/// `monetize-mail` (TLS required, proper MIME, the front's egress door behind its `egress`
/// feature). Holger builds no SMTP transport of its own.
#[test]
fn the_sign_in_mail_goes_through_the_shared_sender() {
    let mail = text("server/lib/src/sign_in_again.rs");
    for gone in [
        "lettre::",
        "AsyncSmtpTransport",
        "fn percent_decoded",
        "Credentials::new",
        "fn send(",
    ] {
        assert!(
            !mail.contains(gone),
            "sign_in_again.rs still carries `{gone}`: the sender is monetize-mail's"
        );
    }
    assert!(
        mail.contains("monetize_mail::Mailer"),
        "sign_in_again.rs mails through monetize-mail"
    );
    let manifest = text("server/lib/Cargo.toml");
    assert!(
        !manifest
            .lines()
            .any(|l| l.trim_start().starts_with("lettre =")),
        "server/lib links no lettre of its own"
    );
    assert!(
        manifest.contains("dep:monetize-mail"),
        "monetize-mail rides `metered`"
    );
    assert!(
        text(".cargo/estate-siblings.toml")
            .contains("monetize-mail = { path = \"../monetize/crates/monetize-mail\" }"),
        "the sibling patch reaches it"
    );
}

/// P4c (A28 M11): **the sign-in-again link is the shared crate's** (monetize-estate-side
/// `sign_in`: the order's checks, the lifetime, the words). holger-fleet re-exports it.
#[test]
fn the_sign_in_link_is_the_shared_crates() {
    assert!(
        !root().join("estate/holger-fleet/src/sign_in.rs").exists(),
        "estate/holger-fleet/src/sign_in.rs is monetize-estate-side::sign_in's"
    );
    assert!(
        text("estate/holger-fleet/src/lib.rs").contains("pub use monetize_estate_side::sign_in;")
    );
}

/// P4c (A28 M11): **the front's mesh probe, its renewal schedule and steps, the box's renewing
/// half and the front's re-admission of a lost box are Skidbladnir's** (`nordisk_pairing::
/// frontside::{mesh_probe, renew, recharge}`, `boxside::renewing`). The front keeps its ports,
/// its jobs, its seed, its shop and estate halves.
#[test]
fn the_fronts_probe_renewal_and_re_admission_are_the_shared_crates() {
    let probe = text("holger-estate-front/src/mesh_probe.rs");
    for gone in [
        "pub fn verdict",
        "pub fn dial",
        "pub fn levels",
        "pub fn due",
        "pub struct Box3",
        "pub struct Watch",
    ] {
        assert!(
            !probe.contains(gone),
            "mesh_probe.rs still carries `{gone}`: it is nordisk-pairing::frontside::mesh_probe's"
        );
    }
    let renew = text("holger-estate-front/src/renew.rs");
    for gone in [
        "pub fn retry_after",
        "pub struct Link",
        "pub struct State",
        "pub fn look(",
        "pub fn renew_ca_due",
        "pub fn renew_boxes",
        "fn named(",
    ] {
        assert!(
            !renew.contains(gone),
            "renew.rs still carries `{gone}`: it is nordisk-pairing::frontside::renew's"
        );
    }
    assert!(
        !root().join("server/cli/src/renewing.rs").exists(),
        "the box's renewing half is nordisk-pairing::boxside::renewing"
    );
    for dir in ["holger-estate-front", "server/cli"] {
        for f in rust_files(&root().join(dir)) {
            assert!(
                !std::fs::read_to_string(&f)
                    .unwrap()
                    .contains("renewing.rs\"]"),
                "{} includes renewing.rs by #[path]",
                f.display()
            );
        }
    }
    let recharge = text("holger-estate-front/src/recharge.rs");
    for gone in [
        "pub trait Shop",
        "pub trait Estate",
        "pub fn due(",
        "pub fn left_alone",
        "pub struct Unsealed",
    ] {
        assert!(
            !recharge.contains(gone),
            "recharge.rs still carries `{gone}`: it is nordisk-pairing::frontside::recharge's"
        );
    }
}