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
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ Native knowledge, plan, fix and configuration commands send the selected organiz

`proofline rerun REVIEW_ID` requests the original immutable subject and waits, while `--no-wait` returns its link. Reruns require `reviews:rerun`. `proofline guidance --repo owner/name` requires `guidance:read`, and `proofline fix-prompt FINDING_ID` requires `findings:read`. History, guidance, and fix prompts print JSON; prompt text remains untrusted.

`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 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, and when the threshold is reached the last line names those 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.
Each finding with a recorded decision prints a `decision:` line naming it (`CONFIRMED`, `DISMISSED`, `FIXED`, `ACCEPTED_RISK` or `ALREADY_COVERED`), who made it, where and when. A decided finding stays listed: a dismissal or risk acceptance can expire, and the review does not say whether it has. The text also lists two kinds of open findings that the counts include but no assessment's findings hold. Environment findings with no severity print under their environment, led by what published them: `CONFIRMED_REQUIREMENT` for a violated gate requirement, `INVESTIGATION` for the environment investigation, or `SHARED_IDENTITY` for a workload that loses access through a shared identity. The environment's finding count includes them, and those of an assessment the review does not list print on their own. Open environment findings of earlier runs that the review did not find again print under `Still open from earlier runs`, with the review that recorded each.

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 decided finding's title ends with its decision, such as `(DISMISSED)`. Environment findings with no severity appear on the job as notices whose title ends with what published them, and earlier runs' open findings as errors or warnings by severity, or notices for a severity this CLI does not know. `--sarif` records each decision as the result's `decision` property, never as a suppression. 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
164 changes: 151 additions & 13 deletions src/annotations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@

use std::io::Write;

use crate::model::{Finding, ReviewDetail};
use crate::model::{EarlierFinding, Finding, InvestigationFinding, ReviewDetail};
use crate::severity::Severity;
use crate::{outcome, 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 finding that is not resolved, then the
/// [`unlisted`] ones, so every finding `--fail-on` measures is on the job. 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.
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) {
Expand All @@ -25,9 +27,64 @@ pub(super) fn write(detail: &ReviewDetail, out: &mut impl Write) -> std::io::Res
annotate(out, finding, &assessment.environment_display_name, head)?;
}
}
unlisted(detail, out)
}

/// The open findings the review counts but lists in no assessment.
fn unlisted(detail: &ReviewDetail, out: &mut impl Write) -> std::io::Result<()> {
for finding in &detail.investigation_findings {
investigation(out, detail, finding)?;
}
for finding in detail
.open_items
.iter()
.flat_map(|open| &open.earlier_findings)
{
earlier(out, finding)?;
}
Ok(())
}

/// A severity this CLI does not know yet is still shown, as a notice.
fn command(severity: &str) -> &'static str {
match Severity::parse(severity) {
Some(Severity::Serious) => "error",
Some(Severity::Warning) => "warning",
None => "notice",
}
}

/// An environment finding with no severity is a notice on the job, its title
/// ending with what published it.
fn investigation(
out: &mut impl Write,
detail: &ReviewDetail,
finding: &InvestigationFinding,
) -> std::io::Result<()> {
let environment = detail
.assessments
.iter()
.find(|assessment| assessment.id == finding.assessment_id)
.map_or("environment", |assessment| {
&assessment.environment_display_name
});
let title = format!(
"Proofline {environment}: {} ({})",
finding.area,
finding.published_by()
);
emit(out, "notice", &[titled(&title)], &finding.title)
}

fn earlier(out: &mut impl Write, finding: &EarlierFinding) -> std::io::Result<()> {
let title = format!("Proofline earlier run {}", finding.run_number);
let message = finding
.title
.as_deref()
.unwrap_or("A finding of an earlier run is still open.");
emit(out, command(&finding.severity), &[titled(&title)], message)
}

fn annotate(
out: &mut impl Write,
finding: &Finding,
Expand All @@ -37,12 +94,6 @@ fn annotate(
if outcome::resolved(finding) {
return Ok(());
}
// A severity this CLI does not know yet is still shown, as a notice.
let command = match Severity::parse(&finding.severity) {
Some(Severity::Serious) => "error",
Some(Severity::Warning) => "warning",
None => "notice",
};
let mut properties = Vec::new();
if let Some((path, start, end)) = finding
.evidence_refs
Expand All @@ -53,14 +104,32 @@ fn annotate(
properties.push(format!("line={start}"));
properties.push(format!("endLine={end}"));
}
let title = format!("Proofline {lane}: {}", finding.risk_domain);
properties.push(format!("title={}", escape_property(&title)));
let decision = finding
.latest_validation
.as_ref()
.map(|decision| format!(" ({})", decision.validation))
.unwrap_or_default();
let title = format!("Proofline {lane}: {}{decision}", finding.risk_domain);
properties.push(titled(&title));
let message = format!("{}\n\n{}", finding.claim, finding.impact);
emit(out, command(&finding.severity), &properties, &message)
}

fn titled(title: &str) -> String {
format!("title={}", escape_property(title))
}

fn emit(
out: &mut impl Write,
command: &str,
properties: &[String],
message: &str,
) -> std::io::Result<()> {
writeln!(
out,
"::{command} {}::{}",
properties.join(","),
escape_data(&message)
escape_data(message)
)
}

Expand All @@ -83,6 +152,75 @@ fn escape_property(value: &str) -> String {
mod tests {
use super::*;

fn written(write: impl FnOnce(&mut Vec<u8>) -> std::io::Result<()>) -> String {
let mut out = Vec::new();
write(&mut out).unwrap();
String::from_utf8(out).unwrap()
}

#[test]
fn an_environment_finding_of_an_unlisted_assessment_still_reaches_the_job() {
let detail: ReviewDetail = serde_json::from_value(serde_json::json!({
"id": "00000000-0000-0000-0000-000000000001",
"kind": "PULL_REQUEST",
"status": "RUNNING",
"assessment_count": 1,
"assessments": [],
"code_assessment": null,
"base_commit_sha": null,
"head_commit_sha": null,
"open_items": null,
"pull_request_number": 1,
"repository_id": null,
"repository_full_name": null,
"run_number": 1,
}))
.unwrap();
let mut finding = InvestigationFinding {
assessment_id: uuid::Uuid::nil(),
area: "network".to_owned(),
title: "egress is blocked".to_owned(),
source: None,
};
assert_eq!(
written(|out| investigation(out, &detail, &finding)),
"::notice title=Proofline environment%3A network (ENVIRONMENT)::egress is blocked\n"
);
finding.source = Some("SHARED_IDENTITY".to_owned());
assert_eq!(
written(|out| investigation(out, &detail, &finding)),
"::notice title=Proofline environment%3A network (SHARED_IDENTITY)::egress is blocked\n"
);
}

#[test]
fn an_earlier_finding_of_an_unknown_severity_is_a_notice() {
let finding = EarlierFinding {
review_id: uuid::Uuid::nil(),
run_number: 2,
severity: "CRITICAL".to_owned(),
title: Some("Disk fills".to_owned()),
};
assert_eq!(
written(|out| earlier(out, &finding)),
"::notice title=Proofline earlier run 2::Disk fills\n"
);
}

#[test]
fn an_untitled_earlier_finding_says_what_it_is() {
let finding = EarlierFinding {
review_id: uuid::Uuid::nil(),
run_number: 3,
severity: "WARNING".to_owned(),
title: None,
};
assert_eq!(
written(|out| earlier(out, &finding)),
"::warning title=Proofline earlier run 3::A finding of an earlier run is still open.\n"
);
}

#[test]
fn values_cannot_end_the_command_or_start_another() {
assert_eq!(escape_data("50% a\r\nb::c"), "50%25 a\u{FFFD}%0Ab::c");
Expand Down
51 changes: 45 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1300,9 +1300,7 @@ async fn show(
Some(Outcome::Completed) => {
let verdict = review_verdict(&detail, fail_on);
match verdict {
Verdict::ThresholdReached => {
say("The review has an open finding at or above the --fail-on severity.");
}
Verdict::ThresholdReached => say(&threshold_reached(measured_by(&detail))),
Verdict::Unavailable => say(
"Proofline returned the completed review without `open_items`, so --fail-on could not be measured. It is not a pass.",
),
Expand Down Expand Up @@ -1606,9 +1604,7 @@ fn say_ci_ending(
api.review_url(review_id)
)),
Some(Outcome::Completed) => match verdict {
Verdict::ThresholdReached => {
say("The review has an open finding at or above the --fail-on severity.");
}
Verdict::ThresholdReached => say(&threshold_reached(measured_by(detail))),
Verdict::Unavailable => say(
"Proofline returned the completed review without `open_items`, so --fail-on could not be measured. It is not a pass.",
),
Expand All @@ -1618,6 +1614,29 @@ fn say_ci_ending(
}
}

/// The counts `review_verdict` measured: a pull-request review's open items.
/// Any other review is measured by its own findings.
fn measured_by(detail: &ReviewDetail) -> Option<&OpenItems> {
detail
.open_items
.as_ref()
.filter(|_| detail.kind == "PULL_REQUEST")
}

/// Why `--fail-on` failed, with the server's counts when they measured it.
fn threshold_reached(measured: Option<&OpenItems>) -> String {
let reason = "The review has an open finding at or above the --fail-on severity.";
measured.map_or_else(
|| reason.to_owned(),
|open| {
format!(
"{reason} Proofline counts {} open findings, {} of them SERIOUS.",
open.open_findings, open.serious_findings
)
},
)
}

/// How `ci review` ends for a review read as `state`. Completeness decides
/// first: only a complete review is measured against `fail_on`, because the
/// findings of a review that did not finish are not its whole result. The
Expand Down Expand Up @@ -2249,13 +2268,33 @@ mod tests {
let unmeasured = detail("PULL_REQUEST", serde_json::Value::Null);
assert_eq!(review_verdict(&unmeasured, serious), Verdict::Unavailable);
assert_eq!(review_verdict(&unmeasured, None), Verdict::Done);
// Only the counts that measured the verdict are reported with it.
assert!(measured_by(&open).is_some());
let counted = json!({ "open_findings": 1, "serious_findings": 1 });
assert!(measured_by(&detail("COMMIT", counted)).is_none());
}

#[test]
fn a_reached_threshold_names_the_counts_only_when_they_measured_it() {
let reason = "The review has an open finding at or above the --fail-on severity.";
assert_eq!(threshold_reached(None), reason);
let open = OpenItems {
open_findings: 3,
serious_findings: 1,
earlier_findings: Vec::new(),
};
assert_eq!(
threshold_reached(Some(&open)),
format!("{reason} Proofline counts 3 open findings, 1 of them SERIOUS.")
);
}

#[test]
fn ci_measures_only_a_complete_review_against_the_open_finding_counts() {
let open = |open_findings, serious_findings| OpenItems {
open_findings,
serious_findings,
earlier_findings: Vec::new(),
};
let (warning, serious) = (Some(Severity::Warning), Some(Severity::Serious));
let complete = Some(Outcome::Completed);
Expand Down
59 changes: 59 additions & 0 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ pub struct ReviewDetail {
pub run_number: Option<i64>,
#[serde(default)]
pub subjects: Vec<ReviewSubject>,
/// Environment findings with no severity, by assessment. They are counted
/// in `open_items` but listed in no assessment's findings.
#[serde(default)]
pub investigation_findings: Vec<InvestigationFinding>,
/// The findings a `--verify` patch review re-verified locally. Absent on
/// every other review.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
Expand Down Expand Up @@ -216,6 +220,43 @@ pub struct OpenItems {
pub open_findings: u64,
/// The `SERIOUS` findings among `open_findings`.
pub serious_findings: u64,
/// The open findings of earlier runs that this review did not find again.
/// They are counted in `open_findings` but listed in no assessment.
#[serde(default)]
pub earlier_findings: Vec<EarlierFinding>,
}

/// One earlier run's finding that is still open, as its first published
/// review recorded it.
#[derive(Debug, Deserialize, Serialize)]
pub struct EarlierFinding {
pub review_id: Uuid,
pub run_number: i64,
/// The severity the open count uses, which may exceed this occurrence's.
pub severity: String,
/// Absent when the occurrence has none or its review withheld it.
pub title: Option<String>,
}

/// An environment finding with no severity, published by a violated gate
/// requirement, the environment investigation or a shared identity's narrowed
/// grant. It is counted in `open_findings` but listed in no assessment's
/// findings.
#[derive(Debug, Deserialize, Serialize)]
pub struct InvestigationFinding {
pub assessment_id: Uuid,
pub area: String,
pub title: String,
/// `CONFIRMED_REQUIREMENT`, `INVESTIGATION` or `SHARED_IDENTITY`.
pub source: Option<String>,
}

impl InvestigationFinding {
/// What published the finding, or `ENVIRONMENT` when the server names
/// nothing.
pub fn published_by(&self) -> &str {
self.source.as_deref().unwrap_or("ENVIRONMENT")
}
}

#[derive(Debug, Deserialize, Serialize)]
Expand Down Expand Up @@ -260,6 +301,24 @@ pub struct Finding {
pub lifecycle_state: String,
pub remediation: Option<String>,
pub evidence_refs: Vec<EvidenceRef>,
/// The latest decision on the finding's series. A dismissal or risk
/// acceptance can expire, and nothing here says whether it has, so the
/// decision labels a finding and never hides it.
#[serde(default)]
pub latest_validation: Option<FindingDecision>,
}

/// Who decided what about a finding, and where.
#[derive(Debug, Deserialize, Serialize)]
pub struct FindingDecision {
/// `CONFIRMED`, `DISMISSED`, `FIXED`, `ACCEPTED_RISK` or `ALREADY_COVERED`.
pub validation: String,
/// `UI`, `GITHUB_COMMENT` or `PROOFLINE`.
pub source: String,
pub recorded_at: String,
/// Null for an automatic decision, as is `actor_login`.
pub actor_name: Option<String>,
pub actor_login: Option<String>,
}

#[derive(Debug, Deserialize, Serialize)]
Expand Down
Loading