From 3152e2f0b945d26a387eea299c0a36cc4a503e49 Mon Sep 17 00:00:00 2001 From: ammartahamohamedy Date: Thu, 3 Dec 2026 16:01:25 +0200 Subject: [PATCH] Name the review a hook could not read --- src/hooks.rs | 52 ++++++++++++++++++++++++++++++++++++++------------ tests/hooks.rs | 43 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 80 insertions(+), 15 deletions(-) diff --git a/src/hooks.rs b/src/hooks.rs index 7d5550a..3c45889 100644 --- a/src/hooks.rs +++ b/src/hooks.rs @@ -370,6 +370,12 @@ enum Report { Nothing, /// No review result, and why. Unreviewed(String), + /// The server accepted the patch, but no read of its review answered. + Unread { + review_id: Uuid, + url: String, + reason: String, + }, /// The review as last read; `state` is `None` while it runs. Read { review_id: Uuid, @@ -505,19 +511,30 @@ async fn request( verify_finding_ids: Vec::new(), }; let requested = api.request_patch_review(repository_id, &request).await?; - let (_, detail, state) = read_review(api, requested.review_id, Some(deadline), false) - .await? - .context("Proofline did not answer a read of the review before the deadline")?; - anyhow::Ok((requested.review_id, detail, state)) + anyhow::Ok(requested.review_id) + }; + let review_id = match requested.await { + Ok(review_id) => review_id, + Err(error) => return Report::Unreviewed(format!("{error:#}")), + }; + // The review exists from here on, so every report names it. + let url = api.review_url(review_id); + let reason = match read_review(api, review_id, Some(deadline), false).await { + Ok(Some((_, detail, state))) => { + return Report::Read { + review_id, + url, + detail: Box::new(detail), + state, + }; + } + Ok(None) => "Proofline did not answer a read of the review before the deadline".to_owned(), + Err(error) => format!("{error:#}"), }; - match requested.await { - Ok((review_id, detail, state)) => Report::Read { - review_id, - url: api.review_url(review_id), - detail: Box::new(detail), - state, - }, - Err(error) => Report::Unreviewed(format!("{error:#}")), + Report::Unread { + review_id, + url: url.to_string(), + reason, } } @@ -645,6 +662,17 @@ fn conclude( one_line(reason) )); } + Report::Unread { + review_id, + url, + reason, + } => { + gap = true; + say(&format!( + "Proofline could not read the review of {label}: {}. It continues at {url}; read it later with `proofline findings --review {review_id}`.", + one_line(reason) + )); + } Report::Read { review_id, url, diff --git a/tests/hooks.rs b/tests/hooks.rs index bc910b0..aed8bcf 100644 --- a/tests/hooks.rs +++ b/tests/hooks.rs @@ -7,6 +7,8 @@ use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::{Arc, Mutex}; use axum::extract::{Query, State}; +use axum::http::StatusCode; +use axum::response::IntoResponse; use axum::routing::{get, post}; use axum::{Json, Router}; use serde_json::{Value, json}; @@ -77,8 +79,9 @@ async fn serve_review( } /// As [`serve_review`], but with `script` read `n` returns the findings at -/// `script.1[n]` in place of `findings`, every read past that list waits past -/// any hook timeout, and `script.0` counts the reads that started. +/// `script.1[n]` in place of `findings` (a `null` step answers 502), every +/// read past that list waits past any hook timeout, and `script.0` counts the +/// reads that started. async fn serve_reads( uploads: Uploads, status: &'static str, @@ -123,6 +126,9 @@ async fn serve_reads( if stall { tokio::time::sleep(std::time::Duration::from_secs(600)).await; } + if findings.is_null() { + return StatusCode::BAD_GATEWAY.into_response(); + } let mut document = json!({ "id": REVIEW, "kind": "PATCH", @@ -150,7 +156,7 @@ async fn serve_reads( document["assessments"][0]["findings"] = json!([]); } } - Json(document) + Json(document).into_response() } }), ) @@ -625,6 +631,37 @@ async fn time_out(script: Vec) -> (usize, Output) { (reads.load(Ordering::SeqCst), output) } +// Once the server accepted the patch, a failed first read (a 502) or one the +// timeout cuts off still names the review that runs. +#[tokio::test] +async fn a_review_the_hook_could_not_read_is_still_named() { + for (script, reason) in [ + (vec![Value::Null], "502"), + ( + vec![], + "did not answer a read of the review before the deadline", + ), + ] { + let (reads, output) = time_out(script).await; + let text = stderr(&output); + assert_eq!(reads, 1, "{text}"); + assert_eq!(output.status.code(), Some(0), "{text}"); + assert!(!text.contains("could not review"), "{text}"); + assert!(text.contains(reason), "{text}"); + // Still a gap, which `onIncomplete` decides. + assert!( + text.contains("The commit proceeds without a complete review."), + "{text}" + ); + assert!( + text.contains(&format!( + "/reviews/{REVIEW}; read it later with `proofline findings --review {REVIEW}`." + )), + "{text}" + ); + } +} + // A read the timeout cuts off leaves the earlier one standing, so the // finding that read recorded still blocks. #[tokio::test]