Private
Public Access
0
0
Files
manual_slop/tests/tier2/phase10_site4_test.py
T
ed ef99b0e3f5 refactor(ai_client): extract _should_cache_gemini_result helper (Phase 10 site 4)
Site L1732: count_tokens block in _send_gemini had:
  try: count_resp = _gemini_client.models.count_tokens(...)
       ... set should_cache based on total_tokens ...
  except Exception as e: _append_comms('[COUNT FAILED]')

Per TIER1_REVIEW: logging is NOT a drain. MIGRATE to Result[bool].

New helper _should_cache_gemini_result(sys_instr: str) -> Result[bool]:
- Result(data=True) if token count >= 2048
- Result(data=False) if below threshold + [CACHING SKIPPED] comms note
- Result(data=False, errors=[ErrorInfo]) on SDK failure + [COUNT FAILED] comms

Caller: should_cache = _should_cache_gemini_result(sys_instr).data

Audit: ai_client BC 6 -> 5. Site L1732 (now shifted to L1752) no longer BC.
2026-06-20 13:02:54 -04:00

18 lines
641 B
Python

"""Phase 10 site 4: _should_cache_gemini_result helper."""
import sys
sys.path.insert(0, ".")
def test_phase10_site4_should_cache_gemini_result_exists():
import src.ai_client
assert hasattr(src.ai_client, "_should_cache_gemini_result"), \
"_should_cache_gemini_result helper missing"
def test_phase10_site4_should_cache_gemini_result_returns_result():
import src.ai_client
import inspect
fn = src.ai_client._should_cache_gemini_result
sig = inspect.signature(fn)
assert "Result" in str(sig.return_annotation), \
f"_should_cache_gemini_result return must be Result, got {sig.return_annotation}"