use std::path::Path;
use ci_config::Trigger;
use crypto::{Basis, CiVerdictBody, Conclusion, StateRef};
use serde::{Deserialize, Serialize};
use crate::{
HermeticEnv, ProcGroupRegistry, ServiceProvider,
result_cache::{ResultCache, SpotCheck},
};
#[derive(Debug, Clone)]
pub struct ExecutionContext {
pub repo: String,
pub state: StateRef,
pub basis: Basis,
pub definition_digest: String,
pub toolchain: Option<String>,
pub pick_id: Option<String>,
pub attempt: u32,
pub runner: Option<String>,
pub image_digest: Option<String>,
}
pub struct RunOptions<'a> {
pub workdir: &'a Path,
pub services: &'a dyn ServiceProvider,
pub now_rfc3339: &'a dyn Fn() -> String,
}
#[derive(Default)]
pub struct RunControls<'a> {
pub trigger: Option<Trigger>,
pub cache_root: Option<&'a Path>,
pub hermetic_env: Option<&'a HermeticEnv>,
pub proc_groups: Option<ProcGroupRegistry>,
pub result_cache: Option<&'a dyn ResultCache>,
pub spot_check: SpotCheck,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct AttemptRecord {
pub attempt: u32,
pub conclusion: Conclusion,
pub duration_ms: u64,
pub flake_matched: bool,
}
#[derive(Debug, Clone)]
pub struct CheckResult {
pub body: CiVerdictBody,
pub combined_output: String,
pub attempts: u32,
pub attempt_records: Vec<AttemptRecord>,
}
impl CheckResult {
#[must_use]
pub fn conclusion(&self) -> Conclusion {
self.body.outcome.conclusion
}
#[must_use]
pub fn recovered_after_flake(&self) -> bool {
self.conclusion() == Conclusion::Success
&& self
.attempt_records
.iter()
.any(|attempt| attempt.flake_matched)
}
}