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