feat(token-viz): Phase 2 — trim warning, Gemini/Anthropic cache status display
This commit is contained in:
@@ -113,3 +113,44 @@ def test_render_token_budget_panel_empty_stats_no_crash(app_instance: App) -> No
|
||||
# We can't render ImGui in tests, so just verify the guard condition logic
|
||||
# by checking the method exists and _token_stats is empty (early-return path)
|
||||
assert not app_instance._token_stats # falsy — method would return early
|
||||
|
||||
|
||||
# --- Trim warning logic ---
|
||||
|
||||
def test_would_trim_boundary_exact() -> None:
|
||||
"""would_trim is False when headroom == 20000 (threshold is strictly < 20000)."""
|
||||
base = {"provider": "test", "limit": 100000, "current": 80000, "percentage": 80.0}
|
||||
result = _add_bleed_derived(base)
|
||||
assert result["headroom_tokens"] == 20000
|
||||
assert result["would_trim"] is False # headroom < 20000 is False at exactly 20000
|
||||
|
||||
|
||||
def test_would_trim_just_below_threshold() -> None:
|
||||
base = {"provider": "test", "limit": 100000, "current": 80001, "percentage": 80.0}
|
||||
result = _add_bleed_derived(base)
|
||||
assert result["headroom_tokens"] == 19999
|
||||
assert result["would_trim"] is True
|
||||
|
||||
|
||||
def test_would_trim_just_above_threshold() -> None:
|
||||
base = {"provider": "test", "limit": 100000, "current": 79999, "percentage": 80.0}
|
||||
result = _add_bleed_derived(base)
|
||||
assert result["headroom_tokens"] == 20001
|
||||
assert result["would_trim"] is False
|
||||
|
||||
|
||||
# --- Cache status fields available from ai_client ---
|
||||
|
||||
def test_gemini_cache_fields_accessible() -> None:
|
||||
"""_gemini_cache, _gemini_cache_created_at, _GEMINI_CACHE_TTL must be accessible."""
|
||||
assert hasattr(ai_client, "_gemini_cache")
|
||||
assert hasattr(ai_client, "_gemini_cache_created_at")
|
||||
assert hasattr(ai_client, "_GEMINI_CACHE_TTL")
|
||||
assert isinstance(ai_client._GEMINI_CACHE_TTL, int)
|
||||
assert ai_client._GEMINI_CACHE_TTL > 0
|
||||
|
||||
|
||||
def test_anthropic_history_lock_accessible() -> None:
|
||||
"""_anthropic_history_lock must be accessible for cache hint rendering."""
|
||||
assert hasattr(ai_client, "_anthropic_history_lock")
|
||||
assert hasattr(ai_client, "_anthropic_history")
|
||||
|
||||
Reference in New Issue
Block a user