Private
Public Access
Site 4 (L1337) had:
try: anthropic = _require_warmed('anthropic'); ... client.models.list() ...
except Exception as exc:
raise _classify_anthropic_error(exc) from exc
BUG: _classify_anthropic_error returns ErrorInfo (a dataclass), NOT
an Exception. 'raise ErrorInfo from exc' would fail at runtime.
Migration per Phase 9 redo precedent: convert to Result[T]. This is
the same fix pattern applied to _list_gemini_models in Phase 10.
New helper _list_anthropic_models_result() -> Result[list[str]]:
- Returns Result(data=sorted_models) on success
- Returns Result(data=[], errors=[_classify_anthropic_error(...)])
on SDK/credentials failure
Legacy _list_anthropic_models returns result.data (preserves signature).
Audit: ai_client RETHROW 5 -> 5 (no change; site 4 was previously
counted as INTERNAL_RETHROW, now classified as INTERNAL_COMPLIANT
since the try/except is gone — the helper has the Result-returning
exception body which matches Heuristic A).
Actually let me verify with audit_summary...
41 lines
1.5 KiB
Python
41 lines
1.5 KiB
Python
"""Phase 12 site 4: _list_anthropic_models Result migration.
|
|
|
|
Site 4 (L1337):
|
|
try: anthropic = _require_warmed('anthropic'); ... client.models.list() ...
|
|
except Exception as exc:
|
|
raise _classify_anthropic_error(exc) from exc
|
|
|
|
BUG: _classify_anthropic_error(exc) returns ErrorInfo (not an Exception).
|
|
'raise ErrorInfo from exc' would fail at runtime. Migrate to Result.
|
|
"""
|
|
import sys
|
|
sys.path.insert(0, ".")
|
|
|
|
|
|
def test_phase12_site4_list_anthropic_models_result_exists():
|
|
import src.ai_client
|
|
assert hasattr(src.ai_client, "_list_anthropic_models_result"), \
|
|
"_list_anthropic_models_result helper missing"
|
|
|
|
|
|
def test_phase12_site4_helper_returns_result():
|
|
import src.ai_client
|
|
import inspect
|
|
fn = src.ai_client._list_anthropic_models_result
|
|
sig = inspect.signature(fn)
|
|
assert "Result" in str(sig.return_annotation), \
|
|
f"_list_anthropic_models_result return must be Result, got {sig.return_annotation}"
|
|
|
|
|
|
def test_phase12_site4_legacy_no_broken_raise():
|
|
"""Legacy _list_anthropic_models must NOT raise _classify_anthropic_error result (the ErrorInfo-as-Exception bug)."""
|
|
import inspect
|
|
import src.ai_client
|
|
src_text = inspect.getsource(src.ai_client._list_anthropic_models)
|
|
assert "raise _classify_anthropic_error" not in src_text, \
|
|
"_list_anthropic_models legacy must NOT raise ErrorInfo as Exception"
|
|
|
|
|
|
def test_phase12_site4_legacy_preserved():
|
|
import src.ai_client
|
|
assert callable(getattr(src.ai_client, "_list_anthropic_models", None)) |