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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 14 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Severity>,
#[command(flatten)]
repository: RepositoryArgs,
#[command(flatten)]
Expand Down Expand Up @@ -1230,7 +1235,15 @@ async fn findings(api: &Api, args: &FindingsArgs) -> anyhow::Result<Verdict> {
} 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)]
Expand Down
90 changes: 86 additions & 4 deletions tests/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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] {
Expand Down Expand Up @@ -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": [],
},
}))
}),
)
Expand Down Expand Up @@ -1940,18 +2010,21 @@ 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,
open,
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")]
Expand All @@ -1964,13 +2037,22 @@ 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!(
"{} {open:?} {assessment} {fail_on:?} {code_finding:?}: {stderr}",
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,
Expand Down