feat(tui): upgrade Tab 7 SSH/Boxes with diagnostics modal, key verification, and recovery watcher hardening
This commit is contained in:
@@ -581,6 +581,90 @@ class TestBoxTUIHeadless(unittest.TestCase):
|
||||
app._handle_key(ord('G'))
|
||||
self.assertEqual(app.dm_logs_sel_idx, 14)
|
||||
|
||||
def test_box_ssh_view_render_scrollbar_and_bounds(self):
|
||||
app = muse_tui.MuseTUI(self.mock_stdscr, initial_mode="box", initial_tab="ssh")
|
||||
self.assertEqual(app.box_tab, 6)
|
||||
|
||||
# Populate multiple nodes to ensure scrolling
|
||||
app.data.nodes = [f"node_{i}" for i in range(15)]
|
||||
app.ssh_sel_idx = 8
|
||||
app._render_ssh_view(2, 0, 10, 100)
|
||||
|
||||
# Check bounds recorded
|
||||
self.assertTrue(hasattr(app, "_ssh_view_bounds"))
|
||||
self.assertEqual(app._ssh_view_bounds[0], 6) # y (2) + 4 = 6
|
||||
self.assertGreater(app._ssh_view_bounds[1], app._ssh_view_bounds[0])
|
||||
|
||||
# Verify scrollbar and tags in screen output
|
||||
rendered_texts = [call[0][2] for call in self.mock_stdscr.addstr.call_args_list if len(call[0]) >= 3 and isinstance(call[0][2], str)]
|
||||
self.assertTrue(any("█" in t or "│" in t for t in rendered_texts))
|
||||
self.assertTrue(any("[Diag]" in t for t in rendered_texts))
|
||||
self.assertTrue(any("[SSH]" in t for t in rendered_texts))
|
||||
|
||||
def test_box_diagnostics_modal_and_hotkeys(self):
|
||||
app = muse_tui.MuseTUI(self.mock_stdscr, initial_mode="box", initial_tab="ssh")
|
||||
self.assertEqual(app.box_tab, 6)
|
||||
app.data.nodes = ["muse-main", "muse", "646"]
|
||||
app.ssh_sel_idx = 0
|
||||
|
||||
# 'd' opens box_diagnostics modal
|
||||
handled = app._handle_key(ord('d'))
|
||||
self.assertTrue(handled)
|
||||
self.assertEqual(app.modal, "box_diagnostics")
|
||||
|
||||
# Render modal
|
||||
app._render_modal(30, 100)
|
||||
rendered_texts = [call[0][2] for call in self.mock_stdscr.addstr.call_args_list if len(call[0]) >= 3 and isinstance(call[0][2], str)]
|
||||
self.assertTrue(any("BOX DIAGNOSTICS & TROUBLESHOOTING" in t for t in rendered_texts))
|
||||
|
||||
# Hotkey '2' / 'c' copies dial command
|
||||
with patch.object(muse_tui, "copy_to_clipboard", return_value=True) as mock_cp:
|
||||
app._handle_key(ord('c'))
|
||||
self.assertTrue(mock_cp.called)
|
||||
|
||||
# Hotkey '4' / 'k' triggers key check
|
||||
with patch.object(app, "_async_ssh_key_check") as mock_kc:
|
||||
app._handle_key(ord('k'))
|
||||
self.assertTrue(mock_kc.called)
|
||||
|
||||
# Hotkey '5' / 'h' triggers recovery probe
|
||||
with patch.object(app, "_async_ssh_recovery_probe") as mock_rp:
|
||||
app._handle_key(ord('h'))
|
||||
self.assertTrue(mock_rp.called)
|
||||
|
||||
# Hotkey 'q' closes modal
|
||||
app._handle_key(ord('q'))
|
||||
self.assertIsNone(app.modal)
|
||||
|
||||
# Enter also opens diagnostics modal
|
||||
app._handle_key(ord('\n'))
|
||||
self.assertEqual(app.modal, "box_diagnostics")
|
||||
app._handle_key(27) # Esc closes
|
||||
self.assertIsNone(app.modal)
|
||||
|
||||
def test_box_ssh_mouse_interactions(self):
|
||||
app = muse_tui.MuseTUI(self.mock_stdscr, initial_mode="box", initial_tab="ssh")
|
||||
app.data.nodes = ["muse-main", "muse", "646"]
|
||||
app.ssh_sel_idx = 0
|
||||
h, w = self.mock_stdscr.getmaxyx()
|
||||
app._render_ssh_view(2, 0, 10, w)
|
||||
|
||||
bounds = app._ssh_view_bounds
|
||||
# Click on row 1 (my = bounds[0] + 1)
|
||||
btn1 = getattr(curses, "BUTTON1_CLICKED", 0x4)
|
||||
app._handle_mouse(10, bounds[0] + 1, btn1)
|
||||
self.assertEqual(app.ssh_sel_idx, 1)
|
||||
|
||||
# Click on [Diag] button (mx = w - 12)
|
||||
app._handle_mouse(w - 12, bounds[0] + 1, btn1)
|
||||
self.assertEqual(app.modal, "box_diagnostics")
|
||||
app.modal = None
|
||||
|
||||
# Click on [SSH] button (mx = w - 4)
|
||||
with patch.object(app, "_ssh_popout_selected") as mock_pop:
|
||||
app._handle_mouse(w - 4, bounds[0] + 1, btn1)
|
||||
self.assertTrue(mock_pop.called)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user