(
repo: &Repository,
report: &IncrementalReport,
input: Option<&[u8]>,
risk_profile: Option<&[u8]>,
)
| 125 | } |
| 126 | |
| 127 | pub(super) fn build( |
| 128 | repo: &Repository, |
| 129 | report: &IncrementalReport, |
| 130 | input: Option<&[u8]>, |
| 131 | risk_profile: Option<&[u8]>, |
| 132 | ) -> CliResult<ReviewGraph> { |
| 133 | let profile = if let Some(bytes) = risk_profile { |
| 134 | if bytes.len() > 64 * 1024 { |
| 135 | return Err(invalid("risk profile exceeds 64 KiB")); |
| 136 | } |
| 137 | serde_json::from_slice::<atomic_audit::risk::RiskProfile>(bytes) |
| 138 | .map_err(|error| invalid(format!("invalid risk profile: {error}")))? |
| 139 | } else { |
| 140 | atomic_audit::risk::RiskProfile::default() |
| 141 | }; |
| 142 | profile.validate().map_err(invalid)?; |
| 143 | let intents = catalog(report); |
| 144 | let mut criterion_ids = BTreeSet::new(); |
| 145 | for intent in &intents { |
| 146 | for criterion in &intent.node.has_acceptance_criterion { |
| 147 | if !criterion_ids.insert(&criterion.id) { |
| 148 | return Err(invalid("ambiguous duplicate criterion ID in review scope")); |
| 149 | } |
| 150 | } |
| 151 | } |
| 152 | let scope = ReviewScope { |
| 153 | project: repo.project_id().map_err(CliError::Repository)?.to_urn(), |
| 154 | view: report.source["view"].as_str().unwrap_or_default().into(), |
| 155 | view_state: report.source["view_state"] |
| 156 | .as_str() |
| 157 | .unwrap_or_default() |
| 158 | .into(), |
| 159 | selected_roots: report.selected_roots.clone(), |
| 160 | dependency_closure: report.dependency_closure.clone(), |
| 161 | source_membership_hash: membership_hash( |
| 162 | repo, |
| 163 | report.source["view"].as_str().unwrap_or_default(), |
| 164 | )?, |
| 165 | intent_sources: intents |
| 166 | .iter() |
| 167 | .map(|intent| (intent.node.id.clone(), intent.source_hash.clone())) |
| 168 | .collect(), |
| 169 | }; |
| 170 | if repo |
| 171 | .get_view_info(&scope.view) |
| 172 | .map_err(CliError::Repository)? |
| 173 | .state |
| 174 | .to_base32() |
| 175 | != scope.view_state |
| 176 | { |
| 177 | return Err(invalid( |
| 178 | "review source changed while resolving graph scope; retry inspection", |
| 179 | )); |
| 180 | } |
| 181 | let mut observations: Vec<_> = report |
| 182 | .analyses() |
| 183 | .flat_map(|(_, analysis)| { |
| 184 | analysis |
no test coverage detected