|
9 | 9 | ROOT = Path(__file__).resolve().parent |
10 | 10 |
|
11 | 11 |
|
| 12 | +class FakeCurses: |
| 13 | + A_BOLD = 1 |
| 14 | + KEY_DOWN = 258 |
| 15 | + KEY_UP = 259 |
| 16 | + KEY_ENTER = 343 |
| 17 | + |
| 18 | + def __init__(self): |
| 19 | + self.cursor_values = [] |
| 20 | + self.endwin_count = 0 |
| 21 | + |
| 22 | + def curs_set(self, value): |
| 23 | + self.cursor_values.append(value) |
| 24 | + |
| 25 | + def endwin(self): |
| 26 | + self.endwin_count += 1 |
| 27 | + |
| 28 | + |
| 29 | +class FakeScreen: |
| 30 | + def __init__(self, keys, height=32, width=100): |
| 31 | + self.keys = list(keys) |
| 32 | + self.height = height |
| 33 | + self.width = width |
| 34 | + self.keypad_enabled = None |
| 35 | + self.clear_count = 0 |
| 36 | + self.current = {} |
| 37 | + self.snapshots = [] |
| 38 | + |
| 39 | + def getmaxyx(self): |
| 40 | + return self.height, self.width |
| 41 | + |
| 42 | + def keypad(self, enabled): |
| 43 | + self.keypad_enabled = enabled |
| 44 | + |
| 45 | + def erase(self): |
| 46 | + self.current = {} |
| 47 | + |
| 48 | + def clear(self): |
| 49 | + self.clear_count += 1 |
| 50 | + self.current = {} |
| 51 | + |
| 52 | + def addstr(self, y, x, text, attr=0): |
| 53 | + self.current[(y, x)] = text |
| 54 | + |
| 55 | + def refresh(self): |
| 56 | + self.snapshots.append(dict(self.current)) |
| 57 | + |
| 58 | + def getch(self): |
| 59 | + if self.keys: |
| 60 | + return self.keys.pop(0) |
| 61 | + return ord("q") |
| 62 | + |
| 63 | + |
12 | 64 | class DashboardTuiTest(unittest.TestCase): |
13 | 65 | def make_project(self, root: Path) -> None: |
14 | 66 | agent = root / ".agent" |
@@ -229,6 +281,54 @@ def test_bare_installed_project_stays_script_safe_without_tty(self): |
229 | 281 | self.assertEqual(result.returncode, 0, result.stderr) |
230 | 282 | self.assertIn("open dashboard", result.stdout) |
231 | 283 |
|
| 284 | + def test_interactive_dashboard_keypress_navigation(self): |
| 285 | + from harness_manager import dashboard_tui |
| 286 | + |
| 287 | + curses = FakeCurses() |
| 288 | + screen = FakeScreen( |
| 289 | + [ |
| 290 | + curses.KEY_DOWN, |
| 291 | + curses.KEY_DOWN, |
| 292 | + ord("r"), |
| 293 | + curses.KEY_UP, |
| 294 | + ord("q"), |
| 295 | + ] |
| 296 | + ) |
| 297 | + with tempfile.TemporaryDirectory() as tmp: |
| 298 | + project = Path(tmp) |
| 299 | + self.make_project(project) |
| 300 | + |
| 301 | + dashboard_tui._run_interactive(screen, project, ROOT, curses) |
| 302 | + |
| 303 | + self.assertEqual(curses.cursor_values, [0]) |
| 304 | + self.assertTrue(screen.keypad_enabled) |
| 305 | + headings = [snapshot.get((4, 21)) for snapshot in screen.snapshots] |
| 306 | + self.assertEqual(headings, ["Overview", "Adapters", "Doctor", "Doctor", "Adapters"]) |
| 307 | + |
| 308 | + def test_interactive_dashboard_enter_opens_selected_section(self): |
| 309 | + from harness_manager import dashboard_tui |
| 310 | + |
| 311 | + curses = FakeCurses() |
| 312 | + screen = FakeScreen([curses.KEY_DOWN, curses.KEY_ENTER, ord("q")]) |
| 313 | + opened = [] |
| 314 | + original_open_section = dashboard_tui._open_section |
| 315 | + |
| 316 | + def fake_open_section(section, target_root, stack_root): |
| 317 | + opened.append((section, target_root, stack_root)) |
| 318 | + |
| 319 | + with tempfile.TemporaryDirectory() as tmp: |
| 320 | + project = Path(tmp) |
| 321 | + self.make_project(project) |
| 322 | + try: |
| 323 | + dashboard_tui._open_section = fake_open_section |
| 324 | + dashboard_tui._run_interactive(screen, project, ROOT, curses) |
| 325 | + finally: |
| 326 | + dashboard_tui._open_section = original_open_section |
| 327 | + |
| 328 | + self.assertEqual(opened, [("Adapters", project, ROOT)]) |
| 329 | + self.assertEqual(curses.endwin_count, 1) |
| 330 | + self.assertEqual(screen.clear_count, 1) |
| 331 | + |
232 | 332 |
|
233 | 333 | if __name__ == "__main__": |
234 | 334 | unittest.main() |
0 commit comments