From ce93cc08d5a2d43dcebf578da54cd3e20e42c661 Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar Date: Fri, 25 Sep 2026 11:31:54 +0000 Subject: [PATCH] test(nightly): the report shows each target's CVE matches (#377) (#396) --- compliance-agent/tests/nightly.rs | 43 +++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/compliance-agent/tests/nightly.rs b/compliance-agent/tests/nightly.rs index 6e49198..f1ed4b3 100644 --- a/compliance-agent/tests/nightly.rs +++ b/compliance-agent/tests/nightly.rs @@ -389,6 +389,20 @@ impl Snapshot { } } +/// A target's heading and one-line summary in the report: what it found, +/// including the CVEs it matched (NVD answers change daily, so the baseline +/// holds a lower bound; the count shows what a run actually saw). +fn summary(key: &str, pass: bool, got: &Collected) -> String { + format!( + "## {key} ({})\n\n{} findings, {} SBOM components, {} CVEs, scan {}\n\n", + if pass { "pass" } else { "FAIL" }, + got.observed.findings, + got.observed.sbom_components, + got.snapshot.cves.len(), + got.snapshot.scan_status, + ) +} + /// Everything one finished target produced. struct Collected { snapshot: Snapshot, @@ -674,14 +688,7 @@ async fn nightly_scan_regression() { )), } } - report.push_str(&format!( - "## {} ({})\n\n{} findings, {} SBOM components, scan {}\n\n", - t.key, - if problems.is_empty() { "pass" } else { "FAIL" }, - got.observed.findings, - got.observed.sbom_components, - got.snapshot.scan_status, - )); + report.push_str(&summary(&t.key, problems.is_empty(), &got)); for p in &problems { report.push_str(&format!("- {p}\n")); } @@ -749,6 +756,26 @@ mod unit { assert!(!diff.iter().any(|d| d.contains("CVE")), "{diff:?}"); } + #[test] + fn the_summary_shows_the_cves_a_run_matched() { + let got = Collected { + snapshot: Snapshot { + scan_status: "completed".into(), + cves: set(&["CVE-2020-22283", "CVE-2020-22284"]), + ..Default::default() + }, + observed: Observed { + findings: 3, + sbom_components: 5, + ..Default::default() + }, + }; + assert_eq!( + summary("fw-embedded-libs", true, &got), + "## fw-embedded-libs (pass)\n\n3 findings, 5 SBOM components, 2 CVEs, scan completed\n\n" + ); + } + #[test] fn our_semgrep_rules_are_recognised_behind_a_config_prefix() { assert_eq!(