adze_bdd_governance_core/
lib.rs1#![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_bdd_governance_reporting_core::{
15 GLR_CONFLICT_FALLBACK, ParserBackend, bdd_progress_report_with_profile,
16 bdd_progress_status_line, describe_backend_for_conflicts,
17};
18pub use adze_bdd_grid_core::{
19 BddPhase, BddScenario, BddScenarioStatus, GLR_CONFLICT_PRESERVATION_GRID, bdd_progress,
20 bdd_progress_report,
21};
22pub use adze_feature_policy_core::ParserFeatureProfile;
23
24#[derive(Debug, Clone, Copy, PartialEq, Eq)]
26pub struct BddGovernanceSnapshot {
27 pub phase: BddPhase,
29 pub implemented: usize,
31 pub total: usize,
33 pub profile: ParserFeatureProfile,
35}
36
37impl BddGovernanceSnapshot {
38 pub const fn is_fully_implemented(self) -> bool {
40 self.implemented == self.total
41 }
42
43 pub const fn non_conflict_backend(self) -> ParserBackend {
45 self.profile.resolve_backend(false)
46 }
47}
48
49#[derive(Debug, Clone, Copy, PartialEq, Eq)]
51pub struct BddGovernanceMatrix {
52 pub phase: BddPhase,
54 pub profile: ParserFeatureProfile,
56 pub scenarios: &'static [BddScenario],
58}
59
60impl BddGovernanceMatrix {
61 pub const fn new(
63 phase: BddPhase,
64 profile: ParserFeatureProfile,
65 scenarios: &'static [BddScenario],
66 ) -> Self {
67 Self {
68 phase,
69 profile,
70 scenarios,
71 }
72 }
73
74 pub const fn standard(profile: ParserFeatureProfile) -> Self {
76 Self {
77 phase: BddPhase::Core,
78 profile,
79 scenarios: GLR_CONFLICT_PRESERVATION_GRID,
80 }
81 }
82
83 pub fn snapshot(self) -> BddGovernanceSnapshot {
85 bdd_governance_snapshot(self.phase, self.scenarios, self.profile)
86 }
87
88 pub fn report(self, phase_title: &str) -> String {
90 bdd_progress_report_with_profile(self.phase, self.scenarios, phase_title, self.profile)
91 }
92
93 pub fn status_line(self) -> String {
95 bdd_progress_status_line(self.phase, self.scenarios, self.profile)
96 }
97
98 pub fn is_fully_implemented(self) -> bool {
100 self.snapshot().is_fully_implemented()
101 }
102}
103
104pub fn bdd_governance_snapshot(
106 phase: BddPhase,
107 scenarios: &[BddScenario],
108 profile: ParserFeatureProfile,
109) -> BddGovernanceSnapshot {
110 let (implemented, total) = bdd_progress(phase, scenarios);
111 BddGovernanceSnapshot {
112 phase,
113 implemented,
114 total,
115 profile,
116 }
117}
118
119#[cfg(test)]
120mod tests {
121 use super::*;
122
123 #[test]
124 fn snapshot_reports_expected_counts() {
125 let snapshot = bdd_governance_snapshot(
126 BddPhase::Core,
127 GLR_CONFLICT_PRESERVATION_GRID,
128 ParserFeatureProfile::current(),
129 );
130 assert_eq!(snapshot.implemented, 6);
131 assert_eq!(snapshot.total, GLR_CONFLICT_PRESERVATION_GRID.len());
132 assert_eq!(snapshot.phase, BddPhase::Core);
133 }
134
135 #[test]
136 fn status_line_stable_shape() {
137 let profile = ParserFeatureProfile {
138 pure_rust: false,
139 tree_sitter_standard: true,
140 tree_sitter_c2rust: false,
141 glr: false,
142 };
143
144 let status =
145 bdd_progress_status_line(BddPhase::Runtime, GLR_CONFLICT_PRESERVATION_GRID, profile);
146 assert!(status.starts_with("runtime:"));
147 assert!(status.contains("tree-sitter C runtime"));
148 assert!(status.contains("tree-sitter-standard"));
149 }
150
151 #[test]
152 fn report_with_profile_is_annotated() {
153 let profile = ParserFeatureProfile::current();
154 let report = bdd_progress_report_with_profile(
155 BddPhase::Runtime,
156 GLR_CONFLICT_PRESERVATION_GRID,
157 "Runtime",
158 profile,
159 );
160
161 assert!(report.contains("Feature profile:"));
162 assert!(report.contains("Non-conflict backend:"));
163 assert!(report.contains("Conflict grammars:"));
164 assert!(report.contains("Governance progress:"));
165 }
166
167 #[test]
168 fn matrix_adapter_stable_api() {
169 let matrix = BddGovernanceMatrix::standard(ParserFeatureProfile::current());
170 assert_eq!(matrix.phase, BddPhase::Core);
171 assert!(
172 matrix
173 .report("Core")
174 .contains("=== BDD GLR Conflict Preservation Test Summary ===")
175 );
176 assert!(matrix.status_line().starts_with("core:"));
177 }
178}