Skip to main content

adze_runtime_governance_matrix/
lib.rs

1//! Shared governance profile and reporting primitives for runtime and runtime2 consumers.
2//!
3//! This crate consolidates parser-feature profile helpers, backend resolution, and
4//! BDD reporting wiring around the canonical GLR preservation grid. It is intended
5//! to be used by façade crates that keep historical public APIs stable.
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
14pub use adze_governance_runtime_core::{
15    BddGovernanceMatrix, BddGovernanceSnapshot, BddPhase, BddScenario, BddScenarioStatus,
16    GLR_CONFLICT_FALLBACK, GLR_CONFLICT_PRESERVATION_GRID, ParserBackend, ParserFeatureProfile,
17    bdd_governance_matrix_for_profile, bdd_governance_matrix_for_runtime,
18    bdd_governance_matrix_for_runtime2, bdd_governance_snapshot, bdd_progress, bdd_progress_report,
19    bdd_progress_report_for_profile, bdd_progress_report_with_profile,
20    bdd_progress_report_with_profile_runtime, bdd_progress_status_line,
21    bdd_progress_status_line_for_profile, describe_backend_for_conflicts,
22    parser_feature_profile_for_runtime, parser_feature_profile_for_runtime2,
23    resolve_backend_for_profile,
24};
25
26/// Select the parser backend for the current compile-time feature profile.
27pub const fn current_backend_for(has_conflicts: bool) -> ParserBackend {
28    ParserBackend::select(has_conflicts)
29}
30
31/// Return a BDD progress report for the active runtime profile.
32pub fn bdd_progress_report_for_current_profile(phase: BddPhase, phase_title: &str) -> String {
33    bdd_progress_report_with_profile_runtime(
34        phase,
35        GLR_CONFLICT_PRESERVATION_GRID,
36        phase_title,
37        parser_feature_profile_for_runtime(),
38    )
39}
40
41/// Build the active runtime governance matrix for a phase.
42pub fn bdd_governance_matrix_for_current_profile(phase: BddPhase) -> BddGovernanceMatrix {
43    bdd_governance_matrix_for_profile(phase, parser_feature_profile_for_runtime())
44}
45
46/// Build a governance matrix for a runtime2-compatible profile.
47pub fn bdd_governance_matrix_for_runtime2_profile(
48    phase: BddPhase,
49    pure_rust_glr: bool,
50) -> BddGovernanceMatrix {
51    bdd_governance_matrix_for_runtime2(phase, pure_rust_glr)
52}
53
54/// Return a BDD status line for the active runtime profile.
55pub fn bdd_status_line_for_current_profile(phase: BddPhase) -> String {
56    bdd_progress_status_line_for_profile(phase, parser_feature_profile_for_runtime())
57}
58
59/// Build a governance snapshot for the active runtime profile.
60pub fn runtime_governance_snapshot(phase: BddPhase) -> BddGovernanceSnapshot {
61    bdd_governance_snapshot(
62        phase,
63        GLR_CONFLICT_PRESERVATION_GRID,
64        parser_feature_profile_for_runtime(),
65    )
66}
67
68/// Build a BDD report for an explicit runtime2 profile.
69pub fn bdd_progress_report_for_runtime2_profile(
70    phase: BddPhase,
71    phase_title: &str,
72    profile: ParserFeatureProfile,
73) -> String {
74    bdd_progress_report_with_profile_runtime(
75        phase,
76        GLR_CONFLICT_PRESERVATION_GRID,
77        phase_title,
78        profile,
79    )
80}
81
82/// Build a BDD status line for an explicit runtime2 profile.
83pub fn bdd_progress_status_line_for_runtime2_profile(
84    phase: BddPhase,
85    profile: ParserFeatureProfile,
86) -> String {
87    bdd_progress_status_line_for_profile(phase, profile)
88}
89
90/// Resolve runtime2 backend resolution from an explicit profile.
91pub const fn resolve_backend_for_runtime2_profile(
92    profile: ParserFeatureProfile,
93    has_conflicts: bool,
94) -> ParserBackend {
95    resolve_backend_for_profile(profile, has_conflicts)
96}
97
98/// Resolve runtime2 backend resolution directly from the `pure-rust-glr` toggle.
99pub const fn resolve_runtime2_backend(pure_rust_glr: bool, has_conflicts: bool) -> ParserBackend {
100    resolve_backend_for_profile(
101        parser_feature_profile_for_runtime2(pure_rust_glr),
102        has_conflicts,
103    )
104}
105
106/// Build a runtime2 governance snapshot for an explicit profile.
107pub fn runtime2_governance_snapshot(
108    phase: BddPhase,
109    profile: ParserFeatureProfile,
110) -> BddGovernanceSnapshot {
111    bdd_governance_snapshot(phase, GLR_CONFLICT_PRESERVATION_GRID, profile)
112}
113
114#[cfg(test)]
115mod tests {
116    use super::*;
117
118    #[test]
119    fn current_profile_matches_cfg() {
120        let profile = parser_feature_profile_for_runtime();
121        assert_eq!(profile.pure_rust, cfg!(feature = "pure-rust"));
122        assert_eq!(
123            profile.tree_sitter_standard,
124            cfg!(feature = "tree-sitter-standard")
125        );
126        assert_eq!(
127            profile.tree_sitter_c2rust,
128            cfg!(feature = "tree-sitter-c2rust")
129        );
130        assert_eq!(profile.glr, cfg!(feature = "glr"));
131    }
132
133    #[test]
134    fn resolve_backend_round_trips_current_profile() {
135        let profile = parser_feature_profile_for_runtime();
136        assert_eq!(current_backend_for(false), profile.resolve_backend(false));
137
138        #[cfg(feature = "glr")]
139        {
140            assert_eq!(current_backend_for(true), profile.resolve_backend(true));
141        }
142    }
143
144    #[test]
145    fn resolve_runtime2_helpers_are_consistent() {
146        let profile = parser_feature_profile_for_runtime2(true);
147        let baseline = parser_feature_profile_for_runtime2(false);
148        assert_eq!(
149            resolve_runtime2_backend(false, true),
150            baseline.resolve_backend(true),
151            "runtime2 helpers should align with explicit profile resolution"
152        );
153
154        let report =
155            bdd_progress_report_for_runtime2_profile(BddPhase::Runtime, "Runtime2", profile);
156        let status = bdd_progress_status_line_for_runtime2_profile(BddPhase::Runtime, profile);
157        let snapshot = runtime2_governance_snapshot(BddPhase::Runtime, profile);
158        assert!(report.contains("Runtime2"));
159        assert!(status.starts_with("runtime:"));
160        assert_eq!(snapshot.profile, profile);
161    }
162
163    #[test]
164    fn matrix_helpers_are_reachable_from_runtime_matrix_crate() {
165        let profile = parser_feature_profile_for_runtime();
166        let runtime_matrix = bdd_governance_matrix_for_current_profile(BddPhase::Core);
167        assert_eq!(runtime_matrix.profile, profile);
168        assert_eq!(runtime_matrix.phase, BddPhase::Core);
169
170        let runtime2_matrix = bdd_governance_matrix_for_runtime2_profile(BddPhase::Runtime, false);
171        assert_eq!(
172            runtime2_matrix.profile,
173            parser_feature_profile_for_runtime2(false)
174        );
175    }
176
177    #[test]
178    fn reports_and_status_for_current_profile() {
179        let report = bdd_progress_report_for_current_profile(BddPhase::Core, "Core");
180        let status = bdd_status_line_for_current_profile(BddPhase::Runtime);
181        let snapshot = runtime_governance_snapshot(BddPhase::Runtime);
182        let current = parser_feature_profile_for_runtime();
183        assert!(report.contains("Core"));
184        assert!(report.contains("Feature profile:"));
185        assert!(report.contains("Governance status"));
186        assert!(status.starts_with("runtime:"));
187        assert_eq!(snapshot.profile, current);
188    }
189
190    #[test]
191    fn resolve_backend_for_runtime2_profile_works() {
192        let profile = parser_feature_profile_for_runtime2(false);
193        let backend = resolve_backend_for_runtime2_profile(profile, false);
194        assert_eq!(backend, profile.resolve_backend(false));
195    }
196
197    #[test]
198    fn runtime2_governance_snapshot_consistency() {
199        let profile = parser_feature_profile_for_runtime2(true);
200        let snap = runtime2_governance_snapshot(BddPhase::Core, profile);
201        assert_eq!(snap.phase, BddPhase::Core);
202        assert_eq!(snap.profile, profile);
203    }
204
205    #[test]
206    fn runtime2_governance_snapshot_runtime_phase() {
207        let profile = parser_feature_profile_for_runtime2(false);
208        let snap = runtime2_governance_snapshot(BddPhase::Runtime, profile);
209        assert_eq!(snap.phase, BddPhase::Runtime);
210        assert_eq!(snap.profile, profile);
211    }
212
213    #[test]
214    fn resolve_runtime2_backend_consistent_with_profile() {
215        let backend_enabled = resolve_runtime2_backend(true, false);
216        let profile = parser_feature_profile_for_runtime2(true);
217        assert_eq!(backend_enabled, profile.resolve_backend(false));
218
219        let backend_disabled = resolve_runtime2_backend(false, false);
220        let profile_off = parser_feature_profile_for_runtime2(false);
221        assert_eq!(backend_disabled, profile_off.resolve_backend(false));
222    }
223
224    #[test]
225    fn resolve_runtime2_backend_with_conflicts() {
226        let backend = resolve_runtime2_backend(true, true);
227        let profile = parser_feature_profile_for_runtime2(true);
228        assert_eq!(backend, profile.resolve_backend(true));
229    }
230
231    #[test]
232    fn current_backend_for_no_conflicts() {
233        let backend = current_backend_for(false);
234        let profile = parser_feature_profile_for_runtime();
235        assert_eq!(backend, profile.resolve_backend(false));
236    }
237
238    #[test]
239    fn bdd_progress_report_for_runtime2_profile_format() {
240        let profile = parser_feature_profile_for_runtime2(true);
241        let report =
242            bdd_progress_report_for_runtime2_profile(BddPhase::Runtime, "RT2 Report", profile);
243        assert!(report.contains("RT2 Report"));
244        assert!(report.contains("Governance status"));
245    }
246
247    #[test]
248    fn bdd_progress_status_line_for_runtime2_profile_format() {
249        let profile = parser_feature_profile_for_runtime2(true);
250        let core = bdd_progress_status_line_for_runtime2_profile(BddPhase::Core, profile);
251        let runtime = bdd_progress_status_line_for_runtime2_profile(BddPhase::Runtime, profile);
252        assert!(core.starts_with("core:"));
253        assert!(runtime.starts_with("runtime:"));
254    }
255
256    #[test]
257    fn bdd_governance_matrix_for_runtime2_profile_constructor() {
258        let matrix = bdd_governance_matrix_for_runtime2_profile(BddPhase::Core, true);
259        assert_eq!(matrix.phase, BddPhase::Core);
260        assert!(matrix.profile.glr);
261
262        let matrix_off = bdd_governance_matrix_for_runtime2_profile(BddPhase::Runtime, false);
263        assert_eq!(matrix_off.phase, BddPhase::Runtime);
264        assert!(!matrix_off.profile.glr);
265    }
266
267    #[test]
268    fn runtime_governance_snapshot_matches_current_profile() {
269        let snap = runtime_governance_snapshot(BddPhase::Runtime);
270        assert_eq!(snap.phase, BddPhase::Runtime);
271        assert_eq!(snap.profile, parser_feature_profile_for_runtime());
272    }
273}