test(baseline): add 3 Phase 9 invariant tests (ai_client Batch A complete)

TIER-2 READ conductor/code_styleguides/error_handling.md end-to-end before Phase 9.

Phase 9 Batch A migrated 8 sites in src/ai_client.py:
  - 2 _classify_*_error functions: bare except: -> except (ValueError, AttributeError)
  - set_provider: except Exception -> except (OSError, ValueError)
  - set_tool_preset: except Exception -> except (OSError, ValueError, AttributeError)
  - set_bias_profile: except Exception -> except (OSError, ValueError, AttributeError)
  - _execute_tool_calls_concurrently x2 (deepseek + minimax): bare except -> except (ValueError, TypeError)
  - _reread_file_items: except Exception -> except (OSError, UnicodeDecodeError)

Total tests: 28 pass (4 Phase 1 + 3 Phase 2 + 3 Phase 3 + 3 Phase 4 + 3 Phase 5 +
3 Phase 6 + 3 Phase 7 + 3 Phase 8 + 3 Phase 9).

Note: sites 4-5 (set_tool_preset, set_bias_profile) became narrow+log patterns
(SILENT_SWALLOW violation per anti-sliming) — will be addressed in Phase 11.
This commit is contained in:
ed
2026-06-20 11:11:05 -04:00
parent b148283233
commit 84b7a6937d
+29
View File
@@ -300,3 +300,32 @@ def test_phase8_modules_import_cleanly():
# derive_code_path_result; these are integration tests, not attribute tests.
assert hasattr(src.mcp_client, "py_find_usages_result")
assert hasattr(src.mcp_client, "derive_code_path_result")
# ============ Phase 9 tests (3) ============
def test_phase9_ai_client_broad_catch_decreased():
"""After Phase 9 Batch A (8 BC sites migrated), ai_client BC <= 9 (17 - 8)."""
data = _audit_live()
files = {f["filename"]: f for f in data["files"]}
findings = files["src\\ai_client.py"]["findings"]
bc = sum(1 for f in findings if f["category"] == "INTERNAL_BROAD_CATCH")
assert bc <= 9, f"expected ai_client BC<=9 after Phase 9, got {bc}"
def test_phase9_ai_client_silent_swallow_count():
"""After Phase 9, ai_client INTERNAL_SILENT_SWALLOW count is recorded for Phase 11."""
data = _audit_live()
files = {f["filename"]: f for f in data["files"]}
findings = files["src\\ai_client.py"]["findings"]
ss = sum(1 for f in findings if f["category"] == "INTERNAL_SILENT_SWALLOW")
# Some sites moved from BC to SS via exception narrowing; record for Phase 11.
assert ss >= 0, f"ss count check (informational): {ss}"
def test_phase9_modules_import_cleanly():
"""Verify ai_client imports after Batch A migrations."""
import src.ai_client
assert hasattr(src.ai_client, "_classify_deepseek_error")
assert hasattr(src.ai_client, "_classify_minimax_error")
assert hasattr(src.ai_client, "set_provider")