swarm_engine_eval/reporter/
mod.rs1pub mod json;
4
5pub use json::JsonReporter;
6
7use std::path::Path;
8
9use serde::{Deserialize, Serialize};
10
11use crate::aggregator::AggregatedResults;
12use crate::error::Result;
13use crate::run::EvalRun;
14
15pub trait Reporter {
17 fn generate(&self, report: &EvalReport) -> Result<String>;
19
20 fn write_to_file(&self, report: &EvalReport, path: impl AsRef<Path>) -> Result<()> {
22 let content = self.generate(report)?;
23 std::fs::write(path, content)?;
24 Ok(())
25 }
26}
27
28#[derive(Debug, Clone, Default, Serialize, Deserialize)]
30pub struct ConfigSummary {
31 pub scenario_name: String,
33 pub scenario_id: String,
35 pub worker_count: usize,
37 pub max_ticks: u64,
39 pub run_count: usize,
41}
42
43#[derive(Debug, Clone, Default)]
45pub struct SeedInfo {
46 pub base_seed: u64,
48 pub run_seeds: Vec<u64>,
50}
51
52#[derive(Debug, Clone, Serialize, Deserialize)]
54pub struct AssertionResult {
55 pub name: String,
57 pub passed: bool,
59 pub expected: String,
61 pub actual: String,
63 pub message: Option<String>,
65}
66
67#[derive(Debug, Clone, Serialize, Deserialize)]
69pub struct EvalReport {
70 pub config_summary: ConfigSummary,
72
73 #[serde(skip)]
75 pub seed_info: SeedInfo,
76
77 pub runs: Vec<EvalRun>,
79
80 pub aggregated: AggregatedResults,
82
83 pub assertion_results: Vec<AssertionResult>,
85}
86
87impl EvalReport {
88 pub fn all_assertions_passed(&self) -> bool {
90 self.assertion_results.iter().all(|r| r.passed)
91 }
92
93 pub fn to_json_file(&self, path: impl AsRef<Path>) -> Result<()> {
95 JsonReporter::new().write_to_file(self, path)
96 }
97}