Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/synapse/blob/main/crates/synapse-bench/src/bin/verify-qualification.rs # synapse A component of the AienOS ecosystem. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `synapse / crates / synapse-bench / src / bin / verify-qualification.rs` 125 lines ยท 4259 bytes Raw Blame History 1 use serde_json::Value; 2 3 fn validate(report: &Value) -> Result<(), &'static str> { 4 if report["qualified"].as_bool() != Some(true) { 5 return Err("qualification verdict must be true"); 6 } 7 for component in ["suite", "parity", "interop"] { 8 if report[component]["exit"].as_i64() != Some(0) { 9 return Err("every qualification component must exit successfully"); 10 } 11 } 12 let scenarios = report["scenarios"] 13 .as_array() 14 .ok_or("qualification scenarios must be an array")?; 15 if scenarios.len() != 12 { 16 return Err("qualification must contain exactly twelve scenarios"); 17 } 18 for i in 1..=12 { 19 let id = format!("S{i:02}"); 20 let mut matches = scenarios 21 .iter() 22 .filter(|scenario| scenario["id"].as_str() == Some(id.as_str())); 23 let scenario = matches.next().ok_or("missing required scenario")?; 24 if matches.next().is_some() { 25 return Err("duplicate qualification scenario"); 26 } 27 match scenario["status"].as_str() { 28 Some("PASS") => {} 29 Some("KNOWN-GAP") if i != 5 => {} 30 _ => return Err("scenario must pass or name an allowed gap; S05 must pass"), 31 } 32 } 33 Ok(()) 34 } 35 36 fn main() -> Result<(), Box> { 37 let mut args = std::env::args().skip(1); 38 let path = args 39 .next() 40 .ok_or("usage: verify-qualification results.json")?; 41 if args.next().is_some() { 42 return Err("usage: verify-qualification results.json".into()); 43 } 44 let report: Value = serde_json::from_slice(&std::fs::read(path)?)?; 45 validate(&report)?; 46 println!("SYNAPSE_QUALIFICATION_REPORT: PASS"); 47 Ok(()) 48 } 49 50 #[cfg(test)] 51 mod tests { 52 use super::*; 53 use serde_json::json; 54 55 fn passing() -> Value { 56 json!({ 57 "qualified": true, 58 "suite": {"exit": 0}, "parity": {"exit": 0}, "interop": {"exit": 0}, 59 "scenarios": (1..=12).map(|i| json!({"id": format!("S{i:02}"), "status": "PASS"})).collect::>() 60 }) 61 } 62 63 #[test] 64 fn accepts_pass_and_declared_gaps_outside_s05() { 65 let mut report = passing(); 66 assert!(validate(&report).is_ok()); 67 report["scenarios"][0]["status"] = json!("KNOWN-GAP"); 68 assert!(validate(&report).is_ok()); 69 } 70 71 #[test] 72 fn refuses_unqualified_or_missing_verdict() { 73 for verdict in [Value::Null, json!(false), json!("true")] { 74 let mut report = passing(); 75 report["qualified"] = verdict; 76 assert!(validate(&report).is_err()); 77 } 78 } 79 80 #[test] 81 fn refuses_failed_or_missing_component_results() { 82 for component in ["suite", "parity", "interop"] { 83 for exit in [Value::Null, json!(1), json!("0")] { 84 let mut report = passing(); 85 report[component]["exit"] = exit; 86 assert!(validate(&report).is_err()); 87 } 88 } 89 } 90 91 #[test] 92 fn refuses_missing_duplicate_or_unknown_scenarios() { 93 let mut report = passing(); 94 report["scenarios"].as_array_mut().unwrap().pop(); 95 assert!(validate(&report).is_err()); 96 let mut report = passing(); 97 report["scenarios"][11]["id"] = json!("S01"); 98 assert!(validate(&report).is_err()); 99 report["scenarios"][11]["id"] = json!("S13"); 100 assert!(validate(&report).is_err()); 101 let mut report = passing(); 102 let duplicate = report["scenarios"][0].clone(); 103 report["scenarios"].as_array_mut().unwrap().push(duplicate); 104 assert!(validate(&report).is_err()); 105 } 106 107 #[test] 108 fn refuses_bad_status_and_s05_gap() { 109 for status in [Value::Null, json!("FAIL"), json!("NOT_RUN")] { 110 let mut report = passing(); 111 report["scenarios"][0]["status"] = status; 112 assert!(validate(&report).is_err()); 113 } 114 let mut report = passing(); 115 report["scenarios"][4]["status"] = json!("KNOWN-GAP"); 116 assert!(validate(&report).is_err()); 117 } 118 119 #[test] 120 fn refuses_missing_scenario_array() { 121 let mut report = passing(); 122 report["scenarios"] = Value::Null; 123 assert!(validate(&report).is_err()); 124 } 125 }