Skip to content

Commit a078f49

Browse files
committed
test(panicbot): fold the severity e2e test into the envelope tests
The grid severity e2e test copied the stub and scan helpers from envelope_parity_test.rs, which SonarCloud counted as duplicated new code. It now lives in envelope_parity_test.rs and reuses those helpers, with a stub_body_with_report helper behind full_stub_body.
1 parent dc90d2d commit a078f49

2 files changed

Lines changed: 58 additions & 103 deletions

File tree

‎bots/panicbot/tests/envelope_parity_test.rs‎

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ fn exit_0_without_a_valid_report_is_not_a_run() {
131131
/// `assail` prints REAL, `assay` writes `ASSAY_JSON` to its `-o` path,
132132
/// `--version` and `diagnostics` answer.
133133
fn full_stub_body(assay_json: &str) -> String {
134+
stub_body_with_report(assay_json, REAL)
135+
}
136+
137+
/// As `full_stub_body`, but `assail` prints `report` instead of REAL.
138+
fn stub_body_with_report(assay_json: &str, report: &str) -> String {
134139
format!(
135140
r#"case "$1" in
136141
--version) echo "panic-attack 2.5.5" ;;
@@ -143,7 +148,7 @@ fn full_stub_body(assay_json: &str) -> String {
143148
J
144149
;;
145150
*) cat <<'J'
146-
{REAL}
151+
{report}
147152
J
148153
;;
149154
esac
@@ -750,3 +755,55 @@ fn staggered_pipe_holders_share_one_deadline() {
750755
);
751756
assert!(!o.status.success());
752757
}
758+
759+
/// One weak point at each panic-attack severity level.
760+
const ALL_LEVELS: &str = r#"Running assail analysis on: .
761+
{"program_path":"/t","language":"rust","statistics":{"total_lines":40},"weak_points":[
762+
{"category":"UnsafeCode","location":"a.rs:1","severity":"Critical","description":"c"},
763+
{"category":"UnsafeCode","location":"a.rs:2","severity":"High","description":"h"},
764+
{"category":"UnsafeCode","location":"a.rs:3","severity":"Medium","description":"m"},
765+
{"category":"UnsafeCode","location":"a.rs:4","severity":"Low","description":"l"}]}"#;
766+
767+
/// `panicbot --format json scan` reports panic-attack's own severity word, so
768+
/// the verdict grid grades panicbot's row exactly as it grades the direct
769+
/// panic-attack row. Before this, panicbot printed the fleet word (`error` for
770+
/// a Critical), which the grid reads as `high`: every finding read one level
771+
/// milder, though both rows ran the same panic-attack revision.
772+
#[test]
773+
fn json_scan_reports_panic_attack_severity_at_every_level() {
774+
let bin = TempDir::new().unwrap();
775+
stub(bin.path(), &stub_body_with_report(ASSAY_NONE, ALL_LEVELS));
776+
let tree = TempDir::new().unwrap();
777+
fs::write(tree.path().join("a.rs"), "fn main() {}\n").unwrap();
778+
779+
let o = scan(bin.path(), tree.path());
780+
// A Critical blocks release (fleet `error`), so exit 1 with a findings array.
781+
assert_eq!(
782+
o.status.code(),
783+
Some(1),
784+
"stderr: {}",
785+
String::from_utf8_lossy(&o.stderr)
786+
);
787+
let v: serde_json::Value = serde_json::from_slice(&o.stdout).expect("a findings array");
788+
let mut got: Vec<(u64, &str, &str)> = v
789+
.as_array()
790+
.unwrap()
791+
.iter()
792+
.filter(|f| f["rule_id"].as_str().unwrap().starts_with("PA"))
793+
.map(|f| {
794+
(
795+
f["line"].as_u64().unwrap(),
796+
f["severity"].as_str().unwrap(),
797+
f["fleet_severity"].as_str().unwrap(),
798+
)
799+
})
800+
.collect();
801+
got.sort();
802+
let want = vec![
803+
(1, "critical", "error"),
804+
(2, "high", "warning"),
805+
(3, "medium", "info"),
806+
(4, "low", "suggestion"),
807+
];
808+
assert_eq!(got, want, "{v}");
809+
}

‎bots/panicbot/tests/grid_severity_parity_test.rs‎

Lines changed: 0 additions & 102 deletions
This file was deleted.

0 commit comments

Comments
 (0)