Skip to main content

adze_governance_runtime_reporting/
lib.rs

1//! Shared runtime report formatting for governance snapshots.
2//!
3//! This crate centralizes the output wiring for BDD progress + parser feature
4//! profile diagnostics so downstream consumers (runtime and fixtures) can render
5//! interoperable status lines and reports.
6
7#![forbid(unsafe_op_in_unsafe_fn)]
8#![deny(missing_docs)]
9#![cfg_attr(feature = "strict_api", deny(unreachable_pub))]
10#![cfg_attr(not(feature = "strict_api"), warn(unreachable_pub))]
11#![cfg_attr(feature = "strict_docs", deny(missing_docs))]
12#![cfg_attr(not(feature = "strict_docs"), allow(missing_docs))]
13
14use core::fmt::Write;
15
16/// Re-exported governance matrix types and helpers for BDD progress tracking.
17pub use adze_governance_matrix_contract::{
18    BddGovernanceMatrix, BddGovernanceSnapshot, BddPhase, BddScenario, BddScenarioStatus,
19    GLR_CONFLICT_FALLBACK, GLR_CONFLICT_PRESERVATION_GRID, ParserBackend, ParserFeatureProfile,
20    bdd_governance_snapshot, bdd_progress, bdd_progress_report, bdd_progress_report_with_profile,
21    bdd_progress_status_line, describe_backend_for_conflicts,
22};
23
24/// Build a runtime-oriented governance report using an explicit feature profile.
25pub fn bdd_progress_report_with_profile_runtime(
26    phase: BddPhase,
27    scenarios: &[BddScenario],
28    phase_title: &str,
29    profile: ParserFeatureProfile,
30) -> String {
31    let mut out = bdd_progress_report_with_profile(phase, scenarios, phase_title, profile);
32    let (implemented, total) = bdd_progress(phase, scenarios);
33
34    let _ = writeln!(
35        &mut out,
36        "Governance status: {implemented}/{total} scenarios implemented"
37    );
38    let _ = writeln!(&mut out, "Feature profile: {profile}");
39    let _ = writeln!(
40        &mut out,
41        "Non-conflict backend: {}",
42        profile.resolve_backend(false).name()
43    );
44    let _ = writeln!(
45        &mut out,
46        "Conflict profiles: {}",
47        describe_backend_for_conflicts(profile)
48    );
49
50    out
51}
52
53#[cfg(test)]
54mod tests {
55    use super::*;
56
57    #[test]
58    fn runtime_report_uses_grid_and_profile_text() {
59        let profile = ParserFeatureProfile {
60            pure_rust: false,
61            tree_sitter_standard: true,
62            tree_sitter_c2rust: false,
63            glr: false,
64        };
65
66        let report = bdd_progress_report_with_profile_runtime(
67            BddPhase::Runtime,
68            GLR_CONFLICT_PRESERVATION_GRID,
69            "Runtime",
70            profile,
71        );
72
73        assert!(report.contains("Runtime"));
74        assert!(report.contains("Feature profile:"));
75        assert!(report.contains("Governance status:"));
76    }
77
78    #[test]
79    fn runtime_status_line_is_reusable() {
80        let profile = ParserFeatureProfile::current();
81        let status =
82            bdd_progress_status_line(BddPhase::Runtime, GLR_CONFLICT_PRESERVATION_GRID, profile);
83
84        assert!(status.starts_with("runtime:"));
85        assert!(status.contains(&format!("{}", profile)));
86    }
87
88    #[test]
89    fn runtime_report_with_empty_scenarios() {
90        let profile = ParserFeatureProfile::current();
91        let report =
92            bdd_progress_report_with_profile_runtime(BddPhase::Core, &[], "Empty", profile);
93        assert!(report.contains("Empty"));
94        assert!(report.contains("Governance status: 0/0"));
95        assert!(report.contains("Feature profile:"));
96        assert!(report.contains("Non-conflict backend:"));
97        assert!(report.contains("Conflict profiles:"));
98    }
99
100    #[test]
101    fn runtime_report_contains_backend_info() {
102        let profile = ParserFeatureProfile {
103            pure_rust: true,
104            tree_sitter_standard: false,
105            tree_sitter_c2rust: false,
106            glr: true,
107        };
108        let report = bdd_progress_report_with_profile_runtime(
109            BddPhase::Runtime,
110            GLR_CONFLICT_PRESERVATION_GRID,
111            "GLR Report",
112            profile,
113        );
114        assert!(report.contains("GLR Report"));
115        assert!(report.contains("Non-conflict backend:"));
116        assert!(report.contains("Conflict profiles:"));
117    }
118
119    #[test]
120    fn core_status_line_starts_with_core() {
121        let profile = ParserFeatureProfile::current();
122        let status =
123            bdd_progress_status_line(BddPhase::Core, GLR_CONFLICT_PRESERVATION_GRID, profile);
124        assert!(status.starts_with("core:"));
125    }
126
127    #[test]
128    fn re_exports_bdd_progress() {
129        let (implemented, total) = bdd_progress(BddPhase::Core, GLR_CONFLICT_PRESERVATION_GRID);
130        assert!(total > 0);
131        assert!(implemented <= total);
132    }
133
134    #[test]
135    fn re_exports_describe_backend() {
136        let desc = describe_backend_for_conflicts(ParserFeatureProfile::current());
137        assert!(!desc.is_empty());
138    }
139
140    #[test]
141    fn re_exports_bdd_governance_snapshot() {
142        let profile = ParserFeatureProfile::current();
143        let snap = bdd_governance_snapshot(BddPhase::Core, GLR_CONFLICT_PRESERVATION_GRID, profile);
144        assert_eq!(snap.phase, BddPhase::Core);
145        assert_eq!(snap.profile, profile);
146    }
147
148    #[test]
149    fn re_exports_matrix_types() {
150        let profile = ParserFeatureProfile::current();
151        let matrix = BddGovernanceMatrix::standard(profile);
152        assert!(!matrix.scenarios.is_empty());
153        let _ = matrix.is_fully_implemented();
154    }
155}