fix(appd): exclude Stopped sessions from running_sessions; add regression test

running_sessions() was returning all sessions regardless of state.
Stopped sessions would reappear in the taskbar on reconnect since
QUERY_RUNNING is sent on every WebSocket open. The filter now matches
the UI expectation: only Starting and Running sessions are returned.
This commit is contained in:
Marco Allegretti 2026-03-11 12:53:07 +01:00
parent de8939a72e
commit c88c948575

View file

@ -66,6 +66,7 @@ impl SessionRegistry {
fn running_sessions(&self) -> Vec<SessionInfo> {
self.sessions
.iter()
.filter(|(_, e)| !matches!(e.state, AppStateKind::Stopped))
.map(|(&session_id, e)| SessionInfo {
session_id,
app_id: e.app_id.clone(),
@ -462,6 +463,17 @@ mod tests {
assert!(matches!(resp, Response::Error { .. }));
}
#[tokio::test]
async fn running_sessions_excludes_stopped() {
let reg = make_registry();
let session_id = reg.lock().await.launch("com.test.app");
reg.lock()
.await
.set_state(session_id, AppStateKind::Stopped);
let sessions = reg.lock().await.running_sessions();
assert!(sessions.is_empty());
}
#[tokio::test]
async fn dispatch_query_running_lists_active_sessions() {
let reg = make_registry();