diff --git a/tests/test_gui_2_result.py b/tests/test_gui_2_result.py index aa3688df..4423e8ee 100644 --- a/tests/test_gui_2_result.py +++ b/tests/test_gui_2_result.py @@ -1270,3 +1270,63 @@ def test_phase_5_l7208_render_beads_tab_list_result_failure(): err = result.errors[0] assert err.source == "gui_2._render_beads_tab_list_result" assert "dolt backend down" in err.message + + +# ============================================================================= +# Phase 5 Invariant Tests (result_migration_gui_2_20260619) +# Lock the per-phase progress: 11 INTERNAL_BROAD_CATCH event-handler sites +# migrated, all have both success and failure tests. +# ============================================================================= + + +def test_phase_5_invariant_batch_c_count_dropped(): + """ + Phase 5 invariant: the audit's INTERNAL_BROAD_CATCH count for src/gui_2.py + has dropped from 14 (pre-Phase 5) to 3 (post-Phase 5). The 3 remaining sites + are in other phases: L591 (Phase 8), L897 (Phase 8), L4321 (Phase 7). + + The 11 migrated sites are: L1284, L1293, L1367, L1393, L1428, L3163, L3582, + L5380, L5786, L5920, L7208. + """ + result = subprocess.run( + ["uv", "run", "python", "scripts/audit_exception_handling.py", "--src", "src", "--json"], + capture_output=True, + text=True, + ) + assert result.returncode == 0, ( + f"audit_exception_handling.py exited {result.returncode}; stderr:\n" + f"{result.stderr[:2000]}" + ) + data = json.loads(result.stdout) + gui2 = [f for f in data.get("files", []) if "gui_2" in f.get("filename", "")][0] + broad_catches = [f for f in gui2.get("findings", []) if f.get("category") == "INTERNAL_BROAD_CATCH"] + # Pre-Phase 5 baseline: 14. Post-Phase 5: 3 (11 sites migrated). + # Per FR-BC-4, the 11 migrated sites drain to app._last_request_errors. + assert len(broad_catches) <= 3, ( + f"Phase 5 invariant: expected <= 3 INTERNAL_BROAD_CATCH sites in src/gui_2.py " + f"(post-Phase 5 baseline, 11 sites migrated); found {len(broad_catches)}. " + f"The 11 Phase 5 Batch C sites (L1284, L1293, L1367, L1393, L1428, L3163, " + f"L3582, L5380, L5786, L5920, L7208) must be migrated to Result[T] helpers. " + f"Lines: {[f.get('line') for f in broad_catches]}" + ) + + +def test_phase_5_invariant_all_11_migration_sites_have_tests(): + """ + Phase 5 invariant: each of the 11 Batch C sites has both success and + failure tests in this test file. + """ + import re + text = Path(__file__).read_text(encoding="utf-8") + expected_lines = [1284, 1293, 1367, 1393, 1428, 3163, 3582, 5380, 5786, 5920, 7208] + for line in expected_lines: + success_pattern = f"test_phase_5_l{line}_.*_result_success" + failure_pattern = f"test_phase_5_l{line}_.*_result_failure" + assert re.search(success_pattern, text), ( + f"Phase 5 invariant: missing success test for L{line}. " + f"Expected a test matching '{success_pattern}'." + ) + assert re.search(failure_pattern, text), ( + f"Phase 5 invariant: missing failure test for L{line}. " + f"Expected a test matching '{failure_pattern}'." + )