Skip to main content

judge

Function judge 

Source
pub fn judge(
    served: &Result<BuildIdentity, Fetched>,
    expected: &str,
    git: &dyn Ancestry,
) -> Judgement
Expand description

Judges what was served against expected, a full commit sha.

The order of the questions is the order in which each makes the next meaningless: no body, no identity, no committed tree, no local knowledge of the served commit, and only then containment.

use majordomus_cli::served::{judge, Ancestry, BuildIdentity, ServedVerdict};

struct Linear;  // a <- b
impl Ancestry for Linear {
    fn has(&self, c: &str) -> Option<bool> { Some(c.starts_with('a') || c.starts_with('b')) }
    fn contains(&self, d: &str, a: &str) -> Option<bool> { Some(d >= a) }
}
let id = |c: &str, dirty| Ok(BuildIdentity {
    commit: c.into(), dirty, source_version: None, source_hash: None });
let (a, b) = ("a".repeat(40), "b".repeat(40));

// the newer build proves the older commit, because it contains it
assert_eq!(judge(&id(&b, false), &a, &Linear).verdict, ServedVerdict::Served);
// the older build does not prove the newer commit
assert_eq!(judge(&id(&a, false), &b, &Linear).verdict, ServedVerdict::Stale);
// and a build from an uncommitted tree proves no commit at all, not even its own
assert_eq!(judge(&id(&b, true), &b, &Linear).verdict, ServedVerdict::Dirty);