xbp-analysis 10.57.0

Language-agnostic static analysis (error-handling / Aspirator-style) for XBP
Documentation
use super::{base_caps, concepts_of, finding_from_concept};
use crate::domain::concepts::ConceptKind;
use crate::domain::model::LanguageModel;
use crate::domain::rule::{Rule, RuleMeta};
use crate::domain::types::{Confidence, Finding, Severity};
use std::sync::OnceLock;

#[derive(Default)]
pub struct UnboundedRetryRule;

impl Rule for UnboundedRetryRule {
    fn meta(&self) -> &RuleMeta {
        static META: OnceLock<RuleMeta> = OnceLock::new();
        META.get_or_init(|| RuleMeta {
            id: "unbounded-retry".into(),
            name: "Unbounded retry".into(),
            description: "Retry loop without limit or backoff.".into(),
            default_severity: Severity::High,
            required_capabilities: base_caps(),
            autofix_safe: false,
        })
    }

    fn evaluate(&self, model: &LanguageModel) -> Vec<Finding> {
        concepts_of(model, ConceptKind::Retry)
            .filter(|(_, c)| c.bounded == Some(false))
            .map(|(lang, c)| {
                finding_from_concept(
                    &self.meta().id,
                    lang,
                    c,
                    Severity::High,
                    Confidence::Medium,
                    "Retry loop has no explicit bound or backoff.",
                    "Hot-loop retries amplify outages and thrash dependencies.",
                    "Cap attempts, add exponential backoff with jitter, and fail after budget.",
                )
            })
            .collect()
    }
}