Build only evidence-linked, constructible work. Execution is not a verdict.
(report: &Value, mut criteria: Vec<CriterionEvidence>)
| 306 | |
| 307 | /// Build only evidence-linked, constructible work. Execution is not a verdict. |
| 308 | pub fn construct(report: &Value, mut criteria: Vec<CriterionEvidence>) -> Self { |
| 309 | criteria.sort_by(|a, b| (&a.intent, &a.criterion).cmp(&(&b.intent, &b.criterion))); |
| 310 | let mut cards = BTreeMap::new(); |
| 311 | let mut diagnostics = BTreeSet::new(); |
| 312 | let observations: Vec<_> = report["graph"]["nodes"] |
| 313 | .as_array() |
| 314 | .into_iter() |
| 315 | .flatten() |
| 316 | .filter(|node| matches!(node["kind"].as_str(), Some("check" | "metric"))) |
| 317 | .collect(); |
| 318 | let mut identities = BTreeMap::new(); |
| 319 | let mut ambiguous = BTreeSet::new(); |
| 320 | for node in &observations { |
| 321 | if let Some(id) = node["id"].as_str() { |
| 322 | if identities |
| 323 | .insert(id, *node) |
| 324 | .is_some_and(|previous| previous != *node) |
| 325 | { |
| 326 | ambiguous.insert(id); |
| 327 | } |
| 328 | } |
| 329 | } |
| 330 | for node in observations { |
| 331 | let reference = node["id"].as_str().unwrap_or_default(); |
| 332 | if reference.is_empty() { |
| 333 | continue; |
| 334 | } |
| 335 | if ambiguous.contains(reference) { |
| 336 | diagnostics.insert(( |
| 337 | reference.into(), |
| 338 | "ambiguous observation identity; no review item was created".into(), |
| 339 | )); |
| 340 | continue; |
| 341 | } |
| 342 | let (source, path, _card, mut result) = match observation(report, node) { |
| 343 | Ok(value) => value, |
| 344 | Err(reason) => { |
| 345 | diagnostics.insert((reference.to_string(), reason)); |
| 346 | continue; |
| 347 | } |
| 348 | }; |
| 349 | result["source"] = json!(source); |
| 350 | result["path"] = json!(path); |
| 351 | let mut linked = false; |
| 352 | for criterion in &criteria { |
| 353 | let delta_anchor = criterion.anchors.iter().find(|anchor| { |
| 354 | cites(anchor, &format!("delta:{reference}")) |
| 355 | || cites(anchor, &format!("delta:{path}")) |
| 356 | }); |
| 357 | if delta_anchor.is_some() && result.get("delta").is_none() { |
| 358 | diagnostics.insert((criterion.criterion.clone(), format!("requested delta for {reference} cannot be constructed; no current-value substitute was queued"))); |
| 359 | continue; |
| 360 | } |
| 361 | let anchor = delta_anchor.or_else(|| { |
| 362 | criterion.anchors.iter().find(|anchor| { |
| 363 | cites(anchor, reference) |
| 364 | || cites(anchor, &path) |
| 365 | || cites(anchor, &format!("current:{reference}")) |
nothing calls this directly
no test coverage detected