diff --git a/openapi.public.json b/openapi.public.json index 22e8774..1cef9a9 100644 --- a/openapi.public.json +++ b/openapi.public.json @@ -704,6 +704,65 @@ ], "type": "object" }, + "ChangeSummary": { + "description": "What a review recorded about its change.", + "properties": { + "base_sha": { + "description": "The compared base commit. Null when the review pinned none.", + "type": [ + "string", + "null" + ] + }, + "files": { + "description": "The changed files the review read, by path, with the depth it read\n them at. Empty when the review recorded no change digest. Files the\n review's filters kept from review are listed apart, with their reason.", + "items": { + "$ref": "#/components/schemas/FileFact" + }, + "type": "array" + }, + "head_sha": { + "description": "The reviewed head commit.", + "type": "string" + }, + "prose": { + "anyOf": [ + { + "$ref": "#/components/schemas/Prose" + }, + { + "type": "null" + } + ], + "description": "Model-written prose. Present only when `prose_outcome` is `PUBLISHED`.\n It is untrusted text: render it inert." + }, + "prose_outcome": { + "allOf": [ + { + "$ref": "#/components/schemas/ProseOutcome" + } + ], + "description": "The recorded prose-generation outcome, before response-time withholding." + }, + "route": { + "anyOf": [ + { + "$ref": "#/components/schemas/SummaryRoute" + }, + { + "type": "null" + } + ], + "description": "The route the summary applied. Null when the review recorded no change\n digest, so no route was asked." + } + }, + "required": [ + "head_sha", + "files", + "prose_outcome" + ], + "type": "object" + }, "CheckLifecycle": { "description": "World's lifecycle disclosure for the evaluator version that answered, as\n the receipt recorded it. A deployment gate counts only `GATING` results\n (`DeterministicCoverage::gate_effective_status`), and only when it\n evaluates a deployment; the lifecycle alone permits or blocks nothing.", "oneOf": [ @@ -1757,6 +1816,17 @@ ], "description": "The change-level diagram: the changed call path from the pinned code\n index and the relations World declares. Absent when the review\n recorded none." }, + "change_summary": { + "anyOf": [ + { + "$ref": "#/components/schemas/ChangeSummary" + }, + { + "type": "null" + } + ], + "description": "What the change does and which files the review read at which depth\n (ยง55). Null until the review's publication records it, and for a\n review that is not of a pull request. Generated text has current\n credentials and recorded protected values withheld; missing or expired\n provenance withholds the generated text whole." + }, "check_run_url": { "description": "The GitHub check run Proofline published for this review. Null when\n none was published.", "type": [ @@ -2206,6 +2276,17 @@ "string", "null" ] + }, + "terraform": { + "anyOf": [ + { + "$ref": "#/components/schemas/TerraformRootsView" + }, + { + "type": "null" + } + ], + "description": "The Terraform addresses the reach also started from, or why it took\n none. Absent when the assessment read reach only from the deployed\n revision." } }, "required": [ @@ -2389,6 +2470,51 @@ ], "type": "string" }, + "FileFact": { + "properties": { + "additions": { + "description": "Lines added in this file's recorded diff.", + "format": "int64", + "type": "integer" + }, + "deletions": { + "description": "Lines deleted in this file's recorded diff.", + "format": "int64", + "type": "integer" + }, + "depth": { + "allOf": [ + { + "$ref": "#/components/schemas/ReviewDepth" + } + ], + "description": "The review depth recorded for this file." + }, + "path": { + "description": "The repository-relative path of the changed file.", + "type": "string" + }, + "previous_path": { + "description": "The path before a rename.", + "type": [ + "string", + "null" + ] + }, + "status": { + "description": "GitHub's file status: `added`, `modified`, `removed`, `renamed` and so on.", + "type": "string" + } + }, + "required": [ + "path", + "status", + "additions", + "deletions", + "depth" + ], + "type": "object" + }, "FileProjection": { "properties": { "depth": { @@ -3954,6 +4080,75 @@ "title": "Problem", "type": "object" }, + "Prose": { + "properties": { + "headline": { + "description": "At most 120 characters.", + "type": "string" + }, + "notable_paths": { + "description": "Paths in the pinned diff the prose calls out.", + "items": { + "type": "string" + }, + "type": "array" + }, + "paragraphs": { + "description": "At most three of at most 400 characters; one on the `SHORT` route.", + "items": { + "type": "string" + }, + "type": "array" + } + }, + "required": [ + "headline", + "paragraphs", + "notable_paths" + ], + "type": "object" + }, + "ProseOutcome": { + "description": "Why the summary carries prose or does not.", + "oneOf": [ + { + "enum": [ + "PUBLISHED" + ], + "type": "string" + }, + { + "const": "NO_CHANGE_DIGEST", + "description": "The review recorded no change digest to summarize.", + "type": "string" + }, + { + "const": "NOT_REQUESTED", + "description": "The applied route was `DETERMINISTIC_ONLY`.", + "type": "string" + }, + { + "const": "MODEL_UNAVAILABLE", + "description": "No fast-tier model was bound, priced or funded, or it did not answer.", + "type": "string" + }, + { + "const": "MALFORMED", + "description": "The answer did not fit the tool's schema or its limits.", + "type": "string" + }, + { + "const": "REJECTED", + "description": "The prose used a word a summary never uses (\"safe\", \"no risk\",\n \"approved\") or named a path outside the diff.", + "type": "string" + }, + { + "const": "UNGROUNDED", + "description": "Jev answered that a statement does not follow from the diff slices.", + "type": "string" + } + ] + }, "PullRequestMergeGate": { "properties": { "assessment_count": { @@ -4435,6 +4630,13 @@ ], "type": "object" }, + "ReviewDepth": { + "description": "The depth the applied route plan read a file at.", + "enum": [ + "STANDARD" + ], + "type": "string" + }, "ReviewDiffStats": { "properties": { "additions": { @@ -5826,6 +6028,56 @@ ], "type": "object" }, + "SummaryRoute": { + "enum": [ + "DETERMINISTIC_ONLY", + "SHORT", + "FULL" + ], + "type": "string" + }, + "TerraformPlanView": { + "enum": [ + "TAKEN", + "NOT_DECLARED", + "NOT_PINNED", + "HEAD_DIFFERS", + "ADDRESSES_UNREPORTED" + ], + "type": "string" + }, + "TerraformRootsView": { + "description": "The Terraform roots of one declared reach read.", + "properties": { + "addresses": { + "description": "The changed resource instance addresses taken as roots.", + "items": { + "type": "string" + }, + "type": "array" + }, + "omitted": { + "description": "Changed addresses left out at World's limit of 100 roots per read.", + "format": "uint", + "minimum": 0, + "type": "integer" + }, + "plan": { + "allOf": [ + { + "$ref": "#/components/schemas/TerraformPlanView" + } + ], + "description": "`TAKEN` when the plan pinned for the reviewed commit named the roots,\n `NOT_DECLARED` when the environment captures no Terraform plan for this\n review, `NOT_PINNED` when it declares one and none was pinned,\n `HEAD_DIFFERS` when the pinned plan is for another commit, and\n `ADDRESSES_UNREPORTED` when the pinned plan records no changed\n addresses because it was pinned before World reported them." + } + }, + "required": [ + "plan", + "addresses", + "omitted" + ], + "type": "object" + }, "ThreadObservationFreshness": { "enum": [ "FRESH", diff --git a/tests/http.rs b/tests/http.rs index 68b8421..57d9800 100644 --- a/tests/http.rs +++ b/tests/http.rs @@ -236,6 +236,7 @@ async fn asynchronous_pull_request_acknowledgment_respects_json_without_polling( struct Fake { polls: Arc, report_organization: bool, + summary: Option, } async fn code() -> Json { @@ -274,7 +275,7 @@ async fn token(State(fake): State, Json(body): Json) -> Response { Json(issued).into_response() } -async fn review(headers: HeaderMap) -> Response { +async fn review(State(fake): State, headers: HeaderMap) -> Response { if headers .get(header::AUTHORIZATION) .and_then(|value| value.to_str().ok()) @@ -286,7 +287,7 @@ async fn review(headers: HeaderMap) -> Response { ) .into_response(); } - Json(json!({ + let mut body = json!({ "id": "0190f3a0-0000-7000-8000-0000000000aa", "public_key": "rev_0190f3a00000700080000000000000aa", "kind": "PULL_REQUEST", @@ -332,8 +333,11 @@ async fn review(headers: HeaderMap) -> Response { "pull_request_number": 42, "repository_full_name": "acme/web", "an_added_field": true, - })) - .into_response() + }); + if let Some(summary) = fake.summary { + body["change_summary"] = summary; + } + Json(body).into_response() } async fn serve(fake: Fake) -> Origin { @@ -420,44 +424,76 @@ async fn a_server_that_omits_the_organization_needs_one_named() { #[tokio::test] async fn a_review_reads_with_unknown_fields_and_keeps_its_gap() { - let origin = serve(Fake::default()).await; - let console = origin.to_string(); - let api = Api::new(Http::new(origin).unwrap(), SecretString::from(TOKEN), org()); - let id = "0190f3a0-0000-7000-8000-0000000000aa".parse().unwrap(); - let (raw, detail) = api.review(id).await.unwrap(); - assert_eq!(raw["an_added_field"], true); - let state = proofline_cli::outcome::terminal(&detail); - assert_eq!(state, Some(proofline_cli::outcome::Outcome::Incomplete)); + let published = json!({ + "head_sha": "89abcdef0123456789abcdef0123456789abcdef", + "base_sha": "0123456789abcdef0123456789abcdef01234567", + "files": [{ + "path": "src/new.rs", "previous_path": "src/old.rs", "status": "renamed", + "additions": 3, "deletions": 1, "depth": "STANDARD", + }], + "route": "SHORT", + "prose_outcome": "PUBLISHED", + "prose": { + "headline": "[withheld] ", + "paragraphs": ["Moves the request handler."], + "notable_paths": ["src/new.rs"], + }, + }); + let mut withheld = published.clone(); + withheld["prose"] = Value::Null; + for summary in [None, Some(Value::Null), Some(published), Some(withheld)] { + let origin = serve(Fake { + summary: summary.clone(), + ..Fake::default() + }) + .await; + let console = origin.to_string(); + let api = Api::new(Http::new(origin).unwrap(), SecretString::from(TOKEN), org()); + let id = "0190f3a0-0000-7000-8000-0000000000aa".parse().unwrap(); + let (raw, detail) = api.review(id).await.unwrap(); + assert_eq!(raw["an_added_field"], true); + assert_eq!(raw.get("change_summary"), summary.as_ref()); + assert_eq!( + raw["head_commit_sha"], + "89abcdef0123456789abcdef0123456789abcdef" + ); + assert_eq!( + raw["base_commit_sha"], + "0123456789abcdef0123456789abcdef01234567" + ); + let state = proofline_cli::outcome::terminal(&detail); + assert_eq!(state, Some(proofline_cli::outcome::Outcome::Incomplete)); - let output = cli( - &console, - &[ - "findings", - "--review", - "0190f3a0-0000-7000-8000-0000000000aa", - "--json", - ], - ) - .await; - assert_eq!(output.status.code(), Some(2), "{output:?}"); - let result: Value = serde_json::from_slice(&output.stdout).unwrap(); - assert_eq!(result["schema"], "proofline.review-result.v1"); - assert_eq!(result["outcome"], "INCOMPLETE"); - assert_eq!(result["review"], raw); - let schema_output = cli(&console, &["review", "--schema"]).await; - assert!(schema_output.status.success(), "{schema_output:?}"); - let result_schema: Value = serde_json::from_slice(&schema_output.stdout).unwrap(); - jsonschema::validator_for(&result_schema) - .unwrap() - .validate(&result) - .unwrap(); + let output = cli( + &console, + &[ + "findings", + "--review", + "0190f3a0-0000-7000-8000-0000000000aa", + "--json", + ], + ) + .await; + assert_eq!(output.status.code(), Some(2), "{output:?}"); + let result: Value = serde_json::from_slice(&output.stdout).unwrap(); + assert_eq!(result["schema"], "proofline.review-result.v1"); + assert_eq!(result["outcome"], "INCOMPLETE"); + assert_eq!(result["review"], raw); + let schema_output = cli(&console, &["review", "--schema"]).await; + assert!(schema_output.status.success(), "{schema_output:?}"); + let result_schema: Value = serde_json::from_slice(&schema_output.stdout).unwrap(); + jsonschema::validator_for(&result_schema) + .unwrap() + .validate(&result) + .unwrap(); - let wrong = Api::new( - Http::new(serve(Fake::default()).await).unwrap(), - SecretString::from("pld_other"), - org(), - ); - assert_eq!(wrong.review(id).await.unwrap_err().status(), Some(401)); + let wrong = Api::new( + Http::new(serve(Fake::default()).await).unwrap(), + SecretString::from("pld_other"), + org(), + ); + assert_eq!(wrong.review(id).await.unwrap_err().status(), Some(401)); + } } #[tokio::test] @@ -1008,7 +1044,8 @@ async fn departed() -> Origin { .route( &format!("/api/v1/organizations/{ORG}/reviews/{{id}}"), get(review), - ); + ) + .with_state(Fake::default()); let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap(); let address = listener.local_addr().unwrap(); tokio::spawn(async move { axum::serve(listener, app).await.unwrap() });