Skip to main content

adze_governance_status_core/
lib.rs

1//! Status-line and backend-description helpers for governance reporting.
2//!
3//! This crate isolates machine-readable status output and conflict-backend
4//! descriptions so BDD governance cores can focus on snapshot/report assembly.
5
6#![forbid(unsafe_op_in_unsafe_fn)]
7#![deny(missing_docs)]
8#![cfg_attr(feature = "strict_api", deny(unreachable_pub))]
9#![cfg_attr(not(feature = "strict_api"), warn(unreachable_pub))]
10#![cfg_attr(feature = "strict_docs", deny(missing_docs))]
11#![cfg_attr(not(feature = "strict_docs"), allow(missing_docs))]
12
13pub use adze_bdd_grid_core::{BddPhase, BddScenario, bdd_progress};
14pub use adze_feature_policy_core::{ParserBackend, ParserFeatureProfile};
15
16/// Advisory profile description for conflict-capable grammars.
17pub const GLR_CONFLICT_FALLBACK: &str =
18    "Pure-rust without GLR: conflicts panic unless `glr` feature is enabled";
19
20/// Describe the conflict backend behavior for a given feature profile.
21pub const fn describe_backend_for_conflicts(profile: ParserFeatureProfile) -> &'static str {
22    if profile.glr {
23        ParserBackend::GLR.name()
24    } else if profile.pure_rust {
25        GLR_CONFLICT_FALLBACK
26    } else {
27        ParserBackend::TreeSitter.name()
28    }
29}
30
31/// Return a stable machine-readable status line for dashboards and CI.
32pub fn bdd_progress_status_line(
33    phase: BddPhase,
34    scenarios: &[BddScenario],
35    profile: ParserFeatureProfile,
36) -> String {
37    let (implemented, total) = bdd_progress(phase, scenarios);
38    let backend = profile.resolve_backend(false).name();
39    let phase_label = match phase {
40        BddPhase::Core => "core",
41        BddPhase::Runtime => "runtime",
42    };
43
44    format!(
45        "{phase_label}:{implemented}/{total}:{backend}:{profile}",
46        implemented = implemented,
47        total = total,
48        backend = backend,
49    )
50}
51
52#[cfg(test)]
53mod tests {
54    use super::*;
55    use adze_bdd_grid_core::GLR_CONFLICT_PRESERVATION_GRID;
56
57    #[test]
58    fn fallback_mentions_glr() {
59        assert!(GLR_CONFLICT_FALLBACK.contains("GLR") || GLR_CONFLICT_FALLBACK.contains("glr"));
60    }
61
62    #[test]
63    fn describe_backend_returns_glr_for_glr_profile() {
64        let profile = ParserFeatureProfile {
65            pure_rust: true,
66            tree_sitter_standard: false,
67            tree_sitter_c2rust: false,
68            glr: true,
69        };
70        assert_eq!(
71            describe_backend_for_conflicts(profile),
72            ParserBackend::GLR.name()
73        );
74    }
75
76    #[test]
77    fn status_line_is_phase_prefixed() {
78        let profile = ParserFeatureProfile::current();
79        let core =
80            bdd_progress_status_line(BddPhase::Core, GLR_CONFLICT_PRESERVATION_GRID, profile);
81        let runtime =
82            bdd_progress_status_line(BddPhase::Runtime, GLR_CONFLICT_PRESERVATION_GRID, profile);
83
84        assert!(core.starts_with("core:"));
85        assert!(runtime.starts_with("runtime:"));
86    }
87}