From 0ccf4e51efbe198fbdd5975864c27eabec171181 Mon Sep 17 00:00:00 2001 From: Ethan Catzel Date: Thu, 5 Nov 2026 11:36:01 +1100 Subject: [PATCH] feat: show declared reach in review text output --- README.md | 5 ++ src/lib.rs | 14 +++++- src/model.rs | 31 ++++++++++++ src/outcome.rs | 1 + src/render.rs | 58 +++++++++++++++++++--- tests/contract.rs | 11 +++-- tests/http.rs | 121 ++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 228 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 5a11980..9948a1d 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,11 @@ the index, or `--include-untracked` to select a new, non-ignored file. The command preserves the real index and applies the usual secret preflight. It cannot be combined with pushed-commit, range or pull-request review. +Review text output shows each environment's declared reach: the services and +queues that depend on what the change deploys. Reach does not change the exit +code. Entity labels must not go to GitHub, so `ci review` shows only the +summary and SARIF leaves reach out. + Read all recorded runs with `proofline history --repo owner/name --pr 7`. `proofline rerun REVIEW_ID` requests the original immutable subject and waits; `--no-wait` returns its link. Reruns require `reviews:rerun`. diff --git a/src/lib.rs b/src/lib.rs index 6096711..ff527ca 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1023,7 +1023,15 @@ async fn show( }; let sarif = matches!(format, OutputFormat::Sarif); let (raw, detail, state) = read_review(api, review_id, deadline, sarif).await?; - print_review(api, review_id, raw, &detail, state, format)?; + print_review( + api, + review_id, + raw, + &detail, + state, + format, + render::Reach::Entities, + )?; match state { Some(Outcome::Completed) => return Ok(Verdict::Done), Some(ended) => say_not_complete(ended), @@ -1183,6 +1191,7 @@ async fn ci_review( &detail, state, OutputFormat::from_json(args.json), + render::Reach::Summary, )?; let verdict = ci_verdict( state, @@ -1254,6 +1263,7 @@ fn print_review( detail: &ReviewDetail, state: Option, format: OutputFormat, + shown: render::Reach, ) -> anyhow::Result<()> { let mut stdout = std::io::stdout().lock(); match format { @@ -1281,7 +1291,7 @@ fn print_review( write!( stdout, "{}", - render::review(detail, state, &api.review_url(detail.id)) + render::review(detail, state, &api.review_url(detail.id), shown) )?; } } diff --git a/src/model.rs b/src/model.rs index 2420134..dd7bee3 100644 --- a/src/model.rs +++ b/src/model.rs @@ -194,6 +194,37 @@ pub struct Assessment { pub incompleteness_kind: Option, pub reason_codes: Option>, pub release_evidence_gap: Option, + /// What World declares depends on what the change deploys. Absent when + /// the assessment's kind records none or the server predates it. + #[serde(default)] + pub declared_reach: Option, +} + +/// A reached entity declares a dependency on what the change deploys; it is +/// never a claim that the change breaks it, so reach never decides an outcome. +#[derive(Debug, Deserialize, Serialize)] +pub struct DeclaredReach { + /// `READ`, `NO_ROOTS`, `ROOTS_UNKNOWN` or `UNAVAILABLE`; only `READ` + /// carries entities or gaps. + pub outcome: String, + pub complete: bool, + pub entities: Vec, + pub gaps: Vec, +} + +#[derive(Debug, Deserialize, Serialize)] +pub struct ReachedEntity { + pub kind: String, + /// Environment evidence for this organization's readers: never publish + /// it to GitHub. + pub label: String, + /// The relation steps from the deployed root. Only their count is shown. + pub path: Vec, +} + +#[derive(Debug, Deserialize, Serialize)] +pub struct ReachGap { + pub code: String, } #[derive(Debug, Deserialize, Serialize)] diff --git a/src/outcome.rs b/src/outcome.rs index c5f87ec..f908fa4 100644 --- a/src/outcome.rs +++ b/src/outcome.rs @@ -186,6 +186,7 @@ mod tests { incompleteness_kind: None, reason_codes: None, release_evidence_gap: None, + declared_reach: None, } } diff --git a/src/render.rs b/src/render.rs index 4c4578b..6467d91 100644 --- a/src/render.rs +++ b/src/render.rs @@ -5,7 +5,7 @@ use std::cmp::Reverse; use url::Url; -use crate::model::{Assessment, CodeAssessment, Finding, ReviewDetail}; +use crate::model::{Assessment, CodeAssessment, DeclaredReach, Finding, ReviewDetail}; use crate::outcome::{self, Outcome}; use crate::severity::Severity; use crate::text::{one_line, terminal_safe}; @@ -41,7 +41,17 @@ fn finding(out: &mut Vec, finding: &Finding) { } } -fn assessment(out: &mut Vec, assessment: &Assessment) { +/// How much of each declared reach the text shows. +#[derive(Debug, Clone, Copy)] +pub enum Reach { + /// The summary and every reached entity. + Entities, + /// The summary only. CI logs can be public, and entity labels must not + /// be published to GitHub. + Summary, +} + +fn assessment(out: &mut Vec, assessment: &Assessment, shown: Reach) { 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. @@ -67,6 +77,39 @@ fn assessment(out: &mut Vec, assessment: &Assessment) { for item in findings { finding(out, item); } + if let Some(reach) = &assessment.declared_reach { + declared_reach(out, reach, shown); + } +} + +/// What depends on the change. Only a complete reach can say "none": an +/// incomplete or unread one says nothing about what depends on the change. +fn declared_reach(out: &mut Vec, reach: &DeclaredReach, shown: Reach) { + let count = reach.entities.len(); + let summary = match (reach.outcome.as_str(), reach.complete) { + ("READ", true) if count == 0 => "complete, none found".to_owned(), + ("READ", true) => format!("complete, {count} found"), + ("READ", false) => { + let gaps: Vec<&str> = reach.gaps.iter().map(|gap| gap.code.as_str()).collect(); + format!( + "incomplete ({}), {count} found so far", + one_line(&gaps.join(", ")) + ) + } + (outcome, _) => format!("unknown ({})", one_line(outcome)), + }; + out.push(format!(" declared reach: {summary}")); + if matches!(shown, Reach::Summary) { + return; + } + for entity in &reach.entities { + out.push(format!( + " {:<8} {} depth {}", + one_line(&entity.kind), + one_line(&entity.label), + entity.path.len() + )); + } } fn code_assessment(out: &mut Vec, code: &CodeAssessment) { @@ -92,7 +135,7 @@ fn code_assessment(out: &mut Vec, code: &CodeAssessment) { } /// The review, with separate CODE and environment assessment blocks. -pub fn review(review: &ReviewDetail, state: Option, url: &Url) -> String { +pub fn review(review: &ReviewDetail, state: Option, url: &Url, shown: Reach) -> String { let mut out = Vec::new(); let subject = match (&review.repository_full_name, review.pull_request_number) { (Some(repository), Some(number)) => format!("{} #{number}", one_line(repository)), @@ -159,7 +202,7 @@ pub fn review(review: &ReviewDetail, state: Option, url: &Url) -> Strin } for item in &review.assessments { out.push(String::new()); - assessment(&mut out, item); + assessment(&mut out, item, shown); } if !review.local_reverifications.is_empty() { out.push(String::new()); @@ -207,6 +250,7 @@ mod tests { .then(|| "WORLD_UNAVAILABLE".to_owned()), reason_codes: None, release_evidence_gap: None, + declared_reach: None, }], base_commit_sha: None, head_commit_sha: Some("0123456789abcdef0123456789abcdef01234567".to_owned()), @@ -249,7 +293,7 @@ mod tests { #[test] fn an_incomplete_assessment_never_reads_as_clean() { let detail = sample("INCOMPLETE", Vec::new()); - let text = review(&detail, outcome::terminal(&detail), &url()); + let text = review(&detail, outcome::terminal(&detail), &url(), Reach::Entities); assert!(text.contains("production: INCOMPLETE (incomplete: WORLD_UNAVAILABLE)")); assert!(!text.contains("no findings")); } @@ -264,7 +308,7 @@ mod tests { finding("SERIOUS", "first"), ], ); - let text = review(&detail, None, &url()); + let text = review(&detail, None, &url(), Reach::Entities); let places = ["first", "second", "third"].map(|claim| text.find(claim).unwrap()); assert!(places.is_sorted(), "{text}"); } @@ -272,7 +316,7 @@ mod tests { #[test] fn model_text_cannot_drive_the_terminal() { let detail = sample("COMPLETED", vec![finding("SERIOUS", "x\u{1b}[2J\ny")]); - let text = review(&detail, None, &url()); + let text = review(&detail, None, &url(), Reach::Entities); assert!(!text.contains('\u{1b}')); assert!(text.contains("x\u{FFFD}[2J y")); } diff --git a/tests/contract.rs b/tests/contract.rs index 1cd1a83..7c016e2 100644 --- a/tests/contract.rs +++ b/tests/contract.rs @@ -5,11 +5,11 @@ use std::process::Command; use proofline_cli::model::{ Assessment, Check, Checks, CodeAssessment, CommitReviewRequest, CommitReviewResponse, - CoverageUploadRequest, CoverageUploadResponse, EvidenceRef, FileReviewRequest, + CoverageUploadRequest, CoverageUploadResponse, DeclaredReach, EvidenceRef, FileReviewRequest, FileReviewResponse, FileScope, FilterChoice, Finding, OpenItems, PatchReviewRequest, - PatchReviewResponse, RepositoryName, RepositoryNames, ReviewDetail, ReviewFilters, ReviewPage, - ReviewSubject, ReviewSummary, RunNowMode, RunNowRequest, RunNowResponse, StopResponse, - UploadedReport, + PatchReviewResponse, ReachGap, ReachedEntity, RepositoryName, RepositoryNames, ReviewDetail, + ReviewFilters, ReviewPage, ReviewSubject, ReviewSummary, RunNowMode, RunNowRequest, + RunNowResponse, StopResponse, UploadedReport, }; use serde::Serialize; use serde::de::DeserializeOwned; @@ -159,6 +159,9 @@ fn types_match_the_public_contract() { holds::("CustomerReviewDetail"); holds::("OpenItemsView"); holds::("CustomerAssessment"); + holds::("DeclaredReachView"); + holds::("ReachedEntityView"); + holds::("ReachGapView"); holds::("CustomerCodeAssessment"); holds::("CustomerChecks"); holds::("CustomerCheck"); diff --git a/tests/http.rs b/tests/http.rs index b65ed37..121608d 100644 --- a/tests/http.rs +++ b/tests/http.rs @@ -386,6 +386,7 @@ struct Fake { polls: Arc, report_organization: bool, summary: Option, + reach: Option, } async fn code() -> Json { @@ -486,6 +487,9 @@ async fn review(State(fake): State, headers: HeaderMap) -> Response { if let Some(summary) = fake.summary { body["change_summary"] = summary; } + if let Some(reach) = fake.reach { + body["assessments"][0]["declared_reach"] = reach; + } Json(body).into_response() } @@ -645,6 +649,87 @@ async fn a_review_reads_with_unknown_fields_and_keeps_its_gap() { } } +#[tokio::test] +async fn declared_reach_prints_in_text_and_stays_out_of_sarif() { + let entity = |kind: &str, label: &str, depth: usize| { + let step = json!({ + "assertion_id": "0190f3a0-0000-7000-8000-0000000000e1", + "relation": "proofline.relation.consumes_api", + "direction": "IN", + }); + json!({ + "entity_id": "0190f3a0-0000-7000-8000-0000000000e2", + "kind": kind, + "label": label, + "type_keys": [], + "path": vec![step; depth], + }) + }; + let reach = |outcome: &str, complete: bool, entities: Vec, gaps: Value| { + json!({ + "outcome": outcome, "complete": complete, "entities": entities, "gaps": gaps, + "receipt_digest": null, "snapshot_id": null, "terraform": null, + }) + }; + let found = vec![ + entity("service", "checkout-api", 1), + entity("queue", "orders\u{1b}[2J", 2), + ]; + let incomplete = json!([{ "code": "COVERAGE_INCOMPLETE" }]); + for (reach, expected) in [ + ( + reach("READ", true, found, json!([])), + vec![ + " declared reach: complete, 2 found", + " service checkout-api depth 1", + // The escape sequence is neutralised before it reaches the terminal. + " queue orders\u{fffd}[2J depth 2", + ], + ), + ( + reach("READ", true, vec![], json!([])), + vec![" declared reach: complete, none found"], + ), + ( + reach("READ", false, vec![], incomplete), + vec![" declared reach: incomplete (COVERAGE_INCOMPLETE), 0 found so far"], + ), + ( + reach("NO_ROOTS", false, vec![], json!([])), + vec![" declared reach: unknown (NO_ROOTS)"], + ), + ] { + let console = serve(Fake { + reach: Some(reach), + ..Fake::default() + }) + .await + .to_string(); + let id = "0190f3a0-0000-7000-8000-0000000000aa"; + + let output = cli(&console, &["findings", "--review", id]).await; + let text = String::from_utf8_lossy(&output.stdout); + let lines: Vec<&str> = text.lines().collect(); + // The reach follows its assessment's heading, in the order the server sent. + let heading = lines + .iter() + .position(|line| line.starts_with("production: ")) + .unwrap(); + assert_eq!( + lines[heading + 1..][..expected.len()], + expected[..], + "{text}" + ); + // The fake assessment is incomplete, so the exit code stays 2 whatever the reach says. + assert_eq!(output.status.code(), Some(2), "{output:?}"); + + let output = cli(&console, &["findings", "--review", id, "--sarif"]).await; + let sarif: Value = serde_json::from_slice(&output.stdout).unwrap(); + assert_eq!(sarif["version"], "2.1.0"); + assert!(!sarif.to_string().contains("checkout-api"), "{sarif:#}"); + } +} + #[tokio::test] async fn redirects_are_refused_so_the_token_stays_on_its_origin() { let api = Api::new( @@ -1254,6 +1339,8 @@ async fn findings_of_a_departed_repository_still_resolve_through_its_reviews() { const CI_REPOSITORY: &str = "0190f3a0-0000-7000-8000-0000000000f0"; const CI_REVIEW: &str = "0190f3a0-0000-7000-8000-0000000000f1"; const CI_HEAD: &str = "89abcdef0123456789abcdef0123456789abcdef"; +/// Every CI assessment declares this dependent; it never decides an exit code. +const CI_REACH_LABEL: &str = "checkout-api"; #[derive(Debug, Clone, Copy)] struct CiCodeFinding { @@ -1387,6 +1474,14 @@ async fn ci_console( "status": assessment, "findings": findings, "checks": { "receipt_recorded": true, "status": "READY", "families": [] }, + "declared_reach": { + "outcome": "READ", "complete": true, "gaps": [], + "receipt_digest": null, "snapshot_id": null, "terraform": null, + "entities": [{ + "entity_id": "0190f3a0-0000-7000-8000-0000000000e2", + "kind": "service", "label": CI_REACH_LABEL, "type_keys": [], "path": [], + }], + }, }], }); if let Some(code) = code { @@ -1438,6 +1533,32 @@ async fn ci_console( (origin, requests) } +#[tokio::test] +async fn ci_review_text_shows_the_reach_summary_without_entity_labels() { + let (origin, _) = ci_console("PULL_REQUEST", StatusCode::OK, "COMPLETED", None, None).await; + let directory = tempfile::tempdir().unwrap(); + let output = tokio::process::Command::new(env!("CARGO_BIN_EXE_proofline")) + .args(["--base-url", &origin, "--org", ORG, "ci", "review"]) + .args(["--repo", "acme/app", "--timeout", "0"]) + .env("PROOFLINE_TOKEN", TOKEN) + .env("COMMIT_SHA", CI_HEAD) + .env_remove("GITHUB_SHA") + .env("PATH", "") + .current_dir(directory.path()) + .kill_on_drop(true) + .output() + .await + .unwrap(); + assert_eq!(output.status.code(), Some(0), "{output:?}"); + let text = String::from_utf8_lossy(&output.stdout); + assert!( + text.lines() + .any(|line| line == " declared reach: complete, 1 found"), + "{text}" + ); + assert!(!text.contains(CI_REACH_LABEL), "{text}"); +} + struct CiCase { listed: &'static str, status: StatusCode,