From f0b2ba4160e41bdf8443f3103249a2247be72339 Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Wed, 16 Sep 2026 12:03:56 +0530 Subject: [PATCH] test(tui_gateway): teardown tests prove agent.close() reached the row finalizer _teardown_session swallows agent.close() failures, so a "row stays open" assertion alone is green even when close() aborted before _finalize_owned_session_row. Assert the one side effect only that finalizer produces (_owns_session_db cleared), give the stub the _memory_manager attr close() reads directly, and assert the flag is untouched on the control paths. Rename the sole-owner cross-process test to what it now asserts. --- tests/tui_gateway/test_cross_process_orphan_ownership.py | 2 +- tests/tui_gateway/test_gateway_owned_session_reap.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/tui_gateway/test_cross_process_orphan_ownership.py b/tests/tui_gateway/test_cross_process_orphan_ownership.py index 750fc6a86c..8658289d4d 100644 --- a/tests/tui_gateway/test_cross_process_orphan_ownership.py +++ b/tests/tui_gateway/test_cross_process_orphan_ownership.py @@ -393,7 +393,7 @@ def test_liveness_guard_serializes_cross_process_acquire(tmp_path: Path) -> None _stop_child(child, release_file) -def test_automatic_desktop_cleanup_preserves_sibling_and_ends_sole_owner( +def test_automatic_desktop_cleanup_preserves_sibling_and_releases_sole_owner_lease( tmp_path: Path, monkeypatch: pytest.MonkeyPatch ) -> None: """Every automatic cleanup reason must preserve another Desktop backend.""" diff --git a/tests/tui_gateway/test_gateway_owned_session_reap.py b/tests/tui_gateway/test_gateway_owned_session_reap.py index 4ca4c9444e..5d58e936b6 100644 --- a/tests/tui_gateway/test_gateway_owned_session_reap.py +++ b/tests/tui_gateway/test_gateway_owned_session_reap.py @@ -72,6 +72,7 @@ def _make_real_session(tmp_path, monkeypatch, *, source, session_id): agent._session_messages = [] agent._active_children_lock = threading.Lock() agent._active_children = [] + agent._memory_manager = None # close() reads it directly; a stub must not rely on _quietly swallowing session = _make_session(session_id) session["agent"] = agent @@ -128,6 +129,7 @@ class TestGatewayOwnedSessionTeardown: assert row["ended_at"] is None assert row["end_reason"] is None assert agent._end_session_on_close is False + assert agent._owns_session_db is False # close() reached _finalize_owned_session_row class TestDesktopAutomaticReclaimTeardown: @@ -146,10 +148,11 @@ class TestDesktopAutomaticReclaimTeardown: row = _read_real_row(db_path, f"desktop-{reason}") assert (row["ended_at"], row["end_reason"]) == (None, None) assert agent._end_session_on_close is False + assert agent._owns_session_db is False # close() reached _finalize_owned_session_row @pytest.mark.parametrize("source,reason", [("desktop", "tui_close"), ("tui", "ws_orphan_reap")]) def test_explicit_close_and_non_desktop_reap_still_end_row(self, tmp_path, monkeypatch, source, reason): - db_path, session, _agent = _make_real_session( + db_path, session, agent = _make_real_session( tmp_path, monkeypatch, source=source, session_id=f"{source}-{reason}" ) @@ -158,3 +161,4 @@ class TestDesktopAutomaticReclaimTeardown: row = _read_real_row(db_path, f"{source}-{reason}") assert row["ended_at"] is not None assert row["end_reason"] == reason + assert agent._end_session_on_close is True # flag untouched when the row was ended here