Skip to main content

policy

Function policy 

Source
pub fn policy(ctx: &Context) -> Result<CompilerPolicy, CapabilityError>
Expand description

The compiler’s rules: the tiers, every edge of the composed graph and what is done with it, the selectors, and the defaults.

It takes no request, because the rules do not depend on what is being asked about. It does take a context, and for one reason: the edge rows are enumerated from the graph this repository derives, so an edge kind the graph gains shows up here as unjudged rather than going quietly unfollowed. The answer is therefore a function of the repository’s graph and this module’s tables, and of nothing else.

Pure over those two: the same tree gives the same answer every time, which is what makes it safe to publish beside the compiled contexts it explains.

use majordomus_cli::devcontext::{policy, Selector, Tier};
use majordomus_cli::synthetic::SyntheticRepository;

let repo = SyntheticRepository::small().unwrap();
let ctx = repo.context().unwrap();

let rules = policy(&ctx).unwrap();
assert_eq!(rules.tiers.len(), Tier::ORDER.len());
assert_eq!(rules.selectors.len(), Selector::ALL.len());

// every edge the graph declares is judged, one way or the other, with a reason
for e in &rules.edges {
    assert!(!e.reason.is_empty(), "{} was neither followed nor explained", e.edge);
    assert_eq!(e.refused, e.forward.is_none() && e.reverse.is_none());
}

// and asking twice over one tree gives one answer
let again = policy(&ctx).unwrap();
assert_eq!(again, rules);