use super::*;
#[test]
fn compaction_budget_drops_schema_overhead_for_the_tools_disabled_summary() {
use super::ResponsesBudgetState;
let mut state = ResponsesBudgetState::new(Some(32_768), 80, None, None, None, None);
let recovered = state.recovered_budget_for_window(32_768);
state.recover_from_cw400(recovered);
state.set_tool_schema_tokens(1_000);
let with_schemas = state.compaction_budget(1.0, true);
let without_schemas = state.compaction_budget(1.0, false);
assert!(
without_schemas > with_schemas,
"dropping the un-sent schemas RAISES the target: {without_schemas} !> {with_schemas}"
);
assert_eq!(
without_schemas - with_schemas,
1_000,
"the tools-disabled target reclaims exactly the un-sent schema overhead"
);
}
#[test]
fn recovery_compaction_target_cannot_exceed_the_next_preflight() {
use super::ResponsesBudgetState;
let est = crate::tokens::TokenEstimation::default();
let mut a = ResponsesBudgetState::new(Some(65_536), 80, None, None, None, Some(12_000));
a.recover_from_cw400(8_000);
assert_eq!(a.actionable_input_budget(), Some(8_000));
assert_eq!(
a.compaction_budget(1.0, true),
8_000,
"targets the 8,000 preflight enforces"
);
let mut b = ResponsesBudgetState::new(Some(65_536), 80, None, None, None, Some(6_000));
b.recover_from_cw400(16_000);
assert_eq!(b.actionable_input_budget(), Some(6_000));
assert_eq!(
b.compaction_budget(1.0, true),
6_000,
"targets the 6,000 preflight enforces"
);
assert_ne!(
b.compaction_budget(1.0, true),
16_000,
"must not target the looser hard ceiling"
);
let mut c = ResponsesBudgetState::new(Some(65_536), 80, None, None, None, None);
c.set_tool_schema_tokens(1_000);
c.recover_from_cw400(20_000);
let actionable_c = c.actionable_input_budget().unwrap();
for ratio in [1.3f32, 2.0, 3.0] {
let target_raw = c.compaction_budget(ratio, true); let calibrated_input = super::calibrate_up(target_raw, ratio);
assert!(
calibrated_input + 1_000 <= actionable_c,
"ratio {ratio}: calibrated compacted input ({calibrated_input}) + tools (1000) \
must fit actionable ({actionable_c})",
);
}
let d = ResponsesBudgetState::new(
Some(16_000),
80,
resolve_output_allowance(None, Some(Cognition::Meticulous)),
None,
None,
None,
);
assert_eq!(d.actionable_input_budget(), Some(0));
assert_eq!(
d.compaction_budget(1.5, true),
0,
"zero budget → zero compaction target"
);
let report =
crate::agentic::responses_context_remaining_report(None, &[], None, &d, 1.5, est, 15);
assert!(
report.contains("0 tokens remaining") && !report.contains("No input-token ceiling"),
"an authoritative zero renders 0 remaining, not unknown: {report}",
);
}