kitchen_tools/tool/
report.rs1use std::path::PathBuf;
4
5use kitchen_contract::{Format, Type};
6use serde::{Deserialize, Serialize};
7
8use crate::tool::Operation;
9
10#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
12pub struct RunReport {
13 pub outputs: Vec<RunOutput>,
14 #[serde(default)]
18 pub review: Vec<ReviewFlag>,
19 #[serde(default)]
21 pub summary: serde_json::Value,
22}
23
24impl RunReport {
25 pub fn check(&self, operation: &Operation, output_dir: &std::path::Path) -> Result<(), String> {
28 for out in &self.outputs {
29 let Some(port) = operation.outputs.iter().find(|p| p.name == out.name) else {
30 return Err(format!("{}: no output port {}", operation.name, out.name));
31 };
32 if port.ty != out.ty || port.format != out.format {
33 return Err(format!(
34 "{}.{}: wrote {} in {}, declared {} in {}",
35 operation.name, out.name, out.ty, out.format, port.ty, port.format
36 ));
37 }
38 if !out.path.starts_with(output_dir) {
39 return Err(format!(
40 "{}.{}: {} is outside the run's folder",
41 operation.name,
42 out.name,
43 out.path.display()
44 ));
45 }
46 }
47 Ok(())
48 }
49}
50
51#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
53pub struct RunOutput {
54 pub name: String,
56 #[serde(rename = "type")]
57 pub ty: Type,
58 pub format: Format,
59 pub path: PathBuf,
60}
61
62#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
64pub struct ReviewFlag {
65 pub reason: String,
67 #[serde(default, skip_serializing_if = "Option::is_none")]
69 pub output: Option<String>,
70}