Skip to main content

resolve_schedule_jitter

Function resolve_schedule_jitter 

Source
pub fn resolve_schedule_jitter(
    own: Option<&str>,
    candidates: &[Option<String>],
) -> ScheduleJitterResolution
Expand description

Pure. The jitter counterpart of effective_timezone, reporting disagreement instead of silently swallowing it (see ScheduleJitterResolution). own is the schedule’s own spec.schedule.jitter; candidates carries one entry per matched target policy repository (None = that repository sets no default).

Rules (the reconciler does the GETs and passes the data in):

  • own set → that window wins, no lookups, never ambiguous.
  • own unset, no candidates → Agreed(None).
  • own unset, all candidates equal → Agreed(that value) (possibly None).
  • own unset, candidates differ → Disagreed (effective window: no jitter).

A single policyRef over a single-repository policy therefore never disagrees.

use kopiur_api::common::{ScheduleJitterResolution, resolve_schedule_jitter};

// Own jitter wins outright.
assert_eq!(
    resolve_schedule_jitter(Some("5m"), &[]),
    ScheduleJitterResolution::Agreed(Some("5m".to_string())),
);
// Unset own, one agreeing default across matched policies.
let defs = [Some("1h".to_string()), Some("1h".to_string())];
assert_eq!(
    resolve_schedule_jitter(None, &defs),
    ScheduleJitterResolution::Agreed(Some("1h".to_string())),
);
// Unset own, disagreeing defaults → reported, not silently dropped.
let defs = [Some("1h".to_string()), None];
assert_eq!(
    resolve_schedule_jitter(None, &defs),
    ScheduleJitterResolution::Disagreed {
        candidates: vec!["(none)".to_string(), "1h".to_string()],
    },
);