From 8c48b78f489312d20435eaa2f0f6f90c4e4ccdb2 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 14 Nov 2026 14:05:24 +0000 Subject: [PATCH] fix(ponsbot): accept the dirty stamp from a cargo-installed pons The first phase 1 shadow run (standards#1562) read ponsbot -> error: "pons exited 0 without a valid report: pons was built from a dirty tree". The CI build is `cargo install --git --rev `, and the real pons stamps source_dirty "true" for it although the checkout is exactly the pinned commit (the direct lane's own report carries the same stamp). The commit stamp, which is checked, identifies the binary; a dirty stamp is now an error only with PONSBOT_REQUIRE_CLEAN=1. A dirty stamp never rescues a wrong commit. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_0136P7ZkEdznGjgTixZgjhB6 --- bots/ponsbot/src/scanner.rs | 55 +++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/bots/ponsbot/src/scanner.rs b/bots/ponsbot/src/scanner.rs index b614121c..699b7930 100644 --- a/bots/ponsbot/src/scanner.rs +++ b/bots/ponsbot/src/scanner.rs @@ -184,7 +184,13 @@ pub fn run_pons(dir: &Path, timeout: Duration, expected_commit: &str) -> Outcome )); } }; - interpret(status.code(), &stdout, &stderr, expected_commit) + interpret_with( + status.code(), + &stdout, + &stderr, + expected_commit, + require_clean_from_env(), + ) } /// SIGKILL the whole process group led by `child`. The child was started with @@ -226,6 +232,26 @@ fn first_line(stderr: &str) -> String { /// Map pons' exit status, stdout and stderr to an [`Outcome`]. Pure, so every /// failure mode is unit-testable without a pons binary. pub fn interpret(code: Option, stdout: &str, stderr: &str, expected_commit: &str) -> Outcome { + interpret_with(code, stdout, stderr, expected_commit, false) +} + +/// Whether a `source_dirty` stamp from pons is fatal. Off by default: +/// `cargo install --git --rev` (how CI builds the pinned pons) stamps +/// `source_dirty: "true"` although the checkout is exactly the pinned commit, +/// and the commit stamp, which is checked, is what identifies the binary. Set +/// `PONSBOT_REQUIRE_CLEAN=1` to refuse a dirty stamp, e.g. for a local build. +fn require_clean_from_env() -> bool { + std::env::var("PONSBOT_REQUIRE_CLEAN").is_ok_and(|v| v == "1") +} + +/// [`interpret`] with the dirty-stamp policy chosen by the caller. +pub fn interpret_with( + code: Option, + stdout: &str, + stderr: &str, + expected_commit: &str, + require_clean: bool, +) -> Outcome { let code = match code { Some(c) => c, None => { @@ -237,7 +263,7 @@ pub fn interpret(code: Option, stdout: &str, stderr: &str, expected_commit: }; let report: Option = serde_json::from_str(stdout).ok(); match code { - 0 | 1 => match validate(report.as_ref(), expected_commit) { + 0 | 1 => match validate(report.as_ref(), expected_commit, require_clean) { Ok(findings) => Outcome::Ran(findings), Err(why) => Outcome::Error(format!("pons exited {code} without a valid report: {why}")), }, @@ -256,7 +282,11 @@ pub fn interpret(code: Option, stdout: &str, stderr: &str, expected_commit: /// Validate a pons scan report and extract its findings. A report that is not /// exactly what pons documents is an error, never an empty finding list. -fn validate(report: Option<&Value>, expected_commit: &str) -> Result, String> { +fn validate( + report: Option<&Value>, + expected_commit: &str, + require_clean: bool, +) -> Result, String> { let r = report.ok_or("stdout is not JSON")?; let tool = r .get("tool") @@ -271,7 +301,7 @@ fn validate(report: Option<&Value>, expected_commit: &str) -> Result