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: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ 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`.

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.
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. A gap in the review, its code lane or an environment appears as an error annotation, and findings from an incomplete lane are marked partial. The review link contains the full result.

`proofline ci deploy --until 1h` waits until Proofline has recorded the deploy checks of the job's commit through the hour check, then exits 0 when each recorded `HEALTHY` with no gap, 3 when a deploy failed or regressed, and 2 when the result is not established. Without `--timeout`, a wait for `--until 20m` or `--until 1h` lasts until that check is due for the selected deploys, and at least 30 minutes; other checks wait 30 minutes, and `--until 1d` needs `--timeout`. `--environment`, `--task`, `--run` and `--attempt` select the deploy, and on a `workflow_run` event the commit, `--run` and `--attempt` default to the completed run's. `--json` prints the response. Each deploy prints one line per check. A deploy that rolled the environment back to an earlier commit first prints a `rollback` line with the page of the deploy it restores, when Proofline recorded one, and the pages of the deploys it rolled back. A deploy whose newest check found its service serving an earlier deploy again first prints a `rolled back` line, and stops printing it once a later check finds none; with `--json` the response carries it as `rolled_back`. Both lines can appear for one deploy. A rollback's exit code comes from its checks like any other deploy's; neither line changes it or means the rollback fixed anything.

Expand Down
206 changes: 192 additions & 14 deletions src/annotations.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,120 @@
//! Findings as GitHub Actions workflow commands. The runner reads each
//! `::error file=...,line=...::message` line from a step's output and shows it
//! on the pull request's diff, on every GitHub plan. Findings quote reviewer
//! output and repository content, so every value is escaped: a newline in a
//! claim must never start a second command.
//! Findings and gaps as GitHub Actions workflow commands. The runner reads
//! each `::error file=...,line=...::message` line from a step's output and
//! shows it on the pull request's diff, on every GitHub plan. Findings quote
//! reviewer output and repository content, so every value is escaped: a
//! newline in a claim must never start a second command.

use std::cmp::Reverse;
use std::collections::BTreeSet;
use std::io::Write;

use crate::model::{Finding, ReviewDetail};
use crate::outcome::{self, Outcome};
use crate::severity::Severity;
use crate::{outcome, sarif, text};
use crate::{sarif, text};

/// Writes one annotation per finding that is not resolved. A finding with a
/// verified location at the review's head is placed on that file and line;
/// any other finding is annotated on the job without a location.
/// Writes one annotation per unresolved finding and one per gap in the
/// result. Gaps come first so a long finding list cannot hide them.
pub(super) fn write(detail: &ReviewDetail, out: &mut impl Write) -> std::io::Result<()> {
let head = detail.head_commit_sha.as_deref().unwrap_or_default();
if let Some(code) = outcome::code_assessment(detail) {
for finding in &code.findings {
annotate(out, finding, "code", head)?;
let state = outcome::terminal(detail);
let code = outcome::code_assessment(detail);

if let Some(code) = code {
for reason in outcome::code_gap(code).unwrap_or_default() {
gap(
out,
"Code-only",
&reason,
&format!("Code-only: {reason}. Findings here are not a complete result."),
)?;
}
} else if outcome::code_unavailable(detail) {
gap(
out,
"Code-only",
"CODE_ASSESSMENT_UNAVAILABLE",
"Code-only: CODE_ASSESSMENT_UNAVAILABLE. Findings here are not a complete result.",
)?;
}
for assessment in &detail.assessments {
let name = text::one_line(&assessment.environment_display_name);
let reasons: BTreeSet<String> = outcome::gap(assessment)
.unwrap_or_default()
.into_iter()
.collect();
for reason in &reasons {
gap(
out,
&name,
reason,
&format!("{name}: {reason}. Findings here are not a complete result."),
)?;
}
}
if let Some(reason) = outcome::review_gap(detail) {
gap(
out,
"Review",
reason,
&format!("Review: {reason}. This is not a complete result."),
)?;
}
if state != Some(Outcome::Completed) {
let reason = match state {
None => "REVIEW_IN_PROGRESS",
Some(Outcome::Failed) => "REVIEW_FAILED",
Some(Outcome::Stopped) => "REVIEW_STOPPED",
Some(Outcome::Incomplete | Outcome::Completed) => "REVIEW_RESULT_INCOMPLETE",
};
gap(
out,
"Review",
reason,
&format!(
"Review {}: {reason}. These annotations are not a complete result.",
detail.id
),
)?;
}

if let Some(code) = code {
let partial = outcome::code_gap(code).is_some();
let mut findings: Vec<&Finding> = code.findings.iter().collect();
findings.sort_by_key(|item| Reverse(Severity::parse(&item.severity)));
for finding in findings {
annotate(out, finding, "code", head, partial)?;
}
}
for assessment in &detail.assessments {
for finding in &assessment.findings {
annotate(out, finding, &assessment.environment_display_name, head)?;
let partial = outcome::gap(assessment).is_some();
let mut findings: Vec<&Finding> = assessment.findings.iter().collect();
findings.sort_by_key(|item| Reverse(Severity::parse(&item.severity)));
let lane = text::one_line(&assessment.environment_display_name);
for finding in findings {
annotate(out, finding, &lane, head, partial)?;
}
}
Ok(())
}

/// A gap is an error on the job, with no file or line to place it on.
fn gap(out: &mut impl Write, lane: &str, reason: &str, message: &str) -> std::io::Result<()> {
let title = format!("Proofline {lane}: {reason}");
writeln!(
out,
"::error title={}::{}",
escape_property(&title),
escape_data(message)
)
}

fn annotate(
out: &mut impl Write,
finding: &Finding,
lane: &str,
head: &str,
partial: bool,
) -> std::io::Result<()> {
if outcome::resolved(finding) {
return Ok(());
Expand All @@ -43,6 +125,11 @@ fn annotate(
Some(Severity::Warning) => "warning",
None => "notice",
};
let lane = if partial {
format!("{lane} (partial)")
} else {
lane.to_owned()
};
let mut properties = Vec::new();
if let Some((path, start, end)) = finding
.evidence_refs
Expand Down Expand Up @@ -82,6 +169,61 @@ fn escape_property(value: &str) -> String {
#[cfg(test)]
mod tests {
use super::*;
use crate::model::{Assessment, Checks};
use uuid::Uuid;

fn assessment(status: &str, incomplete: bool) -> Assessment {
Assessment {
id: Uuid::nil(),
environment_display_name: "production".to_owned(),
status: status.to_owned(),
findings: vec![Finding {
id: Uuid::nil(),
finding_fingerprint: None,
severity: "SERIOUS".to_owned(),
risk_domain: "data_integrity".to_owned(),
claim: "orders are dropped".to_owned(),
impact: "customers are charged twice".to_owned(),
lifecycle_state: "NEW".to_owned(),
remediation: None,
evidence_refs: Vec::new(),
}],
checks: Checks {
receipt_recorded: true,
status: "READY".to_owned(),
families: Vec::new(),
},
incompleteness_kind: incomplete.then(|| "WORLD_UNAVAILABLE".to_owned()),
reason_codes: None,
release_evidence_gap: None,
}
}

fn review(status: &str, assessments: Vec<Assessment>, count: i64) -> ReviewDetail {
ReviewDetail {
id: Uuid::nil(),
kind: "PULL_REQUEST".to_owned(),
status: status.to_owned(),
assessment_count: count,
assessments,
code_assessment: None,
subjects: Vec::new(),
base_commit_sha: None,
head_commit_sha: None,
open_items: None,
pull_request_number: Some(7),
repository_id: None,
repository_full_name: Some("acme/web".to_owned()),
run_number: Some(1),
local_reverifications: Vec::new(),
}
}

fn write_review(detail: &ReviewDetail) -> String {
let mut out = Vec::new();
write(detail, &mut out).unwrap();
String::from_utf8(out).unwrap()
}

#[test]
fn values_cannot_end_the_command_or_start_another() {
Expand All @@ -93,4 +235,40 @@ mod tests {
assert_eq!(escape_property("a:b,c%\nd"), "a%3Ab%2Cc%25%0Ad");
assert_eq!(escape_data("ok\u{1b}[2J"), "ok\u{FFFD}[2J");
}

#[test]
fn an_incomplete_assessment_names_its_gap_and_marks_its_findings_partial() {
let text = write_review(&review(
"COMPLETED",
vec![assessment("INCOMPLETE", true)],
1,
));
assert!(text.contains(
"::error title=Proofline production%3A WORLD_UNAVAILABLE::production: WORLD_UNAVAILABLE. Findings here are not a complete result."
));
assert!(text.contains(
"::error title=Proofline Review%3A REVIEW_RESULT_INCOMPLETE::Review 00000000-0000-0000-0000-000000000000: REVIEW_RESULT_INCOMPLETE. These annotations are not a complete result."
));
assert!(text.contains(
"::error title=Proofline production (partial)%3A data_integrity::orders are dropped"
));
}

#[test]
fn a_complete_review_has_no_gap_annotations() {
let text = write_review(&review(
"COMPLETED",
vec![assessment("COMPLETED", false)],
1,
));
assert!(!text.contains("::error title=Proofline Review"));
assert!(!text.contains("(partial)"));
assert_eq!(text.lines().count(), 1);
}

#[test]
fn a_review_still_running_reports_that_its_result_is_unknown() {
let text = write_review(&review("RUNNING", Vec::new(), 1));
assert!(text.contains("REVIEW_IN_PROGRESS"));
}
}
93 changes: 93 additions & 0 deletions tests/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2521,6 +2521,99 @@ async fn ci_review_annotations_put_open_findings_on_the_diff_as_escaped_workflow
assert_eq!(result["outcome"], "COMPLETED");
}

#[tokio::test]
async fn ci_review_annotations_name_gaps_and_mark_partial_findings() {
let app = Router::new()
.route(
&format!("/api/v1/organizations/{ORG}/repository-names"),
get(|| async {
Json(json!({ "repositories": [{ "id": CI_REPOSITORY, "full_name": "acme/app" }] }))
}),
)
.route(
&format!("/api/v1/organizations/{ORG}/reviews"),
get(|| async {
Json(json!({
"items": [{
"id": CI_REVIEW,
"kind": "PULL_REQUEST",
"status": "COMPLETED",
"created_at": "2026-10-01T00:00:00Z",
"head_commit_sha": CI_HEAD,
"pull_request_number": 12,
"repository_id": CI_REPOSITORY,
"run_number": 1,
}],
"next_cursor": null,
"truncated": false,
"filters": { "repositories": [], "environments": [], "authors": [] },
}))
}),
)
.route(
&format!("/api/v1/organizations/{ORG}/reviews/{CI_REVIEW}"),
get(|| async {
Json(json!({
"id": CI_REVIEW,
"kind": "PULL_REQUEST",
"status": "COMPLETED",
"head_commit_sha": CI_HEAD,
"pull_request_number": 12,
"run_number": 1,
"assessment_count": 1,
"assessments": [{
"id": "0190f3a0-0000-7000-8000-0000000000f2",
"environment_display_name": "production",
"status": "INCOMPLETE",
"incompleteness_kind": "WORLD_UNAVAILABLE",
"findings": [{
"id": "0190f3a0-0000-7000-8000-0000000000a1",
"severity": "SERIOUS",
"risk_domain": "data_integrity",
"claim": "retries drop orders",
"impact": "orders are lost",
"lifecycle_state": "NEW",
"evidence_refs": [],
}],
"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());
tokio::spawn(async move { axum::serve(listener, app).await.unwrap() });

let output = cli(
&origin,
&[
"ci",
"review",
"--repo",
"acme/app",
"--commit",
CI_HEAD,
"--timeout",
"0",
"--json",
"--annotations",
],
)
.await;
assert_eq!(output.status.code(), Some(2));
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(stderr.contains(
"::error title=Proofline production%3A WORLD_UNAVAILABLE::production: WORLD_UNAVAILABLE. Findings here are not a complete result."
));
assert!(stderr.contains("::error title=Proofline Review%3A REVIEW_RESULT_INCOMPLETE::Review "));
assert!(stderr.contains(
"::error title=Proofline production (partial)%3A data_integrity::retries drop orders"
));
// The gap annotations do not change the result on stdout.
let result: Value = serde_json::from_slice(&output.stdout).unwrap();
assert_eq!(result["outcome"], "INCOMPLETE");
}

#[tokio::test]
async fn native_tools_keep_tenant_paths_and_reruns_make_one_attempt() {
let requests = Arc::new(Mutex::new(Vec::new()));
Expand Down