artifactize-core 0.27.1

The library behind artifactize: Artifacts, evals, reviews, the monitor and review models, and the shared operations every interface calls.
Documentation
//! What a Run reference shows in another surface, read by the Run's ID alone.
use super::State;
use crate::{
    store,
    types::{EvalId, RunId},
};
use serde::Serialize;
use std::path::Path;

/// A Run as a reference to it shows it: its state, and the evals that failed or wait for a
/// person, in the Run's order.
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct Reference {
    pub run: RunId,
    pub state: State,
    pub failed: Vec<EvalId>,
    pub waiting: Vec<EvalId>,
}

/// Read the Run `id` of the state directory `state`, whichever surface started it (LIB-RUN-
/// REFERENCE). It reads a snapshot and changes nothing.
pub async fn reference(state: &Path, id: &RunId) -> Result<Reference, String> {
    let view = store::read_run_snapshot(state, id.as_str()).await?;
    let mut reference = Reference {
        run: view.run.id.clone(),
        state: super::observe::state(&view.run, &view.requests),
        failed: Vec::new(),
        waiting: Vec::new(),
    };
    for request in &view.requests {
        match request.status() {
            crate::types::RequestStatus::Red | crate::types::RequestStatus::Error => {
                reference.failed.push(request.eval_id.clone());
            }
            status if status.is_human_wait() => reference.waiting.push(request.eval_id.clone()),
            _ => {}
        }
    }
    Ok(reference)
}