ef99b0e3f5
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.
18 lines
641 B
Python
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}" |