Skip to content
Closed
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
14 changes: 12 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -1183,6 +1191,7 @@ async fn ci_review(
&detail,
state,
OutputFormat::from_json(args.json),
render::Reach::Summary,
)?;
let verdict = ci_verdict(
state,
Expand Down Expand Up @@ -1254,6 +1263,7 @@ fn print_review(
detail: &ReviewDetail,
state: Option<Outcome>,
format: OutputFormat,
shown: render::Reach,
) -> anyhow::Result<()> {
let mut stdout = std::io::stdout().lock();
match format {
Expand Down Expand Up @@ -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)
)?;
}
}
Expand Down
31 changes: 31 additions & 0 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,37 @@ pub struct Assessment {
pub incompleteness_kind: Option<String>,
pub reason_codes: Option<Vec<String>>,
pub release_evidence_gap: Option<String>,
/// 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<DeclaredReach>,
}

/// 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<ReachedEntity>,
pub gaps: Vec<ReachGap>,
}

#[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<serde_json::Value>,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct ReachGap {
pub code: String,
}

#[derive(Debug, Deserialize, Serialize)]
Expand Down
1 change: 1 addition & 0 deletions src/outcome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ mod tests {
incompleteness_kind: None,
reason_codes: None,
release_evidence_gap: None,
declared_reach: None,
}
}

Expand Down
58 changes: 51 additions & 7 deletions src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -41,7 +41,17 @@ fn finding(out: &mut Vec<String>, finding: &Finding) {
}
}

fn assessment(out: &mut Vec<String>, 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<String>, 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.
Expand All @@ -67,6 +77,39 @@ fn assessment(out: &mut Vec<String>, 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<String>, 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<String>, code: &CodeAssessment) {
Expand All @@ -92,7 +135,7 @@ fn code_assessment(out: &mut Vec<String>, code: &CodeAssessment) {
}

/// The review, with separate CODE and environment assessment blocks.
pub fn review(review: &ReviewDetail, state: Option<Outcome>, url: &Url) -> String {
pub fn review(review: &ReviewDetail, state: Option<Outcome>, 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)),
Expand Down Expand Up @@ -159,7 +202,7 @@ pub fn review(review: &ReviewDetail, state: Option<Outcome>, 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());
Expand Down Expand Up @@ -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()),
Expand Down Expand Up @@ -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"));
}
Expand All @@ -264,15 +308,15 @@ 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}");
}

#[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"));
}
Expand Down
11 changes: 7 additions & 4 deletions tests/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -159,6 +159,9 @@ fn types_match_the_public_contract() {
holds::<ReviewDetail>("CustomerReviewDetail");
holds::<OpenItems>("OpenItemsView");
holds::<Assessment>("CustomerAssessment");
holds::<DeclaredReach>("DeclaredReachView");
holds::<ReachedEntity>("ReachedEntityView");
holds::<ReachGap>("ReachGapView");
holds::<CodeAssessment>("CustomerCodeAssessment");
holds::<Checks>("CustomerChecks");
holds::<Check>("CustomerCheck");
Expand Down
Loading