Skip to main content

dsfb_densor_runtime/
index.rs

1//! A small inventory view over a sealed run — "what ran, against what, sealing to what".
2//!
3//! `RuntimeIndex` is the navigable summary of a [`RuntimeReceiptV1`]: the pipeline id, the ordered stage ids, the
4//! distinct authorities cited, and the sealed receipt hash. It is the runtime's analogue of the artifact index —
5//! a read-only re-presentation of already-sealed evidence, useful for logs and dashboards.
6
7use crate::receipt::RuntimeReceiptV1;
8use std::collections::BTreeSet;
9
10/// A read-only summary of one sealed run.
11#[derive(Debug, Clone, PartialEq, Eq)]
12pub struct RuntimeIndex {
13    pub pipeline_id: String,
14    pub stage_ids: Vec<String>,
15    pub authorities: Vec<String>,
16    pub receipt_hash: String,
17}
18
19impl RuntimeIndex {
20    /// Summarise a sealed receipt. Authorities are de-duplicated and sorted (deterministic).
21    pub fn of(receipt: &RuntimeReceiptV1) -> Self {
22        let stage_ids = receipt.stages.iter().map(|s| s.stage_id.clone()).collect();
23        let mut auth: BTreeSet<String> = BTreeSet::new();
24        for s in &receipt.stages {
25            for a in &s.authority_hashes {
26                auth.insert(a.name.clone());
27            }
28        }
29        RuntimeIndex {
30            pipeline_id: receipt.pipeline_id.clone(),
31            stage_ids,
32            authorities: auth.into_iter().collect(),
33            receipt_hash: receipt.receipt_hash.clone(),
34        }
35    }
36
37    /// A one-line human summary.
38    pub fn summary_line(&self) -> String {
39        format!(
40            "{}: {} stage(s) [{}] over authorities [{}] -> {}",
41            self.pipeline_id,
42            self.stage_ids.len(),
43            self.stage_ids.join(", "),
44            self.authorities.join(", "),
45            &self.receipt_hash[..self.receipt_hash.len().min(12)],
46        )
47    }
48}