c5a119d63f
Phase 4 (5 of 9 cruft sites obliterated): OBLITERATED wrappers: 1. _reread_file_items (4 callers in _send_gemini + _send_gemini_cli + 2 others) 2. _list_anthropic_models (1 caller in list_models) 3. _list_gemini_models (1 caller in list_models) 4. _extract_gemini_thoughts (1 caller in _send_gemini) 5. _list_minimax_models (2 callers in _set_minimax_provider_result + set_provider) Migration: each caller now uses the _result sibling directly with .ok check + .data extraction. The Result[T] error context (structured ErrorInfo) is now propagated instead of dropped. _send_gemini gets .data with explicit .ok check. Updated tests to assert OBLITERATED state (5 sub-track 5 tests inverted from '_legacy_preserved' to '_legacy_obliterated'): - tests/test_baseline_result.py: test_phase9_redo_modules_import_cleanly - tests/tier2/phase10_invariant_test.py: _list_gemini_models removed from list - tests/tier2/phase10_site1_test.py: _legacy_unchanged -> _legacy_obliterated - tests/tier2/phase11_invariant_test.py: _extract/_list_minimax moved to obliterated - tests/tier2/phase11_sites78_test.py: _legacy_preserved -> _legacy_obliterated - tests/tier2/phase12_invariant_test.py: _list_anthropic moved to obliterated - tests/tier2/phase12_site4_test.py: _legacy_preserved -> _legacy_obliterated - tests/test_gemini_thinking_format.py: helper uses _result directly - tests/test_cruft_removal.py: 5 new obliterated-wrappers invariant tests Test result: 122/122 pass (31 baseline + 16 heuristic + 9 cruft + 5 thinking + 61 tier2). Audit gate: src/ai_client.py --strict exits 0 (no new violations introduced). Wrapper count: 9 -> 3 (Phase 5-6 remaining: rag_engine 1, gui_2 2).
85 lines
3.1 KiB
Python
85 lines
3.1 KiB
Python
"""Phase 11 invariant tests (GREEN).
|
|
|
|
11 SS sites migrated via 8 helpers + 1 reused helper:
|
|
- _try_warm_sdk_result (sites 1+2; both classify functions)
|
|
- _delete_gemini_cache_result (reused from Phase 10 for sites 3+4)
|
|
- _set_tool_preset_result (site 5)
|
|
- _set_bias_profile_result (site 6; also used by site 11)
|
|
- _extract_gemini_thoughts_result (site 7)
|
|
- _list_minimax_models_result (site 8)
|
|
- _count_gemini_tokens_for_stats_result (sites 9+10)
|
|
- _set_tool_preset_result (site 11; reused from site 5)
|
|
"""
|
|
import sys
|
|
sys.path.insert(0, ".")
|
|
|
|
|
|
def test_phase11_ai_client_ss_count_zero():
|
|
"""After Phase 11: ai_client SS count is 0 (was 11)."""
|
|
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"]
|
|
ss = sum(1 for x in ai["findings"] if x["category"] == "INTERNAL_SILENT_SWALLOW")
|
|
assert ss == 0, f"expected ai_client SS=0 after Phase 11, got {ss}"
|
|
|
|
|
|
def test_phase11_ai_client_unclear_count_zero():
|
|
"""After Phase 11: ai_client UNCLEAR count is 0."""
|
|
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"]
|
|
unclear = sum(1 for x in ai["findings"] if x["category"] == "UNCLEAR")
|
|
assert unclear == 0, f"expected ai_client UNCLEAR=0 after Phase 11, got {unclear}"
|
|
|
|
|
|
def test_phase11_all_helpers_exist():
|
|
"""All 7 new _result helpers must exist on ai_client."""
|
|
import src.ai_client
|
|
expected = [
|
|
"_try_warm_sdk_result",
|
|
"_set_tool_preset_result",
|
|
"_set_bias_profile_result",
|
|
"_extract_gemini_thoughts_result",
|
|
"_list_minimax_models_result",
|
|
"_count_gemini_tokens_for_stats_result",
|
|
]
|
|
for name in expected:
|
|
assert hasattr(src.ai_client, name), f"{name} helper missing"
|
|
|
|
|
|
def test_phase11_legacy_functions_preserved():
|
|
"""All legacy functions must still be callable (some OBLITERATED by cruft-removal Phase 4)."""
|
|
import src.ai_client
|
|
legacy = [
|
|
"_classify_anthropic_error",
|
|
"_classify_gemini_error",
|
|
"cleanup",
|
|
"reset_session",
|
|
"set_tool_preset",
|
|
"set_bias_profile",
|
|
"get_token_stats",
|
|
]
|
|
# OBLITERATED by cruft-removal Phase 4 (no backward compat):
|
|
obliterated = ["_extract_gemini_thoughts", "_list_minimax_models"]
|
|
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 (cruft-removal Phase 4); "
|
|
f"callers must use {name}_result directly"
|
|
) |