diff --git a/src/gui_2.py b/src/gui_2.py index 16f476e9..9562bb89 100644 --- a/src/gui_2.py +++ b/src/gui_2.py @@ -7299,6 +7299,29 @@ def _dag_cycle_check_result(app: "App") -> Result[bool]: source="gui_2._dag_cycle_check_result", original=e, )]) + +def _ticket_id_max_int_result(tid: str) -> Result[int]: + """Drain-aware variant of render_task_dag_panel ticket-ID parsing (L7315 INTERNAL_SILENT_SWALLOW). + + Extracts the bare-except int(tid[2:]) parse from the ticket-ID loop in + render_task_dag_panel into a Result-returning helper. On success (valid + T-XXX id), returns Result(data=int). On failure (T-abc, T-, etc.), + returns Result(data=0, errors=[ErrorInfo]). The legacy loop skips + malformed tickets via the data plane (logging NOT a drain per the + user's principle 2026-06-17). The caller drains to + app._last_request_errors. + + [C: src/gui_2.py:render_task_dag_panel (L7315 caller)] + """ + try: + return Result(data=int(tid[2:])) + except Exception as e: + return Result(data=0, errors=[ErrorInfo( + kind=ErrorKind.INTERNAL, + message=f"ticket id parse failed for {tid!r}: {e}", + source="gui_2._ticket_id_max_int_result", + original=e, + )]) ed.end() # 5. Add Ticket Form @@ -7306,18 +7329,21 @@ def _dag_cycle_check_result(app: "App") -> Result[bool]: if imgui.button("Add Ticket"): app._show_add_ticket_form = not app._show_add_ticket_form if app._show_add_ticket_form: - # Default Ticket ID + # Default Ticket ID max_id = 0 for t in app.active_tickets: tid = t.get('id', '') if tid.startswith('T-'): - #TODO(Ed): Exception(Review) - try: max_id = max(max_id, int(tid[2:])) - except: pass - app.ui_new_ticket_id = f"T-{max_id + 1:03d}" - app.ui_new_ticket_desc = "" - app.ui_new_ticket_target = "" - app.ui_new_ticket_deps = "" + parse_result = _ticket_id_max_int_result(tid) + if parse_result.ok: + max_id = max(max_id, parse_result.data) + else: + if not hasattr(app, '_last_request_errors'): app._last_request_errors = [] + app._last_request_errors.append(("render_task_dag_panel.ticket_id_parse", parse_result.errors[0])) + app.ui_new_ticket_id = f"T-{max_id + 1:03d}" + app.ui_new_ticket_desc = "" + app.ui_new_ticket_target = "" + app.ui_new_ticket_deps = "" if app._show_add_ticket_form: imgui.begin_child("add_ticket_form", imgui.ImVec2(-1, 220), True) imgui.text_colored(C_VAL(), "New Ticket Details") diff --git a/tests/test_gui_2_result.py b/tests/test_gui_2_result.py index a30297d3..c1c031ef 100644 --- a/tests/test_gui_2_result.py +++ b/tests/test_gui_2_result.py @@ -2267,4 +2267,37 @@ def test_phase_10_l7271_dag_cycle_check_result_failure(): assert "dag engine failure" in err.message +def test_phase_10_l7315_ticket_id_max_int_result_success(): + """ + L7315 _ticket_id_max_int_result returns Result(data=int) on success. + + The helper extracts the int(tid[2:]) parsing from the ticket-ID loop + in render_task_dag_panel into a Result-returning helper. On success + (valid T-XXX id), returns Result(data=int). The legacy loop continues + with the maximum value. + """ + import src.gui_2 as gui2_mod + result = gui2_mod._ticket_id_max_int_result("T-042") + assert result.ok, f"Expected ok=True on success, got errors: {result.errors}" + assert result.data == 42 + + +def test_phase_10_l7315_ticket_id_max_int_result_failure(): + """ + L7315 _ticket_id_max_int_result returns Result(data=0, errors=[ErrorInfo]) on failure. + + When tid[2:] is not parseable as int (e.g., "T-abc", "T-"), the helper + converts to ErrorInfo. The legacy loop skips this ticket and continues + with the current max. The caller drains to app._last_request_errors. + """ + import src.gui_2 as gui2_mod + result = gui2_mod._ticket_id_max_int_result("T-abc") + assert not result.ok, f"Expected ok=False on failure, got data: {result.data}" + assert result.data == 0 + assert result.errors, "Expected at least one error on failure" + err = result.errors[0] + assert err.source == "gui_2._ticket_id_max_int_result" + assert "invalid literal" in err.message or "T-abc" in err.message + +