1use serde::{Deserialize, Serialize};
15
16use sail_ledger::{
17 CheckRecord, Establishment, FunctionRecord, ObligationRecord, Outcome, Source, SourceSummary,
18 Verdict,
19};
20
21pub const SCHEMA_VERSION: u32 = 2;
23
24pub const JSON_SCHEMA: &str = include_str!("../schema/verify-output-v2.json");
26
27#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
29pub struct Report {
30 #[serde(default, skip_serializing_if = "Option::is_none")]
32 pub portfolio: Option<PortfolioReport>,
33 pub schema_version: u32,
35 pub sail_version: String,
37 pub mode: String,
39 pub command: Vec<String>,
41 pub exit_code: Option<i32>,
44 pub solver: Option<SolverInfo>,
46 pub cache: CacheInfo,
48 pub attribution: AttributionInfo,
50 pub crates: Vec<CrateReport>,
52 pub diagnostics: Vec<Diagnostic>,
54 pub summary: Summary,
56 pub error: Option<ErrorInfo>,
58 #[serde(default, skip_serializing_if = "Option::is_none")]
61 pub engine: Option<EngineProvenance>,
62}
63
64#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
67pub struct EngineProvenance {
68 pub name: String,
70 pub manifest_sha256: String,
72 pub established_by: EngineEstablishment,
74}
75
76#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
78#[serde(rename_all = "kebab-case")]
79pub enum EngineEstablishment {
80 Engine,
82 StockFallback,
85}
86
87#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
89pub struct SolverConfiguration {
90 pub seed: u32,
92}
93
94#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
96pub struct PortfolioAttempt {
97 pub configuration: SolverConfiguration,
99 pub verified: bool,
101 pub exit_code: Option<i32>,
103 pub wall_ms: f64,
105 pub error: Option<String>,
107 pub report: Option<Box<Report>>,
109 pub stderr: String,
111}
112
113#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
115pub struct PortfolioReport {
116 pub seeds: Vec<u32>,
118 pub winner_seed: Option<u32>,
120 pub attempts: Vec<PortfolioAttempt>,
122}
123
124#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
126pub struct SolverInfo {
127 pub name: String,
129 pub version: Option<String>,
131 pub path: Option<String>,
133 pub sha256: Option<String>,
135}
136
137#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
139pub struct CacheInfo {
140 pub daemon: bool,
142}
143
144#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
146#[serde(rename_all = "kebab-case")]
147pub enum AttributionStatus {
148 Complete,
150 Partial,
152 Unavailable,
154}
155
156#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
158pub struct AttributionInfo {
159 pub status: AttributionStatus,
161 pub notes: Vec<String>,
163 pub unmatched_sessions: u64,
165}
166
167#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
169pub struct CrateReport {
170 pub name: Option<String>,
172 pub verus: VerusResults,
174 pub functions: Vec<FunctionReport>,
176}
177
178#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
180pub struct VerusResults {
181 pub verified: Option<u64>,
183 pub errors: Option<u64>,
185 pub success: Option<bool>,
187 pub encountered_vir_error: Option<bool>,
189}
190
191#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
193#[serde(rename_all = "kebab-case")]
194pub enum VerdictName {
195 Verified,
197 Failed,
199 Unknown,
201 Provisional,
203}
204
205impl From<Verdict> for VerdictName {
206 fn from(v: Verdict) -> Self {
207 match v {
208 Verdict::Verified => Self::Verified,
209 Verdict::Failed => Self::Failed,
210 Verdict::Unknown => Self::Unknown,
211 Verdict::Provisional => Self::Provisional,
212 }
213 }
214}
215
216#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
218#[serde(rename_all = "snake_case")]
219pub enum EstablishmentName {
220 Provisional,
222 Confirmed,
224}
225
226impl From<Establishment> for EstablishmentName {
227 fn from(t: Establishment) -> Self {
228 match t {
229 Establishment::Provisional => Self::Provisional,
230 Establishment::Confirmed => Self::Confirmed,
231 }
232 }
233}
234
235#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
243#[serde(rename_all = "snake_case")]
244pub enum EvidenceTierName {
245 Sampled,
247 Bounded,
249 SmtVerified,
251 CertificateChecked,
253 KernelChecked,
255}
256
257impl EvidenceTierName {
258 #[must_use]
263 pub fn for_smt(verdict: VerdictName, establishment: EstablishmentName) -> Option<Self> {
264 match (verdict, establishment) {
265 (VerdictName::Verified | VerdictName::Failed, EstablishmentName::Confirmed) => {
266 Some(Self::SmtVerified)
267 }
268 _ => None,
269 }
270 }
271}
272
273#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
275pub struct FunctionReport {
276 pub function: String,
278 pub module: String,
280 pub fn_mode: Option<String>,
282 pub verdict: VerdictName,
284 pub establishment: EstablishmentName,
286 pub evidence_tier: Option<EvidenceTierName>,
289 pub unstable: bool,
292 pub verus_success: Option<bool>,
294 pub provenance: ProvenanceReport,
296 pub timing: Timing,
298 pub fragility: Option<Fragility>,
300 pub obligations: Option<Vec<ObligationReport>>,
302}
303
304#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
306#[serde(rename_all = "kebab-case")]
307pub enum SourceSummaryName {
308 Fresh,
310 Cache,
312 Mixed,
314 Unrecorded,
316}
317
318impl From<SourceSummary> for SourceSummaryName {
319 fn from(s: SourceSummary) -> Self {
320 match s {
321 SourceSummary::Fresh => Self::Fresh,
322 SourceSummary::Cache => Self::Cache,
323 SourceSummary::Mixed => Self::Mixed,
324 SourceSummary::Unrecorded => Self::Unrecorded,
325 }
326 }
327}
328
329#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
331pub struct ProvenanceReport {
332 #[serde(default, skip_serializing_if = "Option::is_none")]
334 pub configuration: Option<SolverConfiguration>,
335 pub mode: String,
337 pub source: SourceSummaryName,
339 pub checks_solved: u64,
341 pub checks_served: u64,
343 pub checks_unrecorded: u64,
345 #[serde(default, skip_serializing_if = "Option::is_none")]
347 pub engine: Option<EngineProvenance>,
348}
349
350#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
352pub struct Timing {
353 pub smt_micros: Option<u64>,
355 pub rlimit: Option<u64>,
357}
358
359#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
361pub struct Fragility {
362 pub score: f64,
364 pub runs: u32,
366 pub proved: u32,
368}
369
370#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
372#[serde(rename_all = "kebab-case")]
373pub enum OutcomeName {
374 Proved,
376 Failed,
378 Unknown,
380}
381
382impl From<Outcome> for OutcomeName {
383 fn from(o: Outcome) -> Self {
384 match o {
385 Outcome::Proved => Self::Proved,
386 Outcome::Failed => Self::Failed,
387 Outcome::Unknown => Self::Unknown,
388 }
389 }
390}
391
392#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
394pub struct ObligationReport {
395 pub id: String,
398 pub kind: String,
400 pub ordinal: u32,
403 pub spinoff: Option<SpinoffInfo>,
405 pub advisory: bool,
408 pub span: Option<SourceSpan>,
410 pub outcome: OutcomeName,
412 pub unstable: bool,
414 pub checks: Vec<CheckReport>,
416 pub counterexample: Option<Counterexample>,
418}
419
420#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
422pub struct SpinoffInfo {
423 pub index: u32,
425 pub reason: Option<String>,
427}
428
429#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
431pub struct SourceSpan {
432 pub text: String,
434 pub file: Option<String>,
436 pub line: Option<u64>,
438 pub column: Option<u64>,
440 pub end_line: Option<u64>,
442 pub end_column: Option<u64>,
444}
445
446impl SourceSpan {
447 #[must_use]
449 pub fn parse(text: &str) -> Self {
450 let mut span = Self {
451 text: text.to_owned(),
452 file: None,
453 line: None,
454 column: None,
455 end_line: None,
456 end_column: None,
457 };
458 let body = text.rsplit_once(" (#").map_or(text, |(b, _)| b);
459 let Some((start, end)) = body.rsplit_once(": ") else {
460 return span;
461 };
462 let mut s = start.rsplitn(3, ':');
463 let (Some(col), Some(line), Some(file)) = (s.next(), s.next(), s.next()) else {
464 return span;
465 };
466 let mut e = end.splitn(2, ':');
467 span.file = Some(file.to_owned());
468 span.line = line.parse().ok();
469 span.column = col.parse().ok();
470 span.end_line = e.next().and_then(|v| v.parse().ok());
471 span.end_column = e.next().and_then(|v| v.parse().ok());
472 span
473 }
474}
475
476#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
478#[serde(rename_all = "kebab-case")]
479pub enum AnswerName {
480 Sat,
482 Unsat,
484 Unknown,
486}
487
488impl From<sail_ledger::Answer> for AnswerName {
489 fn from(a: sail_ledger::Answer) -> Self {
490 match a {
491 sail_ledger::Answer::Sat => Self::Sat,
492 sail_ledger::Answer::Unsat => Self::Unsat,
493 sail_ledger::Answer::Unknown => Self::Unknown,
494 }
495 }
496}
497
498#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
500#[serde(rename_all = "kebab-case")]
501pub enum SourceName {
502 Solved,
504 Cache,
506}
507
508impl From<Source> for SourceName {
509 fn from(s: Source) -> Self {
510 match s {
511 Source::Solved => Self::Solved,
512 Source::Cache => Self::Cache,
513 }
514 }
515}
516
517#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
519pub struct CheckReport {
520 pub answer: Option<AnswerName>,
522 pub rlimit_limit: Option<u64>,
524 pub rlimit_used: Option<u64>,
526 pub reason_unknown: Option<String>,
528 pub source: Option<SourceName>,
530}
531
532#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
534pub struct Counterexample {
535 pub check: u32,
537 pub model: String,
539 pub assignments: Vec<Assignment>,
541}
542
543#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
545pub struct Assignment {
546 pub name: String,
549 pub sort: String,
551 pub value: String,
553 pub itf: ItfValue,
556}
557
558#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
567#[serde(untagged)]
568pub enum ItfValue {
569 Bool(bool),
571 BigInt {
573 #[serde(rename = "#bigint")]
575 bigint: String,
576 },
577 Unserializable {
579 #[serde(rename = "#unserializable")]
581 unserializable: String,
582 },
583}
584
585impl ItfValue {
586 #[must_use]
590 pub fn render(sort: &str, value: &str) -> Self {
591 let v = value.trim();
592 let sort = sort.trim();
593 let read = match sort {
594 "Bool" => match v {
595 "true" => Some(Self::Bool(true)),
596 "false" => Some(Self::Bool(false)),
597 _ => None,
598 },
599 "Int" => smt_int(v).map(|bigint| Self::BigInt { bigint }),
600 _ if sort.starts_with("(_ BitVec ") => smt_bit_vector(v).map(|n| Self::BigInt {
601 bigint: n.to_string(),
602 }),
603 _ => None,
604 };
605 read.unwrap_or_else(|| Self::Unserializable {
606 unserializable: value.to_owned(),
607 })
608 }
609}
610
611fn smt_int(v: &str) -> Option<String> {
613 let numeral = |s: &str| !s.is_empty() && s.bytes().all(|b| b.is_ascii_digit());
614 if numeral(v) {
615 return Some(v.to_owned());
616 }
617 let inner = v.strip_prefix('(')?.strip_suffix(')')?.trim();
618 let digits = inner.strip_prefix('-')?.trim();
619 if !numeral(digits) {
620 return None;
621 }
622 Some(if digits.bytes().all(|b| b == b'0') {
623 "0".to_owned()
624 } else {
625 format!("-{digits}")
626 })
627}
628
629fn smt_bit_vector(v: &str) -> Option<u128> {
632 let (digits, radix) = if let Some(d) = v.strip_prefix("#x") {
633 (d, 16)
634 } else {
635 (v.strip_prefix("#b")?, 2)
636 };
637 if digits.is_empty() || !digits.bytes().all(|b| b.is_ascii_hexdigit()) {
638 return None;
639 }
640 u128::from_str_radix(digits, radix).ok()
641}
642
643#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
645pub struct DiagnosticSpan {
646 pub file: String,
648 pub line: u64,
650 pub column: u64,
652 pub primary: bool,
654}
655
656#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
658pub struct Diagnostic {
659 pub level: String,
661 pub code: Option<String>,
663 pub message: String,
665 pub spans: Vec<DiagnosticSpan>,
667 pub rendered: String,
669}
670
671#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
673pub struct Summary {
674 pub functions: u64,
676 pub verified: u64,
678 pub failed: u64,
680 pub unknown: u64,
682 pub provisional: u64,
684 pub unstable: u64,
686}
687
688#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
690pub struct ErrorInfo {
691 pub code: String,
693 pub message: String,
695}
696
697fn check_report(c: &CheckRecord) -> CheckReport {
698 CheckReport {
699 answer: c.answer.map(AnswerName::from),
700 rlimit_limit: c.effort.limit,
701 rlimit_used: c.effort.used,
702 reason_unknown: c.effort.reason.clone(),
703 source: c.source.map(SourceName::from),
704 }
705}
706
707impl From<&ObligationRecord> for ObligationReport {
708 fn from(o: &ObligationRecord) -> Self {
709 let counterexample = o.checks.iter().enumerate().find_map(|(i, c)| {
710 let model = c.model.as_ref()?;
711 Some(Counterexample {
712 check: u32::try_from(i).unwrap_or(u32::MAX),
713 model: model.text.clone(),
714 assignments: model
715 .assignments
716 .iter()
717 .map(|a| Assignment {
718 name: a.name.clone(),
719 sort: a.sort.clone(),
720 value: a.value.clone(),
721 itf: ItfValue::render(&a.sort, &a.value),
722 })
723 .collect(),
724 })
725 });
726 Self {
727 id: o.id.to_string(),
728 kind: o.id.kind.0.clone(),
729 ordinal: o.id.ordinal,
730 spinoff: o.id.spinoff.map(|index| SpinoffInfo {
731 index,
732 reason: o.spinoff_reason.clone(),
733 }),
734 advisory: !o.id.kind.verdict_bearing(),
735 span: o.span.as_deref().map(SourceSpan::parse),
736 outcome: o.outcome().into(),
737 unstable: o.unstable(),
738 checks: o.checks.iter().map(check_report).collect(),
739 counterexample,
740 }
741 }
742}
743
744impl From<&FunctionRecord> for FunctionReport {
745 fn from(f: &FunctionRecord) -> Self {
746 let sources = f.sources();
747 let verdict = VerdictName::from(f.verdict());
748 let establishment = EstablishmentName::from(f.establishment);
749 Self {
750 function: f.function.clone(),
751 module: f.module.clone(),
752 fn_mode: f.fn_mode.clone(),
753 verdict,
754 establishment,
755 evidence_tier: EvidenceTierName::for_smt(verdict, establishment),
756 unstable: f.unstable(),
757 verus_success: f.verus_success,
758 provenance: ProvenanceReport {
759 configuration: None,
760 mode: f.mode.name().to_owned(),
761 source: sources.summary().into(),
762 checks_solved: sources.solved,
763 checks_served: sources.served,
764 checks_unrecorded: sources.unrecorded,
765 engine: None,
766 },
767 timing: Timing {
768 smt_micros: f.smt_micros,
769 rlimit: f.rlimit,
770 },
771 fragility: None,
772 obligations: f
773 .obligations
774 .as_ref()
775 .map(|os| os.iter().map(ObligationReport::from).collect()),
776 }
777 }
778}
779
780impl Summary {
781 #[must_use]
783 pub fn of(crates: &[CrateReport]) -> Self {
784 let mut s = Self::default();
785 for f in crates.iter().flat_map(|c| &c.functions) {
786 s.functions += 1;
787 match f.verdict {
788 VerdictName::Verified => s.verified += 1,
789 VerdictName::Failed => s.failed += 1,
790 VerdictName::Unknown => s.unknown += 1,
791 VerdictName::Provisional => s.provisional += 1,
792 }
793 s.unstable += u64::from(f.unstable);
794 }
795 s
796 }
797}
798
799impl CrateReport {
800 #[must_use]
812 pub fn unknown_passed_by_verus_totals(&self) -> u64 {
813 if self.verus_totals_clear_unknown() {
814 self.count(VerdictName::Unknown)
815 } else {
816 0
817 }
818 }
819
820 #[must_use]
824 pub fn verus_totals_clear_unknown(&self) -> bool {
825 let failed = self.count(VerdictName::Failed);
826 failed > 0
827 && self.verus.errors == Some(failed)
828 && self.verus.verified.is_some()
829 && self.verus.encountered_vir_error != Some(true)
830 }
831
832 fn count(&self, verdict: VerdictName) -> u64 {
833 let n = self
834 .functions
835 .iter()
836 .filter(|f| f.verdict == verdict)
837 .count();
838 u64::try_from(n).unwrap_or(u64::MAX)
839 }
840}
841
842impl Report {
843 #[must_use]
845 pub fn invariant_violations(&self) -> Vec<String> {
846 let mut out = Vec::new();
847 if self.schema_version != SCHEMA_VERSION {
848 out.push(format!("schema_version is {}", self.schema_version));
849 }
850 let mut ids = std::collections::BTreeSet::new();
851 for f in self.crates.iter().flat_map(|c| &c.functions) {
852 if f.verdict == VerdictName::Verified && f.establishment != EstablishmentName::Confirmed
853 {
854 out.push(format!("{}: verified but not confirmed", f.function));
855 }
856 if (f.establishment == EstablishmentName::Provisional)
857 != (f.verdict == VerdictName::Provisional)
858 {
859 out.push(format!(
860 "{}: establishment and verdict disagree",
861 f.function
862 ));
863 }
864 let settled = matches!(f.verdict, VerdictName::Verified | VerdictName::Failed);
865 if settled != f.evidence_tier.is_some() {
866 out.push(format!(
867 "{}: evidence tier and verdict disagree",
868 f.function
869 ));
870 }
871 let p = &f.provenance;
872 let counted = (p.checks_solved, p.checks_served, p.checks_unrecorded);
873 let expected = match p.source {
874 SourceSummaryName::Fresh => counted.0 > 0 && counted.1 == 0 && counted.2 == 0,
875 SourceSummaryName::Cache => counted.0 == 0 && counted.1 > 0 && counted.2 == 0,
876 SourceSummaryName::Mixed => counted.0 > 0 && counted.1 > 0 && counted.2 == 0,
877 SourceSummaryName::Unrecorded => counted.2 > 0 || counted == (0, 0, 0),
878 };
879 if !expected {
880 out.push(format!(
881 "{}: provenance counts disagree with source",
882 f.function
883 ));
884 }
885 for o in f.obligations.iter().flatten() {
886 if !ids.insert(o.id.clone()) {
887 out.push(format!("duplicate obligation id {}", o.id));
888 }
889 if !o.id.starts_with(&format!("{}#", f.function)) {
890 out.push(format!("obligation {} is not {}'s", o.id, f.function));
891 }
892 }
893 }
894 if self.summary != Summary::of(&self.crates) {
895 out.push("summary does not match the functions".to_owned());
896 }
897 out
898 }
899}
900
901#[cfg(test)]
902mod tests {
903 use super::*;
904
905 #[test]
906 fn spans_parse() {
907 let s = SourceSpan::parse("src/lib.rs:46:1: 46:26 (#0)");
908 assert_eq!(s.file.as_deref(), Some("src/lib.rs"));
909 assert_eq!(
910 (s.line, s.column, s.end_line, s.end_column),
911 (Some(46), Some(1), Some(46), Some(26))
912 );
913 let s = SourceSpan::parse("garbage");
914 assert_eq!((s.file, s.line), (None, None));
915 assert_eq!(s.text, "garbage");
916 }
917 #[test]
918 fn the_example_document_is_valid_v2_with_rendered_itf_values() {
919 let text =
920 include_str!("../resources/crates/sail-cli/tests/fixtures/attr/report.golden.json");
921 let golden: Report =
922 serde_json::from_str(text).unwrap_or_else(|e| unreachable!("fixture: {e}"));
923 let schema: serde_json::Value = serde_json::from_str(JSON_SCHEMA).unwrap_or_default();
924 let value: serde_json::Value = serde_json::from_str(text).unwrap_or_default();
925 assert_eq!(
926 crate::schema::validate(&schema, &value),
927 Vec::<String>::new()
928 );
929 assert_eq!(golden.invariant_violations(), Vec::<String>::new());
930 let mut rendered = 0;
931 for o in golden
932 .crates
933 .iter()
934 .flat_map(|c| &c.functions)
935 .flat_map(|f| f.obligations.iter().flatten())
936 {
937 for a in o.counterexample.iter().flat_map(|c| &c.assignments) {
938 assert_eq!(a.itf, ItfValue::render(&a.sort, &a.value), "{}", a.name);
939 assert!(
941 o.counterexample
942 .as_ref()
943 .is_some_and(|c| c.model.contains(&a.value)),
944 "{}",
945 a.name
946 );
947 rendered += usize::from(!matches!(a.itf, ItfValue::Unserializable { .. }));
948 }
949 }
950 assert!(rendered > 0);
951 }
952 #[test]
953 fn engine_provenance_is_additive_and_matches_the_schemas() {
954 let stock: Report = serde_json::from_str(include_str!(
955 "../resources/crates/sail-cli/tests/fixtures/attr/report.golden.json"
956 ))
957 .unwrap_or_else(|e| unreachable!("fixture: {e}"));
958 let stock_text = serde_json::to_string(&stock).unwrap_or_default();
960 assert!(!stock_text.contains("\"engine\""));
961 let engine = EngineProvenance {
962 name: "interactive".to_owned(),
963 manifest_sha256: "ab".repeat(32),
964 established_by: EngineEstablishment::StockFallback,
965 };
966 let mut r = stock.clone();
967 r.engine = Some(engine.clone());
968 for f in r.crates.iter_mut().flat_map(|c| &mut c.functions) {
969 f.provenance.engine = Some(engine.clone());
970 }
971 let schema = serde_json::from_str(JSON_SCHEMA).unwrap_or_default();
972 let value = serde_json::to_value(&r).unwrap_or_default();
973 assert_eq!(
974 crate::schema::validate(&schema, &value),
975 Vec::<String>::new()
976 );
977 assert_eq!(value["engine"]["established_by"], "stock-fallback");
978 let mut wrong = value.clone();
979 wrong["engine"]["established_by"] = serde_json::json!("default");
980 assert_ne!(
981 crate::schema::validate(&schema, &wrong),
982 Vec::<String>::new()
983 );
984 let mut wrong = value;
985 if let Some(engine) = wrong["engine"].as_object_mut() {
986 engine.remove("manifest_sha256");
987 }
988 assert_ne!(
989 crate::schema::validate(&schema, &wrong),
990 Vec::<String>::new()
991 );
992 let project: serde_json::Value =
993 serde_json::from_str(include_str!("../schema/project-result-v2.json"))
994 .unwrap_or_default();
995 let identity = crate::project::EngineIdentity {
996 name: "interactive".to_owned(),
997 manifest_sha256: "cd".repeat(32),
998 };
999 let identity = serde_json::to_value(identity).unwrap_or_default();
1000 assert_eq!(
1001 crate::schema::validate(&project["properties"]["engine"], &identity),
1002 Vec::<String>::new()
1003 );
1004 let mut extra = identity;
1005 extra["established_by"] = serde_json::json!("engine");
1006 assert_ne!(
1007 crate::schema::validate(&project["properties"]["engine"], &extra),
1008 Vec::<String>::new()
1009 );
1010 }
1011 #[test]
1012 fn verus_totals_clear_unknown_functions_only_when_every_error_is_accounted_for() {
1013 let golden: Report = serde_json::from_str(include_str!(
1014 "../resources/crates/sail-cli/tests/fixtures/attr/report.golden.json"
1015 ))
1016 .unwrap_or_else(|e| unreachable!("fixture: {e}"));
1017 let mut krate = golden.crates[0].clone();
1019 assert_eq!(krate.verus.errors, Some(2));
1020 assert_eq!(krate.unknown_passed_by_verus_totals(), 0);
1021 for f in &mut krate.functions {
1023 if f.verdict == VerdictName::Verified {
1024 f.verdict = VerdictName::Unknown;
1025 }
1026 }
1027 assert_eq!(krate.unknown_passed_by_verus_totals(), 6);
1028 krate.verus.errors = Some(3);
1030 assert_eq!(krate.unknown_passed_by_verus_totals(), 0);
1031 krate.verus.errors = Some(2);
1032 krate.verus.encountered_vir_error = Some(true);
1033 assert_eq!(krate.unknown_passed_by_verus_totals(), 0);
1034 krate.verus.encountered_vir_error = Some(false);
1035 krate.verus.verified = None;
1036 assert_eq!(krate.unknown_passed_by_verus_totals(), 0);
1037 krate.verus.verified = Some(9);
1039 for f in &mut krate.functions {
1040 f.verdict = VerdictName::Unknown;
1041 }
1042 krate.verus.errors = Some(0);
1043 assert_eq!(krate.unknown_passed_by_verus_totals(), 0);
1044 }
1045 #[test]
1046 fn portfolio_evidence_matches_the_schema() {
1047 let mut r: Report = serde_json::from_str(include_str!(
1048 "../resources/crates/sail-cli/tests/fixtures/attr/report.golden.json"
1049 ))
1050 .unwrap_or_else(|e| unreachable!("fixture: {e}"));
1051 let attempt = PortfolioAttempt {
1052 configuration: SolverConfiguration { seed: 4 },
1053 verified: false,
1054 exit_code: Some(1),
1055 wall_ms: 1.0,
1056 error: None,
1057 report: Some(Box::new(r.clone())),
1058 stderr: "original diagnostics".to_owned(),
1059 };
1060 r.mode = "accept-first-proof".to_owned();
1061 r.portfolio = Some(PortfolioReport {
1062 seeds: vec![0, 4],
1063 winner_seed: None,
1064 attempts: vec![attempt],
1065 });
1066 let schema = serde_json::from_str(JSON_SCHEMA).unwrap_or_default();
1067 let value = serde_json::to_value(r).unwrap_or_default();
1068 assert!(
1069 crate::schema::validate(&schema, &value).is_empty(),
1070 "{:?}",
1071 crate::schema::validate(&schema, &value)
1072 );
1073 }
1074}