Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/test_database_dal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading