use std::path::PathBuf;
use kitchen_contract::{Format, Type};
use serde::{Deserialize, Serialize};
use crate::tool::Operation;
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct RunReport {
pub outputs: Vec<RunOutput>,
#[serde(default)]
pub review: Vec<ReviewFlag>,
#[serde(default)]
pub summary: serde_json::Value,
}
impl RunReport {
pub fn check(&self, operation: &Operation, output_dir: &std::path::Path) -> Result<(), String> {
for out in &self.outputs {
let Some(port) = operation.outputs.iter().find(|p| p.name == out.name) else {
return Err(format!("{}: no output port {}", operation.name, out.name));
};
if port.ty != out.ty || port.format != out.format {
return Err(format!(
"{}.{}: wrote {} in {}, declared {} in {}",
operation.name, out.name, out.ty, out.format, port.ty, port.format
));
}
if !out.path.starts_with(output_dir) {
return Err(format!(
"{}.{}: {} is outside the run's folder",
operation.name,
out.name,
out.path.display()
));
}
}
Ok(())
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct RunOutput {
pub name: String,
#[serde(rename = "type")]
pub ty: Type,
pub format: Format,
pub path: PathBuf,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ReviewFlag {
pub reason: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub output: Option<String>,
}