Private
Public Access
refactor(ai_client): migrate _extract_gemini_thoughts + _list_minimax_models (Phase 11 sites 7+8)
Site 7 (_extract_gemini_thoughts): try: getattr(resp, 'candidates', None) or [] ... chunks.append(p.text) except Exception: pass return ''.join(chunks).strip() Body: pass + empty default '' = SS violation (silent + data loss). Site 8 (_list_minimax_models): try: client.models.list() ... if found: return sorted(found) except Exception: pass return ['MiniMax-M2.7', 'MiniMax-M2.5', 'MiniMax-M2.1', 'MiniMax-M2'] Body: pass + hardcoded default = SS violation. New helpers: - _extract_gemini_thoughts_result(resp) -> Result[str] Returns Result(data=thinking_text) on success, Result(data='', errors=[ErrorInfo]) on attribute access failure. - _list_minimax_models_result(api_key) -> Result[list[str]] Returns Result(data=sorted_models) on success, Result(data=defaults, errors=[ErrorInfo]) on SDK failure. Defaults extracted to _MINIMAX_DEFAULT_MODELS module constant. Legacy wrappers delegate to _result helpers and return result.data. Audit: ai_client SS 7 -> 5. COMPLIANT 29 -> 31.
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
"""Phase 11 sites 7+8: _extract_gemini_thoughts + _list_minimax_models Result helpers.
|
||||
|
||||
Site 7 (_extract_gemini_thoughts):
|
||||
try: candidates = getattr(resp, "candidates", None) or []
|
||||
for ... parts = getattr(content, "parts", None) or []
|
||||
... if thought: chunks.append(p.text)
|
||||
except Exception: pass
|
||||
return "".join(chunks).strip()
|
||||
|
||||
Body: pass + empty default '' = SS violation (silent + data loss).
|
||||
|
||||
Site 8 (_list_minimax_models):
|
||||
try: client = OpenAI(api_key=api_key, base_url=base_url)
|
||||
models_list = client.models.list()
|
||||
found = [m.id for m in models_list]
|
||||
if found: return sorted(found)
|
||||
except Exception: pass
|
||||
return ["MiniMax-M2.7", "MiniMax-M2.5", "MiniMax-M2.1", "MiniMax-M2"]
|
||||
|
||||
Body: pass + hardcoded default = SS violation.
|
||||
"""
|
||||
import sys
|
||||
sys.path.insert(0, ".")
|
||||
|
||||
|
||||
def test_phase11_sites78_extract_gemini_thoughts_result_exists():
|
||||
import src.ai_client
|
||||
assert hasattr(src.ai_client, "_extract_gemini_thoughts_result"), \
|
||||
"_extract_gemini_thoughts_result helper missing"
|
||||
|
||||
|
||||
def test_phase11_sites78_list_minimax_models_result_exists():
|
||||
import src.ai_client
|
||||
assert hasattr(src.ai_client, "_list_minimax_models_result"), \
|
||||
"_list_minimax_models_result helper missing"
|
||||
|
||||
|
||||
def test_phase11_sites78_helpers_return_result():
|
||||
import src.ai_client
|
||||
import inspect
|
||||
for name in ("_extract_gemini_thoughts_result",
|
||||
"_list_minimax_models_result"):
|
||||
fn = getattr(src.ai_client, name)
|
||||
sig = inspect.signature(fn)
|
||||
assert "Result" in str(sig.return_annotation), \
|
||||
f"{name} return must be Result, got {sig.return_annotation}"
|
||||
|
||||
|
||||
def test_phase11_sites78_legacy_preserved():
|
||||
import src.ai_client
|
||||
assert callable(getattr(src.ai_client, "_extract_gemini_thoughts", None))
|
||||
assert callable(getattr(src.ai_client, "_list_minimax_models", None))
|
||||
Reference in New Issue
Block a user