Apply independent rule triggers and take the highest band. Correlated size signals are not summed into a spurious numeric probability or bug count.
(facts: RiskFacts, profile: &RiskProfile)
| 133 | /// Apply independent rule triggers and take the highest band. Correlated size |
| 134 | /// signals are not summed into a spurious numeric probability or bug count. |
| 135 | pub fn assess(facts: RiskFacts, profile: &RiskProfile) -> Result<RiskEvaluation, &'static str> { |
| 136 | profile.validate()?; |
| 137 | if !facts.available { |
| 138 | return Ok(RiskEvaluation { |
| 139 | model: MODEL.into(), |
| 140 | profile: profile.clone(), |
| 141 | rating: RiskLevel::Unknown, |
| 142 | evidence_complete: false, |
| 143 | rules: vec![], |
| 144 | facts, |
| 145 | }); |
| 146 | } |
| 147 | let mut rules = Vec::new(); |
| 148 | let mut trigger = |id: &str, level, reason: String, dimensions: &[&str]| { |
| 149 | let mut references: Vec<_> = dimensions |
| 150 | .iter() |
| 151 | .flat_map(|key| facts.references.get(*key).into_iter().flatten()) |
| 152 | .cloned() |
| 153 | .collect(); |
| 154 | references.sort(); |
| 155 | references.dedup(); |
| 156 | references.truncate(8); |
| 157 | rules.push(RiskRule { |
| 158 | id: id.into(), |
| 159 | level, |
| 160 | reason, |
| 161 | references, |
| 162 | }); |
| 163 | }; |
| 164 | let public_growth = facts |
| 165 | .public_growth |
| 166 | .unwrap_or(0) |
| 167 | .saturating_add(facts.added_file_public_units.unwrap_or(0)); |
| 168 | let public_churn = public_growth.saturating_add(facts.public_removed.unwrap_or(0)); |
| 169 | if facts.production_functions >= profile.broad_functions |
| 170 | && facts.production_paths.len() >= profile.broad_files |
| 171 | && facts.components.len() >= profile.broad_components |
| 172 | { |
| 173 | trigger("risk.broad-production-change", RiskLevel::High, format!("{} production functions across {} source files and {} components exceed the broad-change thresholds ({}/{}/{})", facts.production_functions, facts.production_paths.len(), facts.components.len(), profile.broad_functions, profile.broad_files, profile.broad_components), &["change"]); |
| 174 | } |
| 175 | if facts.production_functions >= profile.api_functions |
| 176 | && facts.components.len() >= profile.api_components |
| 177 | && public_churn >= profile.api_growth |
| 178 | { |
| 179 | trigger("risk.cross-component-api-churn", RiskLevel::High, format!("{} production functions across {} components with {} declared public units added/removed meet the integration thresholds ({}/{}/{})", facts.production_functions, facts.components.len(), public_churn, profile.api_functions, profile.api_components, profile.api_growth), &["change", "surface"]); |
| 180 | } |
| 181 | if facts.existing_production_callers >= profile.propagation_callers |
| 182 | && facts.existing_caller_files >= profile.propagation_files |
| 183 | && facts.existing_production_functions > 0 |
| 184 | { |
| 185 | trigger("risk.existing-consumer-exposure", RiskLevel::High, format!("Modified existing declarations have {} observed production consumers in {} files (thresholds {}/{})", facts.existing_production_callers, facts.existing_caller_files, profile.propagation_callers, profile.propagation_files), &["change", "calls"]); |
| 186 | } |
| 187 | if facts.production_functions >= profile.moderate_functions |
| 188 | || facts.production_paths.len() >= profile.moderate_files |
| 189 | || facts.components.len() >= 2 |
| 190 | { |
| 191 | trigger( |
| 192 | "risk.change-diffusion", |