From c477cb1ed64234fc3e8376113ceefad614648881 Mon Sep 17 00:00:00 2001 From: Alexandru Ungur Date: Thu, 3 Dec 2026 14:43:49 +0100 Subject: [PATCH] Keep the most severe findings within GitHub's annotation limits The runner shows at most 10 annotations of each level per step and drops the rest without saying so on the pull request. `ci review --annotations` printed findings in review order, so on a large review a critical finding could be dropped while lesser ones were shown, and nothing said annotations were missing. A level with more findings than the runner shows now keeps its most severe ones (CRITICAL before SERIOUS, WARNING before NOTE, located before unlocated, then review order). A notice that counts the annotations left out and links the review comes first, and the kept annotations follow most severe first, so other annotations in the step cannot push them out. The printed result still lists every finding. A review within the limits prints exactly as before. --- README.md | 2 +- src/annotations.rs | 449 +++++++++++++++++++++++++++++++++++++++++---- src/lib.rs | 12 +- tests/http.rs | 187 +++++++++++++------ 4 files changed, 557 insertions(+), 93 deletions(-) diff --git a/README.md b/README.md index ddb19ee..b74331f 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ Repository commands use the checkout’s `origin` by default. Use `--remote NAME `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, including those a partial code assessment recorded. 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. The review link contains the full result. GitHub shows at most 10 error, 10 warning and 10 notice annotations per step, and 50 per job. When a level has more findings, its most severe are kept, and a notice that comes first counts the ones left out; the printed result still lists every finding. Annotations from anything else in the step, and the job's limit, are not taken into account. 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 successful CodePipeline executions and failed, stopped or cancelled ones it ties to the ECS rollout that served the commit. A reader inside a still-running execution finds no matching deploy, 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..34b6707 100644 --- a/src/annotations.rs +++ b/src/annotations.rs @@ -4,63 +4,199 @@ //! 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::io::Write; use crate::model::{Finding, 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. -pub(super) fn write(detail: &ReviewDetail, out: &mut impl Write) -> std::io::Result<()> { +/// The most annotations of one level the runner shows for a step. It keeps +/// the first ten and drops the rest without saying so on the pull request: +/// `_maxCountPerIssueType` and `AddIssue` in actions/runner's +/// `src/Runner.Worker/ExecutionContext.cs`. The actions toolkit's +/// `docs/problem-matchers.md` lists this limit with the job's limit of fifty. +/// A step's other annotations, such as the runner's own error for a nonzero +/// exit code, share the step's limit, and the job's limit depends on its +/// other steps; the CLI sees neither, so neither is taken into account here. +const PER_LEVEL: usize = 10; + +#[derive(Debug, Clone, Copy)] +enum Level { + Error, + Warning, + Notice, +} + +impl Level { + const ALL: [Self; 3] = [Self::Error, Self::Warning, Self::Notice]; + + /// The workflow command's name. + const fn as_str(self) -> &'static str { + match self { + Self::Error => "error", + Self::Warning => "warning", + Self::Notice => "notice", + } + } + + const fn index(self) -> usize { + self as usize + } +} + +struct Annotation<'a> { + finding: &'a Finding, + lane: &'a str, + level: Level, + location: Option<(&'a str, u32, u32)>, +} + +/// Writes an annotation for each finding that is not resolved, up to the +/// number of each level the runner shows. 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. Annotations keep review order. +/// +/// A level with more findings than the runner shows keeps its most severe: +/// `CRITICAL` before `SERIOUS`, `WARNING` before `NOTE`, and within one +/// severity a located finding, which shows on the diff, before one without a +/// location, then review order. The rest are not printed; the result on +/// standard output still lists them. A notice then counts the annotations +/// left out and names the review; it takes one of the notice slots, and it +/// and the kept annotations print most severe first. +pub(super) fn write( + detail: &ReviewDetail, + review_url: &str, + out: &mut impl Write, +) -> std::io::Result<()> { let head = detail.head_commit_sha.as_deref().unwrap_or_default(); + let mut findings = Vec::new(); if let Some(code) = outcome::code_assessment(detail) { - for finding in &code.findings { - annotate(out, finding, "code", head)?; - } + findings.extend(code.findings.iter().map(|finding| (finding, "code"))); } for assessment in &detail.assessments { - for finding in &assessment.findings { - annotate(out, finding, &assessment.environment_display_name, head)?; + let lane = assessment.environment_display_name.as_str(); + findings.extend(assessment.findings.iter().map(|finding| (finding, lane))); + } + let annotations: Vec> = findings + .into_iter() + .filter(|(finding, _)| !outcome::resolved(finding)) + .map(|(finding, lane)| Annotation { + finding, + lane, + // A severity this CLI does not know yet is still shown, as a notice. + level: match Severity::parse(&finding.severity) { + Some(Severity::Serious) => Level::Error, + Some(Severity::Warning) => Level::Warning, + None => Level::Notice, + }, + location: finding + .evidence_refs + .iter() + .find_map(|reference| sarif::location(reference, head)), + }) + .collect(); + + let mut counts = [0; Level::ALL.len()]; + for annotation in &annotations { + counts[annotation.level.index()] += 1; + } + let mut room = [PER_LEVEL; Level::ALL.len()]; + if counts.iter().any(|&count| count > PER_LEVEL) { + // The closing notice needs a notice slot of its own. + room[Level::Notice.index()] -= 1; + } + // Each level's most severe findings, in a stable order, take its room. + let mut ranked: Vec = (0..annotations.len()).collect(); + ranked.sort_by_key(|&index| { + let annotation = &annotations[index]; + ( + Reverse(Severity::display_rank(&annotation.finding.severity)), + annotation.location.is_none(), + ) + }); + let mut kept = Vec::new(); + let mut taken = [0; Level::ALL.len()]; + for index in ranked { + let level = annotations[index].level.index(); + if taken[level] < room[level] { + taken[level] += 1; + kept.push(index); } } + let left_out = Level::ALL.map(|level| (level, counts[level.index()] - taken[level.index()])); + if let Some(message) = closing(&left_out, review_url) { + // Anything else the step annotates also counts toward its limit, and + // the runner keeps the first annotations it reads. So when findings + // were left out, the notice that says so comes first and the rest + // follow most severe first. + command( + out, + Level::Notice, + None, + "Proofline: more findings than annotations", + &message, + )?; + } else { + kept.sort_unstable(); + } + for annotation in kept.into_iter().map(|index| &annotations[index]) { + let finding = annotation.finding; + command( + out, + annotation.level, + annotation.location, + &format!("Proofline {}: {}", annotation.lane, finding.risk_domain), + &format!("{}\n\n{}", finding.claim, finding.impact), + )?; + } Ok(()) } -fn annotate( +/// The closing notice's message, or `None` when nothing was left out. +fn closing(left_out: &[(Level, usize)], review_url: &str) -> Option { + let total: usize = left_out.iter().map(|&(_, count)| count).sum(); + let counted: Vec = left_out + .iter() + .filter(|&&(_, count)| count > 0) + .map(|&(level, count)| { + let plural = if count == 1 { "" } else { "s" }; + format!("{count} {} annotation{plural}", level.as_str()) + }) + .collect(); + let (last, rest) = counted.split_last()?; + let listed = if rest.is_empty() { + last.clone() + } else { + format!("{} and {last}", rest.join(", ")) + }; + let verb = if total == 1 { "was" } else { "were" }; + Some(format!( + "GitHub shows at most {PER_LEVEL} annotations of each level per step, so {listed} {verb} left out. The review lists every finding: {review_url}" + )) +} + +/// Writes one workflow command, placed on `location` when there is one. +fn command( out: &mut impl Write, - finding: &Finding, - lane: &str, - head: &str, + level: Level, + location: Option<(&str, u32, u32)>, + title: &str, + message: &str, ) -> std::io::Result<()> { - 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 - .iter() - .find_map(|reference| sarif::location(reference, head)) - { + if let Some((path, start, end)) = location { properties.push(format!("file={}", escape_property(path))); 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 message = format!("{}\n\n{}", finding.claim, finding.impact); + properties.push(format!("title={}", escape_property(title))); writeln!( out, - "::{command} {}::{}", + "::{} {}::{}", + level.as_str(), properties.join(","), - escape_data(&message) + escape_data(message) ) } @@ -83,6 +219,255 @@ fn escape_property(value: &str) -> String { mod tests { use super::*; + const HEAD: &str = "0123456789abcdef0123456789abcdef01234567"; + const URL: &str = "https://console.example/orgs/by-id/o/reviews/r"; + + fn finding(number: usize, severity: &str, located: bool) -> serde_json::Value { + let refs = if located { + serde_json::json!([{ + "kind": "repository_file", + "label": "src/app.rs", + "provenance_status": "VERIFIED_REPOSITORY_READ", + "repository_path": "src/app.rs", + "start_line": number, + "end_line": number, + "commit_sha": HEAD, + "companion_repository": null, + }]) + } else { + serde_json::json!([]) + }; + serde_json::json!({ + "id": uuid::Uuid::from_u128(number as u128), + "severity": severity, + "risk_domain": "logic", + "claim": format!("finding {number}"), + "impact": "impact", + "lifecycle_state": "NEW", + "evidence_refs": refs, + }) + } + + /// The annotations of a review whose head is `HEAD`, with a code lane + /// holding `code` and an environment for each of `environments`. + fn review_annotations( + code: Vec, + environments: Vec<(&str, Vec)>, + ) -> Vec { + let assessments: Vec<_> = environments + .into_iter() + .enumerate() + .map(|(index, (name, findings))| { + serde_json::json!({ + "id": uuid::Uuid::from_u128(100 + index as u128), + "environment_display_name": name, + "status": "COMPLETED", + "findings": findings, + "checks": { "receipt_recorded": true, "status": "READY", "families": [] }, + }) + }) + .collect(); + let detail: ReviewDetail = serde_json::from_value(serde_json::json!({ + "id": uuid::Uuid::from_u128(1), + "kind": "PULL_REQUEST", + "status": "COMPLETED", + "head_commit_sha": HEAD, + "assessment_count": assessments.len(), + "assessments": assessments, + "code_assessment": { + "id": uuid::Uuid::from_u128(2), + "status": "COMPLETED", + "head_commit_sha": HEAD, + "base_commit_sha": "89abcdef0123456789abcdef0123456789abcdef", + "findings": code, + }, + })) + .unwrap(); + let mut out = Vec::new(); + write(&detail, URL, &mut out).unwrap(); + String::from_utf8(out) + .unwrap() + .lines() + .map(str::to_owned) + .collect() + } + + /// The annotations of a review with one environment holding `findings`. + fn annotations(findings: Vec) -> Vec { + review_annotations(Vec::new(), vec![("production", findings)]) + } + + /// The claim of a finding's annotation. The closing notice has none: its + /// message is one line. + fn claim(line: &str) -> Option<&str> { + let (_, message) = line.rsplit_once("::")?; + message.split_once("%0A").map(|(claim, _)| claim) + } + + fn claims(lines: &[String], level: &str) -> Vec { + lines + .iter() + .filter(|line| line.starts_with(&format!("::{level} "))) + .filter_map(|line| claim(line).map(str::to_owned)) + .collect() + } + + fn numbers(claims: &[String]) -> Vec { + claims + .iter() + .map(|claim| claim.strip_prefix("finding ").unwrap().parse().unwrap()) + .collect() + } + + /// What the closing notice, the first line when there is one, says was + /// left out. + fn left_out(lines: &[String]) -> Option<&str> { + lines + .first() + .filter(|line| line.contains("more findings than annotations")) + .and_then(|line| line.split_once("so ")) + .map(|(_, rest)| rest.split_once(" left out").unwrap().0) + } + + /// The finding numbers of every annotation, in printed order. + fn printed(lines: &[String]) -> Vec { + let claims: Vec = lines + .iter() + .filter_map(|line| claim(line).map(str::to_owned)) + .collect(); + numbers(&claims) + } + + #[test] + fn findings_within_the_limits_keep_review_order() { + let lines = annotations(vec![ + finding(1, "NOTE", true), + finding(2, "SERIOUS", false), + finding(3, "FUTURE", true), + finding(4, "SERIOUS", true), + finding(5, "CRITICAL", false), + ]); + assert_eq!(printed(&lines), [1, 2, 3, 4, 5]); + assert!(lines[0].starts_with("::warning file=")); + assert!(lines[2].starts_with("::notice file=")); + assert_eq!(left_out(&lines), None); + } + + #[test] + fn a_full_level_keeps_its_most_severe_findings() { + let mut findings: Vec<_> = (1..=12) + .map(|n| finding(n, "SERIOUS", n % 2 == 0)) + .collect(); + findings.push(finding(13, "CRITICAL", false)); + findings.extend((14..=16).map(|n| finding(n, "WARNING", true))); + let lines = annotations(findings); + // The notice first, then most severe first: the critical finding, + // although it came last with no location; the six located serious + // findings; the first three unlocated ones; the warnings. + assert_eq!( + printed(&lines), + [13, 2, 4, 6, 8, 10, 12, 1, 3, 5, 14, 15, 16] + ); + assert_eq!( + lines.first().unwrap(), + &format!( + "::notice title=Proofline%3A more findings than annotations::GitHub shows at most 10 annotations of each level per step, so 3 error annotations were left out. The review lists every finding: {URL}" + ) + ); + } + + #[test] + fn one_left_out_annotation_is_counted_in_the_singular() { + let lines = annotations((1..=11).map(|n| finding(n, "SERIOUS", true)).collect()); + assert_eq!(left_out(&lines), Some("1 error annotation was")); + } + + #[test] + fn ten_notices_all_show_until_another_level_overflows() { + let notices: Vec<_> = (1..=10).map(|n| finding(n, "FUTURE", true)).collect(); + let lines = annotations(notices.clone()); + assert_eq!(claims(&lines, "notice").len(), 10); + assert_eq!(left_out(&lines), None); + + let mut findings = notices; + findings.extend((11..=21).map(|n| finding(n, "SERIOUS", true))); + let lines = annotations(findings); + assert_eq!(claims(&lines, "error").len(), 10); + let notices = lines + .iter() + .filter(|line| line.starts_with("::notice ")) + .count(); + assert_eq!(notices, 10, "nine findings and the closing notice"); + let order: Vec = (11..=20).chain(1..=9).collect(); + assert_eq!(printed(&lines), order, "errors before notices"); + assert_eq!( + left_out(&lines), + Some("1 error annotation and 1 notice annotation were") + ); + } + + #[test] + fn every_level_can_overflow_at_once() { + let mut findings: Vec<_> = (1..=12).map(|n| finding(n, "SERIOUS", true)).collect(); + findings.extend((13..=24).map(|n| finding(n, "NOTE", true))); + findings.extend((25..=36).map(|n| finding(n, "FUTURE", true))); + let lines = annotations(findings); + assert_eq!( + left_out(&lines), + Some("2 error annotations, 2 warning annotations and 3 notice annotations were") + ); + } + + #[test] + fn overflowing_notices_leave_a_slot_for_the_closing_notice() { + let lines = annotations((1..=11).map(|n| finding(n, "FUTURE", true)).collect()); + assert_eq!(claims(&lines, "notice").len(), 9); + assert_eq!(lines.len(), 10); + assert_eq!(left_out(&lines), Some("2 notice annotations were")); + } + + #[test] + fn warnings_are_kept_before_notes() { + let mut findings: Vec<_> = (1..=6).map(|n| finding(n, "NOTE", true)).collect(); + findings.extend((7..=12).map(|n| finding(n, "WARNING", false))); + let lines = annotations(findings); + // All six warnings, although none is located, then the first four notes. + assert_eq!(printed(&lines), [7, 8, 9, 10, 11, 12, 1, 2, 3, 4]); + assert_eq!(left_out(&lines), Some("2 warning annotations were")); + } + + #[test] + fn resolved_findings_do_not_count_toward_the_limit() { + let mut findings: Vec<_> = (1..=10).map(|n| finding(n, "SERIOUS", true)).collect(); + findings.extend((11..=13).map(|n| { + let mut resolved = finding(n, "CRITICAL", true); + resolved["lifecycle_state"] = "RESOLVED".into(); + resolved + })); + let lines = annotations(findings); + assert_eq!(claims(&lines, "error").len(), 10); + assert_eq!(left_out(&lines), None); + } + + #[test] + fn the_limit_spans_the_code_lane_and_every_environment() { + let code: Vec<_> = (1..=6).map(|n| finding(n, "SERIOUS", true)).collect(); + let production: Vec<_> = (7..=10).map(|n| finding(n, "SERIOUS", true)).collect(); + let staging = vec![ + finding(11, "SERIOUS", true), + finding(12, "SERIOUS", true), + finding(13, "CRITICAL", false), + ]; + let lines = + review_annotations(code, vec![("production", production), ("staging", staging)]); + // The critical staging finding displaces the last three serious ones. + assert_eq!(printed(&lines), [13, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + assert!(lines[1].contains("title=Proofline staging%3A logic::finding 13%0A")); + assert!(lines[2].contains("title=Proofline code%3A logic::finding 1%0A")); + assert!(lines[8].contains("title=Proofline production%3A logic::finding 7%0A")); + assert_eq!(left_out(&lines), Some("3 error annotations were")); + } + #[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 2ac4644..3890306 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -241,8 +241,10 @@ struct CiReviewArgs { /// Also write the review as SARIF 2.1.0 to this file. #[arg(long, value_name = "FILE")] sarif: Option, - /// Also print each finding that is not resolved as a GitHub Actions - /// annotation on stderr, so it shows on the pull request's diff. Unlike + /// Also print findings that are not resolved as GitHub Actions + /// annotations on stderr, so they show on the pull request's diff. GitHub + /// shows 10 error, 10 warning and 10 notice annotations per step; past + /// that the most severe are kept and a notice counts the rest. Unlike /// uploading `--sarif` to code scanning, this works on every GitHub plan. #[arg(long)] annotations: bool, @@ -1648,7 +1650,11 @@ async fn ci_review( write_sarif(api, review_id, &detail, path).await?; } if args.annotations { - annotations::write(&detail, &mut std::io::stderr().lock())?; + annotations::write( + &detail, + api.review_url(review_id).as_str(), + &mut std::io::stderr().lock(), + )?; } print_review( api, diff --git a/tests/http.rs b/tests/http.rs index eb15b98..6a14054 100644 --- a/tests/http.rs +++ b/tests/http.rs @@ -2440,56 +2440,10 @@ async fn ci_review_accepts_a_review_whose_detail_names_the_repository_by_its_new assert_eq!(result["review"]["repository_full_name"], "acme/renamed"); } -#[tokio::test] -async fn ci_review_annotations_put_open_findings_on_the_diff_as_escaped_workflow_commands() { - let finding = |id: &str, severity: &str, lifecycle_state: &str, claim: &str, refs: Value| { - json!({ - "id": id, - "severity": severity, - "risk_domain": "data_integrity", - "claim": claim, - "impact": "orders are lost", - "lifecycle_state": lifecycle_state, - "evidence_refs": refs, - }) - }; - let reference = |commit: &str| { - json!([{ - "kind": "repository_file", - "label": "src/app.rs", - "provenance_status": "VERIFIED_REPOSITORY_READ", - "repository_path": "src/app.rs", - "start_line": 3, - "end_line": 5, - "commit_sha": commit, - "companion_repository": null, - }]) - }; - let findings = json!([ - // Model text that tries to end its command and start another. - finding( - "0190f3a0-0000-7000-8000-0000000000a1", - "SERIOUS", - "NEW", - "Retries drop 100% of orders, then\n::add-mask::secret", - reference(CI_HEAD), - ), - // Cited at another commit, so it has no place on this diff. - finding( - "0190f3a0-0000-7000-8000-0000000000a2", - "WARNING", - "NEW", - "Stale cache.", - reference("fedcba9876543210fedcba9876543210fedcba98"), - ), - finding( - "0190f3a0-0000-7000-8000-0000000000a3", - "SERIOUS", - "RESOLVED", - "Already fixed.", - json!([]), - ), - ]); +/// A console with one `PULL_REQUEST` review of `CI_HEAD` in `acme/app`, +/// complete, whose production assessment lists `findings` and whose counts +/// are `open_items`. Returns the console's origin. +async fn annotations_console(findings: Value, open_items: Value) -> String { let app = Router::new() .route( &format!("/api/v1/organizations/{ORG}/repository-names"), @@ -2520,7 +2474,7 @@ async fn ci_review_annotations_put_open_findings_on_the_diff_as_escaped_workflow .route( &format!("/api/v1/organizations/{ORG}/reviews/{CI_REVIEW}"), get(move || { - let findings = findings.clone(); + let (findings, open_items) = (findings.clone(), open_items.clone()); async move { Json(json!({ "id": CI_REVIEW, @@ -2530,12 +2484,7 @@ async fn ci_review_annotations_put_open_findings_on_the_diff_as_escaped_workflow "pull_request_number": 12, "run_number": 1, "assessment_count": 1, - "open_items": { - "open_findings": 2, - "serious_findings": 1, - "accepted_risks": 0, - "not_assessed": [], - }, + "open_items": open_items, "assessments": [{ "id": "0190f3a0-0000-7000-8000-0000000000f2", "environment_display_name": "production", @@ -2550,6 +2499,69 @@ async fn ci_review_annotations_put_open_findings_on_the_diff_as_escaped_workflow 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() }); + origin +} + +#[tokio::test] +async fn ci_review_annotations_put_open_findings_on_the_diff_as_escaped_workflow_commands() { + let finding = |id: &str, severity: &str, lifecycle_state: &str, claim: &str, refs: Value| { + json!({ + "id": id, + "severity": severity, + "risk_domain": "data_integrity", + "claim": claim, + "impact": "orders are lost", + "lifecycle_state": lifecycle_state, + "evidence_refs": refs, + }) + }; + let reference = |commit: &str| { + json!([{ + "kind": "repository_file", + "label": "src/app.rs", + "provenance_status": "VERIFIED_REPOSITORY_READ", + "repository_path": "src/app.rs", + "start_line": 3, + "end_line": 5, + "commit_sha": commit, + "companion_repository": null, + }]) + }; + let findings = json!([ + // Model text that tries to end its command and start another. + finding( + "0190f3a0-0000-7000-8000-0000000000a1", + "SERIOUS", + "NEW", + "Retries drop 100% of orders, then\n::add-mask::secret", + reference(CI_HEAD), + ), + // Cited at another commit, so it has no place on this diff. + finding( + "0190f3a0-0000-7000-8000-0000000000a2", + "WARNING", + "NEW", + "Stale cache.", + reference("fedcba9876543210fedcba9876543210fedcba98"), + ), + finding( + "0190f3a0-0000-7000-8000-0000000000a3", + "SERIOUS", + "RESOLVED", + "Already fixed.", + json!([]), + ), + ]); + let origin = annotations_console( + findings, + json!({ + "open_findings": 2, + "serious_findings": 1, + "accepted_risks": 0, + "not_assessed": [], + }), + ) + .await; let mut args = vec!["ci", "review", "--repo", "acme/app", "--commit", CI_HEAD]; args.extend(["--timeout", "0", "--json"]); @@ -2580,6 +2592,67 @@ 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_the_review_when_findings_exceed_the_runner_limit() { + let findings: Vec = (1..=11u128) + .map(|number| { + json!({ + "id": format!("0190f3a0-0000-7000-8000-{number:012x}"), + "severity": "SERIOUS", + "risk_domain": "data_integrity", + "claim": format!("finding {number}"), + "impact": "orders are lost", + "lifecycle_state": "NEW", + "evidence_refs": [], + }) + }) + .collect(); + let origin = annotations_console( + Value::Array(findings), + json!({ + "open_findings": 11, + "serious_findings": 11, + "accepted_risks": 0, + "not_assessed": [], + }), + ) + .await; + + let mut args = vec!["ci", "review", "--repo", "acme/app", "--commit", CI_HEAD]; + args.extend(["--timeout", "0", "--json", "--annotations"]); + let output = cli(&origin, &args).await; + assert_eq!(output.status.code(), Some(0)); + let stderr = String::from_utf8_lossy(&output.stderr); + let commands: Vec<&str> = stderr + .lines() + .filter(|line| line.starts_with("::")) + .collect(); + assert_eq!( + commands + .iter() + .filter(|line| line.starts_with("::error ")) + .count(), + 10 + ); + // The notice comes first, so nothing else in the step can push it out. + assert_eq!( + commands.first().unwrap(), + &format!( + "::notice title=Proofline%3A more findings than annotations::GitHub shows at most 10 annotations of each level per step, so 1 error annotation was left out. The review lists every finding: {origin}/orgs/by-id/{ORG}/reviews/{CI_REVIEW}" + ) + ); + // The printed result still holds every finding. + let result: Value = serde_json::from_slice(&output.stdout).unwrap(); + assert_eq!(result["outcome"], "COMPLETED"); + assert_eq!( + result["review"]["assessments"][0]["findings"] + .as_array() + .unwrap() + .len(), + 11 + ); +} + #[tokio::test] async fn native_tools_keep_tenant_paths_and_reruns_make_one_attempt() { let requests = Arc::new(Mutex::new(Vec::new()));