Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
232 changes: 224 additions & 8 deletions crates/ripr/src/output/pr_review_front_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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_lifecycle_state_from_movement, receipt_lifecycle_state_from_receipt_value,
};

const SCHEMA_VERSION: &str = "0.1";
Expand Down Expand Up @@ -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(),
),
Expand All @@ -1734,24 +1734,107 @@ 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", "source_state"])
.or_else(|| 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;
Comment thread
EffortlessSteven marked this conversation as resolved.
Resolved
}
let lifecycle = receipt_lifecycle_state_from_receipt_value(parsed_receipt);
let selected_lifecycle = receipt_lifecycle_state_from_movement(Some(&selected_movement));
if lifecycle != selected_lifecycle {
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<String>], 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::<Vec<_>>();
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
Expand Down Expand Up @@ -2489,6 +2572,139 @@ 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(())
}

#[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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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
Expand Down
23 changes: 23 additions & 0 deletions fixtures/boundary_gap/expected/pr-review-front-panel/corpus.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
]
}
Original file line number Diff line number Diff line change
@@ -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."
}
}
}
Loading
Loading