Skip to content
Merged
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
24 changes: 23 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,16 @@ struct ReviewArgs {
conflicts_with_all = ["pr", "staged", "include_untracked", "allow_path"]
)]
range: Option<String>,
/// Re-verify these open findings of one pull request against the local
/// changes, and print each one's outcome. The outcome is local: the pull
/// request's findings are unchanged. Needs an API token.
#[arg(
long,
value_name = "FINDING_ID",
num_args = 1..,
conflicts_with_all = ["pr", "commit", "range"]
)]
verify: Vec<Uuid>,
/// Request a fresh full review of the pull request after settlement. An
/// active review is reused with its recorded scope unchanged.
#[arg(long, requires = "pr")]
Expand Down Expand Up @@ -654,6 +664,12 @@ async fn review_local(api: &Api, args: &ReviewArgs) -> anyhow::Result<Verdict> {
)
.await?;
let files = changes.files();
if files == 0 && !args.verify.is_empty() {
bail!(
"nothing to re-verify against: the selected local changes match {}; --verify re-verifies findings against uncommitted changes",
changes.base_commit_sha
);
}
if files == 0 {
say(&format!(
"Nothing to review: the selected local changes match {}.",
Expand All @@ -667,7 +683,7 @@ async fn review_local(api: &Api, args: &ReviewArgs) -> anyhow::Result<Verdict> {
base_commit_sha: changes.base_commit_sha,
patch: changes.patch,
trigger_source: None,
verify_finding_ids: Vec::new(),
verify_finding_ids: args.verify.clone(),
};
let requested = api.request_patch_review(repository_id, &request).await?;
say(&format!(
Expand All @@ -680,6 +696,12 @@ async fn review_local(api: &Api, args: &ReviewArgs) -> anyhow::Result<Verdict> {
if files == 1 { "file" } else { "files" },
request.base_commit_sha
));
for verifying in &requested.verify {
say(&format!(
"Re-verifying finding {} against the local changes (request {} of 3).",
verifying.finding_id, verifying.iteration
));
}
finish(api, requested.review_id, args).await
}

Expand Down
32 changes: 31 additions & 1 deletion src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,24 @@ pub struct ReviewDetail {
pub run_number: Option<i64>,
#[serde(default)]
pub subjects: Vec<ReviewSubject>,
/// The findings a `--verify` patch review re-verified locally. Absent on
/// every other review.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub local_reverifications: Vec<LocalReverification>,
}

/// One finding a patch review re-verified against the local changes. The
/// outcome is local: the pull request's finding is unchanged.
#[derive(Debug, Deserialize, Serialize)]
pub struct LocalReverification {
pub finding_id: Uuid,
pub iteration: i32,
/// `RESOLVED_VERIFIED`, `STILL_PRESENT`, `NOT_VERIFIED` or `PENDING`.
pub outcome: String,
/// Each check the finding cited and its result on the patched head, kept
/// as the API returned it for `--json`.
#[serde(default)]
pub checks: serde_json::Value,
}

#[derive(Debug, Deserialize, Serialize)]
Expand Down Expand Up @@ -246,7 +264,9 @@ pub struct PatchReviewRequest {
/// that predates the field still accepts a plain review.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub trigger_source: Option<TriggerSource>,
/// Open findings to re-verify against the patch. Omitted for a plain review.
/// Open findings of one pull request to re-verify against the patch.
/// Omitted when empty, so a server that predates the field still accepts
/// a plain review.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub verify_finding_ids: Vec<Uuid>,
}
Expand All @@ -264,6 +284,16 @@ pub struct PatchReviewResponse {
pub review_id: Uuid,
pub existing: bool,
pub patch_digest: String,
#[serde(default)]
pub verify: Vec<PatchVerification>,
}

/// One finding a patch review re-verifies, and the request's number among
/// those for its series on this patch.
#[derive(Debug, Deserialize, Serialize)]
pub struct PatchVerification {
pub finding_id: Uuid,
pub iteration: i32,
}

/// Complete selected files at one exact pushed commit.
Expand Down
1 change: 1 addition & 0 deletions src/outcome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ mod tests {
pull_request_number: Some(7),
repository_full_name: Some("acme/web".to_owned()),
run_number: Some(1),
local_reverifications: Vec::new(),
}
}

Expand Down
16 changes: 16 additions & 0 deletions src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,21 @@ pub fn review(review: &ReviewDetail, state: Option<Outcome>, url: &Url) -> Strin
out.push(String::new());
assessment(&mut out, item);
}
if !review.local_reverifications.is_empty() {
out.push(String::new());
out.push(
"Re-verified against the local changes (the pull request's findings are unchanged):"
.to_owned(),
);
for item in &review.local_reverifications {
out.push(format!(
" {} {} (request {} of 3)",
item.finding_id,
one_line(&item.outcome),
item.iteration
));
}
}
out.push(String::new());
out.join("\n")
}
Expand Down Expand Up @@ -199,6 +214,7 @@ mod tests {
pull_request_number: Some(42),
repository_full_name: Some("acme/web".to_owned()),
run_number: Some(2),
local_reverifications: Vec::new(),
}
}

Expand Down
83 changes: 82 additions & 1 deletion tests/local_patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use tokio::sync::oneshot;
const ORG: &str = "0190f3a0-0000-7000-8000-000000000001";
const REPOSITORY: &str = "0190f3a0-0000-7000-8000-000000000022";
const REVIEW: &str = "0190f3a0-0000-7000-8000-000000000033";
const FINDING: &str = "0190f3a0-0000-7000-8000-000000000044";
const TOKEN: &str = "local-patch-test-token";

#[derive(Clone)]
Expand Down Expand Up @@ -60,11 +61,52 @@ async fn upload(
) -> Json<Value> {
assert!(fixture.authorized);
assert_eq!(headers[header::AUTHORIZATION], format!("Bearer {TOKEN}"));
let verify: Vec<Value> = body["verify_finding_ids"]
.as_array()
.into_iter()
.flatten()
.map(|id| json!({ "finding_id": id, "iteration": 1 }))
.collect();
fixture.uploads.lock().unwrap().push(body);
Json(json!({
"review_id": REVIEW,
"existing": false,
"patch_digest": "a".repeat(64),
"verify": verify,
}))
}

/// A settled patch review that re-verified `FINDING` against the patch.
async fn settled_review(headers: HeaderMap) -> Json<Value> {
assert_eq!(headers[header::AUTHORIZATION], format!("Bearer {TOKEN}"));
Json(json!({
"id": REVIEW,
"kind": "PATCH",
"status": "COMPLETED",
"assessment_count": 1,
"assessments": [{
"id": REVIEW,
"environment_display_name": "production",
"status": "COMPLETED",
"findings": [],
"checks": { "receipt_recorded": true, "status": "READY", "families": [] },
"incompleteness_kind": null,
"reason_codes": null,
"release_evidence_gap": null,
}],
"code_assessment": null,
"base_commit_sha": "b".repeat(40),
"head_commit_sha": "c".repeat(40),
"open_items": null,
"pull_request_number": null,
"repository_full_name": "acme/web",
"run_number": null,
"local_reverifications": [{
"finding_id": FINDING,
"iteration": 1,
"outcome": "RESOLVED_VERIFIED",
"checks": [],
}],
}))
}

Expand Down Expand Up @@ -122,6 +164,10 @@ impl Server {
&format!("/api/v1/organizations/{ORG}/repositories/{REPOSITORY}/file-reviews"),
post(file_review),
)
.route(
&format!("/api/v1/organizations/{ORG}/reviews/{REVIEW}"),
get(settled_review),
)
.fallback(|| async { StatusCode::NOT_FOUND })
.with_state(fixture.clone())
.layer(middleware::from_fn_with_state(fixture.clone(), observe));
Expand Down Expand Up @@ -239,6 +285,12 @@ impl Checkout {
}

async fn review(&self, server: &Server, allowed: &[&str], flags: &[&str]) -> Output {
let mut flags = flags.to_vec();
flags.push("--no-wait");
self.review_and_wait(server, allowed, &flags).await
}

async fn review_and_wait(&self, server: &Server, allowed: &[&str], flags: &[&str]) -> Output {
let mut command = Command::new(env!("CARGO_BIN_EXE_proofline"));
command
.current_dir(self.root())
Expand All @@ -251,7 +303,6 @@ impl Checkout {
"review",
"--repo",
"acme/web",
"--no-wait",
])
.args(flags);
self.git_environment(&mut command);
Expand Down Expand Up @@ -340,6 +391,35 @@ async fn asynchronous_patch_acknowledgment_respects_json_without_polling() {
}
}

/// `--verify` sends the named findings with the local patch and, once the
/// review settles, prints each one's local outcome.
#[tokio::test]
async fn verify_sends_the_findings_and_prints_their_local_outcomes() {
let checkout = Checkout::new(&[("kept.txt", "base\n")]).await;
checkout.write("kept.txt", "fixed\n").await;
let server = Server::start(true).await;
let output = checkout
.review_and_wait(&server, &[], &["--verify", FINDING])
.await;
let stderr = String::from_utf8_lossy(&output.stderr);
assert_eq!(output.status.code(), Some(0), "{stderr}");
let uploads = server.fixture.uploads.lock().unwrap().clone();
assert_eq!(uploads.len(), 1);
assert_eq!(uploads[0]["verify_finding_ids"], json!([FINDING]));
assert!(
stderr.contains(&format!(
"Re-verifying finding {FINDING} against the local changes (request 1 of 3)."
)),
"{stderr}"
);
let stdout = String::from_utf8(output.stdout).unwrap();
assert!(
stdout.contains(&format!(" {FINDING} RESOLVED_VERIFIED (request 1 of 3)")),
"{stdout}"
);
server.close().await;
}

#[tokio::test]
async fn local_selection_uploads_only_selected_bytes_and_refuses_before_http() {
let github = format!("ghp_{}", "S".repeat(36));
Expand All @@ -362,6 +442,7 @@ async fn local_selection_uploads_only_selected_bytes_and_refuses_before_http() {
vec!["--staged", "--include-untracked"],
vec!["--staged", "--pr", "7"],
vec!["--include-untracked", "--pr", "7"],
vec!["--verify", FINDING, "--pr", "7"],
] {
let output = checkout.review(&server, &[], &flags).await;
assert_eq!(output.status.code(), Some(1));
Expand Down
Loading