Skip to content

Commit 040211f

Browse files
authored
Update test_tui.py
1 parent 0751fc2 commit 040211f

1 file changed

Lines changed: 67 additions & 0 deletions

File tree

‎tests/test_tui.py‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,6 +1760,73 @@ def test_compact_syncs_tui_conversation_history(self):
17601760
[m.text() for m in compacted],
17611761
)
17621762

1763+
def test_compact_resets_running_state(self):
1764+
tui, _ = make_tui()
1765+
compacted = [
1766+
Message(role="user", content="**[Compacted Summary]**\n\nx"),
1767+
]
1768+
with (
1769+
mock.patch.object(
1770+
tui.session,
1771+
"compact_conversation",
1772+
return_value=(True, "ok"),
1773+
),
1774+
mock.patch.object(
1775+
tui.session,
1776+
"last_messages",
1777+
compacted,
1778+
create=True,
1779+
),
1780+
):
1781+
tui._run_compact()
1782+
self.assertFalse(tui.agent_running)
1783+
self.assertEqual(tui.status, "")
1784+
1785+
def test_compact_failure_prints_error_and_resets_state(self):
1786+
tui, buf = make_tui()
1787+
with mock.patch.object(
1788+
tui.session,
1789+
"compact_conversation",
1790+
side_effect=RuntimeError("boom"),
1791+
):
1792+
tui._run_compact()
1793+
self.assertIn("Compaction failed: boom", buf.getvalue())
1794+
self.assertFalse(tui.agent_running)
1795+
self.assertEqual(tui.status, "")
1796+
1797+
def test_compact_renders_status_bar_while_running(self):
1798+
tui, buf = make_tui()
1799+
started = threading.Event()
1800+
release = threading.Event()
1801+
1802+
def slow_compact():
1803+
started.set()
1804+
release.wait(2)
1805+
return (True, "ok")
1806+
1807+
compacted = [
1808+
Message(role="user", content="**[Compacted Summary]**\n\nx"),
1809+
]
1810+
with (
1811+
mock.patch.object(
1812+
tui.session,
1813+
"compact_conversation",
1814+
side_effect=slow_compact,
1815+
),
1816+
mock.patch.object(
1817+
tui.session,
1818+
"last_messages",
1819+
compacted,
1820+
create=True,
1821+
),
1822+
):
1823+
run_thread = threading.Thread(target=tui._run_compact, daemon=True)
1824+
run_thread.start()
1825+
self.assertTrue(started.wait(2))
1826+
release.set()
1827+
run_thread.join(2)
1828+
self.assertIn("compacting", buf.getvalue())
1829+
17631830
def test_summary_syncs_tui_conversation_history(self):
17641831
tui, _ = make_tui()
17651832
tui.conversation_history = [Message(role="user", content="hello")]

0 commit comments

Comments
 (0)