From 578f8418f97af97bc8eccfd1409ae37098b924ef Mon Sep 17 00:00:00 2001 From: EQ maintenance for AliZakaee <62015010+AliZakaee@users.noreply.github.com> Date: Sun, 9 Aug 2026 21:57:26 +0330 Subject: [PATCH] fix: exclude expired pauses from status count --- database.py | 3 ++- tests/unit/test_database_dal.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/database.py b/database.py index e673020..262b8e6 100644 --- a/database.py +++ b/database.py @@ -570,7 +570,8 @@ def delete_pause(business_connection_id: str, customer_chat_id: int) -> int: def list_active_pauses() -> list[sqlite3.Row]: with read_cursor() as cur: cur.execute("SELECT * FROM paused_chats ORDER BY id") - return cur.fetchall() + rows = cur.fetchall() + return [row for row in rows if not utils.is_expired(row["paused_until"])] def clear_all_pauses() -> int: diff --git a/tests/unit/test_database_dal.py b/tests/unit/test_database_dal.py index 44fc706..8d89cab 100644 --- a/tests/unit/test_database_dal.py +++ b/tests/unit/test_database_dal.py @@ -78,6 +78,18 @@ def test_pauses_dal(db): assert db.delete_pause("bc1", 5) == 0 +def test_list_active_pauses_excludes_expired_deadlines(db): + with freeze_time("2024-01-01 12:00:00"): + db.upsert_pause("bc1", 5, "rate_limit", utils.future_iso(30)) + db.upsert_pause("bc1", 6, "manual", None) + + with freeze_time("2024-01-01 13:00:00"): + active_chat_ids = [row["customer_chat_id"] for row in db.list_active_pauses()] + + assert active_chat_ids == [6] + assert db.get_pause("bc1", 5) is not None # enforcement still owns lazy cleanup + + # --- pending_approvals ------------------------------------------------------- def test_mark_approval_is_atomic(db): aid = db.insert_pending_approval("bc1", 5, 22, "c", "r")