diff --git a/README.md b/README.md index eea0165..bda86f7 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,8 @@ Native knowledge, plan, fix and configuration commands send the selected organiz `proofline review --range BASE..HEAD --fail-on serious` exits 3 when a complete review has an unresolved finding at or above the threshold. PR reviews use the server’s effective open-item counts; other reviews count unresolved findings. Incomplete and unavailable results retain their nonzero exits. `--fail-on` cannot be combined with `--no-wait`. +`proofline findings --pr 7 --fail-on serious` applies the same threshold to the review that `findings` reads, without requesting one, so a merge or release script can gate on the pull request's existing review with a read-only sign-in that lacks `reviews:request`. With no selector it measures the latest review of the checkout's `HEAD`. A review that has not finished exits 2; add `--wait` to wait for its result first. `--fail-on` also works with `--json` and `--sarif`, and changes only the exit code. + In GitHub Actions, `proofline ci review --annotations` prints unresolved findings as workflow annotations at verified cited lines. Findings without a verified head location appear on the job. The review link contains the full result. For a CodePipeline execution or Amplify job, run `proofline ci deploy --commit SHA --aws-run ID` in a later pipeline. Add `--environment-id UUID` to select its Proofline environment. The output names the AWS provider and run ID. Proofline records a CodePipeline deploy only after the execution succeeds, so a reader inside that execution waits until its timeout and exits 2. On a GitHub `workflow_run` event, an explicit `--aws-run` disables the default Actions run and attempt filters. diff --git a/src/lib.rs b/src/lib.rs index 8c6f1d6..f7061fe 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -393,6 +393,11 @@ struct FindingsArgs { /// Export this retained pull-request review as SARIF 2.1.0. #[arg(long, requires = "review", conflicts_with_all = ["json", "pr", "head"])] sarif: bool, + /// Exit 3 when the completed review has an open finding at or above this + /// severity, measured as `review --fail-on` measures it. It only reads the + /// existing review, so it needs no `reviews:request` and starts nothing. + #[arg(long, value_enum, value_name = "SEVERITY")] + fail_on: Option, #[command(flatten)] repository: RepositoryArgs, #[command(flatten)] @@ -1230,7 +1235,15 @@ async fn findings(api: &Api, args: &FindingsArgs) -> anyhow::Result { } else { OutputFormat::from_json(args.output.json) }; - show(api, review_id, args.wait, &args.output, format, None).await + show( + api, + review_id, + args.wait, + &args.output, + format, + args.fail_on, + ) + .await } #[derive(Debug, thiserror::Error)] diff --git a/tests/http.rs b/tests/http.rs index 940dc12..6ef1afd 100644 --- a/tests/http.rs +++ b/tests/http.rs @@ -388,6 +388,72 @@ async fn findings_timeout_applies_only_to_waiting_and_never_panics() { } } +/// `findings --fail-on` measures only a finished review: a review that is +/// still running is not a pass, whatever it has found so far, and `--wait` +/// measures it once it completes. +#[tokio::test] +async fn findings_fail_on_never_passes_a_review_that_has_not_finished() { + for (wait, code) in [(false, 2), (true, 3)] { + let reads = Arc::new(AtomicUsize::new(0)); + let observed = Arc::clone(&reads); + let app = Router::new().route( + &format!("/api/v1/organizations/{ORG}/reviews/{SELECTED_REVIEW}"), + get(move || { + let observed = Arc::clone(&observed); + async move { + let running = observed.fetch_add(1, Ordering::SeqCst) == 0; + let status = if running { "RUNNING" } else { "COMPLETED" }; + Json(json!({ + "id": SELECTED_REVIEW, + "kind": "PULL_REQUEST", + "status": status, + "assessment_count": 1, + "open_items": { + "open_findings": 1, + "serious_findings": 1, + "accepted_risks": 0, + "not_assessed": [], + }, + "assessments": [{ + "id": "0190f3a0-0000-7000-8000-000000000044", + "environment_display_name": "production", + "status": status, + "findings": [], + "checks": { "receipt_recorded": true, "status": "READY", "families": [] }, + }], + })) + } + }), + ); + let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap(); + let origin = format!("http://{}", listener.local_addr().unwrap()); + let server = tokio::spawn(async move { axum::serve(listener, app).await.unwrap() }); + let mut args = vec![ + "findings", + "--review", + SELECTED_REVIEW, + "--fail-on", + "serious", + "--timeout", + "1", + ]; + if wait { + args.push("--wait"); + } + let output = cli(&origin, &args).await; + let stderr = String::from_utf8_lossy(&output.stderr); + assert_eq!(output.status.code(), Some(code), "wait={wait}: {stderr}"); + assert_eq!( + stderr.contains("at or above the --fail-on severity"), + wait, + "{stderr}" + ); + assert_eq!(stderr.contains("pass --wait"), !wait, "{stderr}"); + assert_eq!(reads.load(Ordering::SeqCst), if wait { 2 } else { 1 }); + server.abort(); + } +} + #[tokio::test] async fn asynchronous_pull_request_acknowledgment_respects_json_without_polling() { for existing in [false, true] { @@ -1450,7 +1516,11 @@ async fn ci_console( }], "next_cursor": null, "truncated": false, - "filters": { "repositories": [], "environments": [], "authors": [] }, + "filters": { + "repositories": [{ "id": CI_REPOSITORY, "name": "acme/app" }], + "environments": [], + "authors": [], + }, })) }), ) @@ -1940,7 +2010,7 @@ async fn ci_review_fail_on_exits_three_for_an_open_finding_of_a_complete_review( } else { "COMPLETED" }; - let (origin, _) = ci_console( + let (origin, requests) = ci_console( "PULL_REQUEST", StatusCode::OK, assessment, @@ -1948,10 +2018,13 @@ async fn ci_review_fail_on_exits_three_for_an_open_finding_of_a_complete_review( code_finding, ) .await; - // `review --pr` measures a pull-request review as `ci review` does. - let commands: [&[&str]; 2] = [ + // `review --pr` measures a pull-request review as `ci review` does, + // and `findings` measures the review it reads the same way. + let commands: [&[&str]; 4] = [ &["ci", "review", "--repo", "acme/app", "--commit", CI_HEAD], &["review", "--repo", "acme/app", "--pr", "12"], + &["findings", "--review", CI_REVIEW], + &["findings", "--repo", "acme/app", "--head", CI_HEAD], ]; for (command, (fail_on, code)) in commands.into_iter().flat_map(|command| { [None, Some("warning"), Some("serious")] @@ -1964,6 +2037,7 @@ async fn ci_review_fail_on_exits_three_for_an_open_finding_of_a_complete_review( if let Some(threshold) = fail_on { args.extend(["--fail-on", threshold]); } + requests.lock().unwrap().clear(); let output = cli(&origin, &args).await; let stderr = String::from_utf8_lossy(&output.stderr); let case = format!( @@ -1971,6 +2045,14 @@ async fn ci_review_fail_on_exits_three_for_an_open_finding_of_a_complete_review( command[0] ); assert_eq!(output.status.code(), Some(code), "{case}"); + if command[0] == "findings" { + // `findings --fail-on` only reads: it never requests a review. + let requests = requests.lock().unwrap(); + assert!( + requests.iter().all(|request| request.starts_with("GET ")), + "{case}: {requests:?}" + ); + } assert_eq!( stderr.contains("at or above the --fail-on severity"), code == 3,