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 #[serde(default, skip_serializing_if = "Option::is_none")]
302 pub health: Option<crate::health::FunctionHealth>,
303 pub obligations: Option<Vec<ObligationReport>>,
305}
306
307#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
309#[serde(rename_all = "kebab-case")]
310pub enum SourceSummaryName {
311 Fresh,
313 Cache,
315 Mixed,
317 Unrecorded,
319}
320
321impl From<SourceSummary> for SourceSummaryName {
322 fn from(s: SourceSummary) -> Self {
323 match s {
324 SourceSummary::Fresh => Self::Fresh,
325 SourceSummary::Cache => Self::Cache,
326 SourceSummary::Mixed => Self::Mixed,
327 SourceSummary::Unrecorded => Self::Unrecorded,
328 }
329 }
330}
331
332#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
334pub struct ProvenanceReport {
335 #[serde(default, skip_serializing_if = "Option::is_none")]
337 pub configuration: Option<SolverConfiguration>,
338 pub mode: String,
340 pub source: SourceSummaryName,
342 pub checks_solved: u64,
344 pub checks_served: u64,
346 pub checks_unrecorded: u64,
348 #[serde(default, skip_serializing_if = "Option::is_none")]
350 pub engine: Option<EngineProvenance>,
351}
352
353#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
355pub struct Timing {
356 pub smt_micros: Option<u64>,
358 pub rlimit: Option<u64>,
360}
361
362#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
364pub struct Fragility {
365 pub score: f64,
367 pub runs: u32,
369 pub proved: u32,
371}
372
373#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
375#[serde(rename_all = "kebab-case")]
376pub enum OutcomeName {
377 Proved,
379 Failed,
381 Unknown,
383}
384
385impl From<Outcome> for OutcomeName {
386 fn from(o: Outcome) -> Self {
387 match o {
388 Outcome::Proved => Self::Proved,
389 Outcome::Failed => Self::Failed,
390 Outcome::Unknown => Self::Unknown,
391 }
392 }
393}
394
395#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
397pub struct ObligationReport {
398 pub id: String,
401 pub kind: String,
403 pub ordinal: u32,
406 pub spinoff: Option<SpinoffInfo>,
408 pub advisory: bool,
411 pub span: Option<SourceSpan>,
413 pub outcome: OutcomeName,
415 pub unstable: bool,
417 pub checks: Vec<CheckReport>,
419 pub counterexample: Option<Counterexample>,
421}
422
423#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
425pub struct SpinoffInfo {
426 pub index: u32,
428 pub reason: Option<String>,
430}
431
432#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
434pub struct SourceSpan {
435 pub text: String,
437 pub file: Option<String>,
439 pub line: Option<u64>,
441 pub column: Option<u64>,
443 pub end_line: Option<u64>,
445 pub end_column: Option<u64>,
447}
448
449impl SourceSpan {
450 #[must_use]
452 pub fn parse(text: &str) -> Self {
453 let mut span = Self {
454 text: text.to_owned(),
455 file: None,
456 line: None,
457 column: None,
458 end_line: None,
459 end_column: None,
460 };
461 let body = text.rsplit_once(" (#").map_or(text, |(b, _)| b);
462 let Some((start, end)) = body.rsplit_once(": ") else {
463 return span;
464 };
465 let mut s = start.rsplitn(3, ':');
466 let (Some(col), Some(line), Some(file)) = (s.next(), s.next(), s.next()) else {
467 return span;
468 };
469 let mut e = end.splitn(2, ':');
470 span.file = Some(file.to_owned());
471 span.line = line.parse().ok();
472 span.column = col.parse().ok();
473 span.end_line = e.next().and_then(|v| v.parse().ok());
474 span.end_column = e.next().and_then(|v| v.parse().ok());
475 span
476 }
477}
478
479#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
481#[serde(rename_all = "kebab-case")]
482pub enum AnswerName {
483 Sat,
485 Unsat,
487 Unknown,
489}
490
491impl From<sail_ledger::Answer> for AnswerName {
492 fn from(a: sail_ledger::Answer) -> Self {
493 match a {
494 sail_ledger::Answer::Sat => Self::Sat,
495 sail_ledger::Answer::Unsat => Self::Unsat,
496 sail_ledger::Answer::Unknown => Self::Unknown,
497 }
498 }
499}
500
501#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
503#[serde(rename_all = "kebab-case")]
504pub enum SourceName {
505 Solved,
507 Cache,
509}
510
511impl From<Source> for SourceName {
512 fn from(s: Source) -> Self {
513 match s {
514 Source::Solved => Self::Solved,
515 Source::Cache => Self::Cache,
516 }
517 }
518}
519
520#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
522pub struct CheckReport {
523 pub answer: Option<AnswerName>,
525 pub rlimit_limit: Option<u64>,
527 pub rlimit_used: Option<u64>,
529 pub reason_unknown: Option<String>,
531 pub source: Option<SourceName>,
533}
534
535#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
537pub struct Counterexample {
538 pub check: u32,
540 pub model: String,
542 pub assignments: Vec<Assignment>,
544}
545
546#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
548pub struct Assignment {
549 pub name: String,
552 pub sort: String,
554 pub value: String,
556 pub itf: ItfValue,
559}
560
561#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
570#[serde(untagged)]
571pub enum ItfValue {
572 Bool(bool),
574 BigInt {
576 #[serde(rename = "#bigint")]
578 bigint: String,
579 },
580 Unserializable {
582 #[serde(rename = "#unserializable")]
584 unserializable: String,
585 },
586}
587
588impl ItfValue {
589 #[must_use]
593 pub fn render(sort: &str, value: &str) -> Self {
594 let v = value.trim();
595 let sort = sort.trim();
596 let read = match sort {
597 "Bool" => match v {
598 "true" => Some(Self::Bool(true)),
599 "false" => Some(Self::Bool(false)),
600 _ => None,
601 },
602 "Int" => smt_int(v).map(|bigint| Self::BigInt { bigint }),
603 _ if sort.starts_with("(_ BitVec ") => smt_bit_vector(v).map(|n| Self::BigInt {
604 bigint: n.to_string(),
605 }),
606 _ => None,
607 };
608 read.unwrap_or_else(|| Self::Unserializable {
609 unserializable: value.to_owned(),
610 })
611 }
612}
613
614fn smt_int(v: &str) -> Option<String> {
616 let numeral = |s: &str| !s.is_empty() && s.bytes().all(|b| b.is_ascii_digit());
617 if numeral(v) {
618 return Some(v.to_owned());
619 }
620 let inner = v.strip_prefix('(')?.strip_suffix(')')?.trim();
621 let digits = inner.strip_prefix('-')?.trim();
622 if !numeral(digits) {
623 return None;
624 }
625 Some(if digits.bytes().all(|b| b == b'0') {
626 "0".to_owned()
627 } else {
628 format!("-{digits}")
629 })
630}
631
632fn smt_bit_vector(v: &str) -> Option<u128> {
635 let (digits, radix) = if let Some(d) = v.strip_prefix("#x") {
636 (d, 16)
637 } else {
638 (v.strip_prefix("#b")?, 2)
639 };
640 if digits.is_empty() || !digits.bytes().all(|b| b.is_ascii_hexdigit()) {
641 return None;
642 }
643 u128::from_str_radix(digits, radix).ok()
644}
645
646#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
648pub struct DiagnosticSpan {
649 pub file: String,
651 pub line: u64,
653 pub column: u64,
655 pub primary: bool,
657}
658
659#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
661pub struct Diagnostic {
662 pub level: String,
664 pub code: Option<String>,
666 pub message: String,
668 pub spans: Vec<DiagnosticSpan>,
670 pub rendered: String,
672}
673
674#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
676pub struct Summary {
677 pub functions: u64,
679 pub verified: u64,
681 pub failed: u64,
683 pub unknown: u64,
685 pub provisional: u64,
687 pub unstable: u64,
689}
690
691#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
693pub struct ErrorInfo {
694 pub code: String,
696 pub message: String,
698}
699
700fn check_report(c: &CheckRecord) -> CheckReport {
701 CheckReport {
702 answer: c.answer.map(AnswerName::from),
703 rlimit_limit: c.effort.limit,
704 rlimit_used: c.effort.used,
705 reason_unknown: c.effort.reason.clone(),
706 source: c.source.map(SourceName::from),
707 }
708}
709
710impl From<&ObligationRecord> for ObligationReport {
711 fn from(o: &ObligationRecord) -> Self {
712 let counterexample = o.checks.iter().enumerate().find_map(|(i, c)| {
713 let model = c.model.as_ref()?;
714 Some(Counterexample {
715 check: u32::try_from(i).unwrap_or(u32::MAX),
716 model: model.text.clone(),
717 assignments: model
718 .assignments
719 .iter()
720 .map(|a| Assignment {
721 name: a.name.clone(),
722 sort: a.sort.clone(),
723 value: a.value.clone(),
724 itf: ItfValue::render(&a.sort, &a.value),
725 })
726 .collect(),
727 })
728 });
729 Self {
730 id: o.id.to_string(),
731 kind: o.id.kind.0.clone(),
732 ordinal: o.id.ordinal,
733 spinoff: o.id.spinoff.map(|index| SpinoffInfo {
734 index,
735 reason: o.spinoff_reason.clone(),
736 }),
737 advisory: !o.id.kind.verdict_bearing(),
738 span: o.span.as_deref().map(SourceSpan::parse),
739 outcome: o.outcome().into(),
740 unstable: o.unstable(),
741 checks: o.checks.iter().map(check_report).collect(),
742 counterexample,
743 }
744 }
745}
746
747impl From<&FunctionRecord> for FunctionReport {
748 fn from(f: &FunctionRecord) -> Self {
749 let sources = f.sources();
750 let verdict = VerdictName::from(f.verdict());
751 let establishment = EstablishmentName::from(f.establishment);
752 let obligations: Option<Vec<_>> = f
753 .obligations
754 .as_ref()
755 .map(|obligations| obligations.iter().map(ObligationReport::from).collect());
756 let health = crate::health::FunctionHealth::from_obligations(obligations.as_deref());
757 Self {
758 function: f.function.clone(),
759 module: f.module.clone(),
760 fn_mode: f.fn_mode.clone(),
761 verdict,
762 establishment,
763 evidence_tier: EvidenceTierName::for_smt(verdict, establishment),
764 unstable: f.unstable(),
765 verus_success: f.verus_success,
766 provenance: ProvenanceReport {
767 configuration: None,
768 mode: f.mode.name().to_owned(),
769 source: sources.summary().into(),
770 checks_solved: sources.solved,
771 checks_served: sources.served,
772 checks_unrecorded: sources.unrecorded,
773 engine: None,
774 },
775 timing: Timing {
776 smt_micros: f.smt_micros,
777 rlimit: f.rlimit,
778 },
779 fragility: None,
780 health: Some(health),
781 obligations,
782 }
783 }
784}
785
786impl Summary {
787 #[must_use]
789 pub fn of(crates: &[CrateReport]) -> Self {
790 let mut s = Self::default();
791 for f in crates.iter().flat_map(|c| &c.functions) {
792 s.functions += 1;
793 match f.verdict {
794 VerdictName::Verified => s.verified += 1,
795 VerdictName::Failed => s.failed += 1,
796 VerdictName::Unknown => s.unknown += 1,
797 VerdictName::Provisional => s.provisional += 1,
798 }
799 s.unstable += u64::from(f.unstable);
800 }
801 s
802 }
803}
804
805impl CrateReport {
806 #[must_use]
818 pub fn unknown_passed_by_verus_totals(&self) -> u64 {
819 if self.verus_totals_clear_unknown() {
820 self.count(VerdictName::Unknown)
821 } else {
822 0
823 }
824 }
825
826 #[must_use]
830 pub fn verus_totals_clear_unknown(&self) -> bool {
831 let failed = self.count(VerdictName::Failed);
832 failed > 0
833 && self.verus.errors == Some(failed)
834 && self.verus.verified.is_some()
835 && self.verus.encountered_vir_error != Some(true)
836 }
837
838 fn count(&self, verdict: VerdictName) -> u64 {
839 let n = self
840 .functions
841 .iter()
842 .filter(|f| f.verdict == verdict)
843 .count();
844 u64::try_from(n).unwrap_or(u64::MAX)
845 }
846}
847
848impl Report {
849 #[must_use]
851 pub fn invariant_violations(&self) -> Vec<String> {
852 let mut out = Vec::new();
853 if self.schema_version != SCHEMA_VERSION {
854 out.push(format!("schema_version is {}", self.schema_version));
855 }
856 let mut ids = std::collections::BTreeSet::new();
857 for f in self.crates.iter().flat_map(|c| &c.functions) {
858 if f.verdict == VerdictName::Verified && f.establishment != EstablishmentName::Confirmed
859 {
860 out.push(format!("{}: verified but not confirmed", f.function));
861 }
862 if (f.establishment == EstablishmentName::Provisional)
863 != (f.verdict == VerdictName::Provisional)
864 {
865 out.push(format!(
866 "{}: establishment and verdict disagree",
867 f.function
868 ));
869 }
870 let settled = matches!(f.verdict, VerdictName::Verified | VerdictName::Failed);
871 if settled != f.evidence_tier.is_some() {
872 out.push(format!(
873 "{}: evidence tier and verdict disagree",
874 f.function
875 ));
876 }
877 let p = &f.provenance;
878 let counted = (p.checks_solved, p.checks_served, p.checks_unrecorded);
879 let expected = match p.source {
880 SourceSummaryName::Fresh => counted.0 > 0 && counted.1 == 0 && counted.2 == 0,
881 SourceSummaryName::Cache => counted.0 == 0 && counted.1 > 0 && counted.2 == 0,
882 SourceSummaryName::Mixed => counted.0 > 0 && counted.1 > 0 && counted.2 == 0,
883 SourceSummaryName::Unrecorded => counted.2 > 0 || counted == (0, 0, 0),
884 };
885 if !expected {
886 out.push(format!(
887 "{}: provenance counts disagree with source",
888 f.function
889 ));
890 }
891 for o in f.obligations.iter().flatten() {
892 if !ids.insert(o.id.clone()) {
893 out.push(format!("duplicate obligation id {}", o.id));
894 }
895 if !o.id.starts_with(&format!("{}#", f.function)) {
896 out.push(format!("obligation {} is not {}'s", o.id, f.function));
897 }
898 }
899 }
900 if self.summary != Summary::of(&self.crates) {
901 out.push("summary does not match the functions".to_owned());
902 }
903 out
904 }
905}
906
907#[cfg(test)]
908mod tests {
909 use super::*;
910
911 #[test]
912 fn spans_parse() {
913 let s = SourceSpan::parse("src/lib.rs:46:1: 46:26 (#0)");
914 assert_eq!(s.file.as_deref(), Some("src/lib.rs"));
915 assert_eq!(
916 (s.line, s.column, s.end_line, s.end_column),
917 (Some(46), Some(1), Some(46), Some(26))
918 );
919 let s = SourceSpan::parse("garbage");
920 assert_eq!((s.file, s.line), (None, None));
921 assert_eq!(s.text, "garbage");
922 }
923 #[test]
924 fn the_example_document_is_valid_v2_with_rendered_itf_values() {
925 let text =
926 include_str!("../resources/crates/sail-cli/tests/fixtures/attr/report.golden.json");
927 let golden: Report =
928 serde_json::from_str(text).unwrap_or_else(|e| unreachable!("fixture: {e}"));
929 let schema: serde_json::Value = serde_json::from_str(JSON_SCHEMA).unwrap_or_default();
930 let value: serde_json::Value = serde_json::from_str(text).unwrap_or_default();
931 assert_eq!(
932 crate::schema::validate(&schema, &value),
933 Vec::<String>::new()
934 );
935 assert_eq!(golden.invariant_violations(), Vec::<String>::new());
936 let mut rendered = 0;
937 for o in golden
938 .crates
939 .iter()
940 .flat_map(|c| &c.functions)
941 .flat_map(|f| f.obligations.iter().flatten())
942 {
943 for a in o.counterexample.iter().flat_map(|c| &c.assignments) {
944 assert_eq!(a.itf, ItfValue::render(&a.sort, &a.value), "{}", a.name);
945 assert!(
947 o.counterexample
948 .as_ref()
949 .is_some_and(|c| c.model.contains(&a.value)),
950 "{}",
951 a.name
952 );
953 rendered += usize::from(!matches!(a.itf, ItfValue::Unserializable { .. }));
954 }
955 }
956 assert!(rendered > 0);
957 }
958 #[test]
959 fn engine_provenance_is_additive_and_matches_the_schemas() {
960 let stock: Report = serde_json::from_str(include_str!(
961 "../resources/crates/sail-cli/tests/fixtures/attr/report.golden.json"
962 ))
963 .unwrap_or_else(|e| unreachable!("fixture: {e}"));
964 let stock_text = serde_json::to_string(&stock).unwrap_or_default();
966 assert!(!stock_text.contains("\"engine\""));
967 let engine = EngineProvenance {
968 name: "interactive".to_owned(),
969 manifest_sha256: "ab".repeat(32),
970 established_by: EngineEstablishment::StockFallback,
971 };
972 let mut r = stock.clone();
973 r.engine = Some(engine.clone());
974 for f in r.crates.iter_mut().flat_map(|c| &mut c.functions) {
975 f.provenance.engine = Some(engine.clone());
976 }
977 let schema = serde_json::from_str(JSON_SCHEMA).unwrap_or_default();
978 let value = serde_json::to_value(&r).unwrap_or_default();
979 assert_eq!(
980 crate::schema::validate(&schema, &value),
981 Vec::<String>::new()
982 );
983 assert_eq!(value["engine"]["established_by"], "stock-fallback");
984 let mut wrong = value.clone();
985 wrong["engine"]["established_by"] = serde_json::json!("default");
986 assert_ne!(
987 crate::schema::validate(&schema, &wrong),
988 Vec::<String>::new()
989 );
990 let mut wrong = value;
991 if let Some(engine) = wrong["engine"].as_object_mut() {
992 engine.remove("manifest_sha256");
993 }
994 assert_ne!(
995 crate::schema::validate(&schema, &wrong),
996 Vec::<String>::new()
997 );
998 let project: serde_json::Value =
999 serde_json::from_str(include_str!("../schema/project-result-v2.json"))
1000 .unwrap_or_default();
1001 let identity = crate::project::EngineIdentity {
1002 name: "interactive".to_owned(),
1003 manifest_sha256: "cd".repeat(32),
1004 };
1005 let identity = serde_json::to_value(identity).unwrap_or_default();
1006 assert_eq!(
1007 crate::schema::validate(&project["properties"]["engine"], &identity),
1008 Vec::<String>::new()
1009 );
1010 let mut extra = identity;
1011 extra["established_by"] = serde_json::json!("engine");
1012 assert_ne!(
1013 crate::schema::validate(&project["properties"]["engine"], &extra),
1014 Vec::<String>::new()
1015 );
1016 }
1017 #[test]
1018 fn verus_totals_clear_unknown_functions_only_when_every_error_is_accounted_for() {
1019 let golden: Report = serde_json::from_str(include_str!(
1020 "../resources/crates/sail-cli/tests/fixtures/attr/report.golden.json"
1021 ))
1022 .unwrap_or_else(|e| unreachable!("fixture: {e}"));
1023 let mut krate = golden.crates[0].clone();
1025 assert_eq!(krate.verus.errors, Some(2));
1026 assert_eq!(krate.unknown_passed_by_verus_totals(), 0);
1027 for f in &mut krate.functions {
1029 if f.verdict == VerdictName::Verified {
1030 f.verdict = VerdictName::Unknown;
1031 }
1032 }
1033 assert_eq!(krate.unknown_passed_by_verus_totals(), 6);
1034 krate.verus.errors = Some(3);
1036 assert_eq!(krate.unknown_passed_by_verus_totals(), 0);
1037 krate.verus.errors = Some(2);
1038 krate.verus.encountered_vir_error = Some(true);
1039 assert_eq!(krate.unknown_passed_by_verus_totals(), 0);
1040 krate.verus.encountered_vir_error = Some(false);
1041 krate.verus.verified = None;
1042 assert_eq!(krate.unknown_passed_by_verus_totals(), 0);
1043 krate.verus.verified = Some(9);
1045 for f in &mut krate.functions {
1046 f.verdict = VerdictName::Unknown;
1047 }
1048 krate.verus.errors = Some(0);
1049 assert_eq!(krate.unknown_passed_by_verus_totals(), 0);
1050 }
1051 #[test]
1052 fn portfolio_evidence_matches_the_schema() {
1053 let mut r: Report = serde_json::from_str(include_str!(
1054 "../resources/crates/sail-cli/tests/fixtures/attr/report.golden.json"
1055 ))
1056 .unwrap_or_else(|e| unreachable!("fixture: {e}"));
1057 let attempt = PortfolioAttempt {
1058 configuration: SolverConfiguration { seed: 4 },
1059 verified: false,
1060 exit_code: Some(1),
1061 wall_ms: 1.0,
1062 error: None,
1063 report: Some(Box::new(r.clone())),
1064 stderr: "original diagnostics".to_owned(),
1065 };
1066 r.mode = "accept-first-proof".to_owned();
1067 r.portfolio = Some(PortfolioReport {
1068 seeds: vec![0, 4],
1069 winner_seed: None,
1070 attempts: vec![attempt],
1071 });
1072 let schema = serde_json::from_str(JSON_SCHEMA).unwrap_or_default();
1073 let value = serde_json::to_value(r).unwrap_or_default();
1074 assert!(
1075 crate::schema::validate(&schema, &value).is_empty(),
1076 "{:?}",
1077 crate::schema::validate(&schema, &value)
1078 );
1079 }
1080}