From 18f703e370bea6c91e840b2d3e2db2b360cb713b Mon Sep 17 00:00:00 2001 From: Steven Zimmerman Date: Wed, 12 Aug 2026 16:23:03 -0400 Subject: [PATCH 1/2] fix(output): bind receipt fallback to selected proof --- .../ripr/src/output/pr_review_front_panel.rs | 180 +++++++++++++++++- .../expected/pr-review-front-panel/README.md | 3 + .../pr-review-front-panel/corpus.json | 23 +++ .../agent-receipt.json | 27 +++ .../assistant-loop-health.json | 82 ++++++++ .../pr-review-front-panel.json | 112 +++++++++++ .../pr-review-front-panel.md | 44 +++++ 7 files changed, 462 insertions(+), 9 deletions(-) create mode 100644 fixtures/boundary_gap/expected/pr-review-front-panel/stale-same-path-receipt/agent-receipt.json create mode 100644 fixtures/boundary_gap/expected/pr-review-front-panel/stale-same-path-receipt/assistant-loop-health.json create mode 100644 fixtures/boundary_gap/expected/pr-review-front-panel/stale-same-path-receipt/pr-review-front-panel.json create mode 100644 fixtures/boundary_gap/expected/pr-review-front-panel/stale-same-path-receipt/pr-review-front-panel.md diff --git a/crates/ripr/src/output/pr_review_front_panel.rs b/crates/ripr/src/output/pr_review_front_panel.rs index 1ddc0dcd16e..af13fa4fc4a 100644 --- a/crates/ripr/src/output/pr_review_front_panel.rs +++ b/crates/ripr/src/output/pr_review_front_panel.rs @@ -3,8 +3,8 @@ use serde_json::Value; use super::first_pr::STATIC_EVIDENCE_BOUNDARY; use super::receipt_lifecycle::{ - RECEIPT_MISSING, RECEIPT_NOT_APPLICABLE, receipt_lifecycle_state, - receipt_lifecycle_state_from_receipt_value, + RECEIPT_MISSING, RECEIPT_MOVEMENT_IMPROVED, RECEIPT_MOVEMENT_UNCHANGED, RECEIPT_NOT_APPLICABLE, + receipt_lifecycle_state, receipt_lifecycle_state_from_receipt_value, }; const SCHEMA_VERSION: &str = "0.1"; @@ -1725,7 +1725,7 @@ fn top_issue_from_assistant_health( receipt: PanelReceipt { artifact: receipt.and_then(|value| string_path(value, &["artifact"])), status: selected_proof_receipt_status( - receipt, + proof, parsed.receipt.as_ref(), input.receipt_path.as_deref(), ), @@ -1734,24 +1734,106 @@ fn top_issue_from_assistant_health( } fn selected_proof_receipt_status( - selected_receipt: Option<&Value>, + selected_proof: &Value, parsed_receipt: Option<&Value>, parsed_receipt_artifact: Option<&str>, ) -> String { + let selected_receipt = selected_proof.get("receipt"); if let Some(status) = selected_receipt.and_then(|value| string_path(value, &["status"])) { return receipt_lifecycle_state(Some(&status)); } - if let (Some(selected_artifact), Some(parsed_artifact), Some(parsed_receipt)) = ( - selected_receipt.and_then(|value| string_path(value, &["artifact"])), - parsed_receipt_artifact, - parsed_receipt, - ) && selected_artifact == parsed_artifact + if let Some(parsed_receipt) = parsed_receipt + && parsed_receipt_matches_selected_proof( + selected_proof, + parsed_receipt, + parsed_receipt_artifact, + ) { return receipt_lifecycle_state_from_receipt_value(parsed_receipt); } RECEIPT_MISSING.to_string() } +fn parsed_receipt_matches_selected_proof( + selected_proof: &Value, + parsed_receipt: &Value, + parsed_receipt_artifact: Option<&str>, +) -> bool { + let (Some(selected_artifact), Some(parsed_receipt_artifact)) = ( + string_path(selected_proof, &["receipt", "artifact"]), + parsed_receipt_artifact, + ) else { + return false; + }; + if selected_artifact != parsed_receipt_artifact { + return false; + } + let Some(selected_seam_id) = string_path(selected_proof, &["seam", "seam_id"]) else { + return false; + }; + let parsed_seam_ids = [ + string_path(parsed_receipt, &["provenance", "seam_id"]), + string_path(parsed_receipt, &["seam", "seam_id"]), + ]; + if !all_present_values_match(&parsed_seam_ids, &selected_seam_id) { + return false; + } + + let Some(selected_movement) = string_path(selected_proof, &["movement_state"]) else { + return false; + }; + let parsed_movements = [ + string_path(parsed_receipt, &["provenance", "movement"]), + string_path(parsed_receipt, &["static_movement", "state"]), + string_path(parsed_receipt, &["seam", "change"]), + string_path(parsed_receipt, &["summary", "next_action", "kind"]), + ]; + if !all_present_values_match(&parsed_movements, &selected_movement) { + return false; + } + let lifecycle = receipt_lifecycle_state_from_receipt_value(parsed_receipt); + if (lifecycle == RECEIPT_MOVEMENT_IMPROVED && selected_movement != "improved") + || (lifecycle == RECEIPT_MOVEMENT_UNCHANGED && selected_movement != "unchanged") + { + return false; + } + + selected_class_matches_receipt( + selected_proof, + parsed_receipt, + "before_class", + &[&["provenance", "before_class"], &["seam", "before"]], + ) && selected_class_matches_receipt( + selected_proof, + parsed_receipt, + "after_class", + &[&["provenance", "after_class"], &["seam", "after"]], + ) +} + +fn all_present_values_match(values: &[Option], expected: &str) -> bool { + let mut present = values.iter().flatten(); + present + .next() + .is_some_and(|first| first == expected && present.all(|value| value == expected)) +} + +fn selected_class_matches_receipt( + selected_proof: &Value, + parsed_receipt: &Value, + selected_field: &str, + parsed_paths: &[&[&str]], +) -> bool { + let Some(selected) = string_path(selected_proof, &["movement", selected_field]) else { + return true; + }; + let parsed = parsed_paths + .iter() + .map(|path| string_path(parsed_receipt, path)) + .collect::>(); + parsed.iter().flatten().all(|value| value == &selected) +} + fn selected_assistant_health_proof(health: &Value) -> Option<&Value> { let proofs = health.get("proofs").and_then(Value::as_array)?; proofs @@ -2489,6 +2571,86 @@ mod tests { Ok(()) } + #[test] + fn selected_proof_uses_current_same_path_receipt_only_as_fallback() -> Result<(), String> { + let repo_root = repo_root()?; + let inputs = serde_json::json!({ + "assistant_health": "fixtures/boundary_gap/expected/assistant-loop-health/unchanged/assistant-loop-health.json", + "receipt": "fixtures/boundary_gap/expected/first-useful-action/unchanged-after-attempt/agent-receipt.json" + }); + let expected_md_path = repo_root.join( + "fixtures/boundary_gap/expected/pr-review-front-panel/mixed-health/pr-review-front-panel.md", + ); + let mut input = fixture_input(&repo_root, &inputs, &expected_md_path)?; + let mut health: Value = serde_json::from_str( + input + .assistant_health_json + .as_ref() + .and_then(|result| result.as_ref().ok()) + .ok_or_else(|| "assistant health fixture missing".to_string())?, + ) + .map_err(|err| format!("parse assistant health fixture failed: {err}"))?; + health["proofs"][0]["receipt"] + .as_object_mut() + .ok_or_else(|| "selected proof receipt missing".to_string())? + .remove("status"); + input.assistant_health_json = Some(Ok(health.to_string())); + + let json = render_pr_review_front_panel_json(&build_pr_review_front_panel_report(input))?; + assert!(json.contains("\"status\": \"receipt_movement_unchanged\"")); + Ok(()) + } + + #[test] + fn selected_proof_rejects_regenerated_same_path_receipt_fallback() -> Result<(), String> { + let repo_root = repo_root()?; + let inputs = serde_json::json!({ + "assistant_health": "fixtures/boundary_gap/expected/assistant-loop-health/unchanged/assistant-loop-health.json", + "receipt": "fixtures/boundary_gap/expected/first-useful-action/unchanged-after-attempt/agent-receipt.json" + }); + let expected_md_path = repo_root.join( + "fixtures/boundary_gap/expected/pr-review-front-panel/mixed-health/pr-review-front-panel.md", + ); + let mut input = fixture_input(&repo_root, &inputs, &expected_md_path)?; + let mut health: Value = serde_json::from_str( + input + .assistant_health_json + .as_ref() + .and_then(|result| result.as_ref().ok()) + .ok_or_else(|| "assistant health fixture missing".to_string())?, + ) + .map_err(|err| format!("parse assistant health fixture failed: {err}"))?; + health["proofs"][0]["receipt"] + .as_object_mut() + .ok_or_else(|| "selected proof receipt missing".to_string())? + .remove("status"); + input.assistant_health_json = Some(Ok(health.to_string())); + input.receipt_json = Some(Ok(serde_json::json!({ + "provenance": { + "seam_id": "67fc764ba37d77bd", + "movement": "improved", + "before_class": "weakly_gripped", + "after_class": "strongly_gripped" + }, + "seam": { + "seam_id": "67fc764ba37d77bd", + "change": "improved", + "before": "weakly_gripped", + "after": "strongly_gripped" + }, + "summary": { + "receipt_state": "receipt_movement_improved", + "next_action": {"kind": "improved"} + } + }) + .to_string())); + + let json = render_pr_review_front_panel_json(&build_pr_review_front_panel_report(input))?; + assert!(json.contains("\"status\": \"receipt_missing\"")); + assert!(!json.contains("\"status\": \"receipt_movement_improved\"")); + Ok(()) + } + fn fixture_input( repo_root: &Path, inputs: &Value, diff --git a/fixtures/boundary_gap/expected/pr-review-front-panel/README.md b/fixtures/boundary_gap/expected/pr-review-front-panel/README.md index d0fb61f593a..943d9bc0b2c 100644 --- a/fixtures/boundary_gap/expected/pr-review-front-panel/README.md +++ b/fixtures/boundary_gap/expected/pr-review-front-panel/README.md @@ -28,6 +28,8 @@ The corpus intentionally covers: - missing proof or first-action input; - flat coverage with improved static grip; - mixed assistant-health outcomes that keep repair-bearing proof visible. +- same-path regenerated receipt content that fails closed when its movement no + longer matches the selected proof. Case directories: @@ -41,6 +43,7 @@ Case directories: - `missing-proof/` - `coverage-flat-grip-improved/` - `mixed-health/` +- `stale-same-path-receipt/` Each case pins status, top-issue state, policy state, placement, movement, coverage/grip state, summary counts, artifact groups, warnings, and advisory diff --git a/fixtures/boundary_gap/expected/pr-review-front-panel/corpus.json b/fixtures/boundary_gap/expected/pr-review-front-panel/corpus.json index 7a95ada2e0d..4e8aba539dc 100644 --- a/fixtures/boundary_gap/expected/pr-review-front-panel/corpus.json +++ b/fixtures/boundary_gap/expected/pr-review-front-panel/corpus.json @@ -270,6 +270,29 @@ "warnings": 0 }, "reason": "A repair-bearing proof must outrank aggregate improvement so unchanged and unknown work cannot collapse to a no-repair panel." + }, + { + "id": "stale_same_path_receipt_fails_closed", + "scenario": "selected unchanged proof lacks receipt status while the same receipt path contains regenerated improved content", + "inputs": { + "assistant_health": "fixtures/boundary_gap/expected/pr-review-front-panel/stale-same-path-receipt/assistant-loop-health.json", + "receipt": "fixtures/boundary_gap/expected/pr-review-front-panel/stale-same-path-receipt/agent-receipt.json" + }, + "expected_report": "fixtures/boundary_gap/expected/pr-review-front-panel/stale-same-path-receipt/pr-review-front-panel.json", + "expected_markdown": "fixtures/boundary_gap/expected/pr-review-front-panel/stale-same-path-receipt/pr-review-front-panel.md", + "expected": { + "status": "advisory", + "top_issue_state": "unchanged_after_attempt", + "policy_state": "none", + "placement": "changed_line", + "movement_state": "unchanged", + "coverage_grip_state": "not_available", + "new_policy_eligible": 0, + "baseline_resolved": 0, + "blocking_candidates": 0, + "warnings": 0 + }, + "reason": "Same-path provenance cannot overwrite selected-proof authority; a regenerated receipt must match seam, movement, and available classes before fallback admission." } ] } diff --git a/fixtures/boundary_gap/expected/pr-review-front-panel/stale-same-path-receipt/agent-receipt.json b/fixtures/boundary_gap/expected/pr-review-front-panel/stale-same-path-receipt/agent-receipt.json new file mode 100644 index 00000000000..a18b8a40d3c --- /dev/null +++ b/fixtures/boundary_gap/expected/pr-review-front-panel/stale-same-path-receipt/agent-receipt.json @@ -0,0 +1,27 @@ +{ + "schema_version": "0.5", + "tool": "ripr", + "status": "incomplete", + "provenance": { + "seam_id": "67fc764ba37d77bd", + "movement": "improved", + "before_class": "weakly_gripped", + "after_class": "strongly_gripped" + }, + "seam": { + "seam_id": "67fc764ba37d77bd", + "seam_kind": "predicate_boundary", + "file": "src/lib.rs", + "line": 2, + "before": "weakly_gripped", + "after": "strongly_gripped", + "change": "improved" + }, + "summary": { + "receipt_state": "receipt_movement_improved", + "next_action": { + "kind": "improved", + "summary": "Static grip improved." + } + } +} diff --git a/fixtures/boundary_gap/expected/pr-review-front-panel/stale-same-path-receipt/assistant-loop-health.json b/fixtures/boundary_gap/expected/pr-review-front-panel/stale-same-path-receipt/assistant-loop-health.json new file mode 100644 index 00000000000..4c0a14e67f6 --- /dev/null +++ b/fixtures/boundary_gap/expected/pr-review-front-panel/stale-same-path-receipt/assistant-loop-health.json @@ -0,0 +1,82 @@ +{ + "schema_version": "0.1", + "tool": "ripr", + "kind": "assistant_loop_health", + "status": "advisory", + "root": ".", + "generated_at": "2026-05-09T12:00:00Z", + "summary": { + "proofs": 1, + "complete": 1, + "partial": 0, + "missing_required_input": 0, + "missing_optional_input": 0, + "improved": 0, + "unchanged": 1, + "regressed": 0, + "unknown_movement": 0, + "warnings": 1, + "repair_queue": 1 + }, + "proofs": [ + { + "id": "proof-67fc764ba37d77bd-unchanged-before-regeneration", + "source_artifact": "fixtures/boundary_gap/expected/assistant-loop-health/proofs/unchanged-proof.json", + "proof_state": "complete", + "movement_state": "unchanged", + "seam": { + "seam_id": "67fc764ba37d77bd", + "seam_kind": "predicate_boundary", + "path": "src/lib.rs", + "line": 2, + "grip_class": "weakly_gripped", + "missing_discriminator": "input that hits the boundary: amount >= discount_threshold" + }, + "recommendation": { + "placement": "changed_line", + "related_test": "tests/pricing.rs::below_threshold_has_no_discount", + "suggested_test": "Add a focused boundary test that exercises amount >= discount_threshold and assert the exact discounted_total output.", + "verify_command": "ripr agent verify --root fixtures/boundary_gap/input --before target/ripr/workflow/before.repo-exposure.json --after target/ripr/workflow/after.repo-exposure.json --json" + }, + "handoff": { + "artifact": "fixtures/boundary_gap/expected/editor-agent-loop/agent-brief.json", + "agent_command": "ripr agent start --root fixtures/boundary_gap/input --seam-id 67fc764ba37d77bd --out target/ripr/workflow" + }, + "receipt": { + "artifact": "fixtures/boundary_gap/expected/pr-review-front-panel/stale-same-path-receipt/agent-receipt.json" + }, + "movement": { + "before_class": "weakly_gripped", + "after_class": "weakly_gripped", + "source": "agent_receipt", + "source_state": "unchanged" + }, + "warnings": [ + { + "kind": "unchanged_movement", + "message": "Static movement remained unchanged after the focused attempt.", + "source_artifact": "fixtures/boundary_gap/expected/pr-review-front-panel/stale-same-path-receipt/agent-receipt.json" + } + ] + } + ], + "warning_summary": [ + { + "kind": "unchanged_movement", + "count": 1, + "examples": [ + "Static movement remained unchanged after the focused attempt." + ] + } + ], + "repair_queue": [ + { + "repair_kind": "inspect_unchanged_attempt", + "source_artifact": "fixtures/boundary_gap/expected/assistant-loop-health/proofs/unchanged-proof.json", + "seam_id": "67fc764ba37d77bd", + "path": "src/lib.rs", + "line": 2, + "reason": "Static evidence did not move after the focused attempt." + } + ] +} diff --git a/fixtures/boundary_gap/expected/pr-review-front-panel/stale-same-path-receipt/pr-review-front-panel.json b/fixtures/boundary_gap/expected/pr-review-front-panel/stale-same-path-receipt/pr-review-front-panel.json new file mode 100644 index 00000000000..29bd7b27920 --- /dev/null +++ b/fixtures/boundary_gap/expected/pr-review-front-panel/stale-same-path-receipt/pr-review-front-panel.json @@ -0,0 +1,112 @@ +{ + "schema_version": "0.1", + "tool": "ripr", + "kind": "pr_review_front_panel", + "status": "advisory", + "root": "fixtures/boundary_gap/input", + "generated_at": "2026-05-09T12:00:00Z", + "inputs": { + "pr_guidance": null, + "first_action": null, + "assistant_proof": null, + "assistant_health": "fixtures/boundary_gap/expected/pr-review-front-panel/stale-same-path-receipt/assistant-loop-health.json", + "ledger": null, + "baseline_delta": null, + "zero_status": null, + "gate_decision": null, + "recommendation_calibration": null, + "mutation_calibration": null, + "coverage_frontier": null, + "receipt": "fixtures/boundary_gap/expected/pr-review-front-panel/stale-same-path-receipt/agent-receipt.json" + }, + "summary": { + "status": "advisory", + "headline": "Static grip stayed unchanged after the focused attempt.", + "top_issue_state": "unchanged_after_attempt", + "policy_state": "none", + "placement": "changed_line", + "movement_state": "unchanged", + "coverage_grip_state": "not_available", + "blocking_candidates": 0, + "acknowledged": 0, + "waived": 0, + "suppressed": 0, + "new_policy_eligible": 0, + "baseline_still_present": 0, + "baseline_resolved": 0, + "warnings": 0 + }, + "top_issue": { + "source": "assistant_health", + "source_artifact": "fixtures/boundary_gap/expected/pr-review-front-panel/stale-same-path-receipt/assistant-loop-health.json", + "seam_id": "67fc764ba37d77bd", + "canonical_gap_id": null, + "path": "src/lib.rs", + "line": 2, + "classification": "weakly_exposed", + "current_evidence_strength": "weakly_exposed", + "missing_discriminator": "input that hits the boundary: amount >= discount_threshold", + "focused_proof_intent": "Add a focused boundary test that exercises amount >= discount_threshold and assert the exact discounted_total output.", + "related_test": "tests/pricing.rs::below_threshold_has_no_discount", + "suggested_test": "Add a focused boundary test that exercises amount >= discount_threshold and assert the exact discounted_total output.", + "verify_command": "ripr agent verify --root fixtures/boundary_gap/input --before target/ripr/workflow/before.repo-exposure.json --after target/ripr/workflow/after.repo-exposure.json --json", + "static_evidence_boundary": "static advisory evidence only; not runtime proof, coverage adequacy, mutation confirmation, gate approval, or merge approval.", + "agent_command": "ripr agent start --root fixtures/boundary_gap/input --seam-id 67fc764ba37d77bd --out target/ripr/workflow", + "receipt": { + "artifact": "fixtures/boundary_gap/expected/pr-review-front-panel/stale-same-path-receipt/agent-receipt.json", + "status": "receipt_missing" + } + }, + "movement": { + "state": "unchanged", + "before_class": "weakly_exposed", + "after_class": "weakly_gripped", + "source_artifact": "fixtures/boundary_gap/expected/pr-review-front-panel/stale-same-path-receipt/assistant-loop-health.json" + }, + "debt_delta": { + "new_policy_eligible": 0, + "baseline_still_present": 0, + "baseline_resolved": 0, + "acknowledged": 0, + "waived": 0, + "suppressed": 0, + "blocking_candidates": 0 + }, + "policy": { + "mode": null, + "decision": "advisory", + "authority_artifact": null, + "acknowledgement_label": null + }, + "calibration": { + "recommendation": "not_available", + "mutation": "not_available", + "source_artifacts": [] + }, + "coverage_grip": { + "state": "not_available", + "coverage_delta": null, + "grip_delta": null, + "source_artifact": null + }, + "artifacts": [ + { + "group": "start_here", + "label": "PR review front panel", + "path": "fixtures/boundary_gap/expected/pr-review-front-panel/stale-same-path-receipt/pr-review-front-panel.md", + "available": true, + "required": true + } + ], + "warnings": [], + "limits": [ + "Static RIPR evidence only.", + "Does not provide runtime confirmation.", + "Does not run mutation testing.", + "Does not call providers.", + "Does not edit source or generate tests.", + "Does not publish inline comments.", + "Does not change default CI blocking.", + "Gate evaluator remains pass/fail authority." + ] +} diff --git a/fixtures/boundary_gap/expected/pr-review-front-panel/stale-same-path-receipt/pr-review-front-panel.md b/fixtures/boundary_gap/expected/pr-review-front-panel/stale-same-path-receipt/pr-review-front-panel.md new file mode 100644 index 00000000000..d310ea4b97f --- /dev/null +++ b/fixtures/boundary_gap/expected/pr-review-front-panel/stale-same-path-receipt/pr-review-front-panel.md @@ -0,0 +1,44 @@ +# RIPR PR Review + +Status: advisory + +Start here: +- State: unchanged_after_attempt +- Source: assistant_health +- Identity: 67fc764ba37d77bd +- File: src/lib.rs:2 +- Repair route: focused_test +- Class: weakly_exposed +- Current evidence strength: weakly_exposed +- Missing discriminator: input that hits the boundary: amount >= discount_threshold +- Focused proof intent: Add a focused boundary test that exercises amount >= discount_threshold and assert the exact discounted_total output. +- Suggested focused test: add amount >= discount_threshold boundary assertion +- Related test: tests/pricing.rs::below_threshold_has_no_discount +- Verify command: `ripr agent verify --root fixtures/boundary_gap/input --before target/ripr/workflow/before.repo-exposure.json --after target/ripr/workflow/after.repo-exposure.json --json` +- Receipt: receipt_missing (fixtures/boundary_gap/expected/pr-review-front-panel/stale-same-path-receipt/agent-receipt.json) +- Boundary: static advisory evidence only; not runtime proof, coverage adequacy, mutation confirmation, gate approval, or merge approval. + +Movement: +- New policy-eligible gaps: 0 +- Baseline gaps still present: 0 +- Baseline gaps resolved: 0 +- Static movement: unchanged +- Coverage/grip: not available + +Policy: +- Decision: advisory +- Gate authority: not configured + +Repair: +- Agent handoff: `ripr agent start --root fixtures/boundary_gap/input --seam-id 67fc764ba37d77bd --out target/ripr/workflow` +- Verify: `ripr agent verify --root fixtures/boundary_gap/input --before target/ripr/workflow/before.repo-exposure.json --after target/ripr/workflow/after.repo-exposure.json --json` +- Receipt: fixtures/boundary_gap/expected/pr-review-front-panel/stale-same-path-receipt/agent-receipt.json + +Artifacts: +- Start here: fixtures/boundary_gap/expected/pr-review-front-panel/stale-same-path-receipt/pr-review-front-panel.md + +Limits: +- Static RIPR evidence only. +- Does not run mutation testing. +- Does not edit source or generate tests. +- Gate evaluator remains pass/fail authority. From 0fb638fadbbd19db11688b3ce377bfbdc152ec4f Mon Sep 17 00:00:00 2001 From: Steven Zimmerman Date: Wed, 12 Aug 2026 17:12:24 -0400 Subject: [PATCH 2/2] fix(output): preserve receipt movement semantics --- .../ripr/src/output/pr_review_front_panel.rs | 66 +++++++++++++++++-- .../fixture_contracts/report_validators.rs | 1 + xtask/src/tests.rs | 58 ++++++++++++++++ 3 files changed, 119 insertions(+), 6 deletions(-) diff --git a/crates/ripr/src/output/pr_review_front_panel.rs b/crates/ripr/src/output/pr_review_front_panel.rs index af13fa4fc4a..3a3111e0559 100644 --- a/crates/ripr/src/output/pr_review_front_panel.rs +++ b/crates/ripr/src/output/pr_review_front_panel.rs @@ -3,8 +3,8 @@ use serde_json::Value; use super::first_pr::STATIC_EVIDENCE_BOUNDARY; use super::receipt_lifecycle::{ - RECEIPT_MISSING, RECEIPT_MOVEMENT_IMPROVED, RECEIPT_MOVEMENT_UNCHANGED, RECEIPT_NOT_APPLICABLE, - receipt_lifecycle_state, receipt_lifecycle_state_from_receipt_value, + RECEIPT_MISSING, RECEIPT_NOT_APPLICABLE, receipt_lifecycle_state, + receipt_lifecycle_state_from_movement, receipt_lifecycle_state_from_receipt_value, }; const SCHEMA_VERSION: &str = "0.1"; @@ -1779,7 +1779,9 @@ fn parsed_receipt_matches_selected_proof( return false; } - let Some(selected_movement) = string_path(selected_proof, &["movement_state"]) else { + let Some(selected_movement) = string_path(selected_proof, &["movement", "source_state"]) + .or_else(|| string_path(selected_proof, &["movement_state"])) + else { return false; }; let parsed_movements = [ @@ -1792,9 +1794,8 @@ fn parsed_receipt_matches_selected_proof( return false; } let lifecycle = receipt_lifecycle_state_from_receipt_value(parsed_receipt); - if (lifecycle == RECEIPT_MOVEMENT_IMPROVED && selected_movement != "improved") - || (lifecycle == RECEIPT_MOVEMENT_UNCHANGED && selected_movement != "unchanged") - { + let selected_lifecycle = receipt_lifecycle_state_from_movement(Some(&selected_movement)); + if lifecycle != selected_lifecycle { return false; } @@ -2651,6 +2652,59 @@ mod tests { Ok(()) } + #[test] + fn selected_proof_accepts_matching_changed_source_receipt_fallback() -> Result<(), String> { + let repo_root = repo_root()?; + let inputs = serde_json::json!({ + "assistant_health": "fixtures/boundary_gap/expected/assistant-loop-health/unchanged/assistant-loop-health.json", + "receipt": "fixtures/boundary_gap/expected/first-useful-action/unchanged-after-attempt/agent-receipt.json" + }); + let expected_md_path = repo_root.join( + "fixtures/boundary_gap/expected/pr-review-front-panel/mixed-health/pr-review-front-panel.md", + ); + let mut input = fixture_input(&repo_root, &inputs, &expected_md_path)?; + let mut health: Value = serde_json::from_str( + input + .assistant_health_json + .as_ref() + .and_then(|result| result.as_ref().ok()) + .ok_or_else(|| "assistant health fixture missing".to_string())?, + ) + .map_err(|err| format!("parse assistant health fixture failed: {err}"))?; + let selected = &mut health["proofs"][0]; + selected["movement_state"] = Value::String("unknown".to_string()); + selected["movement"]["source_state"] = Value::String("changed".to_string()); + selected["receipt"] + .as_object_mut() + .ok_or_else(|| "selected proof receipt missing".to_string())? + .remove("status"); + input.assistant_health_json = Some(Ok(health.to_string())); + input.receipt_json = Some(Ok(serde_json::json!({ + "provenance": { + "seam_id": "67fc764ba37d77bd", + "movement": "changed", + "before_class": "weakly_gripped", + "after_class": "weakly_gripped" + }, + "seam": { + "seam_id": "67fc764ba37d77bd", + "change": "changed", + "before": "weakly_gripped", + "after": "weakly_gripped" + }, + "summary": { + "receipt_state": "receipt_found", + "next_action": {"kind": "changed"} + } + }) + .to_string())); + + let json = render_pr_review_front_panel_json(&build_pr_review_front_panel_report(input))?; + assert!(json.contains("\"status\": \"receipt_found\"")); + assert!(!json.contains("\"status\": \"receipt_missing\"")); + Ok(()) + } + fn fixture_input( repo_root: &Path, inputs: &Value, diff --git a/xtask/src/fixture_contracts/report_validators.rs b/xtask/src/fixture_contracts/report_validators.rs index 7dd9115b893..c78b1a5ecef 100644 --- a/xtask/src/fixture_contracts/report_validators.rs +++ b/xtask/src/fixture_contracts/report_validators.rs @@ -340,6 +340,7 @@ pub(crate) fn validate_pr_review_front_panel_fixture_corpus_at( "blocked", "missing_proof", "coverage_flat_grip_improved", + "stale_same_path_receipt_fails_closed", ]; let mut seen_cases = BTreeSet::new(); diff --git a/xtask/src/tests.rs b/xtask/src/tests.rs index 7786cc70f03..a19f4d45922 100644 --- a/xtask/src/tests.rs +++ b/xtask/src/tests.rs @@ -4596,6 +4596,7 @@ fn write_pr_review_front_panel_corpus( "blocked", "missing_proof", "coverage_flat_grip_improved", + "stale_same_path_receipt_fails_closed", ] .into_iter() .map(|id| { @@ -5231,6 +5232,63 @@ fn pr_review_front_panel_fixture_corpus_guard_reports_contract_drift() -> Result Ok(()) } +#[test] +fn pr_review_front_panel_fixture_corpus_guard_rejects_stale_case_removal() -> Result<(), String> { + let root = temp_dir("pr-review-front-panel-stale-case-removal"); + let base = root.join("pr-review-front-panel"); + let report = root.join("pr-review-front-panel.json"); + let markdown = root.join("pr-review-front-panel.md"); + write_pr_review_front_panel_corpus(&base, &report, &markdown, "advisory", 0); + write( + &report, + r#"{ + "kind": "pr_review_front_panel", + "status": "advisory", + "summary": { + "top_issue_state": "actionable", + "policy_state": "new_policy_eligible", + "placement": "changed_line", + "movement_state": "unknown", + "coverage_grip_state": "not_available", + "new_policy_eligible": 1, + "baseline_resolved": 0, + "blocking_candidates": 0, + "warnings": 0 + }, + "artifacts": [{"group": "start_here"}], + "limits": ["Static RIPR evidence only."] +} +"#, + ); + write(&markdown, "# RIPR PR Review\n\nStatus: advisory\n"); + + let corpus_path = base.join("corpus.json"); + let corpus_text = fs::read_to_string(&corpus_path) + .map_err(|err| format!("read temporary front-panel corpus failed: {err}"))?; + let mut corpus: serde_json::Value = serde_json::from_str(&corpus_text) + .map_err(|err| format!("parse temporary front-panel corpus failed: {err}"))?; + corpus["cases"] + .as_array_mut() + .ok_or_else(|| "temporary front-panel corpus cases missing".to_string())? + .retain(|case| { + case.get("id").and_then(serde_json::Value::as_str) + != Some("stale_same_path_receipt_fails_closed") + }); + write( + &corpus_path, + &serde_json::to_string_pretty(&corpus) + .map_err(|err| format!("render temporary front-panel corpus failed: {err}"))?, + ); + + let mut violations = Vec::new(); + super::validate_pr_review_front_panel_fixture_corpus_at(&base, &mut violations)?; + assert_contains_error( + &violations, + "corpus is missing required case stale_same_path_receipt_fails_closed", + ); + Ok(()) +} + #[test] fn report_packet_index_fixture_corpus_guard_accepts_complete_contract() -> Result<(), String> { let root = temp_dir("report-packet-index-valid");