Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,17 +566,17 @@ fn assessment_line(assessment: &Assessment, complete: bool) -> String {
}

/// Whether the review has a finding at or above `fail_on`. A hook's review
/// has no finding decisions, so its findings decide: a CODE finding counts
/// only in a complete review and while it is not `RESOLVED`; an environment
/// finding counts in any review.
/// has no finding decisions, so its open findings decide, as they do for
/// `--fail-on` and the CI annotations: a CODE finding counts only in a
/// complete review, and a resolved finding in either lane never counts.
fn reaches_fail_on(detail: &ReviewDetail, complete: bool, fail_on: Severity) -> bool {
let code = outcome::code_assessment(detail)
.is_some_and(|code| complete && outcome::code_reaches(code, fail_on));
code || detail
.assessments
.iter()
.flat_map(|assessment| &assessment.findings)
.any(|finding| fail_on.reached_by(&finding.severity))
.any(|finding| !outcome::resolved(finding) && fail_on.reached_by(&finding.severity))
}

/// Prints a read review: its status, its CODE result and each environment,
Expand Down
29 changes: 29 additions & 0 deletions tests/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,35 @@ async fn the_exit_policy_blocks_only_on_request_and_never_reads_a_gap_as_clean()
assert!(staged.contains("+fn main() { retry() }"));
}

#[tokio::test]
async fn a_resolved_environment_finding_does_not_block_a_commit() {
let checkout = Checkout::new().await;
tokio::fs::write(checkout.root().join("orders.rs"), "fn main() { retry() }\n")
.await
.unwrap();
checkout.git(&["add", "orders.rs"]).await;
checkout
.git(&["config", "proofline.hook.pre-commit.mode", "block"])
.await;
// The review is complete, and its one environment finding is resolved.
let origin = serve_review(
Uploads::default(),
"COMPLETED",
1,
findings("SERIOUS", false, "RESOLVED"),
None,
)
.await;
let output = checkout
.proofline(&origin, &["hook", "run", "pre-commit"], "")
.await;
let text = stderr(&output);
assert_eq!(output.status.code(), Some(0), "{text}");
assert!(!text.contains("blocked this commit"), "{text}");
// A resolved finding still prints, so the developer sees what was fixed.
assert!(text.contains("SERIOUS orders.rs:1"), "{text}");
}

#[tokio::test]
async fn only_a_complete_review_prints_no_findings() {
let checkout = Checkout::new().await;
Expand Down