mirror of
https://github.com/kuhyx/screen-locker.git
synced 2026-11-11 15:54:05 +01:00
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
pre-commit / pre-commit (push) Waiting to run
Tests / test (push) Waiting to run
Tests / lock-popup-safety (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
The wake_alarm_skip rung has been dead since the repos split: it read ../wake_alarm/wake_state.json (no longer a path) for a skip_workout field nothing ever wrote, and answered "no skip" for a year without an error. It now reads ~/.local/state/wake_alarm/morning_session.json, written HMAC-signed by wake-alarm every two minutes through the morning, and the whole decision is: signature ok, dated today, now < exempt_until. A completed-in-time morning defers the lock to 11:00; a live one until min(start + 90 min, 09:30); nothing else changes the ladder. The enforce path waits up to 30 s for a freshly booted PC's refresher; status paths never wait. Takes Flutter 3.47.5. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tp54ewdXRLaimUuT8LgYyn
88 lines
2.6 KiB
Python
88 lines
2.6 KiB
Python
"""Tests for wake alarm skip integration in screen_lock.py."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
from typing import TYPE_CHECKING
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
from screen_locker._morning_session import MorningSkip
|
|
from screen_locker.tests.conftest import create_locker
|
|
|
|
_SKIP = MorningSkip(outcome="completed", exempt_until=datetime(2099, 1, 1).astimezone())
|
|
|
|
if TYPE_CHECKING:
|
|
from pathlib import Path
|
|
|
|
|
|
class TestWakeSkipIntegration:
|
|
"""Tests for workout skip via wake alarm in screen locker init."""
|
|
|
|
def test_exits_when_wake_skip_active(
|
|
self,
|
|
mock_tk: MagicMock,
|
|
mock_sys_exit: MagicMock,
|
|
tmp_path: Path,
|
|
) -> None:
|
|
"""Screen locker exits if wake alarm granted workout skip today."""
|
|
with patch(
|
|
"screen_locker._auto_upgrade.morning_skip_today",
|
|
return_value=_SKIP,
|
|
):
|
|
create_locker(mock_tk, tmp_path, has_logged=False)
|
|
|
|
mock_sys_exit.assert_called_once_with(0)
|
|
|
|
def test_does_not_exit_when_no_wake_skip(
|
|
self,
|
|
mock_tk: MagicMock,
|
|
mock_sys_exit: MagicMock,
|
|
tmp_path: Path,
|
|
) -> None:
|
|
"""Screen locker proceeds normally if no wake skip active."""
|
|
with patch(
|
|
"screen_locker._auto_upgrade.morning_skip_today",
|
|
return_value=None,
|
|
):
|
|
locker = create_locker(mock_tk, tmp_path, has_logged=False)
|
|
|
|
mock_sys_exit.assert_not_called()
|
|
assert locker is not None
|
|
|
|
def test_logged_today_takes_precedence(
|
|
self,
|
|
mock_tk: MagicMock,
|
|
mock_sys_exit: MagicMock,
|
|
tmp_path: Path,
|
|
) -> None:
|
|
"""has_logged_today exits before wake skip is even checked."""
|
|
with patch(
|
|
"screen_locker._auto_upgrade.morning_skip_today",
|
|
return_value=_SKIP,
|
|
):
|
|
create_locker(mock_tk, tmp_path, has_logged=True)
|
|
|
|
# Exits because has_logged_today, not because of wake skip
|
|
mock_sys_exit.assert_called_once_with(0)
|
|
|
|
def test_verify_only_mode_ignores_wake_skip(
|
|
self,
|
|
mock_tk: MagicMock,
|
|
mock_sys_exit: MagicMock,
|
|
tmp_path: Path,
|
|
) -> None:
|
|
"""verify_only mode checks sick day log, not wake skip."""
|
|
with patch(
|
|
"screen_locker._auto_upgrade.morning_skip_today",
|
|
return_value=_SKIP,
|
|
):
|
|
create_locker(
|
|
mock_tk,
|
|
tmp_path,
|
|
verify_only=True,
|
|
is_sick_day_log=True,
|
|
)
|
|
|
|
# In verify_only mode, exits don't happen from wake skip path
|
|
mock_sys_exit.assert_not_called()
|