test(gui_2): add 2 Phase 5 invariant tests + Phase 5 checkpoint
TIER-2 READ conductor/code_styleguides/error_handling.md end-to-end before Phase 5. Phase 5 Batch C migration complete. 11 INTERNAL_BROAD_CATCH event-handler sites migrated to Result[T] pattern per FR-BC-4. The legacy wrappers drain errors to app._last_request_errors (data plane attribute). Migrated sites: - L1284 _populate_auto_slices outline - L1293 _populate_auto_slices file_read - L1367 _apply_pending_patch - L1393 _open_patch_in_external_editor - L1428 request_patch_from_tier4 - L3163 render_tool_preset_manager_content bias_save - L3582 render_context_batch_actions preview - L5380 render_operations_hub ext_editor_panel - L5786 render_text_viewer_window ced - L5920 render_external_editor_panel config - L7208 render_beads_tab list V count dropped from 14 to 3 (11 sites migrated; remaining 3 in Phase 7/8). Invariant tests: - test_phase_5_invariant_batch_c_count_dropped: locks V count <= 3 - test_phase_5_invariant_all_11_migration_sites_have_tests: locks all 11 sites have both success and failure tests
This commit is contained in:
@@ -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}'."
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user