diff --git a/README.md b/README.md index eea0165..37b9143 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/annotations.rs b/src/annotations.rs index bf62f73..5c44ebd 100644 --- a/src/annotations.rs +++ b/src/annotations.rs @@ -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) { @@ -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, @@ -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 @@ -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) ) } @@ -83,6 +152,75 @@ fn escape_property(value: &str) -> String { mod tests { use super::*; + fn written(write: impl FnOnce(&mut Vec) -> 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"); diff --git a/src/lib.rs b/src/lib.rs index 0fd8d78..549fa0e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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.", ), @@ -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.", ), @@ -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 @@ -2249,6 +2268,25 @@ 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] @@ -2256,6 +2294,7 @@ mod tests { 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); diff --git a/src/model.rs b/src/model.rs index e029008..9c430dc 100644 --- a/src/model.rs +++ b/src/model.rs @@ -94,6 +94,10 @@ pub struct ReviewDetail { pub run_number: Option, #[serde(default)] pub subjects: Vec, + /// 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, /// The findings a `--verify` patch review re-verified locally. Absent on /// every other review. #[serde(default, skip_serializing_if = "Vec::is_empty")] @@ -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, +} + +/// 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, +} + +/// 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, +} + +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)] @@ -260,6 +301,24 @@ pub struct Finding { pub lifecycle_state: String, pub remediation: Option, pub evidence_refs: Vec, + /// 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, +} + +/// 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, + pub actor_login: Option, } #[derive(Debug, Deserialize, Serialize)] diff --git a/src/outcome.rs b/src/outcome.rs index 5bc661b..1a4a9e8 100644 --- a/src/outcome.rs +++ b/src/outcome.rs @@ -333,6 +333,7 @@ mod tests { assessments, code_assessment: None, subjects: Vec::new(), + investigation_findings: Vec::new(), base_commit_sha: None, head_commit_sha: None, open_items: None, @@ -355,6 +356,7 @@ mod tests { lifecycle_state: lifecycle_state.to_owned(), remediation: None, evidence_refs: Vec::new(), + latest_validation: None, } } diff --git a/src/render.rs b/src/render.rs index 782b09f..47cd2ea 100644 --- a/src/render.rs +++ b/src/render.rs @@ -6,7 +6,8 @@ use std::cmp::Reverse; use url::Url; use crate::model::{ - Assessment, CodeAssessment, Finding, LocalReverification, ReviewDetail, StoredCheck, + Assessment, CodeAssessment, EarlierFinding, Finding, FindingDecision, InvestigationFinding, + LocalReverification, ReviewDetail, StoredCheck, }; use crate::outcome::{self, Outcome}; use crate::severity::Severity; @@ -41,15 +42,75 @@ fn finding(out: &mut Vec, finding: &Finding) { if let Some(remediation) = &finding.remediation { out.push(format!(" fix: {}", one_line(remediation))); } + if let Some(decision) = &finding.latest_validation { + out.push(format!(" decision: {}", decided(decision))); + } // fix and session commands take this ID, so text output must not need --json out.push(format!(" id: {}", finding.id)); } -fn assessment(out: &mut Vec, assessment: &Assessment) { +/// `DISMISSED by Ada (GITHUB_COMMENT, 2026-11-20T10:00:00Z)`. An automatic +/// decision names no one. +fn decided(decision: &FindingDecision) -> String { + let actor = decision + .actor_name + .as_deref() + .or(decision.actor_login.as_deref()) + .map(|actor| format!(" by {}", one_line(actor))) + .unwrap_or_default(); + format!( + "{}{actor} ({}, {})", + one_line(&decision.validation), + one_line(&decision.source), + one_line(&decision.recorded_at) + ) +} + +/// An environment finding with no severity prints after the rated findings, +/// led by what published it. +fn investigation(out: &mut Vec, finding: &InvestigationFinding) { + out.push(format!( + " {} {} {}", + one_line(finding.published_by()), + one_line(&finding.area), + one_line(&finding.title) + )); +} + +/// Environment findings of an assessment this review does not list. The +/// counts still include them, so they print on their own. +fn unlisted(out: &mut Vec, review: &ReviewDetail) { + let listed = |finding: &&InvestigationFinding| { + review + .assessments + .iter() + .any(|assessment| assessment.id == finding.assessment_id) + }; + let findings: Vec<&InvestigationFinding> = review + .investigation_findings + .iter() + .filter(|finding| !listed(finding)) + .collect(); + if findings.is_empty() { + return; + } + out.push(String::new()); + out.push("Findings of an environment assessment this review does not list:".to_owned()); + for item in findings { + investigation(out, item); + } +} + +fn assessment( + out: &mut Vec, + assessment: &Assessment, + investigations: &[&InvestigationFinding], +) { let name = one_line(&assessment.environment_display_name); let mut findings: Vec<&Finding> = assessment.findings.iter().collect(); // Most severe first; a severity this CLI does not know prints last. findings.sort_by_key(|item| Reverse(Severity::parse(&item.severity))); + let count = findings.len() + investigations.len(); match outcome::gap(assessment) { Some(reasons) => { out.push(format!( @@ -57,20 +118,46 @@ fn assessment(out: &mut Vec, assessment: &Assessment) { one_line(&assessment.status), one_line(&reasons.join(", ")) )); - if !findings.is_empty() { + if count != 0 { out.push(" findings so far, not a complete result:".to_owned()); } } - None if findings.is_empty() => { + None if count == 0 => { out.push(format!("{name}: COMPLETED, no findings")); } None => { - out.push(format!("{name}: COMPLETED, {} findings", findings.len())); + out.push(format!("{name}: COMPLETED, {count} findings")); } } for item in findings { finding(out, item); } + for item in investigations { + investigation(out, item); + } +} + +/// Earlier runs' findings that this review did not find again. The server +/// still counts them as open, so `--fail-on` measures them too. +fn earlier(out: &mut Vec, findings: &[EarlierFinding]) { + if findings.is_empty() { + return; + } + out.push(String::new()); + out.push("Still open from earlier runs, not found again by this review:".to_owned()); + for item in findings { + let title = item + .title + .as_deref() + .map(|title| format!(" {}", one_line(title))) + .unwrap_or_default(); + out.push(format!( + " {:<8} run {}{title}", + one_line(&item.severity), + item.run_number + )); + out.push(format!(" review: {}", item.review_id)); + } } fn code_assessment(out: &mut Vec, code: &CodeAssessment) { @@ -227,9 +314,22 @@ pub fn review(review: &ReviewDetail, state: Option, url: &Url) -> Strin out.push("no environment assessment has been recorded yet".to_owned()); } for item in &review.assessments { + let investigations: Vec<&InvestigationFinding> = review + .investigation_findings + .iter() + .filter(|finding| finding.assessment_id == item.id) + .collect(); out.push(String::new()); - assessment(&mut out, item); + assessment(&mut out, item, &investigations); } + unlisted(&mut out, review); + earlier( + &mut out, + review + .open_items + .as_ref() + .map_or(&[], |open| &open.earlier_findings), + ); reverifications(&mut out, &review.local_reverifications); out.push(String::new()); out.join("\n") @@ -248,6 +348,7 @@ mod tests { assessment_count: 1, code_assessment: None, subjects: Vec::new(), + investigation_findings: Vec::new(), assessments: vec![Assessment { id: uuid::Uuid::nil(), environment_display_name: "production".to_owned(), @@ -295,6 +396,7 @@ mod tests { commit_sha: None, companion_repository: None, }], + latest_validation: None, } } @@ -344,4 +446,155 @@ mod tests { assert!(!text.contains('\u{1b}')); assert!(text.contains("x\u{FFFD}[2J y")); } + + fn decision(actor_name: Option<&str>, actor_login: Option<&str>) -> FindingDecision { + FindingDecision { + validation: "DISMISSED".to_owned(), + source: "GITHUB_COMMENT".to_owned(), + recorded_at: "2026-11-20T10:00:00Z".to_owned(), + actor_name: actor_name.map(str::to_owned), + actor_login: actor_login.map(str::to_owned), + } + } + + #[test] + fn a_decided_finding_names_its_decision_and_stays_listed() { + let mut item = finding("SERIOUS", "lost order"); + item.latest_validation = Some(decision(Some("Ada\u{1b}[2J"), Some("ada"))); + let detail = sample("COMPLETED", vec![item]); + let text = review(&detail, None, &url()); + assert!(text.contains("production: COMPLETED, 1 findings"), "{text}"); + assert!( + text.contains( + " decision: DISMISSED by Ada\u{FFFD}[2J (GITHUB_COMMENT, 2026-11-20T10:00:00Z)\n" + ), + "{text}" + ); + } + + #[test] + fn a_decision_names_the_login_without_a_name_and_no_one_when_automatic() { + assert_eq!( + decided(&decision(None, Some("ada"))), + "DISMISSED by ada (GITHUB_COMMENT, 2026-11-20T10:00:00Z)" + ); + assert_eq!( + decided(&decision(None, None)), + "DISMISSED (GITHUB_COMMENT, 2026-11-20T10:00:00Z)" + ); + } + + fn investigation_finding( + assessment_id: uuid::Uuid, + source: Option<&str>, + title: &str, + ) -> InvestigationFinding { + InvestigationFinding { + assessment_id, + area: "iam".to_owned(), + title: title.to_owned(), + source: source.map(str::to_owned), + } + } + + #[test] + fn an_environment_finding_prints_under_its_environment_led_by_its_source() { + let mut detail = sample("COMPLETED", Vec::new()); + detail.investigation_findings = vec![ + investigation_finding(uuid::Uuid::nil(), Some("INVESTIGATION"), "no bucket read"), + investigation_finding(uuid::Uuid::nil(), Some("CONFIRMED_REQUIREMENT"), "no TLS"), + investigation_finding(uuid::Uuid::nil(), None, "unnamed\u{1b}[2J"), + ]; + let text = review(&detail, None, &url()); + assert!( + text.contains(concat!( + "production: COMPLETED, 3 findings\n", + " INVESTIGATION iam no bucket read\n", + " CONFIRMED_REQUIREMENT iam no TLS\n", + " ENVIRONMENT iam unnamed\u{FFFD}[2J\n", + )), + "{text}" + ); + assert!(!text.contains("no findings"), "{text}"); + assert!(!text.contains("does not list"), "{text}"); + } + + #[test] + fn an_environment_finding_of_an_unlisted_assessment_still_prints() { + let mut detail = sample("COMPLETED", Vec::new()); + let elsewhere = uuid::Uuid::from_u128(9); + detail.investigation_findings = vec![investigation_finding( + elsewhere, + Some("SHARED_IDENTITY"), + "the worker loses its queue grant", + )]; + let text = review(&detail, None, &url()); + assert!( + text.contains(concat!( + "production: COMPLETED, no findings\n\n", + "Findings of an environment assessment this review does not list:\n", + " SHARED_IDENTITY iam the worker loses its queue grant\n", + )), + "{text}" + ); + } + + #[test] + fn an_incomplete_assessment_marks_its_environment_findings_as_partial() { + let mut detail = sample("INCOMPLETE", Vec::new()); + detail.investigation_findings = vec![investigation_finding( + uuid::Uuid::nil(), + Some("INVESTIGATION"), + "partial", + )]; + let text = review(&detail, outcome::terminal(&detail), &url()); + assert!( + text.contains( + " findings so far, not a complete result:\n INVESTIGATION iam partial\n" + ), + "{text}" + ); + } + + fn earlier_finding(title: Option<&str>) -> EarlierFinding { + EarlierFinding { + review_id: uuid::Uuid::from_u128(7), + run_number: 1, + severity: "SERIOUS".to_owned(), + title: title.map(str::to_owned), + } + } + + #[test] + fn earlier_runs_open_findings_print_after_the_assessments() { + let mut detail = sample("COMPLETED", Vec::new()); + detail.open_items = Some(crate::model::OpenItems { + open_findings: 2, + serious_findings: 2, + earlier_findings: vec![ + earlier_finding(Some("pool\u{1b}[2J")), + earlier_finding(None), + ], + }); + let text = review(&detail, None, &url()); + let review_line = " review: 00000000-0000-0000-0000-000000000007\n"; + assert!( + text.contains(&format!( + "production: COMPLETED, no findings\n\nStill open from earlier runs, not found again by this review:\n SERIOUS run 1 pool\u{FFFD}[2J\n{review_line} SERIOUS run 1\n{review_line}" + )), + "{text}" + ); + } + + #[test] + fn a_review_without_earlier_findings_prints_no_earlier_block() { + let mut detail = sample("COMPLETED", Vec::new()); + detail.open_items = Some(crate::model::OpenItems { + open_findings: 0, + serious_findings: 0, + earlier_findings: Vec::new(), + }); + let text = review(&detail, None, &url()); + assert!(!text.contains("earlier runs"), "{text}"); + } } diff --git a/src/sarif.rs b/src/sarif.rs index 4d30667..a64f5b5 100644 --- a/src/sarif.rs +++ b/src/sarif.rs @@ -199,6 +199,9 @@ struct FindingProperties<'a> { #[serde(skip_serializing_if = "Option::is_none")] environment: Option<&'a str>, lifecycle_state: &'a str, + // A decision can expire unseen, so it is data here, never a suppression. + #[serde(skip_serializing_if = "Option::is_none")] + decision: Option<&'a str>, location_status: LocationStatus, #[serde(skip_serializing_if = "Option::is_none")] remediation: Option<&'a str>, @@ -582,6 +585,10 @@ fn finding_result<'a>( lane, environment, lifecycle_state: &finding.lifecycle_state, + decision: finding + .latest_validation + .as_ref() + .map(|decision| decision.validation.as_str()), location_status, remediation: finding.remediation.as_deref(), evidence_references, diff --git a/tests/contract.rs b/tests/contract.rs index cf7ae44..d01b13f 100644 --- a/tests/contract.rs +++ b/tests/contract.rs @@ -5,10 +5,11 @@ use std::process::Command; use proofline_cli::model::{ Assessment, Check, Checks, CodeAssessment, CommitDeploy, CommitDeployVerifications, CommitReviewRequest, CommitReviewResponse, CoverageUploadRequest, CoverageUploadResponse, - DeployCheckpoint, EvidenceRef, FileReviewRequest, FileReviewResponse, FileScope, FilterChoice, - Finding, OpenItems, PatchReviewRequest, PatchReviewResponse, RepositoryName, RepositoryNames, - ReviewDetail, ReviewFilters, ReviewPage, ReviewSubject, ReviewSummary, RunNowMode, - RunNowRequest, RunNowResponse, StopResponse, UploadedReport, + DeployCheckpoint, EarlierFinding, EvidenceRef, FileReviewRequest, FileReviewResponse, + FileScope, FilterChoice, Finding, FindingDecision, InvestigationFinding, OpenItems, + PatchReviewRequest, PatchReviewResponse, RepositoryName, RepositoryNames, ReviewDetail, + ReviewFilters, ReviewPage, ReviewSubject, ReviewSummary, RunNowMode, RunNowRequest, + RunNowResponse, StopResponse, UploadedReport, }; use serde::Serialize; use serde::de::DeserializeOwned; @@ -156,11 +157,14 @@ fn types_match_the_public_contract() { holds::("ReviewSummary"); holds::("CustomerReviewDetail"); holds::("OpenItemsView"); + holds::("EarlierOpenFinding"); + holds::("ReviewInvestigationFinding"); holds::("CustomerAssessment"); holds::("CustomerCodeAssessment"); holds::("CustomerChecks"); holds::("CustomerCheck"); holds::("CustomerFinding"); + holds::("CustomerFindingValidation"); holds::("CustomerEvidenceRef"); holds::("RunNowRequest"); holds::("RunNowResponse"); diff --git a/tests/http.rs b/tests/http.rs index ed8a0c7..e5bc358 100644 --- a/tests/http.rs +++ b/tests/http.rs @@ -1976,6 +1976,11 @@ async fn ci_review_fail_on_exits_three_for_an_open_finding_of_a_complete_review( code == 3, "{case}" ); + if let (3, Some([open, serious])) = (code, open) { + let counts = + format!("Proofline counts {open} open findings, {serious} of them SERIOUS."); + assert!(stderr.contains(&counts), "{case}"); + } assert_eq!(stderr.contains("without `open_items`"), code == 4, "{case}"); // The flag changes the exit code only: the result keeps its shape, // and `outcome` still reads completeness. @@ -2442,7 +2447,7 @@ async fn ci_review_annotations_put_open_findings_on_the_diff_as_escaped_workflow "companion_repository": null, }]) }; - let findings = json!([ + let mut findings = json!([ // Model text that tries to end its command and start another. finding( "0190f3a0-0000-7000-8000-0000000000a1", @@ -2467,6 +2472,14 @@ async fn ci_review_annotations_put_open_findings_on_the_diff_as_escaped_workflow json!([]), ), ]); + // A dismissal can expire unseen, so the finding stays annotated, labelled. + findings[1]["latest_validation"] = json!({ + "validation": "DISMISSED", + "source": "GITHUB_COMMENT", + "recorded_at": "2026-10-01T00:00:00Z", + "actor_name": null, + "actor_login": "ada", + }); let app = Router::new() .route( &format!("/api/v1/organizations/{ORG}/repository-names"), @@ -2508,11 +2521,27 @@ async fn ci_review_annotations_put_open_findings_on_the_diff_as_escaped_workflow "run_number": 1, "assessment_count": 1, "open_items": { - "open_findings": 2, - "serious_findings": 1, + "open_findings": 4, + "serious_findings": 2, "accepted_risks": 0, "not_assessed": [], + "earlier_findings": [{ + "finding_series_id": "0190f3a0-0000-7000-8000-0000000000e1", + "finding_id": "0190f3a0-0000-7000-8000-0000000000e2", + "review_id": "0190f3a0-0000-7000-8000-0000000000e3", + "run_number": 1, + "severity": "SERIOUS", + "title": "Pool exhausts connections", + }], }, + "investigation_findings": [{ + "assessment_id": "0190f3a0-0000-7000-8000-0000000000f2", + "area": "iam", + "title": "The role cannot read the bucket", + "detail": "s3:GetObject is not granted.", + "citations": [], + "source": "INVESTIGATION", + }], "assessments": [{ "id": "0190f3a0-0000-7000-8000-0000000000f2", "environment_display_name": "production", @@ -2549,12 +2578,26 @@ async fn ci_review_annotations_put_open_findings_on_the_diff_as_escaped_workflow commands(&annotated), [ "::error file=src/app.rs,line=3,endLine=5,title=Proofline production%3A data_integrity::Retries drop 100%25 of orders, then%0A::add-mask::secret%0A%0Aorders are lost", - "::warning title=Proofline production%3A data_integrity::Stale cache.%0A%0Aorders are lost", + "::warning title=Proofline production%3A data_integrity (DISMISSED)::Stale cache.%0A%0Aorders are lost", + "::notice title=Proofline production%3A iam (INVESTIGATION)::The role cannot read the bucket", + "::error title=Proofline earlier run 1::Pool exhausts connections", ] ); // Annotations go to stderr, so the result on stdout keeps its shape. let result: Value = serde_json::from_slice(&annotated.stdout).unwrap(); assert_eq!(result["outcome"], "COMPLETED"); + + // The job's last line says what --fail-on measured. + args.extend(["--fail-on", "serious"]); + let failed = cli(&origin, &args).await; + assert_eq!(failed.status.code(), Some(3)); + assert!( + String::from_utf8_lossy(&failed.stderr).contains( + "The review has an open finding at or above the --fail-on severity. Proofline counts 4 open findings, 2 of them SERIOUS." + ), + "{}", + String::from_utf8_lossy(&failed.stderr) + ); } #[tokio::test] diff --git a/tests/sarif.rs b/tests/sarif.rs index fd65418..2d8868e 100644 --- a/tests/sarif.rs +++ b/tests/sarif.rs @@ -655,6 +655,13 @@ async fn sarif_retains_identity_and_filters_locations_at_the_recorded_head() { })); let mut retained = finding(1, "SERIOUS", references); retained["finding_fingerprint"] = json!(FINGERPRINT); + retained["latest_validation"] = json!({ + "validation": "ACCEPTED_RISK", + "source": "UI", + "recorded_at": "2026-10-01T00:00:00Z", + "actor_name": "Ada", + "actor_login": "ada", + }); let console = Console::new(review(vec![retained, finding(2, "WARNING", Vec::new())])); let origin = serve(console.clone()).await; let schema = schema(); @@ -699,6 +706,10 @@ async fn sarif_retains_identity_and_filters_locations_at_the_recorded_head() { finding(1, "SERIOUS", Vec::new())["id"] ); assert_eq!(serious["level"], "error"); + // A decision can expire unseen, so it is recorded data, not a suppression. + assert_eq!(serious["properties"]["decision"], "ACCEPTED_RISK"); + assert!(serious.get("suppressions").is_none()); + assert!(run["results"][1]["properties"].get("decision").is_none()); assert_eq!(serious["ruleId"], "data_integrity"); let rule_index = serious["ruleIndex"].as_u64().unwrap(); let rule_index = usize::try_from(rule_index).unwrap();