From b7c5cb41126cb322ecd54c7a0d330c86b0c0c583 Mon Sep 17 00:00:00 2001 From: Hunter Bown Date: Sun, 26 Apr 2026 17:55:56 -0500 Subject: [PATCH] test(ui): update auto-compact test for #115 estimate-first behavior --- crates/tui/src/tui/ui/tests.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/crates/tui/src/tui/ui/tests.rs b/crates/tui/src/tui/ui/tests.rs index 47015638..e4a54de5 100644 --- a/crates/tui/src/tui/ui/tests.rs +++ b/crates/tui/src/tui/ui/tests.rs @@ -606,19 +606,35 @@ fn context_usage_snapshot_prefers_live_estimate_while_loading() { #[test] fn should_auto_compact_before_send_respects_threshold_and_setting() { let mut app = create_test_app(); - app.api_messages = vec![Message { + let big_buffer = vec![Message { role: "user".to_string(), content: vec![ContentBlock::Text { text: "context ".repeat(400_000), cache_control: None, }], }]; + + // High estimated context + auto_compact ON → auto-compact triggers. + app.api_messages = big_buffer.clone(); app.auto_compact = true; assert!(should_auto_compact_before_send(&app)); + // Same high context but auto_compact OFF → never triggers. app.auto_compact = false; assert!(!should_auto_compact_before_send(&app)); + // Small estimated context + auto_compact ON → does NOT trigger, + // regardless of what `last_prompt_tokens` reports. This matches the + // #115 fix: the estimate is the primary signal, not the engine's + // turn-cumulative reported value (which used to rule the displayed + // % and could spuriously trigger / suppress auto-compact). + app.api_messages = vec![Message { + role: "user".to_string(), + content: vec![ContentBlock::Text { + text: "small".to_string(), + cache_control: None, + }], + }]; app.auto_compact = true; app.last_prompt_tokens = Some(10_000); assert!(!should_auto_compact_before_send(&app));