Aggregates result bundles and writes result.json, report.html, summary.md and evidence directly. Invalid or missing manifests still produce an aggregate-error report.
(expected_path: &Path, results: &Path, output: &Path)
| 92 | /// Aggregates result bundles and writes result.json, report.html, summary.md and evidence directly. |
| 93 | /// Invalid or missing manifests still produce an aggregate-error report. |
| 94 | pub fn write(expected_path: &Path, results: &Path, output: &Path) -> Result<RunResult> { |
| 95 | fs::create_dir_all(output).wrap_err("create aggregate output")?; |
| 96 | let expected = match Self::load_expected(expected_path) { |
| 97 | Ok(expected) => expected, |
| 98 | Err(error) => { |
| 99 | let run = Self::fallback(format!("invalid or missing expected manifest: {error}")); |
| 100 | Report::write(&run, output)?; |
| 101 | return Ok(run); |
| 102 | } |
| 103 | }; |
| 104 | |
| 105 | let results_root = match results.canonicalize().wrap_err("resolve results directory") { |
| 106 | Ok(path) => path, |
| 107 | Err(error) => { |
| 108 | let run = Self::run_error(&expected, error.to_string()); |
| 109 | Report::write(&run, output)?; |
| 110 | return Ok(run); |
| 111 | } |
| 112 | }; |
| 113 | let output_absolute = if output.exists() { |
| 114 | output.canonicalize()? |
| 115 | } else { |
| 116 | std::env::current_dir()?.join(output) |
| 117 | }; |
| 118 | if output_absolute.starts_with(&results_root) { |
| 119 | let run = Self::run_error(&expected, "aggregate output is inside results input".into()); |
| 120 | Report::write(&run, output)?; |
| 121 | return Ok(run); |
| 122 | } |
| 123 | |
| 124 | let mut paths = Vec::new(); |
| 125 | let mut discovery_errors = Vec::new(); |
| 126 | if let Err(error) = Self::discover(&results_root, 0, &mut paths, &mut discovery_errors) { |
| 127 | let run = Self::run_error(&expected, format!("discover result artifacts: {error}")); |
| 128 | Report::write(&run, output)?; |
| 129 | return Ok(run); |
| 130 | } |
| 131 | let mut found: BTreeMap<String, Vec<(PathBuf, ScenarioResult)>> = BTreeMap::new(); |
| 132 | let mut errors = discovery_errors; |
| 133 | for path in paths { |
| 134 | match Self::bounded_read(&path).and_then(|bytes| { |
| 135 | let run: RunResult = serde_json::from_slice(&bytes)?; |
| 136 | Report::validate(&run)?; |
| 137 | Ok(run) |
| 138 | }) { |
| 139 | Ok(run) |
| 140 | if run.run_id == expected.run_id && run.tested_sha == expected.tested_sha => |
| 141 | { |
| 142 | for scenario in run.scenarios { |
| 143 | found |
| 144 | .entry(scenario.id.clone()) |
| 145 | .or_default() |
| 146 | .push((path.clone(), scenario)); |
| 147 | } |
| 148 | } |
| 149 | Ok(_) => errors.push(format!("stale result identity: {}", path.display())), |
| 150 | Err(error) => errors.push(format!("invalid result {}: {error}", path.display())), |
| 151 | } |
nothing calls this directly
no test coverage detected