forked from hyphen-2025/cyber-pilot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_overwork_alert_notifications.py
More file actions
62 lines (39 loc) · 2.37 KB
/
test_overwork_alert_notifications.py
File metadata and controls
62 lines (39 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from __future__ import annotations
from overwork_alert.notification_policy import apply_notification_policy, should_notify
from overwork_alert.models import Config, TrackerState, TrackerStatus
def test_should_notify_false_when_not_running() -> None:
config = Config()
state = TrackerState(status=TrackerStatus.PAUSED, active_time_seconds=999999, last_tick_at=0.0)
assert should_notify(state=state, config=config, idle_seconds=0, now=10.0) is False
def test_should_notify_false_when_idle_unavailable() -> None:
config = Config()
state = TrackerState(status=TrackerStatus.RUNNING, active_time_seconds=999999, last_tick_at=0.0)
assert should_notify(state=state, config=config, idle_seconds=None, now=10.0) is False
def test_should_notify_false_when_idle_over_threshold() -> None:
config = Config(idle_threshold_seconds=300)
state = TrackerState(status=TrackerStatus.RUNNING, active_time_seconds=999999, last_tick_at=0.0)
assert should_notify(state=state, config=config, idle_seconds=300, now=10.0) is False
def test_should_notify_false_when_under_limit() -> None:
config = Config(limit_seconds=100)
state = TrackerState(status=TrackerStatus.RUNNING, active_time_seconds=100, last_tick_at=0.0)
assert should_notify(state=state, config=config, idle_seconds=0, now=10.0) is False
def test_should_notify_true_for_first_alert() -> None:
config = Config(limit_seconds=100)
state = TrackerState(status=TrackerStatus.RUNNING, active_time_seconds=101, last_tick_at=0.0)
assert should_notify(state=state, config=config, idle_seconds=0, now=10.0) is True
def test_should_notify_true_for_repeat_after_interval() -> None:
config = Config(limit_seconds=100, repeat_interval_seconds=30)
state = TrackerState(
status=TrackerStatus.RUNNING,
active_time_seconds=101,
last_tick_at=0.0,
over_limit_since=10.0,
last_reminder_at=10.0,
)
assert should_notify(state=state, config=config, idle_seconds=0, now=40.0) is True
def test_apply_notification_policy_sets_over_limit_since_and_last_reminder() -> None:
config = Config(limit_seconds=100)
state = TrackerState(status=TrackerStatus.RUNNING, active_time_seconds=101, last_tick_at=0.0)
out = apply_notification_policy(state=state, config=config, idle_seconds=0, now=10.0)
assert out.over_limit_since == 10.0
assert out.last_reminder_at == 10.0