feat: parameterize list_sessions with archived filter
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -881,7 +881,7 @@ class SessionService:
|
|||||||
return {prompt.session_id: prompt for prompt in prompts}
|
return {prompt.session_id: prompt for prompt in prompts}
|
||||||
|
|
||||||
async def list_sessions(
|
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]:
|
) -> list[SessionInfo]:
|
||||||
if now is None:
|
if now is None:
|
||||||
now = time.time()
|
now = time.time()
|
||||||
@@ -889,7 +889,7 @@ class SessionService:
|
|||||||
sessions = (
|
sessions = (
|
||||||
db.query(Session)
|
db.query(Session)
|
||||||
.options(selectinload(Session.harness))
|
.options(selectinload(Session.harness))
|
||||||
.filter_by(project_id=project_id, archived=False)
|
.filter_by(project_id=project_id, archived=archived)
|
||||||
.all()
|
.all()
|
||||||
)
|
)
|
||||||
names = [s.tmux_session_name for s in sessions]
|
names = [s.tmux_session_name for s in sessions]
|
||||||
|
|||||||
@@ -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):
|
async def test_stop_session_for_window_unknown_window_raises(service):
|
||||||
with pytest.raises(ServiceError):
|
with pytest.raises(ServiceError):
|
||||||
await service.stop_session_for_window("not-an-hqt-window")
|
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]
|
||||||
|
|||||||
Reference in New Issue
Block a user