diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9cd34e5..331c3cc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,3 +24,25 @@ jobs: - run: cargo clippy --locked --all-targets -- -D warnings - run: cargo test --locked - run: cargo install cargo-deny --locked --version 0.20.2 && cargo deny check + + windows: + runs-on: windows-2025 + timeout-minutes: 30 + defaults: + run: + shell: bash + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - run: cargo build --release --locked --target x86_64-pc-windows-msvc + - run: python scripts/archive.py x86_64-pc-windows-msvc + - shell: pwsh + run: | + tar -xzf artifacts/proofline-x86_64-pc-windows-msvc.tar.gz -C artifacts + & ./artifacts/proofline.exe --version + if ($LASTEXITCODE -ne 0) { throw "Windows executable failed" } + & ./artifacts/proofline.exe setup --print + if ($LASTEXITCODE -ne 0) { throw "Setup handoff failed" } + & ./artifacts/proofline.exe review --schema | ConvertFrom-Json | Out-Null + if ($LASTEXITCODE -ne 0) { throw "Review schema failed" } diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c1afe2b..4c80479 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -40,10 +40,15 @@ jobs: target: aarch64-unknown-linux-musl - runner: macos-15-intel target: x86_64-apple-darwin + - runner: windows-2025 + target: x86_64-pc-windows-msvc - runner: macos-15 target: aarch64-apple-darwin runs-on: ${{ matrix.runner }} timeout-minutes: 30 + defaults: + run: + shell: bash steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: @@ -63,7 +68,9 @@ jobs: TARGET: ${{ matrix.target }} VERSION: ${{ needs.version.outputs.version }} run: | - test "$(target/"$TARGET"/release/proofline --version)" = "proofline $VERSION" + binary=proofline + if [[ "$TARGET" == *windows* ]]; then binary=proofline.exe; fi + test "$(target/"$TARGET"/release/"$binary" --version)" = "proofline $VERSION" python3 scripts/archive.py "$TARGET" - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: @@ -94,7 +101,7 @@ jobs: GH_TOKEN: ${{ github.token }} run: | set -euo pipefail - test "$(find artifacts -name '*.tar.gz' | wc -l)" -eq 4 + test "$(find artifacts -name '*.tar.gz' | wc -l)" -eq 5 (cd artifacts && LC_ALL=C sha256sum proofline-*.tar.gz > SHA256SUMS) printf '%s\n' "$VERSION" > artifacts/latest # Creating the draft reserves the GitHub version atomically. diff --git a/Cargo.lock b/Cargo.lock index e5f73fd..f4c7bc0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1780,7 +1780,7 @@ dependencies = [ [[package]] name = "proofline-cli" -version = "0.1.3" +version = "0.1.4" dependencies = [ "anyhow", "axum", diff --git a/Cargo.toml b/Cargo.toml index 4a021c5..9241b86 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "proofline-cli" -version = "0.1.3" +version = "0.1.4" edition = "2024" rust-version = "1.95" description = "Proofline command-line client for the review API" diff --git a/README.md b/README.md index 0888b93..6de7bbe 100644 --- a/README.md +++ b/README.md @@ -64,3 +64,45 @@ The bucket-scoped credential is the `CLI_RELEASE_R2_CREDENTIALS` environment sec `CLOUDFLARE_ACCOUNT_ID` is an environment variable. R2 versions are reserved with a conditional write. A failed publication retains its reservation; raise the package version before another release. Install and update URLs stay on proofline.sh. + +## Review and knowledge tools + +`proofline reviews --repository-id UUID --cursor CURSOR` returns one page with its +continuation metadata. All flags are optional. `proofline routing REVIEW_ID` reads +recorded routing. `proofline run --repo owner/name --pr 7 --run 2` reads one retained run. + +`proofline session prompt FINDING_ID` returns the protected prompt and eligible +connections. After reviewing it, use `proofline session start FINDING_ID +--connection-id UUID --prompt-digest DIGEST`. This starts once and can incur vendor +charges. `proofline session get SESSION_ID` reads status. These commands need a +personal token with `agent_sessions:start`; device sign-in cannot grant this authority. + +Knowledge commands return the MCP tool result as JSON, including untrusted-text +wrappers, citations and `isError`. A refused tool exits nonzero. They use the same +origin and credential as the MCP bridge and never retry a tool call. + +```sh +proofline wiki list --repo owner/name +proofline wiki get index --repo owner/name --commit FULL_COMMIT_SHA +proofline ask --repo owner/name 'Where is authentication enforced?' +proofline architecture ENVIRONMENT_ID +proofline plan get PLAN_ID +proofline plan implement PLAN_ID +proofline plan implementation IMPLEMENTATION_ID +``` + +Knowledge reads need `reviews:read` and `knowledge:read`. Implementation also needs +`plans:implement`, a personal token and approval of the exact published plan version. +`proofline setup` opens the browser organization selector. `--organization NAME` +opens that GitHub organization's installation page; `--print` only prints its address. +Cloud trust and connection changes still require a signed-in administrator browser. + +## Windows + +Official releases include `proofline-x86_64-pc-windows-msvc.tar.gz` with `proofline.exe`. +Download it and `SHA256SUMS` from the same GitHub release. Compare its SHA-256 using +`Get-FileHash -Algorithm SHA256`, then extract with `tar -xzf` and put `proofline.exe` +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. diff --git a/scripts/archive.py b/scripts/archive.py index 780b16f..9d4b617 100644 --- a/scripts/archive.py +++ b/scripts/archive.py @@ -6,13 +6,14 @@ import tarfile target = sys.argv[1] -source = Path("target") / target / "release/proofline" +binary = "proofline.exe" if "windows" in target else "proofline" +source = Path("target") / target / "release" / binary data = source.read_bytes() Path("artifacts").mkdir(exist_ok=True) with Path(f"artifacts/proofline-{target}.tar.gz").open("wb") as output: with gzip.GzipFile(filename="", fileobj=output, mode="wb", mtime=0) as compressed: with tarfile.open(fileobj=compressed, mode="w") as archive: - entry = tarfile.TarInfo("proofline") + entry = tarfile.TarInfo(binary) entry.size = len(data) entry.mode = 0o755 entry.mtime = 0 diff --git a/scripts/publish-r2.sh b/scripts/publish-r2.sh index 978c3d2..02e27b2 100755 --- a/scripts/publish-r2.sh +++ b/scripts/publish-r2.sh @@ -19,16 +19,16 @@ unset CLI_RELEASE_R2_CREDENTIALS temporary=$(mktemp -d) trap 'rm -rf "$temporary"' EXIT -targets='aarch64-apple-darwin aarch64-unknown-linux-musl x86_64-apple-darwin x86_64-unknown-linux-musl' +targets='aarch64-apple-darwin aarch64-unknown-linux-musl x86_64-apple-darwin x86_64-pc-windows-msvc x86_64-unknown-linux-musl' # Verify every archive before the first upload. The manifest names exactly -# the four files the installer can download, with their actual digests. +# the five files the installer can download, with their actual digests. for target in $targets; do archive="proofline-$target.tar.gz" [ -f "$dist/$archive" ] || refuse "missing $archive" digest=$(sha256sum "$dist/$archive" | cut -d ' ' -f 1) printf '%s %s\n' "$digest" "$archive" >> "$temporary/SHA256SUMS" done -cmp -s "$temporary/SHA256SUMS" "$dist/SHA256SUMS" || refuse 'SHA256SUMS does not match the four release archives' +cmp -s "$temporary/SHA256SUMS" "$dist/SHA256SUMS" || refuse 'SHA256SUMS does not match the five release archives' put() { local key=$1 source=$2 content_type=$3 cache_control=$4 condition=${5:-} digest @@ -77,7 +77,7 @@ for target in $targets; do put "$version/$archive" "$dist/$archive" application/gzip "$immutable" done put "$version/SHA256SUMS" "$dist/SHA256SUMS" 'text/plain; charset=utf-8' "$immutable" -# Installers see the version only after all five release objects exist. +# Installers see the version only after all six release objects exist. printf '%s\n' "$version" > "$temporary/latest" put latest "$temporary/latest" 'text/plain; charset=utf-8' 'public, max-age=60' printf 'cli publish: uploaded CLI %s\n' "$version" diff --git a/scripts/test_publish_r2.py b/scripts/test_publish_r2.py index 4310880..3db1b30 100644 --- a/scripts/test_publish_r2.py +++ b/scripts/test_publish_r2.py @@ -22,7 +22,7 @@ SECRET = "c" * 64 TARGETS = sorted([ "x86_64-unknown-linux-musl", "aarch64-unknown-linux-musl", - "x86_64-apple-darwin", "aarch64-apple-darwin", + "x86_64-apple-darwin", "aarch64-apple-darwin", "x86_64-pc-windows-msvc", ]) diff --git a/src/api.rs b/src/api.rs index d6ed9f7..f908670 100644 --- a/src/api.rs +++ b/src/api.rs @@ -373,6 +373,48 @@ impl Api { self.decode(&reply.body) } + pub(crate) async fn tool_get(&self, path: &[&str]) -> Result { + self.get(self.url(path)).await + } + + pub(crate) async fn tool_post( + &self, + path: &[&str], + body: &serde_json::Value, + ) -> Result { + let (reply, _) = self + .http + .send(self.request(Method::POST, self.url(path)).json(body)) + .await?; + if !reply.status.is_success() { + return Err(self.http.problem(&reply)); + } + self.decode(&reply.body) + } + + pub(crate) async fn list_page( + &self, + repository: Option, + search: Option<&str>, + cursor: Option<&str>, + ) -> Result { + let mut url = self.url(&["reviews"]); + { + let mut query = url.query_pairs_mut(); + query.append_pair("limit", "50"); + if let Some(repository) = repository { + query.append_pair("repository", &repository.to_string()); + } + if let Some(search) = search { + query.append_pair("search", search); + } + if let Some(cursor) = cursor { + query.append_pair("cursor", cursor); + } + } + self.get(url).await + } + pub(crate) async fn history( &self, repository: &str, diff --git a/src/knowledge.rs b/src/knowledge.rs new file mode 100644 index 0000000..dd44a90 --- /dev/null +++ b/src/knowledge.rs @@ -0,0 +1,108 @@ +//! Native knowledge commands over the existing MCP authorization boundary. +use crate::{Verdict, api::Http, credentials, git, mcp, origin::Origin, tools}; +use clap::{Args, Subcommand}; +use secrecy::SecretString; +use serde_json::{Value, json}; +use uuid::Uuid; + +type Request = (&'static str, Value); + +#[derive(Debug, Args)] +pub(crate) struct Repository { + #[arg(long)] + repo: String, + /// Full indexed commit SHA; omit to use the newest completed build. + #[arg(long)] + commit: Option, +} +impl Repository { + fn arguments(&self) -> anyhow::Result { + let mut value = json!({"repository": self.repo}); + if let Some(commit) = &self.commit { + git::commit_sha(commit)?; + value["commit"] = json!(commit); + } + Ok(value) + } +} +#[derive(Debug, Subcommand)] +pub(crate) enum WikiCommand { + List(Repository), + Get { + page_key: String, + #[command(flatten)] + repository: Repository, + }, +} +impl WikiCommand { + pub fn request(self) -> anyhow::Result { + match self { + Self::List(repository) => Ok(("list_wiki_pages", repository.arguments()?)), + Self::Get { + page_key, + repository, + } => { + let mut args = repository.arguments()?; + args["page_key"] = json!(page_key); + Ok(("get_wiki_page", args)) + } + } + } +} +#[derive(Debug, Args)] +pub(crate) struct AskArgs { + question: String, + #[command(flatten)] + repository: Repository, +} +impl AskArgs { + pub fn request(self) -> anyhow::Result { + let mut args = self.repository.arguments()?; + args["question"] = json!(self.question); + Ok(("ask_codebase", args)) + } +} +#[derive(Debug, Subcommand)] +pub(crate) enum PlanCommand { + Get { + plan_id: Uuid, + }, + /// Start implementation of this exact approved, published plan version. + Implement { + plan_id: Uuid, + }, + Implementation { + implementation_id: Uuid, + }, +} +impl PlanCommand { + pub fn request(self) -> Request { + match self { + Self::Get { plan_id } => ("get_plan", json!({"plan_id": plan_id})), + Self::Implement { plan_id } => { + ("start_plan_implementation", json!({"plan_id": plan_id})) + } + Self::Implementation { implementation_id } => ( + "get_plan_implementation", + json!({"implementation_id": implementation_id}), + ), + } + } +} +pub(crate) async fn run( + origin: Origin, + token: Option, + org: Option, + (name, arguments): Request, +) -> anyhow::Result { + let credential = credentials::load(&origin, token, org).await?; + let value = mcp::call(&Http::new(origin)?, &credential.token, name, arguments).await?; + tools::json(&value)?; + Ok( + if value.get("isError").and_then(Value::as_bool) == Some(true) { + Verdict::Blocked + } else { + Verdict::Done + }, + ) +} diff --git a/src/lib.rs b/src/lib.rs index 65c17d1..2f7e2e0 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 knowledge; mod tools; use crate::model::{ @@ -73,6 +74,33 @@ pub struct Cli { #[derive(Debug, Subcommand)] enum Command { + /// List one page of reviews, retaining its continuation cursor. + Reviews(tools::ListArgs), + /// Read the routing decisions of a review as JSON. + Routing { review_id: Uuid }, + /// Read a specific recorded pull-request run. + Run(tools::RunArgs), + /// Preview, start or inspect a vendor coding-agent session. + #[command(subcommand)] + Session(tools::SessionCommand), + /// Read published wiki pages. + #[command(subcommand)] + Wiki(knowledge::WikiCommand), + /// Ask a codebase question at an optional indexed commit. + Ask(knowledge::AskArgs), + /// Read an environment's published architecture document. + Architecture { environment_id: Uuid }, + /// Read a plan or start and inspect its approved implementation. + #[command(subcommand)] + Plan(knowledge::PlanCommand), + /// Open browser onboarding; cloud trust requires browser sign-in. + Setup { + #[arg(long)] + print: bool, + /// GitHub organization slug; omit to open the authorized organization selector. + #[arg(long)] + organization: Option, + }, /// Rerun the original immutable review subject. Rerun(tools::RerunArgs), /// List the recorded runs of a pull request. @@ -346,6 +374,72 @@ pub async fn run(cli: Cli, token: Option) -> anyhow::Result { + let url = organization.as_deref().map_or_else( + || origin.join(["orgs"]), + |slug| origin.join(["orgs", "github", slug, "settings", "installation"]), + ); + writeln!(std::io::stdout().lock(), "{url}")?; + if !print { + webbrowser::open(url.as_str())?; + } + Ok(Verdict::Done) + } + 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 } => { + knowledge::run( + origin, + token, + cli.org, + ( + "get_architecture_document", + serde_json::json!({"environment_id": environment_id}), + ), + ) + .await + } + Command::Plan(command) => knowledge::run(origin, token, cli.org, command.request()).await, + Command::Reviews(args) => { + let api = connect(Http::new(origin)?, token, cli.org).await?; + tools::json( + &api.list_page( + args.repository_id, + args.search.as_deref(), + args.cursor.as_deref(), + ) + .await?, + ) + } + Command::Routing { review_id } => { + let api = connect(Http::new(origin)?, token, cli.org).await?; + tools::json( + &api.tool_get(&["reviews", &review_id.to_string(), "routing"]) + .await?, + ) + } + Command::Run(args) => { + let api = connect(Http::new(origin)?, token, cli.org).await?; + let name = repository_name(&args.repository).await?; + tools::json( + &api.tool_get(&[ + "reviews", + "pr", + &name, + &args.pr.to_string(), + "runs", + &args.run.to_string(), + ]) + .await?, + ) + } + Command::Session(command) => { + let api = connect(Http::new(origin)?, token, cli.org).await?; + tools::session(&api, command).await + } Command::Agent(args) => agent::run(args, origin).await.map(|()| Verdict::Done), Command::Login(args) => { let http = Http::new(origin)?; diff --git a/src/mcp.rs b/src/mcp.rs index 1a76cd9..fd35716 100644 --- a/src/mcp.rs +++ b/src/mcp.rs @@ -340,3 +340,35 @@ pub(crate) async fn run(http: &Http, token: &SecretString) -> Result<(), McpErro } } } + +/// One native command uses the same negotiated, bounded transport as the bridge. +pub(crate) async fn call( + http: &Http, + token: &SecretString, + name: &str, + arguments: Value, +) -> Result { + let mut session = Session::New; + let frames = [ + json!({"jsonrpc":"2.0", "id":1, "method":"initialize", "params":{ + "protocolVersion":PROTOCOL, "capabilities":{}, + "clientInfo":{"name":"proofline-cli", "version":env!("CARGO_PKG_VERSION")}}}), + json!({"jsonrpc":"2.0", "method":"notifications/initialized"}), + json!({"jsonrpc":"2.0", "id":2, "method":"tools/call", "params":{"name":name, "arguments":arguments}}), + ]; + let mut result = None; + for value in frames { + let frame = serde_json::to_vec(&value).map_err(|_| McpError::Parse)?; + if frame.len() > FRAME_LIMIT { + return Err(McpError::TooLarge); + } + let message = Message::parse(&frame)?; + result = relay(http, token, &mut session, &message, frame).await?; + if result.as_ref().is_some_and(|r| r.get("error").is_some()) { + return Err(McpError::Response); + } + } + result + .and_then(|mut r| r.get_mut("result").map(Value::take)) + .ok_or(McpError::Response) +} diff --git a/src/tools.rs b/src/tools.rs index 8a5a9e0..962f633 100644 --- a/src/tools.rs +++ b/src/tools.rs @@ -2,7 +2,7 @@ use std::io::{IsTerminal as _, Write as _}; use anyhow::{Context as _, bail}; -use clap::{Args, ValueEnum}; +use clap::{Args, Subcommand, ValueEnum}; use uuid::Uuid; use crate::{OutputArgs, OutputFormat, RepositoryArgs, Verdict, api::Api, say, show}; @@ -165,3 +165,51 @@ pub(crate) async fn export(api: &Api, args: &ExportArgs) -> anyhow::Result, + #[arg(long)] + pub search: Option, + #[arg(long)] + pub cursor: Option, +} + +#[derive(Debug, Args)] +pub(crate) struct RunArgs { + #[arg(long)] + pub pr: u64, + #[arg(long)] + pub run: u64, + #[command(flatten)] + pub repository: RepositoryArgs, +} + +#[derive(Debug, Subcommand)] +pub(crate) enum SessionCommand { + /// Read the protected prompt and eligible vendor connections before starting. + Prompt { finding_id: Uuid }, + /// Start once with the digest of the prompt you reviewed. Vendor charges apply. + Start { + finding_id: Uuid, + #[arg(long)] + connection_id: Uuid, + #[arg(long)] + prompt_digest: String, + }, + /// Read the recorded vendor session status. + Get { session_id: Uuid }, +} + +pub(crate) async fn session(api: &Api, command: SessionCommand) -> anyhow::Result { + let value = match command { + SessionCommand::Prompt { finding_id } => api.tool_get(&["findings", &finding_id.to_string(), "agent-session-prompt"]).await?, + SessionCommand::Get { session_id } => api.tool_get(&["agent-sessions", &session_id.to_string()]).await?, + SessionCommand::Start { finding_id, connection_id, prompt_digest } => api.tool_post( + &["findings", &finding_id.to_string(), "agent-sessions"], + &serde_json::json!({"connection_id": connection_id, "prompt_digest": prompt_digest}), + ).await?, + }; + json(&value) +} diff --git a/src/update.rs b/src/update.rs index 1e283d6..76273ab 100644 --- a/src/update.rs +++ b/src/update.rs @@ -108,7 +108,20 @@ pub fn on_invocation() { fn suggestion(cache: &Cache, args: &[std::ffi::OsString], interactive: bool) -> Option { if !interactive || args.iter().any(|arg| { - arg == "history" + matches!( + arg.to_str(), + Some( + "reviews" + | "routing" + | "run" + | "session" + | "wiki" + | "ask" + | "architecture" + | "plan" + | "setup" + ) + ) || arg == "history" || arg == "guidance" || arg == "fix-prompt" || arg == "export" diff --git a/tests/http.rs b/tests/http.rs index c51f002..c128c81 100644 --- a/tests/http.rs +++ b/tests/http.rs @@ -1975,3 +1975,130 @@ async fn native_tools_keep_tenant_paths_and_reruns_make_one_attempt() { assert!(String::from_utf8_lossy(&output.stderr).contains("next-cursor: opaque-next")); server.abort(); } + +#[tokio::test] +async fn native_session_and_collection_keep_scope_cursor_and_single_start() { + let starts = Arc::new(AtomicUsize::new(0)); + let observed = Arc::clone(&starts); + let app = Router::new() + .route( + &format!("/api/v1/organizations/{ORG}/reviews"), + get(|uri: axum::http::Uri| async move { + assert!(uri.query().unwrap().contains("cursor=a%2Fb%2B")); + Json(json!({"items":[], "truncated":true, "next_cursor":"next"})) + }), + ) + .route( + &format!("/api/v1/organizations/{ORG}/findings/{SELECTED_REVIEW}/agent-sessions"), + post(move |headers: HeaderMap, Json(body): Json| { + let observed = Arc::clone(&observed); + async move { + assert_eq!(headers[header::AUTHORIZATION], format!("Bearer {TOKEN}")); + assert_eq!( + body, + json!({"connection_id": REPOSITORY, "prompt_digest":"confirmed-digest"}) + ); + observed.fetch_add(1, Ordering::SeqCst); + ( + StatusCode::SERVICE_UNAVAILABLE, + Json(json!({"detail":"start uncertain; inspect vendor"})), + ) + } + }), + ); + 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() }); + let listed = cli(&origin, &["reviews", "--cursor", "a/b+"]).await; + assert!( + listed.status.success(), + "{}", + String::from_utf8_lossy(&listed.stderr) + ); + assert_eq!( + serde_json::from_slice::(&listed.stdout).unwrap()["next_cursor"], + "next" + ); + let started = cli( + &origin, + &[ + "session", + "start", + SELECTED_REVIEW, + "--connection-id", + REPOSITORY, + "--prompt-digest", + "confirmed-digest", + ], + ) + .await; + assert!(!started.status.success()); + assert_eq!(starts.load(Ordering::SeqCst), 1); + server.abort(); +} + +#[tokio::test] +async fn native_knowledge_negotiates_and_reports_a_tool_refusal() { + let calls = Arc::new(AtomicUsize::new(0)); + 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}")); + match observed.fetch_add(1, Ordering::SeqCst) { + 0 => { + assert_eq!(body["method"], "initialize"); + Json(json!({"jsonrpc":"2.0", "id":1, "result":{"protocolVersion":"2025-11-25"}})).into_response() + } + 1 => { + assert_eq!(body["method"], "notifications/initialized"); + StatusCode::ACCEPTED.into_response() + } + 2 => { + assert_eq!(headers["mcp-protocol-version"], "2025-11-25"); + assert_eq!(body["params"], json!({"name":"get_wiki_page", "arguments":{"repository":"owner/name", "page_key":"index", "commit":"a".repeat(40)}})); + Json(json!({"jsonrpc":"2.0", "id":2, "result":{"isError":true, "content":[{"type":"text", "text":"RESOURCE_NOT_FOUND"}]}})).into_response() + } + _ => panic!("tool call retried"), + } + } + })); + 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() }); + let output = cli( + &origin, + &[ + "wiki", + "get", + "index", + "--repo", + "owner/name", + "--commit", + &"a".repeat(40), + ], + ) + .await; + assert!(!output.status.success()); + assert_eq!( + serde_json::from_slice::(&output.stdout).unwrap()["isError"], + true + ); + assert_eq!(calls.load(Ordering::SeqCst), 3); + server.abort(); +} + +#[tokio::test] +async fn setup_handoff_uses_customer_routes_without_a_token() { + let output = tokio::process::Command::new(env!("CARGO_BIN_EXE_proofline")) + .env_remove("PROOFLINE_TOKEN") + .args(["setup", "--print", "--organization", "example-org"]) + .output() + .await + .unwrap(); + assert!(output.status.success()); + assert_eq!( + String::from_utf8(output.stdout).unwrap().trim(), + "https://proofline.sh/orgs/github/example-org/settings/installation" + ); +}