(
repo: &Repository,
report: &IncrementalReport,
intents: &[IntentCriteria],
observation: &SubmittedFinding,
)
| 522 | } |
| 523 | |
| 524 | fn validate_input( |
| 525 | repo: &Repository, |
| 526 | report: &IncrementalReport, |
| 527 | intents: &[IntentCriteria], |
| 528 | observation: &SubmittedFinding, |
| 529 | ) -> CliResult<()> { |
| 530 | let finding = &observation.finding; |
| 531 | finding.validate().map_err(invalid)?; |
| 532 | let change = report |
| 533 | .changes |
| 534 | .iter() |
| 535 | .find(|change| change.selected_root && change.hash == finding.change) |
| 536 | .ok_or_else(|| invalid("finding is not about an exact selected root"))?; |
| 537 | if observation.pass == ReviewPass::IntentConformance && finding.acceptance_criteria.is_empty() { |
| 538 | return Err(invalid( |
| 539 | "intent-conformance finding requires an explicit acceptance-criterion assessment", |
| 540 | )); |
| 541 | } |
| 542 | let mut linked = BTreeSet::new(); |
| 543 | for link in &finding.acceptance_criteria { |
| 544 | if !linked.insert(&link.criterion) { |
| 545 | return Err(invalid("duplicate criterion assessment")); |
| 546 | } |
| 547 | if !intents |
| 548 | .iter() |
| 549 | .filter(|intent| governed(change, intent)) |
| 550 | .any(|intent| { |
| 551 | intent |
| 552 | .node |
| 553 | .has_acceptance_criterion |
| 554 | .iter() |
| 555 | .any(|criterion| criterion.id == link.criterion) |
| 556 | }) |
| 557 | { |
| 558 | return Err(invalid("finding criterion is missing or does not belong to this change's unambiguous governing intent")); |
| 559 | } |
| 560 | } |
| 561 | let hash = Hash::from_base32(finding.change.as_bytes()) |
| 562 | .ok_or_else(|| invalid("invalid finding change"))?; |
| 563 | for location in &finding.locations { |
| 564 | if location.path.is_empty() |
| 565 | || Path::new(&location.path) |
| 566 | .components() |
| 567 | .any(|part| !matches!(part, Component::Normal(_))) |
| 568 | { |
| 569 | return Err(invalid( |
| 570 | "finding requires a repository-relative recorded path", |
| 571 | )); |
| 572 | } |
| 573 | let bytes = match location.side { |
| 574 | SourceSide::Before => repo.get_file_content_before_change(&location.path, &hash), |
| 575 | SourceSide::After => repo.get_file_content_after_change(&location.path, &hash), |
| 576 | } |
| 577 | .map_err(CliError::Repository)? |
| 578 | .ok_or_else(|| invalid("finding location has no recorded content on the requested side"))?; |
| 579 | let source = std::str::from_utf8(&bytes) |
| 580 | .map_err(|_| invalid("finding source location is not UTF-8 text"))?; |
| 581 | if location.end_line as usize > source.split('\n').count() { |
no test coverage detected