"""Phase 10 invariant tests (GREEN). 9 BC sites migrated via 7 helpers: - _list_gemini_models_result (site 1) - _delete_gemini_cache_result (sites 2+3) - _should_cache_gemini_result (site 4) - _create_gemini_cache_result (site 5) - _send_cli_round_result (site 6) - _run_tier4_analysis_result (site 7) - _run_tier4_patch_callback_result (site 8) - _run_tier4_patch_generation_result (site 9) """ import sys sys.path.insert(0, ".") def test_phase10_ai_client_bc_count_zero(): """After Phase 10: ai_client BC count is 0 (was 17 at baseline).""" import json import subprocess r = subprocess.run( ["uv", "run", "python", "scripts/audit_exception_handling.py", "--include-baseline", "--json"], capture_output=True, text=True ) data = json.loads(r.stdout) files = {f["filename"]: f for f in data["files"]} ai = files["src\\ai_client.py"] bc = sum(1 for x in ai["findings"] if x["category"] == "INTERNAL_BROAD_CATCH") assert bc == 0, f"expected ai_client BC=0 after Phase 10, got {bc}" def test_phase10_all_helpers_exist(): """All 7 new _result helpers must exist on ai_client.""" import src.ai_client expected = [ "_list_gemini_models_result", "_delete_gemini_cache_result", "_should_cache_gemini_result", "_create_gemini_cache_result", "_send_cli_round_result", "_run_tier4_analysis_result", "_run_tier4_patch_callback_result", "_run_tier4_patch_generation_result", ] for name in expected: assert hasattr(src.ai_client, name), f"{name} helper missing from src.ai_client" def test_phase10_legacy_functions_preserved(): """Legacy functions preserved EXCEPT those OBLITERATED by cruft-removal Phase 4 or code_path_audit_phase_2 cleanup.""" import src.ai_client legacy = [ "_send_gemini", "_send_gemini_cli", "run_tier4_analysis", "run_tier4_patch_generation", ] # _list_gemini_models wrapper was OBLITERATED by cruft-removal Phase 4 # run_tier4_patch_callback wrapper was OBLITERATED by code_path_audit_phase_2 cleanup obliterated = ["_list_gemini_models", "run_tier4_patch_callback"] for name in legacy: assert hasattr(src.ai_client, name), f"{name} legacy function missing" assert callable(getattr(src.ai_client, name)), f"{name} not callable" for name in obliterated: assert not hasattr(src.ai_client, name), ( f"{name} wrapper must be OBLITERATED; " f"callers must use {name}_result directly" )