Skip to content
Open
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
52 changes: 40 additions & 12 deletions src/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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,
Expand Down
43 changes: 40 additions & 3 deletions tests/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -150,7 +156,7 @@ async fn serve_reads(
document["assessments"][0]["findings"] = json!([]);
}
}
Json(document)
Json(document).into_response()
}
}),
)
Expand Down Expand Up @@ -625,6 +631,37 @@ async fn time_out(script: Vec<Value>) -> (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]
Expand Down