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

nordisk/monetize

crates/monetize-server/src/estate_order/tests/update_pinned.rs

//! ★ **An open update hands out the release it was OPENED with** (2026-10-17, a lane finding):
//! a newer release fed while it runs never leaks into it — the live apps the front takes, the
//! keep medium a box is upgraded from and the front's keep boot are the opened release's.

use super::*;

/// The shop's media replaced by release `next`'s (fed while the update runs).
fn feed(r: &mut Rig, next: &str) {
    let st = Arc::get_mut(&mut r.state).expect("the rig's state is the test's alone");
    st.estates.cfg = Some(release_cfg(next, true));
}

#[test]
fn a_newer_release_fed_mid_update_never_reaches_the_open_update() {
    let mut r = delivered("pinned-take", release_cfg("02", true));
    let key = client_of(&r, "acme");
    laid_older(&r);
    // The front has asked for updates before (else the box opens it front first).
    assert!(!take(&r, &key).unwrap().open);
    let u = update::start(&r.state, "acme", "", "operator").expect("opened at 02");
    assert_eq!(u.release, "02-gunnar");
    feed(&mut r, "03");
    let t = take(&r, &key).unwrap();
    assert!(
        t.open && t.role == "twin" && t.release == "02-gunnar",
        "{t:?}"
    );
    let g = t.app.expect("the opened release's live app");
    assert!(
        g.url.contains("/release/gunnar/02.live-app.znippy"),
        "03's archive was handed out for an update to 02: {g:?}"
    );
    assert!(
        g.record.app.starts_with("02gunnar"),
        "03's live record was handed out: {:?}",
        g.record
    );
    let f = t.front.expect("the front's live app");
    assert!(f.url.contains("/release/front/02.live-app.znippy"), "{f:?}");
}

#[test]
fn the_media_an_update_reads_are_pinned_at_its_opening() {
    // Its own lifecycles: under nextest (one process per test) no other test registered them.
    crate::testing::lifecycles::install();
    let opened = release_cfg("02", true);
    let plan = lifecycle::of(&opened).unwrap().update_plan();
    let pinned = update::pin(&opened, &plan);
    assert!(!pinned.is_empty());
    let mut u = update::EstateUpdate::open("02-gunnar", "02-front", true, "operator", 0);
    u.media = pinned;
    let now = update::as_opened(&release_cfg("03", true), &u);
    assert_eq!(release_id(&now, "gunnar"), "02-gunnar");
    assert_eq!(
        now.media.get(KEEP_MEDIUM).map(String::as_str),
        Some("02-gunnar-keep"),
        "the keep medium a box is upgraded from"
    );
    assert_eq!(
        now.media.get(update::FRONT_KEEP_MEDIUM).map(String::as_str),
        Some("02-front-keep"),
        "the front's keep boot"
    );
    assert_eq!(now.live_apps.get("gunnar"), opened.live_apps.get("gunnar"));
    // An update opened before pinning reads what is fed, as it always did.
    let old = update::EstateUpdate::open("02-gunnar", "02-front", true, "operator", 0);
    assert_eq!(
        release_id(&update::as_opened(&release_cfg("03", true), &old), "gunnar"),
        "03-gunnar"
    );
}