Skip to main content

check

Function check 

Source
pub fn check(
    index: &Index,
    plan: &Plan,
    id: &str,
    transition: Transition,
    now: &str,
) -> Result<(), TransitionError>
Expand description

Whether transition is legal for issue as the plan reads now, and why not when it is not.

Separate from the write so that a surface can offer or withhold a control without performing it: the Cockpit disables a button by asking this, and never by reimplementing the rule.

use majordomus_cli::plan::{check, Plan, Transition, TransitionError};
let plan = Plan::build(index);
let now = "2026-09-11T12:00:00Z";
// Offer the control only when the model would accept it, and show the reason when not.
let offered = check(index, &plan, "I0001", Transition::Start, now).is_ok();

// An issue the plan does not hold is not found, never merely refused: the two are
// different answers and a surface maps them to different statuses.
let missing = check(index, &plan, "no-such-issue", Transition::Start, now);
assert_eq!(missing, Err(TransitionError::NoSuchIssue("no-such-issue".into())));

// Asking twice never changes anything: this is the question, not the move.
assert_eq!(offered, check(index, &plan, "I0001", Transition::Start, now).is_ok());