Private
Public Access
0
0

fix(gui): Gen+Send and MD Only with empty context no-op silently

ROOT CAUSE: 3 mismatched names in the empty-context warning path:

1. _handle_generate_send set self.show_empty_context_warning_modal = True
   but render_empty_context_modal checks self.show_empty_context_modal.
   The modal never opened.

2. _handle_generate_send / _handle_md_only never set
   self._pending_generation_action, so the modal's 'Proceed Anyway'
   button always saw None and dispatched nothing.

3. After Proceed Anyway, _pending_generation_action was never reset,
   so subsequent empty-context calls would dispatch the wrong action.

FIX:
- gui_2.py:494,501: show_empty_context_warning_modal -> show_empty_context_modal
- gui_2.py:494,501: set _pending_generation_action before showing modal
- gui_2.py:5385: reset _pending_generation_action = None after dispatch

Tests: tests/test_gen_send_empty_context.py (5 cases) covers all 4 dispatch
paths (generate/md_only x proceed/skip) plus the happy path with context.

37/37 regression pass. No new ImGui scope errors (2 pre-existing unrelated).
This commit is contained in:
2026-06-03 12:41:13 -04:00
parent d42f3cce34
commit 9396154779
2 changed files with 70 additions and 2 deletions
+5 -2
View File
@@ -491,14 +491,16 @@ class App:
def _handle_generate_send(self) -> None:
if not self.ui_selected_context_files and not getattr(self, "_pending_proceed_generate", False):
self.show_empty_context_warning_modal = True
self._pending_generation_action = 'generate'
self.show_empty_context_modal = True
else:
self._pending_proceed_generate = False
self.controller._handle_generate_send()
def _handle_md_only(self) -> None:
if not self.ui_selected_context_files and not getattr(self, "_pending_proceed_md_only", False):
self.show_empty_context_warning_modal = True
self._pending_generation_action = 'md_only'
self.show_empty_context_modal = True
else:
self._pending_proceed_md_only = False
self.controller._handle_md_only()
@@ -5384,6 +5386,7 @@ def render_empty_context_modal(app: App) -> None:
if imgui.button("Proceed Anyway", imgui.ImVec2(150, 0)):
if app._pending_generation_action == 'generate': app.controller._handle_generate_send()
elif app._pending_generation_action == 'md_only': app.controller._handle_md_only()
app._pending_generation_action = None
imgui.close_current_popup()
imgui.same_line()
if imgui.button("Cancel", imgui.ImVec2(120, 0)):
+65
View File
@@ -0,0 +1,65 @@
from unittest.mock import MagicMock, patch
from src.gui_2 import App, render_empty_context_modal
class _StubController:
def __init__(self):
self.calls = []
def _handle_generate_send(self): self.calls.append("generate")
def _handle_md_only(self): self.calls.append("md_only")
def shutdown(self): pass
def test_gen_send_empty_context_opens_warning_modal(app_instance):
app_instance.ui_selected_context_files = set()
app_instance.show_empty_context_modal = False
app_instance._pending_generation_action = None
app_instance._handle_generate_send()
assert app_instance.show_empty_context_modal is True
assert app_instance._pending_generation_action == 'generate'
def test_md_only_empty_context_opens_warning_modal(app_instance):
app_instance.ui_selected_context_files = set()
app_instance.show_empty_context_modal = False
app_instance._pending_generation_action = None
app_instance._handle_md_only()
assert app_instance.show_empty_context_modal is True
assert app_instance._pending_generation_action == 'md_only'
def test_proceed_anyway_dispatches_generate(app_instance):
app_instance.ui_selected_context_files = set()
app_instance.show_empty_context_modal = False
app_instance._pending_generation_action = None
app_instance._handle_generate_send()
with patch("src.gui_2.imgui") as mock_imgui:
mock_imgui.open_popup = MagicMock()
mock_imgui.begin_popup_modal.return_value = (True, True)
mock_imgui.button.return_value = True
mock_imgui.WindowFlags_ = type("W", (), {"always_auto_resize": 1})()
stub_ctrl = _StubController()
app_instance.controller = stub_ctrl
render_empty_context_modal(app_instance)
assert "generate" in stub_ctrl.calls
assert app_instance._pending_generation_action is None
def test_proceed_anyway_dispatches_md_only(app_instance):
app_instance.ui_selected_context_files = set()
app_instance.show_empty_context_modal = False
app_instance._pending_generation_action = None
app_instance._handle_md_only()
with patch("src.gui_2.imgui") as mock_imgui:
mock_imgui.open_popup = MagicMock()
mock_imgui.begin_popup_modal.return_value = (True, True)
mock_imgui.button.return_value = True
mock_imgui.WindowFlags_ = type("W", (), {"always_auto_resize": 1})()
stub_ctrl = _StubController()
app_instance.controller = stub_ctrl
render_empty_context_modal(app_instance)
assert "md_only" in stub_ctrl.calls
def test_gen_send_with_context_skips_warning(app_instance):
app_instance.ui_selected_context_files = {"some_file.py"}
app_instance._pending_generation_action = None
stub_ctrl = _StubController()
app_instance.controller = stub_ctrl
app_instance._handle_generate_send()
assert "generate" in stub_ctrl.calls
assert app_instance._pending_generation_action is None