use vyre_conform::enforce::reference_trust::shrinker::{
delta_debug_slice_with_limit, shrink_bytes, shrink_bytes_with_limit,
};
use vyre_conform::enforce::reference_trust::{validate_spec, ReferenceTrustCriterion};
fn broken_hex_cpu(input: &[u8]) -> Vec<u8> {
if input == b"ff" {
return vec![0xff];
}
Vec::new()
}
#[test]
fn byte_shrinker_terminates_and_preserves_failure() {
let input = b"prefix-needle-suffix";
let result = shrink_bytes(input, |candidate| {
candidate.windows(6).any(|w| w == b"needle")
});
assert_eq!(result.minimal, b"needle");
assert!(result.iterations <= 100);
assert!(!result.timed_out);
}
#[test]
fn byte_shrinker_reports_timeout_with_best_candidate() {
let input = b"abcdef";
let result = shrink_bytes_with_limit(input, 1, |candidate| candidate.contains(&b'e'));
assert!(result.timed_out);
assert!(result.iterations <= 1);
assert_eq!(result.minimal, input);
}
#[test]
fn structured_delta_debug_removes_irrelevant_components() {
let items = ["law-a", "bad-law", "law-b", "law-c"];
let result =
delta_debug_slice_with_limit(&items, 100, |candidate| candidate.contains(&"bad-law"));
assert_eq!(result.minimal, vec!["bad-law"]);
assert!(result.iterations <= 100);
assert!(!result.timed_out);
}
#[test]
fn reference_trust_finding_carries_minimal_differential_input() {
let mut spec = vyre_conform::specs::decode::hex::vyre_op();
spec.cpu_fn = broken_hex_cpu;
let findings = validate_spec(&spec);
let finding = findings
.iter()
.find(|finding| finding.criterion == ReferenceTrustCriterion::Differential)
.expect("broken hex reference must fail the external differential check");
assert!(!finding.original_input.is_empty());
assert_eq!(finding.minimal_input, b"00");
assert!(
finding.message().contains("minimal_input=0x3030"),
"message must report minimized bytes: {}",
finding.message()
);
}