40a60e63d6
All 3 run_tier4_* functions had the same pattern:
try: ... AI call ...
except Exception as e: return '[XXX FAILED] {e}' (or None)
Per TIER1_REVIEW: empty-default return = MIGRATE to Result[T].
New helpers:
- _run_tier4_analysis_result(stderr: str) -> Result[str]
Returns Result(data=analysis) on success, Result(data='', errors=[ErrorInfo])
on SDK failure. Empty stderr short-circuits to Result(data='').
- _run_tier4_patch_callback_result(stderr: str, base_dir: str) -> Result[Optional[str]]
Returns Result(data=patch) on valid diff, Result(data=None) when no
valid diff, Result(data=None, errors=[ErrorInfo]) on SDK failure.
- _run_tier4_patch_generation_result(error: str, file_context: str) -> Result[str]
Returns Result(data=patch) on success, Result(data='', errors=[ErrorInfo])
on SDK failure. Empty error short-circuits to Result(data='').
Legacy wrappers delegate to _result helpers and return result.data,
preserving original signatures (str for sites 7,9; Optional[str] for site 8).
Existing tier4 tests pass (13/13 in test_tier4_patch_generation +
test_tier4_interceptor).
Audit: ai_client BC 3 -> 0. All 9 Phase 10 BC sites migrated.
54 lines
2.0 KiB
Python
54 lines
2.0 KiB
Python
"""Phase 10 sites 7+8+9: run_tier4_* Result helpers.
|
|
|
|
Site 7 (run_tier4_analysis): returns str with '[QA ANALYSIS FAILED]' on error.
|
|
Site 8 (run_tier4_patch_callback): returns Optional[str] with None on error.
|
|
Site 9 (run_tier4_patch_generation): returns str with '[PATCH GENERATION FAILED]' on error.
|
|
|
|
All 3 follow the same pattern:
|
|
try: ...AI call...
|
|
except Exception as e: return "[XXX FAILED] {e}" (or None)
|
|
|
|
Migrate via Result[str] / Result[Optional[str]] helpers.
|
|
"""
|
|
import sys
|
|
sys.path.insert(0, ".")
|
|
|
|
|
|
def test_phase10_sites789_run_tier4_analysis_result_exists():
|
|
import src.ai_client
|
|
assert hasattr(src.ai_client, "_run_tier4_analysis_result"), \
|
|
"_run_tier4_analysis_result helper missing"
|
|
|
|
|
|
def test_phase10_sites789_run_tier4_patch_callback_result_exists():
|
|
import src.ai_client
|
|
assert hasattr(src.ai_client, "_run_tier4_patch_callback_result"), \
|
|
"_run_tier4_patch_callback_result helper missing"
|
|
|
|
|
|
def test_phase10_sites789_run_tier4_patch_generation_result_exists():
|
|
import src.ai_client
|
|
assert hasattr(src.ai_client, "_run_tier4_patch_generation_result"), \
|
|
"_run_tier4_patch_generation_result helper missing"
|
|
|
|
|
|
def test_phase10_sites789_all_helpers_return_result():
|
|
import src.ai_client
|
|
import inspect
|
|
for name in ("_run_tier4_analysis_result",
|
|
"_run_tier4_patch_callback_result",
|
|
"_run_tier4_patch_generation_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_phase10_sites789_legacy_unchanged():
|
|
"""Legacy functions must still exist + be callable."""
|
|
import src.ai_client
|
|
for name in ("run_tier4_analysis",
|
|
"run_tier4_patch_callback",
|
|
"run_tier4_patch_generation"):
|
|
assert hasattr(src.ai_client, name), f"{name} missing"
|
|
assert callable(getattr(src.ai_client, name)), f"{name} not callable" |