use super::*;
#[test]
fn calibration_helpers_round_in_the_safe_direction() {
use super::{calibrate_down, calibrate_up, sanitize_estimate_ratio};
assert_eq!(calibrate_up(6_068, 1.0), 6_068);
assert_eq!(calibrate_down(6_068, 1.0), 6_068);
assert_eq!(calibrate_up(1_000, 1.3), 1_300);
assert_eq!(calibrate_down(1_000, 1.3), 769, "floor, never round up");
assert_eq!(calibrate_up(3, 1.5), 5, "4.5 ceils to 5");
assert_eq!(calibrate_down(3, 2.0), 1, "1.5 floors to 1");
assert_eq!(sanitize_estimate_ratio(None), 1.0);
assert_eq!(sanitize_estimate_ratio(Some(f32::NAN)), 1.0);
assert_eq!(sanitize_estimate_ratio(Some(0.1)), 1.0);
assert_eq!(sanitize_estimate_ratio(Some(5.0)), 1.0);
assert_eq!(sanitize_estimate_ratio(Some(1.29)), 1.29);
assert_eq!(sanitize_estimate_ratio(Some(3.0)), 3.0, "clamp inclusive");
}
#[test]
fn sanitize_estimate_ratio_floors_dispatch_at_1_0() {
use super::sanitize_estimate_ratio;
assert_eq!(
sanitize_estimate_ratio(Some(0.5)),
1.0,
"the clamp's own lower bound must not loosen the gate"
);
assert_eq!(sanitize_estimate_ratio(Some(0.9994337)), 1.0);
assert_eq!(sanitize_estimate_ratio(Some(1.0)), 1.0);
assert_eq!(sanitize_estimate_ratio(Some(1.3)), 1.3);
}
#[test]
fn is_truncation_suspect_replays_the_1967_incident_numbers() {
use super::is_truncation_suspect;
assert!(
is_truncation_suspect(205_189, Some(209_715)),
"205,189 is 97.8% of 209,715 — inside the suspect zone"
);
assert!(is_truncation_suspect(199_229, Some(209_715)));
assert!(!is_truncation_suspect(199_228, Some(209_715)));
assert!(!is_truncation_suspect(205_189, None));
assert!(!is_truncation_suspect(4_136, Some(209_715)));
}
#[test]
fn calibration_composes_across_the_trigger_boundary() {
use super::{calibrate_down, calibrate_up};
let cal = 1.3_f32;
let send_budget = 8_734_usize; let tool_tokens_est = 1_000_usize; let tool_tokens_real = calibrate_up(tool_tokens_est, cal); let current_real = calibrate_up(9_000, cal); let trigger = compression_trigger(
3,
current_real,
9_000,
CompressionTriggerLimits {
count_threshold: 40,
token_threshold: None,
send_budget: Some(send_budget),
tool_tokens: tool_tokens_real,
policy: CompactionTriggerPolicy::HeadroomAware,
has_authoritative_headroom: true,
},
)
.expect("over-budget context fires the guard");
assert!(trigger.hard_budget);
assert_eq!(trigger.budget, send_budget - tool_tokens_real);
let pipeline_budget = calibrate_down(trigger.budget, cal);
assert_eq!(pipeline_budget, calibrate_down(8_734 - 1_300, cal));
assert!(
pipeline_budget < trigger.budget,
"ratio > 1: the estimate-space target is tighter than the real one"
);
}