Skip to main content

adze_bdd_governance_core/
lib.rs

1//! Core implementation of governance matrix snapshots and profile-aware matrix composition.
2//!
3//! Reporting helpers are split into `adze-bdd-governance-reporting-core`, which
4//! in turn re-exports status helpers from `adze-governance-status-core`. This
5//! crate re-exports those reporting helpers for compatibility.
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_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/// Snapshot of governance progress for one phase and feature profile.
25#[derive(Debug, Clone, Copy, PartialEq, Eq)]
26pub struct BddGovernanceSnapshot {
27    /// The phase being evaluated.
28    pub phase: BddPhase,
29    /// Number of implemented scenarios.
30    pub implemented: usize,
31    /// Total number of scenarios in the slice.
32    pub total: usize,
33    /// The active parser feature profile used to interpret behavior.
34    pub profile: ParserFeatureProfile,
35}
36
37impl BddGovernanceSnapshot {
38    /// Returns true when all scenarios for this phase are implemented.
39    pub const fn is_fully_implemented(self) -> bool {
40        self.implemented == self.total
41    }
42
43    /// Convenience helper to expose the active non-conflict backend.
44    pub const fn non_conflict_backend(self) -> ParserBackend {
45        self.profile.resolve_backend(false)
46    }
47}
48
49/// Typed composition of a BDD scenario grid and a parser feature profile.
50#[derive(Debug, Clone, Copy, PartialEq, Eq)]
51pub struct BddGovernanceMatrix {
52    /// BDD phase being evaluated.
53    pub phase: BddPhase,
54    /// Active parser feature profile for this build.
55    pub profile: ParserFeatureProfile,
56    /// Scenario source used for reporting.
57    pub scenarios: &'static [BddScenario],
58}
59
60impl BddGovernanceMatrix {
61    /// Construct a matrix view from an explicit scenario slice.
62    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    /// Construct the canonical matrix for conflict-preservation development.
75    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    /// Build a full snapshot for the configured matrix.
84    pub fn snapshot(self) -> BddGovernanceSnapshot {
85        bdd_governance_snapshot(self.phase, self.scenarios, self.profile)
86    }
87
88    /// Render a profile-aware progress report for the configured matrix.
89    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    /// Render a compact status line for the configured matrix.
94    pub fn status_line(self) -> String {
95        bdd_progress_status_line(self.phase, self.scenarios, self.profile)
96    }
97
98    /// Returns true when all scenarios in the matrix are implemented.
99    pub fn is_fully_implemented(self) -> bool {
100        self.snapshot().is_fully_implemented()
101    }
102}
103
104/// Build a compact governance snapshot for a phase.
105pub 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}