From bc5fabc76f2459d4888b44b132cf9fd96fedf9c5 Mon Sep 17 00:00:00 2001 From: Mohsen Azimi Date: Mon, 26 Oct 2026 09:32:45 +0100 Subject: [PATCH 1/3] Add native fix context and pushed-head verification commands --- README.md | 23 ++++++++++++++ src/fixes.rs | 72 ++++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 5 +++ tests/http.rs | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 186 insertions(+) create mode 100644 src/fixes.rs diff --git a/README.md b/README.md index 6de7bbe..917af23 100644 --- a/README.md +++ b/README.md @@ -106,3 +106,26 @@ in a directory on PATH. Run `proofline login` to store credentials in Windows Credential Manager. To update, close running Proofline processes and replace the executable from a verified release. The Unix shell installer and self-update command do not install Windows binaries. + +## Fix context and pushed fixes + +```sh +proofline fix list --repo owner/repository --pr 42 +proofline fix context FINDING_ID +proofline fix verify --review REVIEW_ID --findings FINDING_ID --commit FULL_PUSHED_SHA +proofline fix status REQUEST_ID +``` + +`fix list` returns open ENV findings at the live pull-request head, including +availability, assessment gaps and truncation. `fix context` reads captured source +excerpts and untrusted remediation. `fix verify` requests re-verification of 1–20 +distinct findings from one review at the exact commit you pushed; the server +confirms that it is the live head. Optional `--note` accepts 1–2,000 characters. +The command makes one attempt. After an ambiguous failure, inspect the review +before requesting again. + +These commands return MCP tool results as JSON. `isError: true` exits nonzero. +A successful read is not a verdict: `PENDING`, `UNAVAILABLE` and `NOT_VERIFIED` +retain their meaning. Only the server's recorded re-verification establishes a +fix. Reads need `reviews:read`; verification also needs `reviews:request` and +current repository write access. For unpushed local changes, use `review --verify`. diff --git a/src/fixes.rs b/src/fixes.rs new file mode 100644 index 0000000..80979df --- /dev/null +++ b/src/fixes.rs @@ -0,0 +1,72 @@ +//! Read captured fix context and request verification of an explicitly pushed commit. +use crate::git; +use clap::Subcommand; +use serde_json::{Value, json}; +use uuid::Uuid; + +#[derive(Debug, Subcommand)] +pub(crate) enum FixCommand { + /// List open ENV findings at a pull request's live head, retaining availability and gaps. + List { + #[arg(long)] + repo: String, + #[arg(long, value_parser = clap::value_parser!(u64).range(1..))] + pr: u64, + }, + /// Read captured source excerpts and untrusted remediation for one finding. + Context { finding_id: Uuid }, + /// Request re-verification after pushing this exact commit. Makes one attempt. + Verify { + #[arg(long)] + review: Uuid, + #[arg(long, num_args = 1..=20, required = true)] + findings: Vec, + /// Full pushed commit SHA; the server requires the pull request's live head. + #[arg(long)] + commit: String, + #[arg(long)] + note: Option, + }, + /// Read recorded outcomes. PENDING and NOT_VERIFIED do not establish a fix. + Status { request_id: Uuid }, +} + +impl FixCommand { + pub fn request(self) -> anyhow::Result<(&'static str, Value)> { + Ok(match self { + Self::List { repo, pr } => ( + "list_open_findings", + json!({"repository": repo, "pull_request_number": pr}), + ), + Self::Context { finding_id } => ("get_fix_context", json!({"finding_id": finding_id})), + Self::Verify { + review, + findings, + commit, + note, + } => { + git::commit_sha(&commit)?; + let mut unique = findings.clone(); + unique.sort_unstable(); + unique.dedup(); + anyhow::ensure!( + unique.len() == findings.len(), + "finding IDs must be distinct" + ); + let mut args = + json!({"review_id": review, "finding_ids": findings, "commit_sha": commit}); + if let Some(note) = note { + anyhow::ensure!( + (1..=2000).contains(¬e.chars().count()), + "note must contain 1 to 2000 characters" + ); + args["note"] = json!(note); + } + ("request_reverification", args) + } + Self::Status { request_id } => { + ("get_reverification", json!({"request_id": request_id})) + } + }) + } +} diff --git a/src/lib.rs b/src/lib.rs index 2f7e2e0..352f36f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,6 +33,7 @@ use uuid::Uuid; use crate::api::{Api, ApiError, Http}; use crate::credentials::{Credential, Source}; +mod fixes; mod knowledge; mod tools; @@ -74,6 +75,9 @@ pub struct Cli { #[derive(Debug, Subcommand)] enum Command { + /// Read fix context and verify fixes at an explicitly pushed commit. + #[command(subcommand)] + Fix(fixes::FixCommand), /// List one page of reviews, retaining its continuation cursor. Reviews(tools::ListArgs), /// Read the routing decisions of a review as JSON. @@ -388,6 +392,7 @@ pub async fn run(cli: Cli, token: Option) -> anyhow::Result knowledge::run(origin, token, cli.org, command.request()?).await, Command::Wiki(command) => knowledge::run(origin, token, cli.org, command.request()?).await, Command::Ask(args) => knowledge::run(origin, token, cli.org, args.request()?).await, Command::Architecture { environment_id } => { diff --git a/tests/http.rs b/tests/http.rs index c128c81..a7243c6 100644 --- a/tests/http.rs +++ b/tests/http.rs @@ -2102,3 +2102,89 @@ async fn setup_handoff_uses_customer_routes_without_a_token() { "https://proofline.sh/orgs/github/example-org/settings/installation" ); } + +#[tokio::test] +async fn fix_commands_preserve_context_and_never_retry_verification() { + let calls = Arc::new(std::sync::Mutex::new(Vec::::new())); + let observed = Arc::clone(&calls); + let app = Router::new().route("/mcp", post(move |headers: HeaderMap, Json(body): Json| { + let observed = Arc::clone(&observed); + async move { + assert_eq!(headers[header::AUTHORIZATION], format!("Bearer {TOKEN}")); + if body["method"] == "initialize" { + return Json(json!({"jsonrpc":"2.0", "id":1, "result":{"protocolVersion":"2025-11-25"}})).into_response(); + } + if body["method"] == "notifications/initialized" { + return StatusCode::ACCEPTED.into_response(); + } + observed.lock().unwrap().push(body["params"].clone()); + if body["params"]["name"] == "request_reverification" { + return (StatusCode::SERVICE_UNAVAILABLE, [(header::RETRY_AFTER, "0")], "private failure").into_response(); + } + Json(json!({"jsonrpc":"2.0", "id":2, "result":{"content":[], "structuredContent":{"status":"UNAVAILABLE", "items":null}}})).into_response() + } + })); + let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap(); + let origin = format!("http://{}", listener.local_addr().unwrap()); + let server = tokio::spawn(async move { axum::serve(listener, app).await.unwrap() }); + for args in [ + vec!["fix", "list", "--repo", "owner/name", "--pr", "7"], + vec!["fix", "context", SELECTED_REVIEW], + vec!["fix", "status", SELECTED_REVIEW], + ] { + let output = cli(&origin, &args).await; + assert!( + output.status.success(), + "{}", + String::from_utf8_lossy(&output.stderr) + ); + let result: Value = serde_json::from_slice(&output.stdout).unwrap(); + assert_eq!(result["structuredContent"]["status"], "UNAVAILABLE"); + assert!(result["structuredContent"]["items"].is_null()); + } + let sha = "a".repeat(40); + let output = cli( + &origin, + &[ + "fix", + "verify", + "--review", + SELECTED_REVIEW, + "--findings", + SELECTED_REVIEW, + "--commit", + &sha, + "--note", + "fixed code", + ], + ) + .await; + assert!(!output.status.success()); + assert!(!String::from_utf8_lossy(&output.stderr).contains("private failure")); + assert_eq!( + *calls.lock().unwrap(), + vec![ + json!({"name":"list_open_findings", "arguments":{"repository":"owner/name", "pull_request_number":7}}), + json!({"name":"get_fix_context", "arguments":{"finding_id":SELECTED_REVIEW}}), + json!({"name":"get_reverification", "arguments":{"request_id":SELECTED_REVIEW}}), + json!({"name":"request_reverification", "arguments":{"review_id":SELECTED_REVIEW, "finding_ids":[SELECTED_REVIEW], "commit_sha":sha, "note":"fixed code"}}), + ] + ); + let output = cli( + &origin, + &[ + "fix", + "verify", + "--review", + SELECTED_REVIEW, + "--findings", + SELECTED_REVIEW, + "--commit", + "main", + ], + ) + .await; + assert!(!output.status.success()); + assert_eq!(calls.lock().unwrap().len(), 4); + server.abort(); +} From d55070c8fa891783ea0b3f8354d5daca4be070db Mon Sep 17 00:00:00 2001 From: Mohsen Azimi Date: Mon, 26 Oct 2026 09:37:05 +0100 Subject: [PATCH 2/3] Format status identifiers in command documentation --- src/fixes.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fixes.rs b/src/fixes.rs index 80979df..0c87a0a 100644 --- a/src/fixes.rs +++ b/src/fixes.rs @@ -27,7 +27,7 @@ pub(crate) enum FixCommand { #[arg(long)] note: Option, }, - /// Read recorded outcomes. PENDING and NOT_VERIFIED do not establish a fix. + /// Read recorded outcomes. `PENDING` and `NOT_VERIFIED` do not establish a fix. Status { request_id: Uuid }, } From e8f3ff477926e1f0143d3fd1c08b844cce7a3522 Mon Sep 17 00:00:00 2001 From: Mohsen Azimi Date: Mon, 26 Oct 2026 09:39:36 +0100 Subject: [PATCH 3/3] Use the imported mutex type in the HTTP regression --- tests/http.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/http.rs b/tests/http.rs index a7243c6..b65ed37 100644 --- a/tests/http.rs +++ b/tests/http.rs @@ -2105,7 +2105,7 @@ async fn setup_handoff_uses_customer_routes_without_a_token() { #[tokio::test] async fn fix_commands_preserve_context_and_never_retry_verification() { - let calls = Arc::new(std::sync::Mutex::new(Vec::::new())); + let calls = Arc::new(Mutex::new(Vec::::new())); let observed = Arc::clone(&calls); let app = Router::new().route("/mcp", post(move |headers: HeaderMap, Json(body): Json| { let observed = Arc::clone(&observed);