From cea5652b5840e0ae1842a86606656214426a6022 Mon Sep 17 00:00:00 2001 From: pbean Date: Tue, 21 Jul 2026 15:28:02 -0700 Subject: [PATCH] test(tui): de-flake cleanup-session summary toast assertion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The cleanup worker marshals its 'removed N session(s)' summary toast AFTER the 'unverifiable engine pid' warning (app.py _cleanup_sessions_worker), each via a separate call_from_thread hop. Both cleanup tests waited `until` the earlier pid warning appeared, then did a BARE assert on the later summary — so on slow Windows timing the summary had not reached the message pump yet, and the assert raced it. Surfaced as a py3.11 Windows-only failure of test_cleanup_sessions_mux_error_notifies on the v0.9.0 merge commit, where the identical tree had passed in the PR's own CI. Wrap the summary check in the same `until` poll the surrounding waits use. --- tests/test_tui_app.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/test_tui_app.py b/tests/test_tui_app.py index cb2769fe..63ed6f99 100644 --- a/tests/test_tui_app.py +++ b/tests/test_tui_app.py @@ -1728,7 +1728,10 @@ async def test_cleanup_unknown_sessions_notifies(project, monkeypatch): await until(pilot, lambda: isinstance(app.screen, ConfirmModal)) await pilot.click(await ready(pilot, "#ok")) await until(pilot, lambda: any("unverifiable engine pid" in m for m in notifications(app))) - assert any("removed 1 session(s)" in m for m in notifications(app)) + # `until`, not a bare assert: the summary toast is marshalled from the + # worker AFTER the pid warning, so waiting on the earlier one does not + # guarantee this one has reached the message pump yet (Windows flake). + await until(pilot, lambda: any("removed 1 session(s)" in m for m in notifications(app))) async def test_cleanup_sessions_mux_error_notifies(project, monkeypatch): @@ -1760,7 +1763,10 @@ def boom(_p): # the ctl-window failure is surfaced, but the session pruning that already # completed is still reported — not swallowed by an early return await until(pilot, lambda: any("unverifiable engine pid" in m for m in notifications(app))) - assert any("removed 1 session(s)" in m for m in notifications(app)) + # `until`, not a bare assert: the summary toast is marshalled from the + # worker AFTER the pid warning, so waiting on the earlier one does not + # guarantee this one has reached the message pump yet (Windows flake). + await until(pilot, lambda: any("removed 1 session(s)" in m for m in notifications(app))) assert isinstance(app.screen, DashboardScreen) # worker failed soft, no crash