lean_ctx_ext/core/
verification_observability.rs1use serde::Serialize;
3
4#[derive(Debug, Clone, Serialize)]
5pub struct VerificationObservabilityV1 {
6 pub schema_version: u32,
7 pub created_at: String,
8 pub role: String,
9 pub profile: String,
10 pub verification: crate::core::output_verification::VerificationSnapshot,
11 pub proof: crate::core::context_proof::ProofStatsSnapshot,
12 pub pipeline: crate::core::pipeline::PipelineStats,
13}
14
15pub fn snapshot_v1() -> VerificationObservabilityV1 {
16 let created_at = lean_ctx_time::UtcDateTime::now().to_rfc3339();
17 let role = crate::core::roles::active_role_name();
18 let profile = crate::core::profiles::active_profile_name();
19
20 let verification = crate::core::output_verification::stats_snapshot();
21 let proof = crate::core::context_proof::proof_stats_snapshot();
22 let pipeline = crate::core::pipeline::PipelineStats::load();
23
24 VerificationObservabilityV1 {
25 schema_version: crate::core::contracts::VERIFICATION_OBSERVABILITY_V1_SCHEMA_VERSION,
26 created_at,
27 role,
28 profile,
29 verification,
30 proof,
31 pipeline,
32 }
33}
34
35pub fn format_compact(v: &VerificationObservabilityV1) -> String {
36 let proof_last = v
37 .proof
38 .last_written_at
39 .clone()
40 .unwrap_or_else(|| "-".to_string());
41 format!(
42 "{}\nProof: written={} last={proof_last}",
43 v.verification.format_compact(),
44 v.proof.written
45 )
46}
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51
52 #[test]
53 fn snapshot_has_schema_version() {
54 let s = snapshot_v1();
55 assert_eq!(s.schema_version, 1);
56 assert!(s.created_at.contains('T'));
57 let compact = format_compact(&s);
58 assert!(compact.contains("Verification:"));
59 assert!(compact.contains("Proof: written="));
60 }
61}