From c8380be72dc8c4bab4dc76180ba46fb55f45f6b5 Mon Sep 17 00:00:00 2001 From: Felix Martin Date: Thu, 11 Jun 2026 12:05:19 -0400 Subject: [PATCH] feat: parameterize list_sessions with archived filter Co-Authored-By: Claude Sonnet 4.6 --- src/hqt/sessions/service.py | 4 ++-- tests/test_sessions.py | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/hqt/sessions/service.py b/src/hqt/sessions/service.py index 47c5826..c11e6be 100644 --- a/src/hqt/sessions/service.py +++ b/src/hqt/sessions/service.py @@ -881,7 +881,7 @@ class SessionService: return {prompt.session_id: prompt for prompt in prompts} async def list_sessions( - self, project_id: int, now: float | None = None + self, project_id: int, archived: bool = False, now: float | None = None ) -> list[SessionInfo]: if now is None: now = time.time() @@ -889,7 +889,7 @@ class SessionService: sessions = ( db.query(Session) .options(selectinload(Session.harness)) - .filter_by(project_id=project_id, archived=False) + .filter_by(project_id=project_id, archived=archived) .all() ) names = [s.tmux_session_name for s in sessions] diff --git a/tests/test_sessions.py b/tests/test_sessions.py index e6c3500..bbf4902 100644 --- a/tests/test_sessions.py +++ b/tests/test_sessions.py @@ -2150,3 +2150,23 @@ async def test_stop_session_for_window_kills_by_name(service, db, tmux): async def test_stop_session_for_window_unknown_window_raises(service): with pytest.raises(ServiceError): await service.stop_session_for_window("not-an-hqt-window") + + +@pytest.mark.asyncio +async def test_list_sessions_archived_filter(service, db, tmux): + h = db.query(Harness).filter_by(name="claude-code").first() + active = Session( + project_id=1, harness_id=h.id, tmux_session_name="hqt-active", archived=False + ) + arch = Session( + project_id=1, harness_id=h.id, tmux_session_name="hqt-arch", archived=True + ) + db.add_all([active, arch]) + db.commit() + active_id, arch_id = active.id, arch.id + + default = await service.list_sessions(project_id=1) + assert [i.session.id for i in default] == [active_id] + + archived = await service.list_sessions(project_id=1, archived=True) + assert [i.session.id for i in archived] == [arch_id]