From 6edb2b23004ce0df8048e8cf889b7d87beb53839 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 18 Oct 2026 12:23:53 +0000 Subject: [PATCH] Add review --verify to re-verify findings against local changes `proofline review --verify FINDING_ID...` sends `verify_finding_ids` with the local patch review and, once the review settles, prints each finding's local outcome and iteration. A clean working tree is an error with --verify, and --verify conflicts with --pr, --commit and --range. The public contract gains the verify request, response and local_reverifications fields from the server. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01LHXYbSMM1iHjbQqLZZCAjm --- openapi.public.json | 84 ++++++++++++++++++++++++++++++++++++++++++-- src/hooks.rs | 1 + src/lib.rs | 23 ++++++++++++ src/model.rs | 33 +++++++++++++++++ src/outcome.rs | 1 + src/render.rs | 16 +++++++++ tests/local_patch.rs | 83 ++++++++++++++++++++++++++++++++++++++++++- 7 files changed, 238 insertions(+), 3 deletions(-) diff --git a/openapi.public.json b/openapi.public.json index 43def6b..0d85adb 100644 --- a/openapi.public.json +++ b/openapi.public.json @@ -1866,6 +1866,13 @@ "description": "`PULL_REQUEST`, `DEPLOYMENT`, `PATCH`, a review of local changes\n sent as a patch, `COMMIT`, a review of pushed commits, or `FILES`,\n complete selected files at one pushed commit.", "type": "string" }, + "local_reverifications": { + "description": "For a patch review requested with `verify_finding_ids`, each finding\n it re-verifies against the patch and the outcome. The outcome is\n local: the pull request's finding is unchanged whatever it is. Absent\n otherwise.", + "items": { + "$ref": "#/components/schemas/LocalReverification" + }, + "type": "array" + }, "merge_gate": { "anyOf": [ { @@ -3348,6 +3355,43 @@ ], "type": "string" }, + "LocalReverification": { + "description": "One finding a patch review re-verified against the patch. The outcome is\n local: the pull request's finding is unchanged whatever it is.", + "properties": { + "checks": { + "description": "Each deterministic check the finding cited and its result on the\n patched head. Empty until an outcome is recorded." + }, + "finding_id": { + "format": "uuid", + "type": "string" + }, + "iteration": { + "description": "The request's number among the requests to re-verify the finding's\n series on this patch, at most 3.", + "format": "int32", + "type": "integer" + }, + "outcome": { + "$ref": "#/components/schemas/LocalReverificationOutcome" + } + }, + "required": [ + "finding_id", + "iteration", + "outcome", + "checks" + ], + "type": "object" + }, + "LocalReverificationOutcome": { + "description": "`RESOLVED_VERIFIED` needs the re-investigation to reject the finding's\n hypothesis and every cited check to pass. `STILL_PRESENT`: the hypothesis\n is supported, or a check still finds the mechanism. `NOT_VERIFIED`:\n anything else, including a review that ended without an answer.\n `PENDING`: the review is still running.", + "enum": [ + "RESOLVED_VERIFIED", + "STILL_PRESENT", + "NOT_VERIFIED", + "PENDING" + ], + "type": "string" + }, "NotAssessedView": { "properties": { "environment_display_name": { @@ -3738,6 +3782,15 @@ ], "default": null, "description": "The git hook that sent this request, when one did. A review recorded\n by an earlier identical request keeps the source it recorded." + }, + "verify_finding_ids": { + "default": [], + "description": "Open findings of one pull request in this repository to re-verify\n against the patch, at most 20. The review re-investigates each one\n and reports its outcome in `local_reverifications`; the pull\n request's findings are unchanged whatever it is. Requires an API\n token. Each finding's series takes at most 3 requests per patch, and\n the pull request at most 10 re-verification requests per hour,\n counted with those a coding agent makes through MCP.", + "items": { + "format": "uuid", + "type": "string" + }, + "type": "array" } }, "required": [ @@ -3761,12 +3814,20 @@ "description": "The review of this patch on this base, readable through the review\n and findings routes.", "format": "uuid", "type": "string" + }, + "verify": { + "description": "Each finding of `verify_finding_ids` the review re-verifies, one per\n finding series. Empty without `verify_finding_ids`.", + "items": { + "$ref": "#/components/schemas/PatchVerification" + }, + "type": "array" } }, "required": [ "review_id", "existing", - "patch_digest" + "patch_digest", + "verify" ], "type": "object" }, @@ -3778,6 +3839,25 @@ ], "type": "string" }, + "PatchVerification": { + "description": "One finding a patch review re-verifies against the patch.", + "properties": { + "finding_id": { + "format": "uuid", + "type": "string" + }, + "iteration": { + "description": "This request's number among the requests to re-verify the finding's\n series on this patch, at most 3.", + "format": "int32", + "type": "integer" + } + }, + "required": [ + "finding_id", + "iteration" + ], + "type": "object" + }, "PermissionView": { "enum": [ "PERMIT", @@ -6491,7 +6571,7 @@ }, "/api/v1/organizations/{org_id}/repositories/{repo_id}/patch-reviews": { "post": { - "description": "Reviews a unified diff against a commit GitHub has in the repository, and returns that patch's review when one exists. The review reads only that commit and the patch, and is never posted to a pull request. Requires live GitHub read access; the same patch on the same base always returns the same review.", + "description": "Reviews a unified diff against a commit GitHub has in the repository, and returns that patch's review when one exists. The review reads only that commit and the patch, and is never posted to a pull request. With `verify_finding_ids`, the review also re-verifies those open findings of one pull request against the patch and reports each outcome on the review, without changing the pull request's findings. Requires live GitHub read access; the same patch on the same base, re-verifying the same findings, always returns the same review.", "operationId": "request_patch_review", "parameters": [ { diff --git a/src/hooks.rs b/src/hooks.rs index 1dbcd9f..df17a55 100644 --- a/src/hooks.rs +++ b/src/hooks.rs @@ -490,6 +490,7 @@ async fn request( base_commit_sha: changes.base_commit_sha, patch: changes.patch, trigger_source: Some(hook.trigger_source()), + verify_finding_ids: Vec::new(), }; let requested = api.request_patch_review(repository_id, &request).await?; let (_, detail, state) = diff --git a/src/lib.rs b/src/lib.rs index ce648d2..562870e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -219,6 +219,16 @@ struct ReviewArgs { conflicts_with_all = ["pr", "staged", "include_untracked", "allow_path"] )] range: Option, + /// 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, /// 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")] @@ -654,6 +664,12 @@ async fn review_local(api: &Api, args: &ReviewArgs) -> anyhow::Result { ) .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 {}.", @@ -667,6 +683,7 @@ async fn review_local(api: &Api, args: &ReviewArgs) -> anyhow::Result { base_commit_sha: changes.base_commit_sha, patch: changes.patch, trigger_source: None, + verify_finding_ids: args.verify.clone(), }; let requested = api.request_patch_review(repository_id, &request).await?; say(&format!( @@ -679,6 +696,12 @@ async fn review_local(api: &Api, args: &ReviewArgs) -> anyhow::Result { 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 } diff --git a/src/model.rs b/src/model.rs index dc0dcf3..bfca8d7 100644 --- a/src/model.rs +++ b/src/model.rs @@ -64,6 +64,24 @@ pub struct ReviewDetail { pub run_number: Option, #[serde(default)] pub subjects: Vec, + /// 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, +} + +/// 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)] @@ -246,6 +264,11 @@ pub struct PatchReviewRequest { /// that predates the field still accepts a plain review. #[serde(default, skip_serializing_if = "Option::is_none")] pub trigger_source: Option, + /// 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, } /// The git hook that asked for a patch review. @@ -261,6 +284,16 @@ pub struct PatchReviewResponse { pub review_id: Uuid, pub existing: bool, pub patch_digest: String, + #[serde(default)] + pub verify: Vec, +} + +/// 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. diff --git a/src/outcome.rs b/src/outcome.rs index bc906ff..c5f87ec 100644 --- a/src/outcome.rs +++ b/src/outcome.rs @@ -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(), } } diff --git a/src/render.rs b/src/render.rs index c7a7d18..4c4578b 100644 --- a/src/render.rs +++ b/src/render.rs @@ -161,6 +161,21 @@ pub fn review(review: &ReviewDetail, state: Option, 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") } @@ -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(), } } diff --git a/tests/local_patch.rs b/tests/local_patch.rs index 538e023..6704439 100644 --- a/tests/local_patch.rs +++ b/tests/local_patch.rs @@ -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)] @@ -60,11 +61,52 @@ async fn upload( ) -> Json { assert!(fixture.authorized); assert_eq!(headers[header::AUTHORIZATION], format!("Bearer {TOKEN}")); + let verify: Vec = 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 { + 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": [], + }], })) } @@ -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)); @@ -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()) @@ -251,7 +303,6 @@ impl Checkout { "review", "--repo", "acme/web", - "--no-wait", ]) .args(flags); self.git_environment(&mut command); @@ -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)); @@ -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));