use core::fmt::Write as _;
use super::{Outcome, Report};
impl Report {
#[must_use]
pub fn render_human(&self) -> String {
let mut out = String::new();
let _ = writeln!(out, "MCP trace validation — revision {}", self.revision);
self.write_revision_mismatch(&mut out);
for row in &self.requirements {
let marker = match row.outcome {
Outcome::Pass => "PASS",
Outcome::Fail => "FAIL",
Outcome::Warn => "WARN",
Outcome::Excluded => "EXCL",
Outcome::Unsupported => "UNSUP",
Outcome::NotApplicable => "N/A",
Outcome::NotObserved => "NOBS",
};
let _ = writeln!(out, " {marker:<5} {} ({})", row.id, row.level);
for finding in &row.findings {
match finding.seq {
Some(seq) => {
let _ = writeln!(out, " seq {seq}: {}", finding.detail);
}
None => {
let _ = writeln!(out, " {}", finding.detail);
}
}
}
if let Some(exclusion) = &row.exclusion {
let _ = writeln!(out, " excluded: {exclusion}");
}
for check in &row.missing_checks {
let _ = writeln!(out, " unsupported check: {check}");
}
if let Some(capability) = &row.capability {
let _ = writeln!(
out,
" not applicable: capability {capability} was not declared in this session"
);
}
if row.outcome == Outcome::NotObserved {
let _ = writeln!(
out,
" not observed: the session carried none of the traffic this clause binds to"
);
}
}
let _ = writeln!(out, "totals: {}", self.totals);
let _ = writeln!(out, "verdict: {}", self.verdict());
self.write_revision_mismatch(&mut out);
out
}
fn write_revision_mismatch(&self, out: &mut String) {
let Some(declared) = &self.revision_mismatch else {
return;
};
let subject = if declared.len() == 1 {
"revision"
} else {
"revisions"
};
let suggestion = declared.last().map_or("<revision>", String::as_str);
let _ = writeln!(
out,
" NOTE this session declares protocol {subject} {}, not {}.",
declared.join(", "),
self.revision
);
let _ = writeln!(
out,
" Every outcome here judges it against rules it was not playing by;"
);
let _ = writeln!(
out,
" re-run with `--revision {suggestion}` to judge it against its own."
);
}
}