From faa6ec6e51aa3e4cbd918706f028a073fca32280 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Sat, 20 Jun 2026 08:35:44 -0400 Subject: [PATCH] test(baseline): add 3 Phase 3 invariant tests (Batch A complete) TIER-2 READ conductor/code_styleguides/error_handling.md end-to-end before Phase 3. Phase 3 tests assert: 1. mcp_client BC count 40 -> 32 (Batch A migrated 8 sites) 2. Total MIG 88 -> 80 (88 - 8 Batch A) 3. PHASE1_AUDIT_BASELINE.json still has 88 baseline (immutable) Total: 10 tests pass (4 Phase 1 + 3 Phase 2 + 3 Phase 3). --- tests/test_baseline_result.py | 59 ++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 14 deletions(-) diff --git a/tests/test_baseline_result.py b/tests/test_baseline_result.py index a7ab5750..e3f70c90 100644 --- a/tests/test_baseline_result.py +++ b/tests/test_baseline_result.py @@ -1,8 +1,8 @@ -"""Phase 1 + Phase 2 invariant tests for result_migration_baseline_cleanup_20260620. +"""Invariant tests for result_migration_baseline_cleanup_20260620. -Phase 1: 4 tests assert the audit + inventory docs match expected counts. -Phase 2: 3 tests assert the BASELINE state is correct (88 migration-target sites - in 3 files; the migration is starting from this exact state). +Phase 1 (4): audit + inventory doc counts match expected baseline +Phase 2 (3): baseline state is correct (88 MIG sites in 3 files) +Phase 3 (3): mcp_client BC count decreased from 40 -> 32 after Batch A """ import json import subprocess @@ -30,6 +30,15 @@ def _load_audit(): return json.loads(AUDIT_PATH.read_text(encoding="utf-8")) +def _audit_live(): + r = subprocess.run( + ["uv", "run", "python", "scripts/audit_exception_handling.py", + "--include-baseline", "--json"], + capture_output=True, text=True + ) + return json.loads(r.stdout) + + # ============ Phase 1 tests (4) ============ def test_phase1_audit_json_exists(): @@ -54,7 +63,6 @@ def test_phase1_total_migration_target_is_88(): def test_phase1_per_file_site_counts(): - """mcp=46, ai=33, rag=9 = (BC, SS, OPT, RETHROW, UNCLEAR, total)""" data = _load_audit() files = {f["filename"]: f for f in data["files"]} for key, expected in EXPECTED.items(): @@ -76,7 +84,6 @@ def test_phase1_per_file_site_counts(): # ============ Phase 2 tests (3) ============ def test_phase2_baseline_audit_runs(): - """The audit --include-baseline --json command exits 0.""" r = subprocess.run( ["uv", "run", "python", "scripts/audit_exception_handling.py", "--include-baseline", "--json"], @@ -89,7 +96,6 @@ def test_phase2_baseline_audit_runs(): def test_phase2_all_3_targets_have_migration_sites(): - """Each of the 3 baseline files has at least 1 migration-target site.""" data = _load_audit() files = {f["filename"]: f for f in data["files"]} for target in TARGETS: @@ -99,17 +105,42 @@ def test_phase2_all_3_targets_have_migration_sites(): def test_phase2_per_file_baseline_counts_match_inventory(): - """The baseline per-file counts match the Phase 1 inventory docs.""" data = _load_audit() files = {f["filename"]: f for f in data["files"]} - BASELINE = { - "src\\mcp_client.py": 46, - "src\\ai_client.py": 33, - "src\\rag_engine.py": 9, - } + BASELINE = {"src\\mcp_client.py": 46, "src\\ai_client.py": 33, "src\\rag_engine.py": 9} for target, expected in BASELINE.items(): mig = [f for f in files[target]["findings"] if f["category"] in MIG] assert len(mig) == expected, ( f"{target}: baseline expected {expected}, got {len(mig)} " f"(a previous phase may have introduced a violation)" - ) \ No newline at end of file + ) + + +# ============ Phase 3 tests (3) ============ + +def test_phase3_mcp_client_broad_catch_decreased_from_40_to_32(): + data = _audit_live() + files = {f["filename"]: f for f in data["files"]} + findings = files["src\\mcp_client.py"]["findings"] + bc = sum(1 for f in findings if f["category"] == "INTERNAL_BROAD_CATCH") + assert bc == 32, f"expected mcp_client BC=32 after Batch A, got {bc}" + + +def test_phase3_total_migration_target_decreased_to_80(): + data = _audit_live() + files = {f["filename"]: f for f in data["files"]} + total = 0 + for key in TARGETS: + findings = files[key]["findings"] + total += sum(1 for f in findings if f["category"] in MIG) + assert total == 80, f"expected total MIG=80 after Phase 3, got {total}" + + +def test_phase3_audit_baseline_matches_phase1_audit_json(): + data = _load_audit() + files = {f["filename"]: f for f in data["files"]} + total = 0 + for key in TARGETS: + findings = files[key]["findings"] + total += sum(1 for f in findings if f["category"] in MIG) + assert total == 88, f"PHASE1_AUDIT_BASELINE.json expected 88 baseline MIG, got {total}" \ No newline at end of file