Renders a self-contained, offline HTML report.
(run: &RunResult)
| 78 | impl Report { |
| 79 | /// Renders a self-contained, offline HTML report. |
| 80 | pub fn html(run: &RunResult) -> Result<String> { |
| 81 | Self::validate(run)?; |
| 82 | let counts = ReportCounts::from_run(run); |
| 83 | let mut scenarios: Vec<_> = run.scenarios.iter().collect(); |
| 84 | scenarios.sort_by_key(|scenario| (scenario.outcome() == Status::Passed, &scenario.id)); |
| 85 | let verdict = ReportCounts::verdict(run); |
| 86 | let mut out = String::with_capacity(32_000); |
| 87 | write!( |
| 88 | out, |
| 89 | "<!doctype html><html lang=\"en\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width,initial-scale=1\"><meta http-equiv=\"Content-Security-Policy\" content=\"default-src 'none'; style-src 'unsafe-inline'; img-src data:; base-uri 'none'; form-action 'none'; frame-ancestors 'none'\"><title>Acceptance report — {}</title><style>{}</style></head><body><main>", |
| 90 | Self::escape_html(&run.run_id), |
| 91 | include_str!("../report/style.css") |
| 92 | )?; |
| 93 | write!( |
| 94 | out, |
| 95 | "<header class=\"hero\"><div class=\"eyebrow\">BASE ACCEPTANCE · schema {}</div><h1>Acceptance report</h1><div class=\"verdict {}\">{}</div><p>Run <strong>{}</strong> · revision <code>{}</code> · started {} ms Unix</p><div class=\"counters\">", |
| 96 | run.schema_version, |
| 97 | verdict.label(), |
| 98 | ReportCounts::status_phrase(run), |
| 99 | Self::escape_html(&run.run_id), |
| 100 | Self::escape_html(&run.tested_sha), |
| 101 | run.started_at_unix_ms |
| 102 | )?; |
| 103 | for (label, value, class) in [ |
| 104 | ("Passed", counts.passed, "passed"), |
| 105 | ("Failed", counts.failed, "failed"), |
| 106 | ("Error", counts.error, "error"), |
| 107 | ("Blocked", counts.blocked, "blocked"), |
| 108 | ("Cancelled", counts.cancelled, "cancelled"), |
| 109 | ] { |
| 110 | write!( |
| 111 | out, |
| 112 | "<div class=\"counter\"><span>{label}</span><strong class=\"{class}\">{value}</strong></div>" |
| 113 | )?; |
| 114 | } |
| 115 | out.push_str("</div></header><section class=\"card\"><h2>Scenario lifecycle</h2><div class=\"scroll\"><table><thead><tr><th>Scenario</th><th>Setup</th><th>Readiness</th><th>Checks</th><th>Cleanup</th><th>Result</th></tr></thead><tbody>"); |
| 116 | for scenario in &scenarios { |
| 117 | write!( |
| 118 | out, |
| 119 | "<tr><th><a href=\"#scenario-{}\">{}</a></th>", |
| 120 | Self::anchor(&scenario.id), |
| 121 | Self::escape_html(&scenario.id) |
| 122 | )?; |
| 123 | for stage in ["setup", "readiness", "checks", "cleanup"] { |
| 124 | out.push_str(&Self::stage_cell(scenario, stage)); |
| 125 | } |
| 126 | out.push_str(&Self::status_html(scenario.outcome())); |
| 127 | out.push_str("</tr>"); |
| 128 | } |
| 129 | out.push_str("</tbody></table></div></section>"); |
| 130 | for scenario in scenarios { |
| 131 | Self::render_scenario(&mut out, scenario)?; |
| 132 | } |
| 133 | out.push_str("</main></body></html>"); |
| 134 | Ok(out) |
| 135 | } |
| 136 | |
| 137 | /// Renders the bounded marker-owned Markdown summary used for PR comments. |