hive-agent: tests for the unknown-window paths, and the two vale errors
This commit is contained in:
parent
1bfee54414
commit
c45615a555
2 changed files with 65 additions and 3 deletions
|
|
@ -981,6 +981,34 @@ mod tests {
|
|||
assert!(low.take_compact().is_none(), "a refusal queues nothing");
|
||||
}
|
||||
|
||||
/// Without a window to divide by, the tool refuses and says why; once a turn
|
||||
/// reports one, the same usage is judged against it.
|
||||
#[test]
|
||||
fn compact_is_refused_while_the_context_window_is_unknown() {
|
||||
let (_dir, todos, _) = stores();
|
||||
let wake = Notify::new();
|
||||
let bus = Bus::new();
|
||||
let usage: hive_claude::TokenUsage = serde_json::from_value(serde_json::json!({
|
||||
"input_tokens": 50,
|
||||
"output_tokens": 0,
|
||||
"cache_read_input_tokens": 0,
|
||||
"cache_creation_input_tokens": 0,
|
||||
}))
|
||||
.expect("a usage block");
|
||||
bus.record_turn_usage(usage, usage);
|
||||
|
||||
let resp = dispatch(compact_req(None), &todos, &wake, None, &bus);
|
||||
assert!(
|
||||
matches!(&resp, Response::Err { message } if message.contains("window is unknown")),
|
||||
"{resp:?}"
|
||||
);
|
||||
assert!(bus.take_compact().is_none(), "a refusal queues nothing");
|
||||
|
||||
bus.set_api_context_window(100);
|
||||
let resp = dispatch(compact_req(None), &todos, &wake, None, &bus);
|
||||
assert!(matches!(resp, Response::Ok), "{resp:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_compact_floor_is_forty_percent_of_the_window() {
|
||||
let (_dir, todos, _) = stores();
|
||||
|
|
|
|||
|
|
@ -875,7 +875,7 @@ fn archive_session(bus: &Bus, session: &AgentSession) {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{PercentPolicy, SoftLimitPolicy};
|
||||
use super::{PercentPolicy, SoftLimitPolicy, auto_reset_watermark_tokens};
|
||||
use super::{
|
||||
PermissionAsk, TurnError, TurnOutcome, acp_permits, apply_telemetry, emit_turn_end,
|
||||
error_to_turn, nonzero_or, parse_u64, report_compact, runtime_error_to_turn,
|
||||
|
|
@ -922,6 +922,40 @@ mod tests {
|
|||
assert!(policy(75).should_compact(high));
|
||||
}
|
||||
|
||||
/// The auto-reset watermark is half the window the API reported, and none
|
||||
/// (`0`, off) before one is, instead of half a guessed size.
|
||||
#[test]
|
||||
fn the_auto_reset_watermark_waits_for_a_reported_window() {
|
||||
let bus = Bus::new();
|
||||
assert_eq!(auto_reset_watermark_tokens(&bus), 0);
|
||||
bus.set_api_context_window(1_000_000);
|
||||
assert_eq!(auto_reset_watermark_tokens(&bus), 500_000);
|
||||
}
|
||||
|
||||
/// A turn that reports no window never triggers the proactive compaction,
|
||||
/// however full the context: there is nothing to take a percent of.
|
||||
#[test]
|
||||
fn no_reported_window_means_no_proactive_compaction() {
|
||||
let policy = SoftLimitPolicy {
|
||||
percent: PercentPolicy {
|
||||
percent: 75,
|
||||
default_window: None,
|
||||
checkpoint_prompt: None,
|
||||
},
|
||||
bus: Bus::new(),
|
||||
};
|
||||
let unreported = Usage {
|
||||
context_tokens: 900_000,
|
||||
context_window: None,
|
||||
};
|
||||
assert!(!policy.should_compact(unreported));
|
||||
let reported = Usage {
|
||||
context_window: Some(1_000_000),
|
||||
..unreported
|
||||
};
|
||||
assert!(policy.should_compact(reported));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_turn_that_parsed_nothing_does_not_keep_the_previous_resolved_model() {
|
||||
let resolved = crate::paths::with_harness_dir(|| {
|
||||
|
|
|
|||
Loading…
Reference in a new issue