diff --git a/src/gui_2.py b/src/gui_2.py index 5fd000a3..0392f046 100644 --- a/src/gui_2.py +++ b/src/gui_2.py @@ -1690,12 +1690,36 @@ def _focus_response_window_result() -> Result[None]: now = time.time() if now - app._last_autosave >= app._autosave_interval: app._last_autosave = now - try: - app._flush_to_project() - app._flush_to_config() - app.save_config() - except Exception: - pass # silent — don't disrupt the GUI loop + autosave_result = _autosave_flush_result(app) + if not autosave_result.ok: + if not hasattr(app, '_last_request_errors'): app._last_request_errors = [] + app._last_request_errors.append(("render_main_interface.autosave", autosave_result.errors[0])) + +def _autosave_flush_result(app: "App") -> Result[None]: + """Drain-aware variant of render_main_interface auto-save try block (L1693 INTERNAL_SILENT_SWALLOW). + + Extracts the auto-save flush_to_project + flush_to_config + save_config + try/except from render_main_interface into a Result-returning helper. On + exception (disk full, JSON parse error), converts to ErrorInfo (logging + NOT a drain per the user's principle 2026-06-17). The caller drains to + app._last_request_errors and continues with the GUI loop, preserving + the original "don't disrupt the GUI loop" intent via the data plane + rather than silent swallow. + + [C: src/gui_2.py:render_main_interface (L1693 legacy wrapper)] + """ + try: + app._flush_to_project() + app._flush_to_config() + app.save_config() + return Result(data=None) + except Exception as e: + return Result(data=None, errors=[ErrorInfo( + kind=ErrorKind.INTERNAL, + message=f"autosave flush failed: {e}", + source="gui_2._autosave_flush_result", + original=e, + )]) # Sync pending comms with app._pending_comms_lock: diff --git a/tests/test_gui_2_result.py b/tests/test_gui_2_result.py index 19d2592d..304a5b93 100644 --- a/tests/test_gui_2_result.py +++ b/tests/test_gui_2_result.py @@ -2068,4 +2068,47 @@ def test_phase_10_l1647_focus_response_window_result_failure(): assert "IM_ASSERT" in err.message +def test_phase_10_l1693_autosave_flush_result_success(): + """ + L1693 _autosave_flush_result returns Result(data=None) on success. + + The helper extracts the auto-save flush_to_project + flush_to_config + + save_config try/except from render_main_interface into a Result-returning + helper. On success, returns Result(data=None). The legacy wrapper + continues with the GUI loop. + """ + from unittest.mock import MagicMock + import src.gui_2 as gui2_mod + app = MagicMock() + result = gui2_mod._autosave_flush_result(app) + assert result.ok, f"Expected ok=True on success, got errors: {result.errors}" + assert result.data is None + app._flush_to_project.assert_called_once() + app._flush_to_config.assert_called_once() + app.save_config.assert_called_once() + + +def test_phase_10_l1693_autosave_flush_result_failure(): + """ + L1693 _autosave_flush_result returns Result(data=None, errors=[ErrorInfo]) on failure. + + When any of _flush_to_project/_flush_to_config/save_config raises + (disk full, JSON parse error), the helper converts to ErrorInfo. The + caller (render_main_interface) drains to self._last_request_errors and + continues with the GUI loop (preserving the original "don't disrupt the + GUI loop" intent via the data plane rather than silent swallow). + """ + from unittest.mock import MagicMock + import src.gui_2 as gui2_mod + app = MagicMock() + app._flush_to_project.side_effect = OSError("disk full") + result = gui2_mod._autosave_flush_result(app) + assert not result.ok, f"Expected ok=False on failure, got data: {result.data}" + assert result.data is None + assert result.errors, "Expected at least one error on failure" + err = result.errors[0] + assert err.source == "gui_2._autosave_flush_result" + assert "disk full" in err.message + +