Skip to main content

normalize_native_rules/
budget.rs

1//! Native rule integration for the budget system.
2//!
3//! Delegates to `normalize_budget::service::build_budget_report`.
4
5use normalize_output::OutputFormatter;
6use normalize_output::diagnostics::DiagnosticsReport;
7use serde::Serialize;
8use std::path::Path;
9
10/// Report returned by the budget native rule check.
11///
12/// Wraps the `DiagnosticsReport` produced by the budget service so that it
13/// can be formatted standalone (as text) or converted to a `DiagnosticsReport`
14/// for the rules engine.
15#[derive(Debug, Serialize, schemars::JsonSchema)]
16pub struct BudgetRulesReport(pub DiagnosticsReport);
17
18impl OutputFormatter for BudgetRulesReport {
19    fn format_text(&self) -> String {
20        self.0.format_text()
21    }
22
23    fn format_pretty(&self) -> String {
24        self.0.format_pretty()
25    }
26}
27
28impl From<BudgetRulesReport> for DiagnosticsReport {
29    fn from(report: BudgetRulesReport) -> Self {
30        report.0
31    }
32}
33
34/// Build a BudgetRulesReport from the budget check for use in `normalize rules run`.
35///
36/// Called by the native rules engine. Returns an empty report if no budget file
37/// exists or all limits are within bounds.
38pub fn build_budget_report(root: &Path) -> BudgetRulesReport {
39    let factory: normalize_budget::DiffMetricFactory = normalize_budget::default_diff_metrics;
40    BudgetRulesReport(normalize_budget::service::build_budget_report(
41        root, &factory,
42    ))
43}