Skip to main content

artifactize_core/runs/
reference.rs

1//! What a Run reference shows in another surface, read by the Run's ID alone.
2use super::State;
3use crate::{
4    store,
5    types::{EvalId, RunId},
6};
7use serde::Serialize;
8use std::path::Path;
9
10/// A Run as a reference to it shows it: its state, and the evals that failed or wait for a
11/// person, in the Run's order.
12#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
13pub struct Reference {
14    pub run: RunId,
15    pub state: State,
16    pub failed: Vec<EvalId>,
17    pub waiting: Vec<EvalId>,
18}
19
20/// Read the Run `id` of the state directory `state`, whichever surface started it (LIB-RUN-
21/// REFERENCE). It reads a snapshot and changes nothing.
22pub async fn reference(state: &Path, id: &RunId) -> Result<Reference, String> {
23    let view = store::read_run_snapshot(state, id.as_str()).await?;
24    let mut reference = Reference {
25        run: view.run.id.clone(),
26        state: super::observe::state(&view.run, &view.requests),
27        failed: Vec::new(),
28        waiting: Vec::new(),
29    };
30    for request in &view.requests {
31        match request.status() {
32            crate::types::RequestStatus::Red | crate::types::RequestStatus::Error => {
33                reference.failed.push(request.eval_id.clone());
34            }
35            status if status.is_human_wait() => reference.waiting.push(request.eval_id.clone()),
36            _ => {}
37        }
38    }
39    Ok(reference)
40}