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

nordisk/monetize

crates/monetize-fast/src/refeed.rs

//! **The site refeed, end to end** (lane OX-SALE, RA5-18 + MAIL-RELAY 2026-10-28): once the site
//! is ready, the operator feeds it its public repositories again (`site refeed <site> --only
//! public_repositories`, `EstateOrder.Refeed`), the ONE box queues ONE signed `refeed` order per
//! data role, the site's main pulls it over the door it already pulls through and answers it,
//! and `EstateOrder.Status` says the answer (`refeed_answered`, `refeed_kept`, `refeed_words`).
//!
//! The fast site declares no public repository, so the order carries the cleared list (`""`,
//! none public: RA5-18), the case the main once refused. A product whose boxes take no public
//! repositories (its facts) is refused by name ([`NOT_TAKEN`]), and that is its answer here.

pub use monetize_server::estate_order::refeed::NOT_TAKEN;

/// The step's words.
pub const STEP: &str = "refeed: the operator feeds the laid site its public repositories again (EstateOrder.Refeed --only public_repositories); its main pulls the signed order and answers it (EstateOrder.Status)";
/// The group asked.
pub const GROUP: &str = "public_repositories";
/// How long the main has to pull and answer the order.
pub const ANSWER_WITHIN_S: u64 = 180;

/// What `EstateOrder.Refeed` answered.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Asked {
    /// Queued: the seq of the order for the primary, and the box's words.
    Queued { asked: u64, words: String },
    /// Refused: the box's words.
    Refused(String),
}

/// Pure: **the refeed's verdict** from what Refeed answered and the site's status
/// (`refeed_answered`, `refeed_kept`, `refeed_words`); `None` while the main has not answered
/// this order yet.
pub fn verdict(asked: &Asked, answered: u64, kept: bool, main_words: &str) -> Option<Result<String, String>> {
    match asked {
        Asked::Refused(why) if why.contains(NOT_TAKEN) => Some(Ok(format!("refused by name, as the product's facts say: {why}"))),
        Asked::Refused(why) => Some(Err(format!("the ONE box refused the refeed: {why}"))),
        Asked::Queued { asked: 0, words } => Some(Err(format!("the ONE box queued no order for the main: {words}"))),
        Asked::Queued { asked, words } if answered >= *asked => Some(if kept {
            Ok(format!("{words}; the main answered order {answered}: {main_words}"))
        } else {
            Err(format!("the main answered order {answered} and kept nothing: {main_words} (asked: {words})"))
        }),
        Asked::Queued { .. } => None,
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    /// ★ **A refeed is judged by the main's answer to THIS order** (RA5-18: the main once
    /// refused the cleared list); a product whose facts take no public repositories is refused
    /// by name, and any other refusal is red.
    #[test]
    fn a_refeed_is_judged_by_the_mains_answer_to_its_order() {
        let q = Asked::Queued { asked: 7, words: "public_repositories none fed again to acme's main and twin".into() };
        assert_eq!(verdict(&q, 0, false, ""), None, "not answered yet: wait");
        assert_eq!(verdict(&q, 6, true, "an older order"), None, "an older answer is not this order's");
        let kept = verdict(&q, 7, true, "kept public_repositories").expect("answered").expect("kept");
        assert!(kept.contains("order 7") && kept.contains("kept public_repositories") && kept.contains("fed again"), "{kept}");
        let refused = verdict(&q, 7, false, "refused: a repository is one plain word").expect("answered").unwrap_err();
        assert!(refused.contains("kept nothing") && refused.contains("one plain word"), "{refused}");
        let gunnar = Asked::Refused(format!("{NOT_TAKEN} the gunnar boxes take no public_repositories (the product's facts): nothing was fed to acme"));
        assert!(verdict(&gunnar, 0, false, "").expect("judged at once").unwrap().contains(NOT_TAKEN));
        assert!(verdict(&Asked::Refused("[site-refeed-not-laid] acme is not laid".into()), 0, false, "").expect("judged at once").is_err());
        assert!(verdict(&Asked::Queued { asked: 0, words: String::new() }, 0, false, "").expect("judged at once").is_err(), "no order for the main is red");
    }
}