From 235e1bca252540d07b02a73830b073aa58ccf649 Mon Sep 17 00:00:00 2001 From: "Steven Zimmerman, CPA" <15812269+EffortlessSteven@users.noreply.github.com> Date: Fri, 9 Oct 2026 05:48:23 -0700 Subject: [PATCH 01/10] test: reject PR producer configuration drift (#1627) --- crates/ripr/src/app/pr_evidence.rs | 282 +++++++++++++++++++++++++++ xtask/src/reports/pr_evidence.rs | 293 +++++++++++++++++++++++++++++ 2 files changed, 575 insertions(+) diff --git a/crates/ripr/src/app/pr_evidence.rs b/crates/ripr/src/app/pr_evidence.rs index 4780b9b14..fd6e35fca 100644 --- a/crates/ripr/src/app/pr_evidence.rs +++ b/crates/ripr/src/app/pr_evidence.rs @@ -1525,6 +1525,288 @@ mod tests { use super::*; use crate::review_input::{REVIEW_INDEX_MAX_BYTES, REVIEW_INDEX_MAX_ENTRIES}; + + #[cfg(feature = "lang-rust")] + const CONFIGURATION_A: &str = "[analysis]\ninclude_unchanged_tests = true\n"; + #[cfg(feature = "lang-rust")] + const CONFIGURATION_B: &str = "[analysis]\ninclude_unchanged_tests = false\n"; + + #[cfg(feature = "lang-rust")] + fn with_configuration_fixture( + name: &str, + initial_config: Option<&str>, + test: impl FnOnce( + &Path, + &PrEvidenceOptions, + &str, + &dyn Fn(&Path, &PrEvidenceOptions) -> Result, + ) -> Result<(), String>, + ) -> Result<(), String> { + + let repo = temp_repo(name)?; + let result = (|| { + run_git( + &repo, + &["-c", "init.templateDir=", "init", "--quiet", "-b", "trunk"], + )?; + run_git( + &repo, + &["config", "user.email", "config-fixture@example.invalid"], + )?; + run_git(&repo, &["config", "user.name", "RIPR Config Fixture"])?; + run_git(&repo, &["config", "commit.gpgSign", "false"])?; + write_repo_file(&repo, ".gitignore", "target/\n")?; + write_repo_file( + &repo, + "Cargo.toml", + "[package]\nname = \"config-probe\"\nversion = \"0.1.0\"\nedition = \"2021\"\n", + )?; + if let Some(config) = initial_config { + write_repo_file(&repo, "ripr.toml", config)?; + } + write_repo_file( + &repo, + "src/lib.rs", + "pub fn eligible(value: i32) -> bool { value > 0 }\n", + )?; + // This unchanged evidence is present in the whole head. Preserve + // each adapter's existing choice about selecting it. + write_repo_file( + &repo, + "tests/eligible.rs", + "#[test]\nfn boundary() { assert!(!config_probe::eligible(1)); }\n", + )?; + run_git(&repo, &["add", "-A"])?; + run_git(&repo, &["commit", "--quiet", "-m", "base"])?; + write_repo_file( + &repo, + "src/lib.rs", + "pub fn eligible(value: i32) -> bool { value > 1 }\n", + )?; + run_git(&repo, &["commit", "--quiet", "-a", "-m", "predicate"])?; + let options = PrEvidenceOptions { + base: resolve_revision(&repo, "HEAD~1", "commit")?, + head: resolve_revision(&repo, "HEAD", "commit")?, + ..options() + }; + let run_check = |repo: &Path, options: &PrEvidenceOptions| { + run_ripr_check(repo, options) + }; + write_pr_evidence_with_runner(&repo, &options, |repo, options| { + run_check(repo, options) + })?; + let check = fs::read_to_string(repo.join(PR_CHECK_JSON)) + .map_err(|error| error.to_string())?; + let value: Value = serde_json::from_str(&check).map_err(|error| error.to_string())?; + if value + .pointer("/analysis_outcome/analysis_complete") + .and_then(Value::as_bool) + != Some(true) + || value + .get("findings") + .and_then(Value::as_array) + .is_none_or(Vec::is_empty) + { + return Err("configuration fixture must execute complete nonempty analysis".into()); + } + check_pr_evidence(&repo, &options)?; + configuration_fixture_review(&repo, &options)?; + test(&repo, &options, &check, &run_check) + })(); + let cleanup = fs::remove_dir_all(&repo) + .map_err(|error| format!("cleanup {}: {error}", repo.display())); + result.and(cleanup) + } + + #[cfg(feature = "lang-rust")] + fn configuration_fixture_review( + repo: &Path, + options: &PrEvidenceOptions, + ) -> Result<(), String> { + crate::cli::run(vec![ + "ripr".into(), + "review-comments".into(), + "--root".into(), + repo.display().to_string(), + "--base".into(), + options.base.clone(), + "--head".into(), + options.head.clone(), + "--check-output".into(), + repo.join(PR_CHECK_JSON).display().to_string(), + "--out".into(), + repo.join("target/config-review.json").display().to_string(), + ]) + .map_err(|error| error.message().to_string()) + } + + #[cfg(feature = "lang-rust")] + #[test] + fn producer_configuration_drift_is_rejected_after_actual_check() -> Result<(), String> { + with_configuration_fixture( + "ripr-pr-config-drift", + Some(CONFIGURATION_A), + |repo, options, check, run_check| { + let first: Value = + serde_json::from_str(check).map_err(|error| error.to_string())?; + let recorded = first + .pointer("/analysis_outcome/outcome/identity/config_identity") + .and_then(Value::as_str) + .ok_or("actual configured check must carry a text identity")?; + let config_a = crate::config::load_for_root(repo)?; + write_repo_file(repo, "ripr.toml", CONFIGURATION_B)?; + let config_b = crate::config::load_for_root(repo)?; + if crate::config::repo_exposure_config_identity_hash(&config_a) + != crate::config::repo_exposure_config_identity_hash(&config_b) + { + return Err("fixture must preserve the seven-field seam fingerprint".into()); + } + write_repo_file(repo, "ripr.toml", CONFIGURATION_A)?; + let result = write_pr_evidence_with_runner(repo, options, |repo, options| { + let generated = run_check(repo, options)?; + let value: Value = + serde_json::from_str(&generated).map_err(|error| error.to_string())?; + if value + .pointer("/analysis_outcome/outcome/identity/config_identity") + .and_then(Value::as_str) + != Some(recorded) + { + return Err("fresh runner did not analyze configuration A".into()); + } + // Change only live configuration after this actual check, + // before the existing packet writer reloads it. + write_repo_file(repo, "ripr.toml", CONFIGURATION_B)?; + Ok(generated) + }); + let failure = result.err().ok_or_else(|| { + format!("configuration drift published old analysis {recorded}") + })?; + if !failure.contains("config_identity") || repo.join(PR_CHECK_SUBJECT_JSON).exists() + { + return Err(format!( + "wrong drift refusal or retained authority: {failure}" + )); + } + let packet: Value = serde_json::from_slice( + &fs::read(repo.join(PR_EVIDENCE_JSON)).map_err(|error| error.to_string())?, + ) + .map_err(|error| error.to_string())?; + if packet["status"] != "error" { + return Err("configuration drift did not publish an error packet".into()); + } + write_repo_file(repo, "ripr.toml", CONFIGURATION_A)?; + write_pr_evidence_with_runner(repo, options, |_, _| Ok(check.to_string()))?; + check_pr_evidence(repo, options)?; + configuration_fixture_review(repo, options) + }, + ) + } + + #[cfg(feature = "lang-rust")] + #[test] + fn stale_configuration_is_rejected_by_saved_check_and_review() -> Result<(), String> { + with_configuration_fixture( + "ripr-pr-config-stale", + Some(CONFIGURATION_A), + |repo, options, _, _| { + for config in [Some(CONFIGURATION_B), Some(""), None] { + match config { + Some(text) => write_repo_file(repo, "ripr.toml", text)?, + None => fs::remove_file(repo.join("ripr.toml")) + .map_err(|error| error.to_string())?, + } + let saved = check_pr_evidence(repo, options) + .err() + .ok_or("saved check admitted stale loaded configuration")?; + if !saved.contains("config_identity") { + return Err(format!("wrong saved configuration refusal: {saved}")); + } + let review = configuration_fixture_review(repo, options) + .err() + .ok_or("direct review admitted stale loaded configuration")?; + if !review.contains("config_identity") { + return Err(format!("wrong review configuration refusal: {review}")); + } + write_repo_file(repo, "ripr.toml", CONFIGURATION_A)?; + check_pr_evidence(repo, options)?; + configuration_fixture_review(repo, options)?; + } + Ok(()) + }, + ) + } + + #[cfg(feature = "lang-rust")] + #[test] + fn copied_configuration_identity_requires_present_string_or_null() -> Result<(), String> { + for initial in [Some(CONFIGURATION_A), Some(""), None] { + with_configuration_fixture( + "ripr-pr-config-shape", + initial, + |repo, options, _, _| { + let path = repo.join(PR_CHECK_SUBJECT_JSON); + let original = fs::read(&path).map_err(|error| error.to_string())?; + let subject: Value = + serde_json::from_slice(&original).map_err(|error| error.to_string())?; + let actual = subject + .pointer("/analysis_outcome/outcome/identity/config_identity") + .ok_or("actual producer did not carry config_identity")?; + if initial.is_some() != actual.is_string() + || initial.is_none() != actual.is_null() + { + return Err( + "loaded-empty config and no config lost their distinction".into(), + ); + } + for wrong in [ + None, + Some(json!(7)), + Some(json!(false)), + Some(json!([])), + Some(json!({})), + Some(json!("fnv1a64:foreign")), + ] { + let mut mutated = subject.clone(); + let identity = mutated + .pointer_mut("/analysis_outcome/outcome/identity") + .and_then(Value::as_object_mut) + .ok_or("actual outcome identity is not an object")?; + match wrong { + Some(value) => { + identity.insert("config_identity".into(), value); + } + None => { + identity.remove("config_identity"); + } + } + fs::write( + &path, + serde_json::to_vec(&mutated).map_err(|error| error.to_string())?, + ) + .map_err(|error| error.to_string())?; + let saved = check_pr_evidence(repo, options) + .err() + .ok_or("saved check admitted missing or malformed config identity")?; + if !saved.contains("config_identity") { + return Err(format!("wrong saved shape refusal: {saved}")); + } + let review = configuration_fixture_review(repo, options) + .err() + .ok_or("review admitted missing or malformed config identity")?; + if !review.contains("config_identity") { + return Err(format!("wrong review shape refusal: {review}")); + } + fs::write(&path, &original).map_err(|error| error.to_string())?; + check_pr_evidence(repo, options)?; + configuration_fixture_review(repo, options)?; + } + Ok(()) + }, + )?; + } + Ok(()) + } + fn options() -> PrEvidenceOptions { PrEvidenceOptions { root: ".".to_string(), diff --git a/xtask/src/reports/pr_evidence.rs b/xtask/src/reports/pr_evidence.rs index ee34f4300..de07de7ca 100644 --- a/xtask/src/reports/pr_evidence.rs +++ b/xtask/src/reports/pr_evidence.rs @@ -1664,6 +1664,299 @@ mod tests { use ripr::review_input::projection_summary; use ripr::review_input::{REVIEW_INDEX_MAX_BYTES, REVIEW_INDEX_MAX_ENTRIES}; + + const CONFIGURATION_A: &str = "[analysis]\ninclude_unchanged_tests = true\n"; + const CONFIGURATION_B: &str = "[analysis]\ninclude_unchanged_tests = false\n"; + + fn with_configuration_fixture( + name: &str, + initial_config: Option<&str>, + test: impl FnOnce( + &Path, + &PrEvidenceOptions, + &str, + &dyn Fn(&Path, &PrEvidenceOptions) -> Result, + ) -> Result<(), String>, + ) -> Result<(), String> { + let _cwd_guard = crate::acquire_test_cwd_read_guard(); + crate::reports::fixtures::ripr_fixture_binary()?; + let binary = built_ripr_binary_path(&repo_root()?)?.display().to_string(); + let repo = temp_repo(name)?; + let result = (|| { + run_git( + &repo, + &["-c", "init.templateDir=", "init", "--quiet", "-b", "trunk"], + )?; + run_git( + &repo, + &["config", "user.email", "config-fixture@example.invalid"], + )?; + run_git(&repo, &["config", "user.name", "RIPR Config Fixture"])?; + run_git(&repo, &["config", "commit.gpgSign", "false"])?; + write_repo_file(&repo, ".gitignore", "target/\n")?; + write_repo_file( + &repo, + "Cargo.toml", + "[package]\nname = \"config-probe\"\nversion = \"0.1.0\"\nedition = \"2021\"\n", + )?; + if let Some(config) = initial_config { + write_repo_file(&repo, "ripr.toml", config)?; + } + write_repo_file( + &repo, + "src/lib.rs", + "pub fn eligible(value: i32) -> bool { value > 0 }\n", + )?; + // This unchanged evidence is present in the whole head. Preserve + // each adapter's existing choice about selecting it. + write_repo_file( + &repo, + "tests/eligible.rs", + "#[test]\nfn boundary() { assert!(!config_probe::eligible(1)); }\n", + )?; + run_git(&repo, &["add", "-A"])?; + run_git(&repo, &["commit", "--quiet", "-m", "base"])?; + write_repo_file( + &repo, + "src/lib.rs", + "pub fn eligible(value: i32) -> bool { value > 1 }\n", + )?; + run_git(&repo, &["commit", "--quiet", "-a", "-m", "predicate"])?; + let options = PrEvidenceOptions { + base: resolve_revision(&repo, "HEAD~1", "commit")?, + head: resolve_revision(&repo, "HEAD", "commit")?, + ..options() + }; + let run_check = |repo: &Path, options: &PrEvidenceOptions| { + run_ripr_check_binary( + &binary, + vec![ + "check".into(), + "--root".into(), + command_root_arg(repo, &options.root), + "--base".into(), + options.base.clone(), + "--diff".into(), + repo.join(PR_CANONICAL_DIFF).display().to_string(), + "--no-unchanged-tests".into(), + "--format".into(), + "json".into(), + ], + options, + Duration::from_mins(2), + ) + }; + write_pr_evidence_with_runner(&repo, &options, |repo, options| { + run_check(repo, options) + })?; + let check = fs::read_to_string(repo.join(PR_CHECK_JSON)) + .map_err(|error| error.to_string())?; + let value: Value = serde_json::from_str(&check).map_err(|error| error.to_string())?; + if value + .pointer("/analysis_outcome/analysis_complete") + .and_then(Value::as_bool) + != Some(true) + || value + .get("findings") + .and_then(Value::as_array) + .is_none_or(Vec::is_empty) + { + return Err("configuration fixture must execute complete nonempty analysis".into()); + } + check_pr_evidence(&repo, &options)?; + configuration_fixture_review(&repo, &options)?; + test(&repo, &options, &check, &run_check) + })(); + let cleanup = fs::remove_dir_all(&repo) + .map_err(|error| format!("cleanup {}: {error}", repo.display())); + result.and(cleanup) + } + + fn configuration_fixture_review( + repo: &Path, + options: &PrEvidenceOptions, + ) -> Result<(), String> { + ripr::cli::run(vec![ + "ripr".into(), + "review-comments".into(), + "--root".into(), + repo.display().to_string(), + "--base".into(), + options.base.clone(), + "--head".into(), + options.head.clone(), + "--check-output".into(), + repo.join(PR_CHECK_JSON).display().to_string(), + "--out".into(), + repo.join("target/config-review.json").display().to_string(), + ]) + .map_err(|error| error.message().to_string()) + } + + #[test] + fn producer_configuration_drift_is_rejected_after_actual_check() -> Result<(), String> { + with_configuration_fixture( + "ripr-pr-config-drift", + Some(CONFIGURATION_A), + |repo, options, check, run_check| { + let first: Value = + serde_json::from_str(check).map_err(|error| error.to_string())?; + let recorded = first + .pointer("/analysis_outcome/outcome/identity/config_identity") + .and_then(Value::as_str) + .ok_or("actual configured check must carry a text identity")?; + let config_a = ripr::config::load_for_root(repo)?; + write_repo_file(repo, "ripr.toml", CONFIGURATION_B)?; + let config_b = ripr::config::load_for_root(repo)?; + if ripr::config::repo_exposure_config_identity_hash(&config_a) + != ripr::config::repo_exposure_config_identity_hash(&config_b) + { + return Err("fixture must preserve the seven-field seam fingerprint".into()); + } + write_repo_file(repo, "ripr.toml", CONFIGURATION_A)?; + let result = write_pr_evidence_with_runner(repo, options, |repo, options| { + let generated = run_check(repo, options)?; + let value: Value = + serde_json::from_str(&generated).map_err(|error| error.to_string())?; + if value + .pointer("/analysis_outcome/outcome/identity/config_identity") + .and_then(Value::as_str) + != Some(recorded) + { + return Err("fresh runner did not analyze configuration A".into()); + } + // Change only live configuration after this actual check, + // before the existing packet writer reloads it. + write_repo_file(repo, "ripr.toml", CONFIGURATION_B)?; + Ok(generated) + }); + let failure = result.err().ok_or_else(|| { + format!("configuration drift published old analysis {recorded}") + })?; + if !failure.contains("config_identity") || repo.join(PR_CHECK_SUBJECT_JSON).exists() + { + return Err(format!( + "wrong drift refusal or retained authority: {failure}" + )); + } + let packet: Value = serde_json::from_slice( + &fs::read(repo.join(PR_EVIDENCE_JSON)).map_err(|error| error.to_string())?, + ) + .map_err(|error| error.to_string())?; + if packet["status"] != "error" { + return Err("configuration drift did not publish an error packet".into()); + } + write_repo_file(repo, "ripr.toml", CONFIGURATION_A)?; + write_pr_evidence_with_runner(repo, options, |_, _| Ok(check.to_string()))?; + check_pr_evidence(repo, options)?; + configuration_fixture_review(repo, options) + }, + ) + } + + #[test] + fn stale_configuration_is_rejected_by_saved_check_and_review() -> Result<(), String> { + with_configuration_fixture( + "ripr-pr-config-stale", + Some(CONFIGURATION_A), + |repo, options, _, _| { + for config in [Some(CONFIGURATION_B), Some(""), None] { + match config { + Some(text) => write_repo_file(repo, "ripr.toml", text)?, + None => fs::remove_file(repo.join("ripr.toml")) + .map_err(|error| error.to_string())?, + } + let saved = check_pr_evidence(repo, options) + .err() + .ok_or("saved check admitted stale loaded configuration")?; + if !saved.contains("config_identity") { + return Err(format!("wrong saved configuration refusal: {saved}")); + } + let review = configuration_fixture_review(repo, options) + .err() + .ok_or("direct review admitted stale loaded configuration")?; + if !review.contains("config_identity") { + return Err(format!("wrong review configuration refusal: {review}")); + } + write_repo_file(repo, "ripr.toml", CONFIGURATION_A)?; + check_pr_evidence(repo, options)?; + configuration_fixture_review(repo, options)?; + } + Ok(()) + }, + ) + } + + #[test] + fn copied_configuration_identity_requires_present_string_or_null() -> Result<(), String> { + for initial in [Some(CONFIGURATION_A), Some(""), None] { + with_configuration_fixture( + "ripr-pr-config-shape", + initial, + |repo, options, _, _| { + let path = repo.join(PR_CHECK_SUBJECT_JSON); + let original = fs::read(&path).map_err(|error| error.to_string())?; + let subject: Value = + serde_json::from_slice(&original).map_err(|error| error.to_string())?; + let actual = subject + .pointer("/analysis_outcome/outcome/identity/config_identity") + .ok_or("actual producer did not carry config_identity")?; + if initial.is_some() != actual.is_string() + || initial.is_none() != actual.is_null() + { + return Err( + "loaded-empty config and no config lost their distinction".into(), + ); + } + for wrong in [ + None, + Some(json!(7)), + Some(json!(false)), + Some(json!([])), + Some(json!({})), + Some(json!("fnv1a64:foreign")), + ] { + let mut mutated = subject.clone(); + let identity = mutated + .pointer_mut("/analysis_outcome/outcome/identity") + .and_then(Value::as_object_mut) + .ok_or("actual outcome identity is not an object")?; + match wrong { + Some(value) => { + identity.insert("config_identity".into(), value); + } + None => { + identity.remove("config_identity"); + } + } + fs::write( + &path, + serde_json::to_vec(&mutated).map_err(|error| error.to_string())?, + ) + .map_err(|error| error.to_string())?; + let saved = check_pr_evidence(repo, options) + .err() + .ok_or("saved check admitted missing or malformed config identity")?; + if !saved.contains("config_identity") { + return Err(format!("wrong saved shape refusal: {saved}")); + } + let review = configuration_fixture_review(repo, options) + .err() + .ok_or("review admitted missing or malformed config identity")?; + if !review.contains("config_identity") { + return Err(format!("wrong review shape refusal: {review}")); + } + fs::write(&path, &original).map_err(|error| error.to_string())?; + check_pr_evidence(repo, options)?; + configuration_fixture_review(repo, options)?; + } + Ok(()) + }, + )?; + } + Ok(()) + } + fn options() -> PrEvidenceOptions { PrEvidenceOptions { root: ".".to_string(), From f94f75d9ea4badd358ab117763c7bb2a1cdaa770 Mon Sep 17 00:00:00 2001 From: "Steven Zimmerman, CPA" <15812269+EffortlessSteven@users.noreply.github.com> Date: Fri, 9 Oct 2026 05:52:58 -0700 Subject: [PATCH 02/10] test: strengthen configuration admission and recovery controls --- crates/ripr/src/app/pr_evidence.rs | 28 +++++++++++++++++++++++----- xtask/src/reports/pr_evidence.rs | 27 +++++++++++++++++++++++---- 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/crates/ripr/src/app/pr_evidence.rs b/crates/ripr/src/app/pr_evidence.rs index fd6e35fca..19e3d127d 100644 --- a/crates/ripr/src/app/pr_evidence.rs +++ b/crates/ripr/src/app/pr_evidence.rs @@ -1525,7 +1525,6 @@ mod tests { use super::*; use crate::review_input::{REVIEW_INDEX_MAX_BYTES, REVIEW_INDEX_MAX_ENTRIES}; - #[cfg(feature = "lang-rust")] const CONFIGURATION_A: &str = "[analysis]\ninclude_unchanged_tests = true\n"; #[cfg(feature = "lang-rust")] @@ -1542,7 +1541,6 @@ mod tests { &dyn Fn(&Path, &PrEvidenceOptions) -> Result, ) -> Result<(), String>, ) -> Result<(), String> { - let repo = temp_repo(name)?; let result = (|| { run_git( @@ -1637,7 +1635,23 @@ mod tests { "--out".into(), repo.join("target/config-review.json").display().to_string(), ]) - .map_err(|error| error.message().to_string()) + .map_err(|error| error.message().to_string())?; + let rendered: Value = serde_json::from_slice( + &fs::read(repo.join("target/config-review.json")).map_err(|error| error.to_string())?, + ) + .map_err(|error| error.to_string())?; + if rendered + .pointer("/analysis_scope/basis") + .and_then(Value::as_str) + != Some("producer_check_projection") + || rendered + .pointer("/analysis_scope/classified_seams_considered") + .and_then(Value::as_u64) + .is_none_or(|count| count == 0) + { + return Err("review did not reuse nonempty producer analysis".into()); + } + Ok(()) } #[cfg(feature = "lang-rust")] @@ -1758,14 +1772,18 @@ mod tests { "loaded-empty config and no config lost their distinction".into(), ); } - for wrong in [ + let mut wrong_identities = vec![ None, Some(json!(7)), Some(json!(false)), Some(json!([])), Some(json!({})), Some(json!("fnv1a64:foreign")), - ] { + ]; + if initial.is_some() { + wrong_identities.push(Some(Value::Null)); + } + for wrong in wrong_identities { let mut mutated = subject.clone(); let identity = mutated .pointer_mut("/analysis_outcome/outcome/identity") diff --git a/xtask/src/reports/pr_evidence.rs b/xtask/src/reports/pr_evidence.rs index de07de7ca..5d6a4e896 100644 --- a/xtask/src/reports/pr_evidence.rs +++ b/xtask/src/reports/pr_evidence.rs @@ -1664,7 +1664,6 @@ mod tests { use ripr::review_input::projection_summary; use ripr::review_input::{REVIEW_INDEX_MAX_BYTES, REVIEW_INDEX_MAX_ENTRIES}; - const CONFIGURATION_A: &str = "[analysis]\ninclude_unchanged_tests = true\n"; const CONFIGURATION_B: &str = "[analysis]\ninclude_unchanged_tests = false\n"; @@ -1790,7 +1789,23 @@ mod tests { "--out".into(), repo.join("target/config-review.json").display().to_string(), ]) - .map_err(|error| error.message().to_string()) + .map_err(|error| error.message().to_string())?; + let rendered: Value = serde_json::from_slice( + &fs::read(repo.join("target/config-review.json")).map_err(|error| error.to_string())?, + ) + .map_err(|error| error.to_string())?; + if rendered + .pointer("/analysis_scope/basis") + .and_then(Value::as_str) + != Some("producer_check_projection") + || rendered + .pointer("/analysis_scope/classified_seams_considered") + .and_then(Value::as_u64) + .is_none_or(|count| count == 0) + { + return Err("review did not reuse nonempty producer analysis".into()); + } + Ok(()) } #[test] @@ -1908,14 +1923,18 @@ mod tests { "loaded-empty config and no config lost their distinction".into(), ); } - for wrong in [ + let mut wrong_identities = vec![ None, Some(json!(7)), Some(json!(false)), Some(json!([])), Some(json!({})), Some(json!("fnv1a64:foreign")), - ] { + ]; + if initial.is_some() { + wrong_identities.push(Some(Value::Null)); + } + for wrong in wrong_identities { let mut mutated = subject.clone(); let identity = mutated .pointer_mut("/analysis_outcome/outcome/identity") From e92ef1df028f5db4ce2816484eb81a59793dba3b Mon Sep 17 00:00:00 2001 From: "Steven Zimmerman, CPA" <15812269+EffortlessSteven@users.noreply.github.com> Date: Fri, 9 Oct 2026 05:54:06 -0700 Subject: [PATCH 03/10] fix: reconcile PR evidence with loaded configuration (#1627) --- crates/ripr/src/app/pr_evidence.rs | 50 +++++++++++++++++++++++++- crates/ripr/src/app/review_comments.rs | 8 ++++- policy/public_api_surface.txt | 1 + xtask/src/reports/pr_evidence.rs | 22 +++++++++++- 4 files changed, 78 insertions(+), 3 deletions(-) diff --git a/crates/ripr/src/app/pr_evidence.rs b/crates/ripr/src/app/pr_evidence.rs index 19e3d127d..d9fde6cd8 100644 --- a/crates/ripr/src/app/pr_evidence.rs +++ b/crates/ripr/src/app/pr_evidence.rs @@ -215,6 +215,42 @@ fn write_pr_evidence_from_check_json( write_pr_evidence_packet(repo, options, &changed_files, check_json) } +/// Validate the loaded-configuration identity carried by a PR analysis outcome. +/// +/// Producers pass the actual returned check envelope; saved/review consumers +/// pass the bounded receipt's copy. This does not authenticate that copy against +/// the forensic check body or establish immutable source context. +/// +/// # Errors +/// +/// Returns an error for missing, malformed, or mismatched config_identity. +/// An explicit null is valid only when no configuration text was loaded. +pub fn validate_pr_evidence_check_configuration( + analysis_outcome: &Value, + config: &crate::config::RiprConfig, +) -> Result<(), String> { + let value = analysis_outcome + .pointer("/outcome/identity/config_identity") + .ok_or_else(|| "producer analysis_outcome config_identity is missing".to_string())?; + let actual = match value { + Value::Null => None, + Value::String(value) => Some(value.as_str()), + _ => { + return Err( + "producer analysis_outcome config_identity must be a string or null".to_string(), + ); + } + }; + let expected = crate::config::loaded_config_identity(config); + if actual != expected.as_deref() { + return Err( + "producer analysis_outcome config_identity does not match the loaded configuration" + .to_string(), + ); + } + Ok(()) +} + fn write_pr_evidence_packet( repo: &Path, options: &PrEvidenceOptions, @@ -292,6 +328,11 @@ fn write_pr_evidence_packet( .map_err(|err| format!("serialize check subject receipt: {err}"))? ); + validate_pr_evidence_check_configuration( + check_value.get("analysis_outcome").unwrap_or(&Value::Null), + &config, + )?; + write_parented_file(&repo.join(PR_CHECK_JSON), PR_CHECK_JSON, check_json_text)?; write_parented_file( &repo.join(PR_REVIEW_INPUT_JSON), @@ -685,6 +726,10 @@ fn validate_producer_artifacts(repo: &Path, options: &PrEvidenceOptions) -> Resu "{PR_CHECK_SUBJECT_JSON} review_input_byte_count does not match {PR_REVIEW_INPUT_JSON}" )); } + validate_pr_evidence_check_configuration( + subject.get("analysis_outcome").unwrap_or(&Value::Null), + &config, + )?; Ok(()) } @@ -2904,7 +2949,10 @@ mod tests { let check_json = r#"{ "schema_version": "ripr.check.v1", "mode": "draft", - "analysis_outcome": {"analysis_complete": true}, + "analysis_outcome": { + "analysis_complete": true, + "outcome": {"identity": {"config_identity": null}} + }, "findings": [ { "id": "probe:src_lib_rs:value:00000000", diff --git a/crates/ripr/src/app/review_comments.rs b/crates/ripr/src/app/review_comments.rs index 4c9864a78..707c71d87 100644 --- a/crates/ripr/src/app/review_comments.rs +++ b/crates/ripr/src/app/review_comments.rs @@ -218,7 +218,13 @@ pub(crate) fn admit_producer_evidence( review_input.total_finding_count, Some(&canonical_projection_from_subject(&subject)?), )?; - let outcome_value = required_value(&subject, "analysis_outcome")?.clone(); + let outcome_envelope = required_value(&subject, "analysis_outcome")?; + super::pr_evidence::validate_pr_evidence_check_configuration(outcome_envelope, config) + .map_err(|error| ProducerAdmissionError { + category: "producer_identity_mismatch", + message: error, + })?; + let outcome_value = outcome_envelope.clone(); let outcome_value = outcome_value.get("outcome").cloned().ok_or_else(|| { ProducerAdmissionError::malformed( "producer review input analysis_outcome is missing outcome", diff --git a/policy/public_api_surface.txt b/policy/public_api_surface.txt index ee8f915cd..53e24830a 100644 --- a/policy/public_api_surface.txt +++ b/policy/public_api_surface.txt @@ -71,6 +71,7 @@ pub enum ripr::lsp::diagnostic_budget::OmittedDiagnosticReason pub fn ripr::analysis::run_analysis pub fn ripr::analysis::run_repo_analysis pub fn ripr::app::pr_evidence::reject_pr_evidence_error_packet +pub fn ripr::app::pr_evidence::validate_pr_evidence_check_configuration pub fn ripr::app::qualify_legacy_ripr_plus_receipt pub fn ripr::app::render_check pub fn ripr::app::repair_card_usability::repair_card_usability_report diff --git a/xtask/src/reports/pr_evidence.rs b/xtask/src/reports/pr_evidence.rs index 5d6a4e896..3acf729a9 100644 --- a/xtask/src/reports/pr_evidence.rs +++ b/xtask/src/reports/pr_evidence.rs @@ -257,6 +257,11 @@ fn write_pr_evidence_packet( .map_err(|err| format!("serialize check subject receipt: {err}"))? ); + ripr::app::pr_evidence::validate_pr_evidence_check_configuration( + check_value.get("analysis_outcome").unwrap_or(&Value::Null), + &config, + )?; + write_parented_file(&repo.join(PR_CHECK_JSON), PR_CHECK_JSON, check_json_text)?; write_parented_file( &repo.join(PR_REVIEW_INPUT_JSON), @@ -634,6 +639,17 @@ fn check_subject_violations(repo: &Path, options: &PrEvidenceOptions) -> Vec { + if let Err(error) = ripr::app::pr_evidence::validate_pr_evidence_check_configuration( + subject.get("analysis_outcome").unwrap_or(&Value::Null), + &config, + ) { + violations.push(error); + } + } + Err(error) => violations.push(format!("load producer evidence configuration: {error}")), + } violations } @@ -3418,7 +3434,11 @@ mod tests { "reachable_unrevealed": 0, "no_static_path": 0 }, - "findings": [] + "findings": [], + "analysis_outcome": { + "analysis_complete": false, + "outcome": {"identity": {"config_identity": null}} + } }"#; #[test] From f46e705b8269cde4038bb3e32f1d0d6e540b635e Mon Sep 17 00:00:00 2001 From: "Steven Zimmerman, CPA" <15812269+EffortlessSteven@users.noreply.github.com> Date: Fri, 9 Oct 2026 06:05:03 -0700 Subject: [PATCH 04/10] Preserve malformed-producer configuration admission failures Retain prior missing-outcome admission and distinguish malformed configuration identity shapes from valid but mismatched identities. Exercise failure receipts and live absent-to-present configuration changes. --- crates/ripr/src/app/pr_evidence.rs | 103 +++++++++++++++++++++---- crates/ripr/src/app/review_comments.rs | 19 +++-- xtask/src/reports/pr_evidence.rs | 60 ++++++++++++-- 3 files changed, 153 insertions(+), 29 deletions(-) diff --git a/crates/ripr/src/app/pr_evidence.rs b/crates/ripr/src/app/pr_evidence.rs index d9fde6cd8..ce021b7f5 100644 --- a/crates/ripr/src/app/pr_evidence.rs +++ b/crates/ripr/src/app/pr_evidence.rs @@ -229,24 +229,46 @@ pub fn validate_pr_evidence_check_configuration( analysis_outcome: &Value, config: &crate::config::RiprConfig, ) -> Result<(), String> { + validate_pr_evidence_check_configuration_core(analysis_outcome, config) + .map_err(|error| error.message().to_string()) +} + +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub(crate) enum PrEvidenceConfigurationError { + Missing, + Malformed, + Mismatch, +} + +impl PrEvidenceConfigurationError { + pub(crate) fn message(self) -> &'static str { + match self { + Self::Missing => "producer analysis_outcome config_identity is missing", + Self::Malformed => { + "producer analysis_outcome config_identity must be a string or null" + } + Self::Mismatch => { + "producer analysis_outcome config_identity does not match the loaded configuration" + } + } + } +} + +pub(crate) fn validate_pr_evidence_check_configuration_core( + analysis_outcome: &Value, + config: &crate::config::RiprConfig, +) -> Result<(), PrEvidenceConfigurationError> { let value = analysis_outcome .pointer("/outcome/identity/config_identity") - .ok_or_else(|| "producer analysis_outcome config_identity is missing".to_string())?; + .ok_or(PrEvidenceConfigurationError::Missing)?; let actual = match value { Value::Null => None, Value::String(value) => Some(value.as_str()), - _ => { - return Err( - "producer analysis_outcome config_identity must be a string or null".to_string(), - ); - } + _ => return Err(PrEvidenceConfigurationError::Malformed), }; let expected = crate::config::loaded_config_identity(config); if actual != expected.as_deref() { - return Err( - "producer analysis_outcome config_identity does not match the loaded configuration" - .to_string(), - ); + return Err(PrEvidenceConfigurationError::Mismatch); } Ok(()) } @@ -1699,6 +1721,30 @@ mod tests { Ok(()) } + #[cfg(feature = "lang-rust")] + fn configuration_fixture_refusal( + repo: &Path, + error: &str, + category: &str, + ) -> Result<(), String> { + if !error.contains("config_identity") || !error.contains(category) { + return Err(format!("wrong configuration refusal: {error}")); + } + let receipt: Value = serde_json::from_slice( + &fs::read(repo.join("target/run-receipt.json")).map_err(|error| error.to_string())?, + ) + .map_err(|error| error.to_string())?; + if receipt["status"] != "failed" + || receipt.pointer("/primary_failure/phase").and_then(Value::as_str) + != Some("producer_evidence_admission") + || receipt.pointer("/primary_failure/category").and_then(Value::as_str) + != Some(category) + { + return Err(format!("wrong configuration refusal receipt: {receipt}")); + } + Ok(()) + } + #[cfg(feature = "lang-rust")] #[test] fn producer_configuration_drift_is_rejected_after_actual_check() -> Result<(), String> { @@ -1783,9 +1829,7 @@ mod tests { let review = configuration_fixture_review(repo, options) .err() .ok_or("direct review admitted stale loaded configuration")?; - if !review.contains("config_identity") { - return Err(format!("wrong review configuration refusal: {review}")); - } + configuration_fixture_refusal(repo, &review, "producer_identity_mismatch")?; write_repo_file(repo, "ripr.toml", CONFIGURATION_A)?; check_pr_evidence(repo, options)?; configuration_fixture_review(repo, options)?; @@ -1829,6 +1873,10 @@ mod tests { wrong_identities.push(Some(Value::Null)); } for wrong in wrong_identities { + let category = match wrong.as_ref() { + Some(Value::String(_) | Value::Null) => "producer_identity_mismatch", + _ => "malformed_producer", + }; let mut mutated = subject.clone(); let identity = mutated .pointer_mut("/analysis_outcome/outcome/identity") @@ -1856,13 +1904,36 @@ mod tests { let review = configuration_fixture_review(repo, options) .err() .ok_or("review admitted missing or malformed config identity")?; - if !review.contains("config_identity") { - return Err(format!("wrong review shape refusal: {review}")); - } + configuration_fixture_refusal(repo, &review, category)?; fs::write(&path, &original).map_err(|error| error.to_string())?; check_pr_evidence(repo, options)?; configuration_fixture_review(repo, options)?; } + if initial.is_none() { + // Adding even an empty config must differ from the + // captured defaults-only null identity. + for text in [CONFIGURATION_A, ""] { + write_repo_file(repo, "ripr.toml", text)?; + let saved = check_pr_evidence(repo, options) + .err() + .ok_or("saved check admitted newly present configuration")?; + if !saved.contains("config_identity") { + return Err(format!("wrong new-config saved refusal: {saved}")); + } + let review = configuration_fixture_review(repo, options) + .err() + .ok_or("review admitted newly present configuration")?; + configuration_fixture_refusal( + repo, + &review, + "producer_identity_mismatch", + )?; + fs::remove_file(repo.join("ripr.toml")) + .map_err(|error| error.to_string())?; + check_pr_evidence(repo, options)?; + configuration_fixture_review(repo, options)?; + } + } Ok(()) }, )?; diff --git a/crates/ripr/src/app/review_comments.rs b/crates/ripr/src/app/review_comments.rs index 707c71d87..65c0e01e6 100644 --- a/crates/ripr/src/app/review_comments.rs +++ b/crates/ripr/src/app/review_comments.rs @@ -219,17 +219,22 @@ pub(crate) fn admit_producer_evidence( Some(&canonical_projection_from_subject(&subject)?), )?; let outcome_envelope = required_value(&subject, "analysis_outcome")?; - super::pr_evidence::validate_pr_evidence_check_configuration(outcome_envelope, config) - .map_err(|error| ProducerAdmissionError { - category: "producer_identity_mismatch", - message: error, - })?; - let outcome_value = outcome_envelope.clone(); - let outcome_value = outcome_value.get("outcome").cloned().ok_or_else(|| { + let outcome_value = outcome_envelope.get("outcome").cloned().ok_or_else(|| { ProducerAdmissionError::malformed( "producer review input analysis_outcome is missing outcome", ) })?; + super::pr_evidence::validate_pr_evidence_check_configuration_core(outcome_envelope, config) + .map_err(|error| ProducerAdmissionError { + category: match error { + super::pr_evidence::PrEvidenceConfigurationError::Missing + | super::pr_evidence::PrEvidenceConfigurationError::Malformed => "malformed_producer", + super::pr_evidence::PrEvidenceConfigurationError::Mismatch => { + "producer_identity_mismatch" + } + }, + message: error.message().to_string(), + })?; let outcome: AnalysisOutcome = serde_json::from_value(outcome_value).map_err(|error| { ProducerAdmissionError::malformed(format!( "producer review input analysis_outcome is invalid: {error}" diff --git a/xtask/src/reports/pr_evidence.rs b/xtask/src/reports/pr_evidence.rs index 3acf729a9..081ae37df 100644 --- a/xtask/src/reports/pr_evidence.rs +++ b/xtask/src/reports/pr_evidence.rs @@ -1824,6 +1824,29 @@ mod tests { Ok(()) } + fn configuration_fixture_refusal( + repo: &Path, + error: &str, + category: &str, + ) -> Result<(), String> { + if !error.contains("config_identity") || !error.contains(category) { + return Err(format!("wrong configuration refusal: {error}")); + } + let receipt: Value = serde_json::from_slice( + &fs::read(repo.join("target/run-receipt.json")).map_err(|error| error.to_string())?, + ) + .map_err(|error| error.to_string())?; + if receipt["status"] != "failed" + || receipt.pointer("/primary_failure/phase").and_then(Value::as_str) + != Some("producer_evidence_admission") + || receipt.pointer("/primary_failure/category").and_then(Value::as_str) + != Some(category) + { + return Err(format!("wrong configuration refusal receipt: {receipt}")); + } + Ok(()) + } + #[test] fn producer_configuration_drift_is_rejected_after_actual_check() -> Result<(), String> { with_configuration_fixture( @@ -1906,9 +1929,7 @@ mod tests { let review = configuration_fixture_review(repo, options) .err() .ok_or("direct review admitted stale loaded configuration")?; - if !review.contains("config_identity") { - return Err(format!("wrong review configuration refusal: {review}")); - } + configuration_fixture_refusal(repo, &review, "producer_identity_mismatch")?; write_repo_file(repo, "ripr.toml", CONFIGURATION_A)?; check_pr_evidence(repo, options)?; configuration_fixture_review(repo, options)?; @@ -1951,6 +1972,10 @@ mod tests { wrong_identities.push(Some(Value::Null)); } for wrong in wrong_identities { + let category = match wrong.as_ref() { + Some(Value::String(_) | Value::Null) => "producer_identity_mismatch", + _ => "malformed_producer", + }; let mut mutated = subject.clone(); let identity = mutated .pointer_mut("/analysis_outcome/outcome/identity") @@ -1978,13 +2003,36 @@ mod tests { let review = configuration_fixture_review(repo, options) .err() .ok_or("review admitted missing or malformed config identity")?; - if !review.contains("config_identity") { - return Err(format!("wrong review shape refusal: {review}")); - } + configuration_fixture_refusal(repo, &review, category)?; fs::write(&path, &original).map_err(|error| error.to_string())?; check_pr_evidence(repo, options)?; configuration_fixture_review(repo, options)?; } + if initial.is_none() { + // Adding even an empty config must differ from the + // captured defaults-only null identity. + for text in [CONFIGURATION_A, ""] { + write_repo_file(repo, "ripr.toml", text)?; + let saved = check_pr_evidence(repo, options) + .err() + .ok_or("saved check admitted newly present configuration")?; + if !saved.contains("config_identity") { + return Err(format!("wrong new-config saved refusal: {saved}")); + } + let review = configuration_fixture_review(repo, options) + .err() + .ok_or("review admitted newly present configuration")?; + configuration_fixture_refusal( + repo, + &review, + "producer_identity_mismatch", + )?; + fs::remove_file(repo.join("ripr.toml")) + .map_err(|error| error.to_string())?; + check_pr_evidence(repo, options)?; + configuration_fixture_review(repo, options)?; + } + } Ok(()) }, )?; From ce7f58c92c9236a100551db426de6a99fd794693 Mon Sep 17 00:00:00 2001 From: "Steven Zimmerman, CPA" <15812269+EffortlessSteven@users.noreply.github.com> Date: Fri, 9 Oct 2026 06:31:28 -0700 Subject: [PATCH 05/10] Apply pinned formatter diagnostics to configuration admission controls --- crates/ripr/src/app/pr_evidence.rs | 176 ++++++++++++------------- crates/ripr/src/app/review_comments.rs | 4 +- xtask/src/reports/pr_evidence.rs | 167 +++++++++++------------ 3 files changed, 166 insertions(+), 181 deletions(-) diff --git a/crates/ripr/src/app/pr_evidence.rs b/crates/ripr/src/app/pr_evidence.rs index ce021b7f5..b34cd1a81 100644 --- a/crates/ripr/src/app/pr_evidence.rs +++ b/crates/ripr/src/app/pr_evidence.rs @@ -244,9 +244,7 @@ impl PrEvidenceConfigurationError { pub(crate) fn message(self) -> &'static str { match self { Self::Missing => "producer analysis_outcome config_identity is missing", - Self::Malformed => { - "producer analysis_outcome config_identity must be a string or null" - } + Self::Malformed => "producer analysis_outcome config_identity must be a string or null", Self::Mismatch => { "producer analysis_outcome config_identity does not match the loaded configuration" } @@ -1654,14 +1652,13 @@ mod tests { head: resolve_revision(&repo, "HEAD", "commit")?, ..options() }; - let run_check = |repo: &Path, options: &PrEvidenceOptions| { - run_ripr_check(repo, options) - }; + let run_check = + |repo: &Path, options: &PrEvidenceOptions| run_ripr_check(repo, options); write_pr_evidence_with_runner(&repo, &options, |repo, options| { run_check(repo, options) })?; - let check = fs::read_to_string(repo.join(PR_CHECK_JSON)) - .map_err(|error| error.to_string())?; + let check = + fs::read_to_string(repo.join(PR_CHECK_JSON)).map_err(|error| error.to_string())?; let value: Value = serde_json::from_str(&check).map_err(|error| error.to_string())?; if value .pointer("/analysis_outcome/analysis_complete") @@ -1735,9 +1732,13 @@ mod tests { ) .map_err(|error| error.to_string())?; if receipt["status"] != "failed" - || receipt.pointer("/primary_failure/phase").and_then(Value::as_str) + || receipt + .pointer("/primary_failure/phase") + .and_then(Value::as_str) != Some("producer_evidence_admission") - || receipt.pointer("/primary_failure/category").and_then(Value::as_str) + || receipt + .pointer("/primary_failure/category") + .and_then(Value::as_str) != Some(category) { return Err(format!("wrong configuration refusal receipt: {receipt}")); @@ -1843,100 +1844,89 @@ mod tests { #[test] fn copied_configuration_identity_requires_present_string_or_null() -> Result<(), String> { for initial in [Some(CONFIGURATION_A), Some(""), None] { - with_configuration_fixture( - "ripr-pr-config-shape", - initial, - |repo, options, _, _| { - let path = repo.join(PR_CHECK_SUBJECT_JSON); - let original = fs::read(&path).map_err(|error| error.to_string())?; - let subject: Value = - serde_json::from_slice(&original).map_err(|error| error.to_string())?; - let actual = subject - .pointer("/analysis_outcome/outcome/identity/config_identity") - .ok_or("actual producer did not carry config_identity")?; - if initial.is_some() != actual.is_string() - || initial.is_none() != actual.is_null() - { - return Err( - "loaded-empty config and no config lost their distinction".into(), - ); + with_configuration_fixture("ripr-pr-config-shape", initial, |repo, options, _, _| { + let path = repo.join(PR_CHECK_SUBJECT_JSON); + let original = fs::read(&path).map_err(|error| error.to_string())?; + let subject: Value = + serde_json::from_slice(&original).map_err(|error| error.to_string())?; + let actual = subject + .pointer("/analysis_outcome/outcome/identity/config_identity") + .ok_or("actual producer did not carry config_identity")?; + if initial.is_some() != actual.is_string() || initial.is_none() != actual.is_null() + { + return Err("loaded-empty config and no config lost their distinction".into()); + } + let mut wrong_identities = vec![ + None, + Some(json!(7)), + Some(json!(false)), + Some(json!([])), + Some(json!({})), + Some(json!("fnv1a64:foreign")), + ]; + if initial.is_some() { + wrong_identities.push(Some(Value::Null)); + } + for wrong in wrong_identities { + let category = match wrong.as_ref() { + Some(Value::String(_) | Value::Null) => "producer_identity_mismatch", + _ => "malformed_producer", + }; + let mut mutated = subject.clone(); + let identity = mutated + .pointer_mut("/analysis_outcome/outcome/identity") + .and_then(Value::as_object_mut) + .ok_or("actual outcome identity is not an object")?; + match wrong { + Some(value) => { + identity.insert("config_identity".into(), value); + } + None => { + identity.remove("config_identity"); + } } - let mut wrong_identities = vec![ - None, - Some(json!(7)), - Some(json!(false)), - Some(json!([])), - Some(json!({})), - Some(json!("fnv1a64:foreign")), - ]; - if initial.is_some() { - wrong_identities.push(Some(Value::Null)); + fs::write( + &path, + serde_json::to_vec(&mutated).map_err(|error| error.to_string())?, + ) + .map_err(|error| error.to_string())?; + let saved = check_pr_evidence(repo, options) + .err() + .ok_or("saved check admitted missing or malformed config identity")?; + if !saved.contains("config_identity") { + return Err(format!("wrong saved shape refusal: {saved}")); } - for wrong in wrong_identities { - let category = match wrong.as_ref() { - Some(Value::String(_) | Value::Null) => "producer_identity_mismatch", - _ => "malformed_producer", - }; - let mut mutated = subject.clone(); - let identity = mutated - .pointer_mut("/analysis_outcome/outcome/identity") - .and_then(Value::as_object_mut) - .ok_or("actual outcome identity is not an object")?; - match wrong { - Some(value) => { - identity.insert("config_identity".into(), value); - } - None => { - identity.remove("config_identity"); - } - } - fs::write( - &path, - serde_json::to_vec(&mutated).map_err(|error| error.to_string())?, - ) - .map_err(|error| error.to_string())?; + let review = configuration_fixture_review(repo, options) + .err() + .ok_or("review admitted missing or malformed config identity")?; + configuration_fixture_refusal(repo, &review, category)?; + fs::write(&path, &original).map_err(|error| error.to_string())?; + check_pr_evidence(repo, options)?; + configuration_fixture_review(repo, options)?; + } + if initial.is_none() { + // Adding even an empty config must differ from the + // captured defaults-only null identity. + for text in [CONFIGURATION_A, ""] { + write_repo_file(repo, "ripr.toml", text)?; let saved = check_pr_evidence(repo, options) .err() - .ok_or("saved check admitted missing or malformed config identity")?; + .ok_or("saved check admitted newly present configuration")?; if !saved.contains("config_identity") { - return Err(format!("wrong saved shape refusal: {saved}")); + return Err(format!("wrong new-config saved refusal: {saved}")); } let review = configuration_fixture_review(repo, options) .err() - .ok_or("review admitted missing or malformed config identity")?; - configuration_fixture_refusal(repo, &review, category)?; - fs::write(&path, &original).map_err(|error| error.to_string())?; + .ok_or("review admitted newly present configuration")?; + configuration_fixture_refusal(repo, &review, "producer_identity_mismatch")?; + fs::remove_file(repo.join("ripr.toml")) + .map_err(|error| error.to_string())?; check_pr_evidence(repo, options)?; configuration_fixture_review(repo, options)?; } - if initial.is_none() { - // Adding even an empty config must differ from the - // captured defaults-only null identity. - for text in [CONFIGURATION_A, ""] { - write_repo_file(repo, "ripr.toml", text)?; - let saved = check_pr_evidence(repo, options) - .err() - .ok_or("saved check admitted newly present configuration")?; - if !saved.contains("config_identity") { - return Err(format!("wrong new-config saved refusal: {saved}")); - } - let review = configuration_fixture_review(repo, options) - .err() - .ok_or("review admitted newly present configuration")?; - configuration_fixture_refusal( - repo, - &review, - "producer_identity_mismatch", - )?; - fs::remove_file(repo.join("ripr.toml")) - .map_err(|error| error.to_string())?; - check_pr_evidence(repo, options)?; - configuration_fixture_review(repo, options)?; - } - } - Ok(()) - }, - )?; + } + Ok(()) + })?; } Ok(()) } diff --git a/crates/ripr/src/app/review_comments.rs b/crates/ripr/src/app/review_comments.rs index 65c0e01e6..a35a93dbe 100644 --- a/crates/ripr/src/app/review_comments.rs +++ b/crates/ripr/src/app/review_comments.rs @@ -228,7 +228,9 @@ pub(crate) fn admit_producer_evidence( .map_err(|error| ProducerAdmissionError { category: match error { super::pr_evidence::PrEvidenceConfigurationError::Missing - | super::pr_evidence::PrEvidenceConfigurationError::Malformed => "malformed_producer", + | super::pr_evidence::PrEvidenceConfigurationError::Malformed => { + "malformed_producer" + } super::pr_evidence::PrEvidenceConfigurationError::Mismatch => { "producer_identity_mismatch" } diff --git a/xtask/src/reports/pr_evidence.rs b/xtask/src/reports/pr_evidence.rs index 081ae37df..ed0ab60ee 100644 --- a/xtask/src/reports/pr_evidence.rs +++ b/xtask/src/reports/pr_evidence.rs @@ -1764,8 +1764,8 @@ mod tests { write_pr_evidence_with_runner(&repo, &options, |repo, options| { run_check(repo, options) })?; - let check = fs::read_to_string(repo.join(PR_CHECK_JSON)) - .map_err(|error| error.to_string())?; + let check = + fs::read_to_string(repo.join(PR_CHECK_JSON)).map_err(|error| error.to_string())?; let value: Value = serde_json::from_str(&check).map_err(|error| error.to_string())?; if value .pointer("/analysis_outcome/analysis_complete") @@ -1837,9 +1837,13 @@ mod tests { ) .map_err(|error| error.to_string())?; if receipt["status"] != "failed" - || receipt.pointer("/primary_failure/phase").and_then(Value::as_str) + || receipt + .pointer("/primary_failure/phase") + .and_then(Value::as_str) != Some("producer_evidence_admission") - || receipt.pointer("/primary_failure/category").and_then(Value::as_str) + || receipt + .pointer("/primary_failure/category") + .and_then(Value::as_str) != Some(category) { return Err(format!("wrong configuration refusal receipt: {receipt}")); @@ -1942,100 +1946,89 @@ mod tests { #[test] fn copied_configuration_identity_requires_present_string_or_null() -> Result<(), String> { for initial in [Some(CONFIGURATION_A), Some(""), None] { - with_configuration_fixture( - "ripr-pr-config-shape", - initial, - |repo, options, _, _| { - let path = repo.join(PR_CHECK_SUBJECT_JSON); - let original = fs::read(&path).map_err(|error| error.to_string())?; - let subject: Value = - serde_json::from_slice(&original).map_err(|error| error.to_string())?; - let actual = subject - .pointer("/analysis_outcome/outcome/identity/config_identity") - .ok_or("actual producer did not carry config_identity")?; - if initial.is_some() != actual.is_string() - || initial.is_none() != actual.is_null() - { - return Err( - "loaded-empty config and no config lost their distinction".into(), - ); + with_configuration_fixture("ripr-pr-config-shape", initial, |repo, options, _, _| { + let path = repo.join(PR_CHECK_SUBJECT_JSON); + let original = fs::read(&path).map_err(|error| error.to_string())?; + let subject: Value = + serde_json::from_slice(&original).map_err(|error| error.to_string())?; + let actual = subject + .pointer("/analysis_outcome/outcome/identity/config_identity") + .ok_or("actual producer did not carry config_identity")?; + if initial.is_some() != actual.is_string() || initial.is_none() != actual.is_null() + { + return Err("loaded-empty config and no config lost their distinction".into()); + } + let mut wrong_identities = vec![ + None, + Some(json!(7)), + Some(json!(false)), + Some(json!([])), + Some(json!({})), + Some(json!("fnv1a64:foreign")), + ]; + if initial.is_some() { + wrong_identities.push(Some(Value::Null)); + } + for wrong in wrong_identities { + let category = match wrong.as_ref() { + Some(Value::String(_) | Value::Null) => "producer_identity_mismatch", + _ => "malformed_producer", + }; + let mut mutated = subject.clone(); + let identity = mutated + .pointer_mut("/analysis_outcome/outcome/identity") + .and_then(Value::as_object_mut) + .ok_or("actual outcome identity is not an object")?; + match wrong { + Some(value) => { + identity.insert("config_identity".into(), value); + } + None => { + identity.remove("config_identity"); + } } - let mut wrong_identities = vec![ - None, - Some(json!(7)), - Some(json!(false)), - Some(json!([])), - Some(json!({})), - Some(json!("fnv1a64:foreign")), - ]; - if initial.is_some() { - wrong_identities.push(Some(Value::Null)); + fs::write( + &path, + serde_json::to_vec(&mutated).map_err(|error| error.to_string())?, + ) + .map_err(|error| error.to_string())?; + let saved = check_pr_evidence(repo, options) + .err() + .ok_or("saved check admitted missing or malformed config identity")?; + if !saved.contains("config_identity") { + return Err(format!("wrong saved shape refusal: {saved}")); } - for wrong in wrong_identities { - let category = match wrong.as_ref() { - Some(Value::String(_) | Value::Null) => "producer_identity_mismatch", - _ => "malformed_producer", - }; - let mut mutated = subject.clone(); - let identity = mutated - .pointer_mut("/analysis_outcome/outcome/identity") - .and_then(Value::as_object_mut) - .ok_or("actual outcome identity is not an object")?; - match wrong { - Some(value) => { - identity.insert("config_identity".into(), value); - } - None => { - identity.remove("config_identity"); - } - } - fs::write( - &path, - serde_json::to_vec(&mutated).map_err(|error| error.to_string())?, - ) - .map_err(|error| error.to_string())?; + let review = configuration_fixture_review(repo, options) + .err() + .ok_or("review admitted missing or malformed config identity")?; + configuration_fixture_refusal(repo, &review, category)?; + fs::write(&path, &original).map_err(|error| error.to_string())?; + check_pr_evidence(repo, options)?; + configuration_fixture_review(repo, options)?; + } + if initial.is_none() { + // Adding even an empty config must differ from the + // captured defaults-only null identity. + for text in [CONFIGURATION_A, ""] { + write_repo_file(repo, "ripr.toml", text)?; let saved = check_pr_evidence(repo, options) .err() - .ok_or("saved check admitted missing or malformed config identity")?; + .ok_or("saved check admitted newly present configuration")?; if !saved.contains("config_identity") { - return Err(format!("wrong saved shape refusal: {saved}")); + return Err(format!("wrong new-config saved refusal: {saved}")); } let review = configuration_fixture_review(repo, options) .err() - .ok_or("review admitted missing or malformed config identity")?; - configuration_fixture_refusal(repo, &review, category)?; - fs::write(&path, &original).map_err(|error| error.to_string())?; + .ok_or("review admitted newly present configuration")?; + configuration_fixture_refusal(repo, &review, "producer_identity_mismatch")?; + fs::remove_file(repo.join("ripr.toml")) + .map_err(|error| error.to_string())?; check_pr_evidence(repo, options)?; configuration_fixture_review(repo, options)?; } - if initial.is_none() { - // Adding even an empty config must differ from the - // captured defaults-only null identity. - for text in [CONFIGURATION_A, ""] { - write_repo_file(repo, "ripr.toml", text)?; - let saved = check_pr_evidence(repo, options) - .err() - .ok_or("saved check admitted newly present configuration")?; - if !saved.contains("config_identity") { - return Err(format!("wrong new-config saved refusal: {saved}")); - } - let review = configuration_fixture_review(repo, options) - .err() - .ok_or("review admitted newly present configuration")?; - configuration_fixture_refusal( - repo, - &review, - "producer_identity_mismatch", - )?; - fs::remove_file(repo.join("ripr.toml")) - .map_err(|error| error.to_string())?; - check_pr_evidence(repo, options)?; - configuration_fixture_review(repo, options)?; - } - } - Ok(()) - }, - )?; + } + Ok(()) + })?; } Ok(()) } From f72883dc9f5324d0dde9645c3d0dc26202a8cff7 Mon Sep 17 00:00:00 2001 From: "Steven Zimmerman, CPA" <15812269+EffortlessSteven@users.noreply.github.com> Date: Fri, 9 Oct 2026 09:26:53 -0700 Subject: [PATCH 06/10] test: expose cached configuration at final evidence decisions --- crates/ripr/src/app/pr_evidence.rs | 173 ++++++++++++++++++ .../ripr/src/cli/commands/review_comments.rs | 77 ++++++++ xtask/src/reports/pr_evidence.rs | 115 ++++++++++++ 3 files changed, 365 insertions(+) diff --git a/crates/ripr/src/app/pr_evidence.rs b/crates/ripr/src/app/pr_evidence.rs index b34cd1a81..131fba159 100644 --- a/crates/ripr/src/app/pr_evidence.rs +++ b/crates/ripr/src/app/pr_evidence.rs @@ -296,6 +296,8 @@ fn write_pr_evidence_packet( .canonicalize() .map_err(|err| format!("resolve review input root failed: {err}"))?; let config = load_for_root(&root)?; + #[cfg(test)] + mutate_configuration_after_load(&root, ConfigurationObservation::Publication)?; let canonical_diff = fs::read(repo.join(PR_CANONICAL_DIFF)) .map_err(|err| format!("read canonical diff for check subject binding: {err}"))?; let findings = check_value @@ -389,6 +391,74 @@ fn write_pr_evidence_packet( ) } + +#[cfg(test)] +#[derive(Clone, Copy, PartialEq, Eq)] +enum ConfigurationObservation { + Publication, + SavedCheck, +} + +#[cfg(test)] +thread_local! { + static CONFIGURATION_MUTATION: std::cell::RefCell< + Option<(ConfigurationObservation, PathBuf, Option)> + > = const { std::cell::RefCell::new(None) }; +} + +#[cfg(test)] +fn mutate_configuration_after_load(root: &Path, point: ConfigurationObservation) -> Result<(), String> { + let selected = CONFIGURATION_MUTATION.with(|slot| { + slot.borrow().as_ref().is_some_and(|entry| entry.0 == point) + }); + if !selected { + return Ok(()); + } + let mutation = CONFIGURATION_MUTATION.with(|slot| slot.borrow_mut().take()); + let Some((_, expected_root, text)) = mutation else { + return Err("controlled configuration mutation was not retained".into()); + }; + if root != expected_root { + return Err("controlled configuration mutation reached a different root".into()); + } + let path = root.join("ripr.toml"); + match text { + Some(text) => fs::write(path, text), + None => fs::remove_file(path), + } + .map_err(|error| format!("controlled configuration mutation failed: {error}")) +} + +#[cfg(test)] +fn with_configuration_mutation( + root: &Path, + point: ConfigurationObservation, + text: Option<&str>, + work: impl FnOnce() -> Result<(), String>, +) -> Result<(), String> { + struct MutationLease; + impl Drop for MutationLease { + fn drop(&mut self) { + let _ = CONFIGURATION_MUTATION.with(|slot| slot.borrow_mut().take()); + } + } + let root = root.canonicalize().map_err(|error| error.to_string())?; + let occupied = CONFIGURATION_MUTATION.with(|slot| slot.borrow().is_some()); + if occupied { + return Err("nested controlled configuration mutation".into()); + } + CONFIGURATION_MUTATION.with(|slot| { + *slot.borrow_mut() = Some((point, root, text.map(str::to_string))); + }); + let _lease = MutationLease; + let result = work(); + let pending = CONFIGURATION_MUTATION.with(|slot| slot.borrow().is_some()); + if pending { + return Err("controlled configuration mutation checkpoint was not reached".into()); + } + result +} + fn producer_review_input( check: &Value, repo: &Path, @@ -577,6 +647,8 @@ fn validate_producer_artifacts(repo: &Path, options: &PrEvidenceOptions) -> Resu .canonicalize() .map_err(|error| format!("resolve producer evidence root: {error}"))?; let config = load_for_root(&expected_root)?; + #[cfg(test)] + mutate_configuration_after_load(&expected_root, ConfigurationObservation::SavedCheck)?; let mut expected_input = CheckInput { root: expected_root.clone(), ..CheckInput::default() @@ -1585,6 +1657,14 @@ fn write_parented_file(path: &Path, label: &str, contents: impl AsRef<[u8]>) -> fs::write(path, contents).map_err(|err| format!("failed to write {label}: {err}")) } + +#[cfg(all(test, feature = "lang-rust"))] +pub(crate) fn with_live_configuration_admission_fixture( + test: impl FnOnce(&Path, &str, &str, &Path, &str, &str) -> Result<(), String>, +) -> Result<(), String> { + tests::with_live_configuration_admission_fixture(test) +} + #[cfg(test)] mod tests { use super::*; @@ -1680,6 +1760,26 @@ mod tests { result.and(cleanup) } + #[cfg(feature = "lang-rust")] + pub(super) fn with_live_configuration_admission_fixture( + test: impl FnOnce(&Path, &str, &str, &Path, &str, &str) -> Result<(), String>, + ) -> Result<(), String> { + with_configuration_fixture( + "ripr-cli-config-discovery-drift", + Some(CONFIGURATION_A), + |repo, options, _check, _run_check| { + test( + repo, + &options.base, + &options.head, + &repo.join(PR_CHECK_JSON), + CONFIGURATION_A, + CONFIGURATION_B, + ) + }, + ) + } + #[cfg(feature = "lang-rust")] fn configuration_fixture_review( repo: &Path, @@ -1746,6 +1846,79 @@ mod tests { Ok(()) } + #[cfg(feature = "lang-rust")] + #[test] + fn configuration_drift_after_publication_load_is_refused() -> Result<(), String> { + with_configuration_fixture( + "ripr-pr-after-load-config-drift", + Some(CONFIGURATION_A), + |repo, options, check, _run_check| { + let config_a = crate::config::load_for_root(repo)?; + write_repo_file(repo, "ripr.toml", CONFIGURATION_B)?; + let config_b = crate::config::load_for_root(repo)?; + assert_eq!( + crate::config::repo_exposure_config_identity_hash(&config_a), + crate::config::repo_exposure_config_identity_hash(&config_b), + ); + write_repo_file(repo, "ripr.toml", CONFIGURATION_A)?; + with_configuration_mutation( + repo, + ConfigurationObservation::Publication, + Some(CONFIGURATION_B), + || { + let failure = write_pr_evidence_with_runner(repo, options, |_, _| { + Ok(check.to_string()) + }) + .err() + .ok_or("after-load configuration drift published cached analysis")?; + assert!(failure.contains("config_identity"), "{failure}"); + for path in [PR_CHECK_JSON, PR_CHECK_SUBJECT_JSON, PR_REVIEW_INPUT_JSON] { + assert!(!repo.join(path).exists(), "retained authority: {path}"); + } + let packet: Value = serde_json::from_slice( + &fs::read(repo.join(PR_EVIDENCE_JSON)) + .map_err(|error| error.to_string())?, + ) + .map_err(|error| error.to_string())?; + assert_eq!(packet["status"], "error"); + assert!(check_pr_evidence(repo, options).is_err()); + Ok(()) + }, + )?; + write_repo_file(repo, "ripr.toml", CONFIGURATION_A)?; + write_pr_evidence_with_runner(repo, options, |_, _| Ok(check.to_string()))?; + check_pr_evidence(repo, options)?; + configuration_fixture_review(repo, options) + }, + ) + } + + #[cfg(feature = "lang-rust")] + #[test] + fn configuration_drift_after_saved_check_load_is_refused() -> Result<(), String> { + with_configuration_fixture( + "ripr-pr-after-load-saved-check-drift", + Some(CONFIGURATION_A), + |repo, options, _check, _run_check| { + with_configuration_mutation( + repo, + ConfigurationObservation::SavedCheck, + Some(CONFIGURATION_B), + || { + let failure = check_pr_evidence(repo, options) + .err() + .ok_or("saved check admitted cached configuration after live drift")?; + assert!(failure.contains("config_identity"), "{failure}"); + Ok(()) + }, + )?; + write_repo_file(repo, "ripr.toml", CONFIGURATION_A)?; + check_pr_evidence(repo, options)?; + configuration_fixture_review(repo, options) + }, + ) + } + #[cfg(feature = "lang-rust")] #[test] fn producer_configuration_drift_is_rejected_after_actual_check() -> Result<(), String> { diff --git a/crates/ripr/src/cli/commands/review_comments.rs b/crates/ripr/src/cli/commands/review_comments.rs index 2254afe63..061247bd2 100644 --- a/crates/ripr/src/cli/commands/review_comments.rs +++ b/crates/ripr/src/cli/commands/review_comments.rs @@ -1234,6 +1234,83 @@ mod tests { } } + #[cfg(feature = "lang-rust")] + #[test] + fn direct_producer_review_reloads_configuration_after_diff_discovery() -> Result<(), String> { + crate::app::pr_evidence::with_live_configuration_admission_fixture( + |root, base, head, check_path, config_a, config_b| { + let output_path = root.join("target/timing-refusal.json"); + let markdown_path = output_path.with_extension("md"); + assert!(!output_path.exists()); + assert!(!markdown_path.exists()); + let args = vec![ + "--root".to_string(), + root.display().to_string(), + "--base".to_string(), + base.to_string(), + "--head".to_string(), + head.to_string(), + "--check-output".to_string(), + check_path.display().to_string(), + "--out".to_string(), + output_path.display().to_string(), + ]; + let calls = std::cell::Cell::new(0_u32); + let mutation = std::cell::RefCell::new(None); + let result = review_comments_with_diff_loader(&args, |root, base, head| { + let diff = load_review_comments_diff(root, base, head)?; + calls.set(calls.get() + 1); + let written = std::fs::write(root.join("ripr.toml"), config_b) + .map_err(|error| error.to_string()); + let _ = mutation.replace(Some(written)); + Ok(diff) + }); + assert_eq!(calls.get(), 1, "actual diff loader was not reached exactly once"); + mutation + .into_inner() + .ok_or("configuration mutation did not execute")??; + let failure = result + .err() + .ok_or("direct review admitted cached A after discovery changed live config to B")?; + assert!(failure.contains("producer_identity_mismatch"), "{failure}"); + assert!(failure.contains("config_identity"), "{failure}"); + let receipt: serde_json::Value = serde_json::from_slice( + &std::fs::read(root.join("target/run-receipt.json")) + .map_err(|error| error.to_string())?, + ) + .map_err(|error| error.to_string())?; + assert_eq!(receipt["status"], "failed"); + assert_eq!( + receipt["primary_failure"]["phase"], + "producer_evidence_admission" + ); + assert_eq!( + receipt["primary_failure"]["category"], + "producer_identity_mismatch" + ); + assert!(!output_path.exists(), "refusal published new JSON"); + assert!(!markdown_path.exists(), "refusal published new Markdown"); + std::fs::write(root.join("ripr.toml"), config_a) + .map_err(|error| error.to_string())?; + review_comments(&args)?; + let recovered: serde_json::Value = serde_json::from_slice( + &std::fs::read(&output_path).map_err(|error| error.to_string())?, + ) + .map_err(|error| error.to_string())?; + assert_eq!( + recovered["analysis_scope"]["basis"], + "producer_check_projection" + ); + assert!( + recovered["analysis_scope"]["classified_seams_considered"] + .as_u64() + .is_some_and(|count| count > 0) + ); + Ok(()) + }, + ) + } + #[test] fn review_comments_parses_required_revisions_and_out() { assert_eq!( diff --git a/xtask/src/reports/pr_evidence.rs b/xtask/src/reports/pr_evidence.rs index ed0ab60ee..b45f44514 100644 --- a/xtask/src/reports/pr_evidence.rs +++ b/xtask/src/reports/pr_evidence.rs @@ -205,6 +205,8 @@ fn write_pr_evidence_packet( .map_err(|err| format!("resolve review input root failed: {err}"))?; let config = ripr::config::load_for_root(&root) .map_err(|err| format!("load review input config: {err}"))?; + #[cfg(test)] + mutate_configuration_after_load(&root, ConfigurationObservation::Publication)?; let canonical_diff = fs::read(repo.join(PR_CANONICAL_DIFF)) .map_err(|err| format!("read canonical diff for check subject binding: {err}"))?; let mut subject = json!({ @@ -296,6 +298,73 @@ fn write_pr_evidence_packet( publish_check_subject(repo, &subject_text) } + +#[cfg(test)] +#[derive(Clone, Copy, PartialEq, Eq)] +enum ConfigurationObservation { + Publication, +} + +#[cfg(test)] +thread_local! { + static CONFIGURATION_MUTATION: std::cell::RefCell< + Option<(ConfigurationObservation, PathBuf, Option)> + > = const { std::cell::RefCell::new(None) }; +} + +#[cfg(test)] +fn mutate_configuration_after_load(root: &Path, point: ConfigurationObservation) -> Result<(), String> { + let selected = CONFIGURATION_MUTATION.with(|slot| { + slot.borrow().as_ref().is_some_and(|entry| entry.0 == point) + }); + if !selected { + return Ok(()); + } + let mutation = CONFIGURATION_MUTATION.with(|slot| slot.borrow_mut().take()); + let Some((_, expected_root, text)) = mutation else { + return Err("controlled configuration mutation was not retained".into()); + }; + if root != expected_root { + return Err("controlled configuration mutation reached a different root".into()); + } + let path = root.join("ripr.toml"); + match text { + Some(text) => fs::write(path, text), + None => fs::remove_file(path), + } + .map_err(|error| format!("controlled configuration mutation failed: {error}")) +} + +#[cfg(test)] +fn with_configuration_mutation( + root: &Path, + point: ConfigurationObservation, + text: Option<&str>, + work: impl FnOnce() -> Result<(), String>, +) -> Result<(), String> { + struct MutationLease; + impl Drop for MutationLease { + fn drop(&mut self) { + let _ = CONFIGURATION_MUTATION.with(|slot| slot.borrow_mut().take()); + } + } + let root = root.canonicalize().map_err(|error| error.to_string())?; + let occupied = CONFIGURATION_MUTATION.with(|slot| slot.borrow().is_some()); + if occupied { + return Err("nested controlled configuration mutation".into()); + } + CONFIGURATION_MUTATION.with(|slot| { + *slot.borrow_mut() = Some((point, root, text.map(str::to_string))); + }); + let _lease = MutationLease; + let result = work(); + let pending = CONFIGURATION_MUTATION.with(|slot| slot.borrow().is_some()); + if pending { + return Err("controlled configuration mutation checkpoint was not reached".into()); + } + result +} + fn producer_review_input( check: &Value, repo: &Path, @@ -1851,6 +1920,52 @@ mod tests { Ok(()) } + #[test] + fn configuration_drift_after_publication_load_is_refused() -> Result<(), String> { + with_configuration_fixture( + "ripr-pr-after-load-config-drift", + Some(CONFIGURATION_A), + |repo, options, check, _run_check| { + let config_a = ripr::config::load_for_root(repo)?; + write_repo_file(repo, "ripr.toml", CONFIGURATION_B)?; + let config_b = ripr::config::load_for_root(repo)?; + assert_eq!( + ripr::config::repo_exposure_config_identity_hash(&config_a), + ripr::config::repo_exposure_config_identity_hash(&config_b), + ); + write_repo_file(repo, "ripr.toml", CONFIGURATION_A)?; + with_configuration_mutation( + repo, + ConfigurationObservation::Publication, + Some(CONFIGURATION_B), + || { + let failure = write_pr_evidence_with_runner(repo, options, |_, _| { + Ok(check.to_string()) + }) + .err() + .ok_or("after-load configuration drift published cached analysis")?; + assert!(failure.contains("config_identity"), "{failure}"); + for path in [PR_CHECK_JSON, PR_CHECK_SUBJECT_JSON, PR_REVIEW_INPUT_JSON] { + assert!(!repo.join(path).exists(), "retained authority: {path}"); + } + let packet: Value = serde_json::from_slice( + &fs::read(repo.join(PR_EVIDENCE_JSON)) + .map_err(|error| error.to_string())?, + ) + .map_err(|error| error.to_string())?; + assert_eq!(packet["status"], "error"); + assert!(check_pr_evidence(repo, options).is_err()); + Ok(()) + }, + )?; + write_repo_file(repo, "ripr.toml", CONFIGURATION_A)?; + write_pr_evidence_with_runner(repo, options, |_, _| Ok(check.to_string()))?; + check_pr_evidence(repo, options)?; + configuration_fixture_review(repo, options) + }, + ) + } + #[test] fn producer_configuration_drift_is_rejected_after_actual_check() -> Result<(), String> { with_configuration_fixture( From d28c4e5b63cb01cb02cc75430567a1ceac6198d1 Mon Sep 17 00:00:00 2001 From: "Steven Zimmerman, CPA" <15812269+EffortlessSteven@users.noreply.github.com> Date: Fri, 9 Oct 2026 09:35:12 -0700 Subject: [PATCH 07/10] fix: reobserve configuration before evidence authority publication --- crates/ripr/src/app/pr_evidence.rs | 35 +++- crates/ripr/src/app/review_comments.rs | 43 +++-- .../ripr/src/cli/commands/review_comments.rs | 162 +++++++++++------- xtask/src/reports/pr_evidence.rs | 37 +++- 4 files changed, 194 insertions(+), 83 deletions(-) diff --git a/crates/ripr/src/app/pr_evidence.rs b/crates/ripr/src/app/pr_evidence.rs index 131fba159..dd345dfb6 100644 --- a/crates/ripr/src/app/pr_evidence.rs +++ b/crates/ripr/src/app/pr_evidence.rs @@ -271,6 +271,23 @@ pub(crate) fn validate_pr_evidence_check_configuration_core( Ok(()) } +fn validate_current_pr_evidence_configuration( + root: &Path, + analysis_outcome: &Value, + expected_config: &crate::config::RiprConfig, +) -> Result<(), String> { + let current_config = load_for_root(root)?; + validate_pr_evidence_check_configuration(analysis_outcome, ¤t_config)?; + if repo_exposure_config_identity_hash(¤t_config) + != repo_exposure_config_identity_hash(expected_config) + { + return Err( + "producer configuration_fingerprint does not match the current configuration".to_string(), + ); + } + Ok(()) +} + fn write_pr_evidence_packet( repo: &Path, options: &PrEvidenceOptions, @@ -383,6 +400,12 @@ fn write_pr_evidence_packet( println!("Wrote {PR_EVIDENCE_JSON}"); println!("Wrote {PR_EVIDENCE_MD}"); + // Reobserve configuration immediately before committing admission authority. + validate_current_pr_evidence_configuration( + &root, + check_value.get("analysis_outcome").unwrap_or(&Value::Null), + &config, + )?; // Commit admission authority only after every fallible producer operation. crate::atomic_file::write( &repo.join(PR_CHECK_SUBJECT_JSON), @@ -391,7 +414,6 @@ fn write_pr_evidence_packet( ) } - #[cfg(test)] #[derive(Clone, Copy, PartialEq, Eq)] enum ConfigurationObservation { @@ -407,7 +429,10 @@ thread_local! { } #[cfg(test)] -fn mutate_configuration_after_load(root: &Path, point: ConfigurationObservation) -> Result<(), String> { +fn mutate_configuration_after_load( + root: &Path, + point: ConfigurationObservation, +) -> Result<(), String> { let selected = CONFIGURATION_MUTATION.with(|slot| { slot.borrow().as_ref().is_some_and(|entry| entry.0 == point) }); @@ -822,6 +847,11 @@ fn validate_producer_artifacts(repo: &Path, options: &PrEvidenceOptions) -> Resu subject.get("analysis_outcome").unwrap_or(&Value::Null), &config, )?; + validate_current_pr_evidence_configuration( + &expected_input.root, + subject.get("analysis_outcome").unwrap_or(&Value::Null), + &config, + )?; Ok(()) } @@ -1657,7 +1687,6 @@ fn write_parented_file(path: &Path, label: &str, contents: impl AsRef<[u8]>) -> fs::write(path, contents).map_err(|err| format!("failed to write {label}: {err}")) } - #[cfg(all(test, feature = "lang-rust"))] pub(crate) fn with_live_configuration_admission_fixture( test: impl FnOnce(&Path, &str, &str, &Path, &str, &str) -> Result<(), String>, diff --git a/crates/ripr/src/app/review_comments.rs b/crates/ripr/src/app/review_comments.rs index a35a93dbe..acf12dc54 100644 --- a/crates/ripr/src/app/review_comments.rs +++ b/crates/ripr/src/app/review_comments.rs @@ -111,6 +111,25 @@ impl ProducerAdmissionError { } } } +fn validate_configuration_for_producer_admission( + outcome_envelope: &Value, + config: &RiprConfig, +) -> Result<(), ProducerAdmissionError> { + super::pr_evidence::validate_pr_evidence_check_configuration_core(outcome_envelope, config) + .map_err(|error| ProducerAdmissionError { + category: match error { + super::pr_evidence::PrEvidenceConfigurationError::Missing + | super::pr_evidence::PrEvidenceConfigurationError::Malformed => { + "malformed_producer" + } + super::pr_evidence::PrEvidenceConfigurationError::Mismatch => { + "producer_identity_mismatch" + } + }, + message: error.message().to_string(), + }) +} + pub(crate) fn admit_producer_evidence( check_path: &Path, input: &CheckInput, @@ -224,19 +243,7 @@ pub(crate) fn admit_producer_evidence( "producer review input analysis_outcome is missing outcome", ) })?; - super::pr_evidence::validate_pr_evidence_check_configuration_core(outcome_envelope, config) - .map_err(|error| ProducerAdmissionError { - category: match error { - super::pr_evidence::PrEvidenceConfigurationError::Missing - | super::pr_evidence::PrEvidenceConfigurationError::Malformed => { - "malformed_producer" - } - super::pr_evidence::PrEvidenceConfigurationError::Mismatch => { - "producer_identity_mismatch" - } - }, - message: error.message().to_string(), - })?; + validate_configuration_for_producer_admission(outcome_envelope, config)?; let outcome: AnalysisOutcome = serde_json::from_value(outcome_value).map_err(|error| { ProducerAdmissionError::malformed(format!( "producer review input analysis_outcome is invalid: {error}" @@ -256,6 +263,16 @@ pub(crate) fn admit_producer_evidence( "producer review input projection is invalid: {error}" )) })?; + // Diff discovery and receipt validation may outlive the caller's config load. + let current_config = crate::config::load_for_root(&input.root).map_err(|error| { + ProducerAdmissionError::malformed(format!("load producer evidence configuration: {error}")) + })?; + validate_configuration_for_producer_admission(outcome_envelope, ¤t_config)?; + require_equal( + "configuration_fingerprint", + &repo_exposure_config_identity_hash(¤t_config), + &identity.configuration_fingerprint, + )?; Ok(AdmittedReviewAnalysis { identity, outcome, diff --git a/crates/ripr/src/cli/commands/review_comments.rs b/crates/ripr/src/cli/commands/review_comments.rs index 061247bd2..2b165a024 100644 --- a/crates/ripr/src/cli/commands/review_comments.rs +++ b/crates/ripr/src/cli/commands/review_comments.rs @@ -1239,73 +1239,105 @@ mod tests { fn direct_producer_review_reloads_configuration_after_diff_discovery() -> Result<(), String> { crate::app::pr_evidence::with_live_configuration_admission_fixture( |root, base, head, check_path, config_a, config_b| { - let output_path = root.join("target/timing-refusal.json"); - let markdown_path = output_path.with_extension("md"); - assert!(!output_path.exists()); - assert!(!markdown_path.exists()); - let args = vec![ - "--root".to_string(), - root.display().to_string(), - "--base".to_string(), - base.to_string(), - "--head".to_string(), - head.to_string(), - "--check-output".to_string(), - check_path.display().to_string(), - "--out".to_string(), - output_path.display().to_string(), - ]; - let calls = std::cell::Cell::new(0_u32); - let mutation = std::cell::RefCell::new(None); - let result = review_comments_with_diff_loader(&args, |root, base, head| { - let diff = load_review_comments_diff(root, base, head)?; - calls.set(calls.get() + 1); - let written = std::fs::write(root.join("ripr.toml"), config_b) + for (label, text, category, diagnostic) in [ + ( + "changed", + Some(config_b), + "producer_identity_mismatch", + "config_identity", + ), + ( + "empty", + Some(""), + "producer_identity_mismatch", + "config_identity", + ), + ( + "removed", + None, + "producer_identity_mismatch", + "config_identity", + ), + ( + "invalid", + Some("[analysis]\ninclude_unchanged_tests = [\n"), + "malformed_producer", + "load producer evidence configuration", + ), + ] { + let output_path = root.join(format!("target/timing-refusal-{label}.json")); + let markdown_path = output_path.with_extension("md"); + assert!(!output_path.exists()); + assert!(!markdown_path.exists()); + let args = vec![ + "--root".to_string(), + root.display().to_string(), + "--base".to_string(), + base.to_string(), + "--head".to_string(), + head.to_string(), + "--check-output".to_string(), + check_path.display().to_string(), + "--out".to_string(), + output_path.display().to_string(), + ]; + let calls = std::cell::Cell::new(0_u32); + let mutation = std::cell::RefCell::new(None); + let result = review_comments_with_diff_loader(&args, |root, base, head| { + let diff = load_review_comments_diff(root, base, head)?; + calls.set(calls.get() + 1); + let path = root.join("ripr.toml"); + let written = match text { + Some(text) => std::fs::write(path, text), + None => std::fs::remove_file(path), + } .map_err(|error| error.to_string()); - let _ = mutation.replace(Some(written)); - Ok(diff) - }); - assert_eq!(calls.get(), 1, "actual diff loader was not reached exactly once"); - mutation - .into_inner() - .ok_or("configuration mutation did not execute")??; - let failure = result - .err() - .ok_or("direct review admitted cached A after discovery changed live config to B")?; - assert!(failure.contains("producer_identity_mismatch"), "{failure}"); - assert!(failure.contains("config_identity"), "{failure}"); - let receipt: serde_json::Value = serde_json::from_slice( - &std::fs::read(root.join("target/run-receipt.json")) - .map_err(|error| error.to_string())?, - ) - .map_err(|error| error.to_string())?; - assert_eq!(receipt["status"], "failed"); - assert_eq!( - receipt["primary_failure"]["phase"], - "producer_evidence_admission" - ); - assert_eq!( - receipt["primary_failure"]["category"], - "producer_identity_mismatch" - ); - assert!(!output_path.exists(), "refusal published new JSON"); - assert!(!markdown_path.exists(), "refusal published new Markdown"); - std::fs::write(root.join("ripr.toml"), config_a) + let _ = mutation.replace(Some(written)); + Ok(diff) + }); + assert_eq!( + calls.get(), + 1, + "actual diff loader was not reached exactly once" + ); + mutation + .into_inner() + .ok_or("configuration mutation did not execute")??; + let failure = result.err().ok_or( + "direct review admitted cached A after discovery changed live config", + )?; + assert!(failure.contains(category), "{label}: {failure}"); + assert!(failure.contains(diagnostic), "{label}: {failure}"); + let receipt: serde_json::Value = serde_json::from_slice( + &std::fs::read(root.join("target/run-receipt.json")) + .map_err(|error| error.to_string())?, + ) .map_err(|error| error.to_string())?; - review_comments(&args)?; - let recovered: serde_json::Value = serde_json::from_slice( - &std::fs::read(&output_path).map_err(|error| error.to_string())?, - ) - .map_err(|error| error.to_string())?; - assert_eq!( - recovered["analysis_scope"]["basis"], - "producer_check_projection" - ); - assert!( - recovered["analysis_scope"]["classified_seams_considered"] - .as_u64() - .is_some_and(|count| count > 0) - ); + assert_eq!(receipt["status"], "failed"); + assert_eq!( + receipt["primary_failure"]["phase"], + "producer_evidence_admission" + ); + assert_eq!(receipt["primary_failure"]["category"], category); + assert!(!output_path.exists(), "refusal published new JSON"); + assert!(!markdown_path.exists(), "refusal published new Markdown"); + std::fs::write(root.join("ripr.toml"), config_a) + .map_err(|error| error.to_string())?; + review_comments(&args)?; + let recovered: serde_json::Value = serde_json::from_slice( + &std::fs::read(&output_path).map_err(|error| error.to_string())?, + ) + .map_err(|error| error.to_string())?; + assert_eq!( + recovered["analysis_scope"]["basis"], + "producer_check_projection" + ); + assert!( + recovered["analysis_scope"]["classified_seams_considered"] + .as_u64() + .is_some_and(|count| count > 0) + ); + } Ok(()) }, ) diff --git a/xtask/src/reports/pr_evidence.rs b/xtask/src/reports/pr_evidence.rs index b45f44514..9d57a18fa 100644 --- a/xtask/src/reports/pr_evidence.rs +++ b/xtask/src/reports/pr_evidence.rs @@ -179,6 +179,24 @@ fn write_pr_evidence_from_check_json( write_pr_evidence_packet(repo, options, &changed_files, check_json) } +fn validate_current_pr_evidence_configuration( + root: &Path, + analysis_outcome: &Value, + expected_config: &ripr::config::RiprConfig, +) -> Result<(), String> { + let current_config = ripr::config::load_for_root(root) + .map_err(|error| format!("load producer evidence configuration: {error}"))?; + ripr::app::pr_evidence::validate_pr_evidence_check_configuration(analysis_outcome, ¤t_config)?; + if ripr::config::repo_exposure_config_identity_hash(¤t_config) + != ripr::config::repo_exposure_config_identity_hash(expected_config) + { + return Err( + "producer configuration_fingerprint does not match the current configuration".to_string(), + ); + } + Ok(()) +} + fn write_pr_evidence_packet( repo: &Path, options: &PrEvidenceOptions, @@ -294,11 +312,16 @@ fn write_pr_evidence_packet( reject_error_packet(repo)?; println!("Wrote {PR_EVIDENCE_JSON}"); println!("Wrote {PR_EVIDENCE_MD}"); + // Reobserve configuration immediately before committing admission authority. + validate_current_pr_evidence_configuration( + &root, + check_value.get("analysis_outcome").unwrap_or(&Value::Null), + &config, + )?; // Commit admission authority only after every fallible producer operation. publish_check_subject(repo, &subject_text) } - #[cfg(test)] #[derive(Clone, Copy, PartialEq, Eq)] enum ConfigurationObservation { @@ -313,7 +336,10 @@ thread_local! { } #[cfg(test)] -fn mutate_configuration_after_load(root: &Path, point: ConfigurationObservation) -> Result<(), String> { +fn mutate_configuration_after_load( + root: &Path, + point: ConfigurationObservation, +) -> Result<(), String> { let selected = CONFIGURATION_MUTATION.with(|slot| { slot.borrow().as_ref().is_some_and(|entry| entry.0 == point) }); @@ -716,6 +742,13 @@ fn check_subject_violations(repo: &Path, options: &PrEvidenceOptions) -> Vec violations.push(format!("load producer evidence configuration: {error}")), } From 59f5819bc6449413468ad9537f5f5ff0fe2cac14 Mon Sep 17 00:00:00 2001 From: "Steven Zimmerman, CPA" <15812269+EffortlessSteven@users.noreply.github.com> Date: Fri, 9 Oct 2026 09:39:50 -0700 Subject: [PATCH 08/10] fix: revoke failed evidence and isolate admission fixture --- crates/ripr/src/app/pr_evidence.rs | 14 ++-- crates/ripr/src/app/review_comments.rs | 109 ++++++++++++++++++------- xtask/src/reports/pr_evidence.rs | 8 +- 3 files changed, 93 insertions(+), 38 deletions(-) diff --git a/crates/ripr/src/app/pr_evidence.rs b/crates/ripr/src/app/pr_evidence.rs index dd345dfb6..a81055a48 100644 --- a/crates/ripr/src/app/pr_evidence.rs +++ b/crates/ripr/src/app/pr_evidence.rs @@ -188,12 +188,14 @@ fn write_pr_evidence_with_runner( Ok(check_json) => { match write_pr_evidence_packet(repo, options, &changed_files, &check_json) { Ok(()) => Ok(()), - Err(err) => write_pr_evidence_error_packet( - repo, - options, - &changed_files, - &format!("RIPR check output could not be converted into PR evidence: {err}"), - ), + Err(err) => { + let diagnostic = + format!("RIPR check output could not be converted into PR evidence: {err}"); + remove_stale_check_artifact(repo).map_err(|cleanup| { + format!("{diagnostic}; artifact revocation failed: {cleanup}") + })?; + write_pr_evidence_error_packet(repo, options, &changed_files, &diagnostic) + } } } Err(err) => write_pr_evidence_error_packet(repo, options, &changed_files, &err), diff --git a/crates/ripr/src/app/review_comments.rs b/crates/ripr/src/app/review_comments.rs index acf12dc54..2d6981a5b 100644 --- a/crates/ripr/src/app/review_comments.rs +++ b/crates/ripr/src/app/review_comments.rs @@ -1061,16 +1061,63 @@ mod tests { #[test] fn complete_producer_is_admitted_with_exact_subject_identity() -> Result<(), String> { - let root = std::env::current_dir().map_err(|error| error.to_string())?; - // Hosted test jobs use a depth-one checkout; keep the fixture - // independent of unavailable parent objects while still exercising - // exact commit/tree subject binding. + struct RepositoryLease(PathBuf); + impl Drop for RepositoryLease { + fn drop(&mut self) { + let _ = std::fs::remove_dir_all(&self.0); + } + } + let nonce = std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .map_err(|error| error.to_string())? + .as_nanos(); + let root = std::env::temp_dir().join(format!( + "ripr-review-subject-{}-{nonce}", + std::process::id() + )); + let _lease = RepositoryLease(root.clone()); + std::fs::create_dir_all(&root).map_err(|error| error.to_string())?; + for args in [ + &["init", "--initial-branch=main"][..], + &[ + "-c", + "user.email=ripr@example.invalid", + "-c", + "user.name=ripr test", + "commit", + "--allow-empty", + "-m", + "isolated admission fixture", + ][..], + ] { + let output = crate::git::run_git_output_with_deadline( + &root, + args, + Some(Duration::from_secs(5)), + ) + .map_err(|error| error.to_string())?; + if !output.status.success() { + return Err(format!( + "initialize admission fixture: {}", + String::from_utf8_lossy(&output.stderr) + )); + } + } + let root = std::fs::canonicalize(root).map_err(|error| error.to_string())?; + let config = crate::config::load_for_root(&root)?; + assert!(config.source_text().is_none()); + let input = CheckInput { + root: root.clone(), + ..CheckInput::default() + }; + // An isolated empty commit binds the subject without inheriting the + // checkout's configuration or requiring parent objects. let base = "HEAD"; let head = "HEAD"; let diff_text = "fixture diff"; let root_identity = logical_path(&root); let configuration_fingerprint = - crate::config::repo_exposure_config_identity_hash(&RiprConfig::default()); + crate::config::repo_exposure_config_identity_hash(&config); let outcome = AnalysisOutcome::new( crate::analysis_outcome::AnalysisOutcomeKind::NoScope, crate::analysis_outcome::AnalysisIdentity { @@ -1179,8 +1226,8 @@ mod tests { let admitted = admit_producer_evidence( &check_path, - &CheckInput::default(), - &RiprConfig::default(), + &input, + &config, base, head, diff_text, @@ -1199,8 +1246,8 @@ mod tests { .map_err(|error| format!("create unreadable subject fixture: {error}"))?; let unreadable_subject = admit_producer_evidence( &check_path, - &CheckInput::default(), - &RiprConfig::default(), + &input, + &config, base, head, diff_text, @@ -1222,8 +1269,8 @@ mod tests { .map_err(|error| format!("create unreadable review input: {error}"))?; let unreadable_review_input = admit_producer_evidence( &check_path, - &CheckInput::default(), - &RiprConfig::default(), + &input, + &config, base, head, diff_text, @@ -1260,8 +1307,8 @@ mod tests { .map_err(|error| format!("write {name} subject: {error}"))?; let error = admit_producer_evidence( &check_path, - &CheckInput::default(), - &RiprConfig::default(), + &input, + &config, base, head, diff_text, @@ -1279,8 +1326,8 @@ mod tests { .map_err(|error| format!("write malformed review input: {error}"))?; let malformed_review_input = admit_producer_evidence( &check_path, - &CheckInput::default(), - &RiprConfig::default(), + &input, + &config, base, head, diff_text, @@ -1305,8 +1352,8 @@ mod tests { .map_err(|error| format!("write invalid byte-count subject: {error}"))?; let invalid_byte_count_error = admit_producer_evidence( &check_path, - &CheckInput::default(), - &RiprConfig::default(), + &input, + &config, base, head, diff_text, @@ -1346,8 +1393,8 @@ mod tests { .map_err(|error| format!("write {name} subject: {error}"))?; let error = admit_producer_evidence( &check_path, - &CheckInput::default(), - &RiprConfig::default(), + &input, + &config, base, head, diff_text, @@ -1371,8 +1418,8 @@ mod tests { .map_err(|error| format!("write mismatched-outcome subject: {error}"))?; let mismatched_outcome_error = admit_producer_evidence( &check_path, - &CheckInput::default(), - &RiprConfig::default(), + &input, + &config, base, head, diff_text, @@ -1391,8 +1438,8 @@ mod tests { std::fs::remove_file(&check_path).map_err(|error| error.to_string())?; admit_producer_evidence( &check_path, - &CheckInput::default(), - &RiprConfig::default(), + &input, + &config, base, head, diff_text, @@ -1423,8 +1470,8 @@ mod tests { .map_err(|error| format!("write incomplete review input: {error}"))?; let incomplete = admit_producer_evidence( &check_path, - &CheckInput::default(), - &RiprConfig::default(), + &input, + &config, base, head, diff_text, @@ -1467,8 +1514,8 @@ mod tests { .map_err(|error| format!("write subject mutation {field}: {error}"))?; let error = admit_producer_evidence( &check_path, - &CheckInput::default(), - &RiprConfig::default(), + &input, + &config, base, head, diff_text, @@ -1497,8 +1544,8 @@ mod tests { std::fs::remove_file(&subject_path).map_err(|error| error.to_string())?; let missing_subject = admit_producer_evidence( &check_path, - &CheckInput::default(), - &RiprConfig::default(), + &input, + &config, base, head, diff_text, @@ -1514,8 +1561,8 @@ mod tests { std::fs::write(&subject_path, b"{").map_err(|error| error.to_string())?; let malformed_subject = admit_producer_evidence( &check_path, - &CheckInput::default(), - &RiprConfig::default(), + &input, + &config, base, head, diff_text, diff --git a/xtask/src/reports/pr_evidence.rs b/xtask/src/reports/pr_evidence.rs index 9d57a18fa..910b95d64 100644 --- a/xtask/src/reports/pr_evidence.rs +++ b/xtask/src/reports/pr_evidence.rs @@ -152,6 +152,9 @@ fn write_pr_evidence_with_runner( Err(err) => { let diagnostic = format!("RIPR check output could not be converted into PR evidence: {err}"); + remove_stale_check_artifact(repo).map_err(|cleanup| { + format!("{diagnostic}; artifact revocation failed: {cleanup}") + })?; write_pr_evidence_error_packet(repo, options, &changed_files, &diagnostic)?; Err(diagnostic) } @@ -186,7 +189,10 @@ fn validate_current_pr_evidence_configuration( ) -> Result<(), String> { let current_config = ripr::config::load_for_root(root) .map_err(|error| format!("load producer evidence configuration: {error}"))?; - ripr::app::pr_evidence::validate_pr_evidence_check_configuration(analysis_outcome, ¤t_config)?; + ripr::app::pr_evidence::validate_pr_evidence_check_configuration( + analysis_outcome, + ¤t_config, + )?; if ripr::config::repo_exposure_config_identity_hash(¤t_config) != ripr::config::repo_exposure_config_identity_hash(expected_config) { From 9d2def5eb3705613643bd16640be79f9de033a59 Mon Sep 17 00:00:00 2001 From: "Steven Zimmerman, CPA" <15812269+EffortlessSteven@users.noreply.github.com> Date: Fri, 9 Oct 2026 09:43:47 -0700 Subject: [PATCH 09/10] test: isolate configuration admission fixture Git setup --- crates/ripr/src/app/review_comments.rs | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/crates/ripr/src/app/review_comments.rs b/crates/ripr/src/app/review_comments.rs index 2d6981a5b..00d300027 100644 --- a/crates/ripr/src/app/review_comments.rs +++ b/crates/ripr/src/app/review_comments.rs @@ -1064,7 +1064,7 @@ mod tests { struct RepositoryLease(PathBuf); impl Drop for RepositoryLease { fn drop(&mut self) { - let _ = std::fs::remove_dir_all(&self.0); + let _ = crate::testing::fixture_git::remove_fixture_tree(&self.0); } } let nonce = std::time::SystemTime::now() @@ -1078,30 +1078,21 @@ mod tests { let _lease = RepositoryLease(root.clone()); std::fs::create_dir_all(&root).map_err(|error| error.to_string())?; for args in [ - &["init", "--initial-branch=main"][..], + &["-c", "init.templateDir=", "init", "--initial-branch=main"][..], &[ "-c", "user.email=ripr@example.invalid", "-c", "user.name=ripr test", + "-c", + "commit.gpgSign=false", "commit", "--allow-empty", "-m", "isolated admission fixture", ][..], ] { - let output = crate::git::run_git_output_with_deadline( - &root, - args, - Some(Duration::from_secs(5)), - ) - .map_err(|error| error.to_string())?; - if !output.status.success() { - return Err(format!( - "initialize admission fixture: {}", - String::from_utf8_lossy(&output.stderr) - )); - } + crate::testing::fixture_git::fixture_git_ok(&root, args)?; } let root = std::fs::canonicalize(root).map_err(|error| error.to_string())?; let config = crate::config::load_for_root(&root)?; From 0f7774c55ca6b270c4e68a28c6c6ac7677c9ddf6 Mon Sep 17 00:00:00 2001 From: "Steven Zimmerman, CPA" <15812269+EffortlessSteven@users.noreply.github.com> Date: Fri, 9 Oct 2026 10:47:11 -0700 Subject: [PATCH 10/10] style: apply pinned formatter to configuration timing repair --- crates/ripr/src/app/pr_evidence.rs | 8 +- crates/ripr/src/app/review_comments.rs | 190 +++++++------------------ xtask/src/reports/pr_evidence.rs | 12 +- 3 files changed, 66 insertions(+), 144 deletions(-) diff --git a/crates/ripr/src/app/pr_evidence.rs b/crates/ripr/src/app/pr_evidence.rs index a81055a48..8b4b13f72 100644 --- a/crates/ripr/src/app/pr_evidence.rs +++ b/crates/ripr/src/app/pr_evidence.rs @@ -284,7 +284,8 @@ fn validate_current_pr_evidence_configuration( != repo_exposure_config_identity_hash(expected_config) { return Err( - "producer configuration_fingerprint does not match the current configuration".to_string(), + "producer configuration_fingerprint does not match the current configuration" + .to_string(), ); } Ok(()) @@ -435,9 +436,8 @@ fn mutate_configuration_after_load( root: &Path, point: ConfigurationObservation, ) -> Result<(), String> { - let selected = CONFIGURATION_MUTATION.with(|slot| { - slot.borrow().as_ref().is_some_and(|entry| entry.0 == point) - }); + let selected = CONFIGURATION_MUTATION + .with(|slot| slot.borrow().as_ref().is_some_and(|entry| entry.0 == point)); if !selected { return Ok(()); } diff --git a/crates/ripr/src/app/review_comments.rs b/crates/ripr/src/app/review_comments.rs index 00d300027..10e1f2f77 100644 --- a/crates/ripr/src/app/review_comments.rs +++ b/crates/ripr/src/app/review_comments.rs @@ -1107,8 +1107,7 @@ mod tests { let head = "HEAD"; let diff_text = "fixture diff"; let root_identity = logical_path(&root); - let configuration_fingerprint = - crate::config::repo_exposure_config_identity_hash(&config); + let configuration_fingerprint = crate::config::repo_exposure_config_identity_hash(&config); let outcome = AnalysisOutcome::new( crate::analysis_outcome::AnalysisOutcomeKind::NoScope, crate::analysis_outcome::AnalysisIdentity { @@ -1215,15 +1214,8 @@ mod tests { std::fs::write(&review_input_path, &review_input_bytes) .map_err(|error| format!("write review input fixture: {error}"))?; - let admitted = admit_producer_evidence( - &check_path, - &input, - &config, - base, - head, - diff_text, - ) - .map_err(|error| error.message)?; + let admitted = admit_producer_evidence(&check_path, &input, &config, base, head, diff_text) + .map_err(|error| error.message)?; if admitted.identity.mode != "draft" || admitted.identity.base_sha != base_sha || admitted.identity.head_sha != head_sha @@ -1235,16 +1227,10 @@ mod tests { std::fs::remove_file(&subject_path).map_err(|error| error.to_string())?; std::fs::create_dir(&subject_path) .map_err(|error| format!("create unreadable subject fixture: {error}"))?; - let unreadable_subject = admit_producer_evidence( - &check_path, - &input, - &config, - base, - head, - diff_text, - ) - .err() - .ok_or_else(|| "directory subject receipt must fail".to_string())?; + let unreadable_subject = + admit_producer_evidence(&check_path, &input, &config, base, head, diff_text) + .err() + .ok_or_else(|| "directory subject receipt must fail".to_string())?; if unreadable_subject.category != "malformed_producer" { return Err(format!( "directory subject receipt returned {}", @@ -1258,16 +1244,10 @@ mod tests { std::fs::remove_file(&review_input_path).map_err(|error| error.to_string())?; std::fs::create_dir(&review_input_path) .map_err(|error| format!("create unreadable review input: {error}"))?; - let unreadable_review_input = admit_producer_evidence( - &check_path, - &input, - &config, - base, - head, - diff_text, - ) - .err() - .ok_or_else(|| "directory review input must fail".to_string())?; + let unreadable_review_input = + admit_producer_evidence(&check_path, &input, &config, base, head, diff_text) + .err() + .ok_or_else(|| "directory review input must fail".to_string())?; if unreadable_review_input.category != "malformed_producer" { return Err(format!( "directory review input returned {}", @@ -1296,16 +1276,10 @@ mod tests { serde_json::to_vec(&mutated).map_err(|error| error.to_string())?, ) .map_err(|error| format!("write {name} subject: {error}"))?; - let error = admit_producer_evidence( - &check_path, - &input, - &config, - base, - head, - diff_text, - ) - .err() - .ok_or_else(|| format!("{name} must fail"))?; + let error = + admit_producer_evidence(&check_path, &input, &config, base, head, diff_text) + .err() + .ok_or_else(|| format!("{name} must fail"))?; if error.category != "malformed_producer" { return Err(format!("{name} returned {}", error.category)); } @@ -1315,16 +1289,10 @@ mod tests { std::fs::write(&review_input_path, b"{") .map_err(|error| format!("write malformed review input: {error}"))?; - let malformed_review_input = admit_producer_evidence( - &check_path, - &input, - &config, - base, - head, - diff_text, - ) - .err() - .ok_or_else(|| "malformed review input must fail".to_string())?; + let malformed_review_input = + admit_producer_evidence(&check_path, &input, &config, base, head, diff_text) + .err() + .ok_or_else(|| "malformed review input must fail".to_string())?; if malformed_review_input.category != "malformed_producer" { return Err(format!( "malformed review input returned {}", @@ -1341,16 +1309,10 @@ mod tests { serde_json::to_vec(&invalid_byte_count).map_err(|error| error.to_string())?, ) .map_err(|error| format!("write invalid byte-count subject: {error}"))?; - let invalid_byte_count_error = admit_producer_evidence( - &check_path, - &input, - &config, - base, - head, - diff_text, - ) - .err() - .ok_or_else(|| "invalid review-input byte count must fail".to_string())?; + let invalid_byte_count_error = + admit_producer_evidence(&check_path, &input, &config, base, head, diff_text) + .err() + .ok_or_else(|| "invalid review-input byte count must fail".to_string())?; if invalid_byte_count_error.category != "malformed_producer" { return Err(format!( "invalid review-input byte count returned {}", @@ -1382,16 +1344,10 @@ mod tests { serde_json::to_vec(&mutated).map_err(|error| error.to_string())?, ) .map_err(|error| format!("write {name} subject: {error}"))?; - let error = admit_producer_evidence( - &check_path, - &input, - &config, - base, - head, - diff_text, - ) - .err() - .ok_or_else(|| format!("{name} must fail"))?; + let error = + admit_producer_evidence(&check_path, &input, &config, base, head, diff_text) + .err() + .ok_or_else(|| format!("{name} must fail"))?; if error.category != expected_category { return Err(format!("{name} returned {}", error.category)); } @@ -1407,16 +1363,10 @@ mod tests { serde_json::to_vec(&mismatched_outcome).map_err(|error| error.to_string())?, ) .map_err(|error| format!("write mismatched-outcome subject: {error}"))?; - let mismatched_outcome_error = admit_producer_evidence( - &check_path, - &input, - &config, - base, - head, - diff_text, - ) - .err() - .ok_or_else(|| "mismatched outcome must fail".to_string())?; + let mismatched_outcome_error = + admit_producer_evidence(&check_path, &input, &config, base, head, diff_text) + .err() + .ok_or_else(|| "mismatched outcome must fail".to_string())?; if mismatched_outcome_error.category != "incomplete_producer" { return Err(format!( "mismatched outcome returned {}", @@ -1427,20 +1377,14 @@ mod tests { std::fs::write(&subject_path, &original_subject_bytes) .map_err(|error| format!("restore subject before cleanup: {error}"))?; std::fs::remove_file(&check_path).map_err(|error| error.to_string())?; - admit_producer_evidence( - &check_path, - &input, - &config, - base, - head, - diff_text, - ) - .map_err(|error| { - format!( - "consumer unexpectedly required check.json: {}", - error.message - ) - })?; + admit_producer_evidence(&check_path, &input, &config, base, head, diff_text).map_err( + |error| { + format!( + "consumer unexpectedly required check.json: {}", + error.message + ) + }, + )?; let original_subject = subject.clone(); let mut incomplete_input = review_input.clone(); @@ -1459,16 +1403,10 @@ mod tests { .map_err(|error| format!("write incomplete subject: {error}"))?; std::fs::write(&review_input_path, &incomplete_bytes) .map_err(|error| format!("write incomplete review input: {error}"))?; - let incomplete = admit_producer_evidence( - &check_path, - &input, - &config, - base, - head, - diff_text, - ) - .err() - .ok_or_else(|| "incomplete producer must fail closed".to_string())?; + let incomplete = + admit_producer_evidence(&check_path, &input, &config, base, head, diff_text) + .err() + .ok_or_else(|| "incomplete producer must fail closed".to_string())?; if incomplete.category != "incomplete_producer" { return Err(format!( "unexpected incomplete-producer category: {}", @@ -1503,16 +1441,10 @@ mod tests { serde_json::to_vec(&mutated).map_err(|error| error.to_string())?, ) .map_err(|error| format!("write subject mutation {field}: {error}"))?; - let error = admit_producer_evidence( - &check_path, - &input, - &config, - base, - head, - diff_text, - ) - .err() - .ok_or_else(|| format!("subject mutation {field} must fail"))?; + let error = + admit_producer_evidence(&check_path, &input, &config, base, head, diff_text) + .err() + .ok_or_else(|| format!("subject mutation {field} must fail"))?; let expected_category = if field == "mode" { "producer_mode_mismatch" } else if field == "review_input_byte_count" { @@ -1533,16 +1465,10 @@ mod tests { ) .map_err(|error| format!("restore subject before cleanup: {error}"))?; std::fs::remove_file(&subject_path).map_err(|error| error.to_string())?; - let missing_subject = admit_producer_evidence( - &check_path, - &input, - &config, - base, - head, - diff_text, - ) - .err() - .ok_or_else(|| "missing subject receipt must fail closed".to_string())?; + let missing_subject = + admit_producer_evidence(&check_path, &input, &config, base, head, diff_text) + .err() + .ok_or_else(|| "missing subject receipt must fail closed".to_string())?; if missing_subject.category != "missing_producer" { return Err(format!( "unexpected missing-subject category: {}", @@ -1550,16 +1476,10 @@ mod tests { )); } std::fs::write(&subject_path, b"{").map_err(|error| error.to_string())?; - let malformed_subject = admit_producer_evidence( - &check_path, - &input, - &config, - base, - head, - diff_text, - ) - .err() - .ok_or_else(|| "malformed subject receipt must fail closed".to_string())?; + let malformed_subject = + admit_producer_evidence(&check_path, &input, &config, base, head, diff_text) + .err() + .ok_or_else(|| "malformed subject receipt must fail closed".to_string())?; if malformed_subject.category != "malformed_producer" { return Err(format!( "unexpected malformed-subject category: {}", diff --git a/xtask/src/reports/pr_evidence.rs b/xtask/src/reports/pr_evidence.rs index 910b95d64..53d5e893f 100644 --- a/xtask/src/reports/pr_evidence.rs +++ b/xtask/src/reports/pr_evidence.rs @@ -197,7 +197,8 @@ fn validate_current_pr_evidence_configuration( != ripr::config::repo_exposure_config_identity_hash(expected_config) { return Err( - "producer configuration_fingerprint does not match the current configuration".to_string(), + "producer configuration_fingerprint does not match the current configuration" + .to_string(), ); } Ok(()) @@ -346,9 +347,8 @@ fn mutate_configuration_after_load( root: &Path, point: ConfigurationObservation, ) -> Result<(), String> { - let selected = CONFIGURATION_MUTATION.with(|slot| { - slot.borrow().as_ref().is_some_and(|entry| entry.0 == point) - }); + let selected = CONFIGURATION_MUTATION + .with(|slot| slot.borrow().as_ref().is_some_and(|entry| entry.0 == point)); if !selected { return Ok(()); } @@ -748,7 +748,9 @@ fn check_subject_violations(repo: &Path, options: &PrEvidenceOptions) -> Vec