Skip to content
Merged
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
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
72 changes: 72 additions & 0 deletions src/fixes.rs
Original file line number Diff line number Diff line change
@@ -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<Uuid>,
/// Full pushed commit SHA; the server requires the pull request's live head.
#[arg(long)]
commit: String,
#[arg(long)]
note: Option<String>,
},
/// 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(&note.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}))
}
})
}
}
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use uuid::Uuid;

use crate::api::{Api, ApiError, Http};
use crate::credentials::{Credential, Source};
mod fixes;
mod knowledge;
mod tools;

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -388,6 +392,7 @@ pub async fn run(cli: Cli, token: Option<SecretString>) -> anyhow::Result<Verdic
}
Ok(Verdict::Done)
}
Command::Fix(command) => 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 } => {
Expand Down
86 changes: 86 additions & 0 deletions tests/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(Mutex::new(Vec::<Value>::new()));
let observed = Arc::clone(&calls);
let app = Router::new().route("/mcp", post(move |headers: HeaderMap, Json(body): Json<Value>| {
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();
}
Loading