b057301915
The original function had a broken pattern: 'raise _classify_gemini_error(exc) from exc' which raises an ErrorInfo (not an Exception) — a runtime bug. Per TIER1_REVIEW 2026-06-20 directive: per-site decision. The body raised a structured error carrier (ErrorInfo), but the pattern was incorrect (ErrorInfo is not an Exception). Cleanest fix: full Result[T] migration. New helper: - _list_gemini_models_result(api_key: str) -> Result[list[str]] Returns Result(data=sorted_models) on success, Result(data=[], errors=[ErrorInfo]) on SDK/network failure. Legacy wrapper: - _list_gemini_models(api_key: str) -> list[str] Returns result.data (preserves original signature; callers don't see errors). Audit: ai_client BC 9 -> 8. Site L1594 (now shifted to L1609 due to helper insertion) no longer in INTERNAL_BROAD_CATCH.
37 lines
1.4 KiB
Python
37 lines
1.4 KiB
Python
"""Phase 10 invariant tests (RED).
|
|
|
|
Site 1 (L1594): _list_gemini_models_result helper must exist + return Result[list[str]].
|
|
"""
|
|
import sys
|
|
sys.path.insert(0, ".")
|
|
|
|
from src.result_types import Result, ErrorInfo
|
|
|
|
|
|
def test_phase10_site1_list_gemini_models_result_exists():
|
|
import src.ai_client
|
|
assert hasattr(src.ai_client, "_list_gemini_models_result"), \
|
|
"_list_gemini_models_result helper missing from src.ai_client"
|
|
|
|
|
|
def test_phase10_site1_list_gemini_models_result_returns_result():
|
|
"""The helper must return a Result[list[str]]."""
|
|
import src.ai_client
|
|
fn = getattr(src.ai_client, "_list_gemini_models_result", None)
|
|
assert fn is not None
|
|
import inspect
|
|
sig = inspect.signature(fn)
|
|
# Should have a return annotation of Result
|
|
assert "Result" in str(sig.return_annotation), \
|
|
f"_list_gemini_models_result return annotation must be Result, got {sig.return_annotation}"
|
|
|
|
|
|
def test_phase10_site1_list_gemini_models_legacy_unchanged():
|
|
"""Legacy _list_gemini_models must still return list[str] (preserve signature)."""
|
|
import src.ai_client
|
|
fn = getattr(src.ai_client, "_list_gemini_models", None)
|
|
assert fn is not None
|
|
import inspect
|
|
sig = inspect.signature(fn)
|
|
assert "list[str]" in str(sig.return_annotation) or "list" in str(sig.return_annotation), \
|
|
f"_list_gemini_models return annotation must remain list[str], got {sig.return_annotation}" |