use std::collections::HashMap;
use std::path::PathBuf;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct CommandSpec {
pub argv: Vec<String>,
#[serde(default)]
pub cwd: Option<String>,
#[serde(default)]
pub env: HashMap<String, String>,
#[serde(default = "default_true")]
pub pty: bool,
}
fn default_true() -> bool {
true
}
impl Default for CommandSpec {
fn default() -> Self {
Self {
argv: vec![],
cwd: None,
env: HashMap::new(),
pty: true,
}
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Recipe {
pub name: String,
pub command: CommandSpec,
#[serde(default = "default_version")]
pub recipe_version: u32,
#[serde(default)]
pub description: String,
#[serde(default)]
pub intent: String,
#[serde(default = "default_priority")]
pub priority: String,
#[serde(default = "default_execution")]
pub execution: String,
#[serde(default)]
pub checks: Vec<String>,
#[serde(default)]
pub operator: HashMap<String, serde_json::Value>,
#[serde(default)]
pub steps: Vec<serde_json::Value>,
#[serde(default)]
pub assertions: Vec<serde_json::Value>,
#[serde(default = "default_expect")]
pub expect_exit_code: Option<i32>,
#[serde(default = "default_timeout")]
pub timeout_seconds: f64,
#[serde(default = "default_cols")]
pub cols: u16,
#[serde(default = "default_rows")]
pub rows: u16,
#[serde(skip)]
pub source_path: Option<PathBuf>,
}
fn default_version() -> u32 {
1
}
fn default_priority() -> String {
"P2".to_string()
}
fn default_execution() -> String {
"scripted".to_string()
}
fn default_expect() -> Option<i32> {
Some(0)
}
fn default_timeout() -> f64 {
30.0
}
fn default_cols() -> u16 {
100
}
fn default_rows() -> u16 {
30
}
impl Default for Recipe {
fn default() -> Self {
Self {
name: String::new(),
command: CommandSpec::default(),
recipe_version: 1,
description: String::new(),
intent: String::new(),
priority: "P2".to_string(),
execution: "scripted".to_string(),
checks: vec![],
operator: HashMap::new(),
steps: vec![],
assertions: vec![],
expect_exit_code: Some(0),
timeout_seconds: 30.0,
cols: 100,
rows: 30,
source_path: None,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct StepResult {
pub name: String,
pub passed: bool,
pub detail: String,
pub screen: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct AssertionResult {
pub name: String,
pub passed: bool,
pub detail: String,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct RunResult {
pub recipe_name: String,
pub passed: bool,
pub exit_code: Option<i32>,
pub duration_seconds: f64,
pub priority: String,
pub execution: String,
pub renderer: String,
pub score: f64,
pub steps: Vec<StepResult>,
pub assertions: Vec<AssertionResult>,
pub artifacts: HashMap<String, String>,
}