diff --git a/src/hooks.rs b/src/hooks.rs index 90b3997..ce10094 100644 --- a/src/hooks.rs +++ b/src/hooks.rs @@ -566,9 +566,9 @@ 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)); @@ -576,7 +576,7 @@ fn reaches_fail_on(detail: &ReviewDetail, complete: bool, fail_on: Severity) -> .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, diff --git a/tests/hooks.rs b/tests/hooks.rs index 3473f84..0627f96 100644 --- a/tests/hooks.rs +++ b/tests/hooks.rs @@ -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;