mirror of
https://github.com/kuhyx/screen-locker.git
synced 2026-11-10 20:27:13 +01:00
A sick day is now a date in the shared sickdays pool (utils sickdays 0.1.0) and nothing else. Removed: the 7/30/90-day budget, the escalating lockout countdown, the justification form, the commitment prompt and its double debt, the workout-debt counter, the -60 min shutdown cut and its sick_day_state.json, the post-sick-day --verify-workout mode, the sick auto-upgrade, scripts/revoke_sick_day.py and their tests. - Lock screen: "I'm sick" on the retry, no-phone and both Tue-Thu screens; one tap -> sickdays.add_sick_day(today) -> sick floor -> best-effort background sickdays.sync_quietly -> unlock. Refusals (free day, unreadable pool) are shown and the lock stays. - Shutdown: the reset resolves with earned_time.resolve(..., sick=True) (max(20:00, ladder), capped 23:00) and saves the sick lift with the grace lift, so later credits absorb it instead of stacking on 20:00. A day marked after the reset is lifted by the new _sick_floor live pass (every 5-min tick, --sync-only, --apply-bonuses, and the tap itself). - Workout lock and grace floor stand down on a sick day; workouts that day credit normally through the sync paths. - wake-alarm workday_penalty.json is void when its issued_date or penalty_date is a sick day. - Status window, i3 line, CLI --status, MCP flags and web reasons read sickdays. - scripts/migrate_sick_history.py imports sick_history.json's dates via sickdays.import_legacy, verifies and removes the file; idempotent, run by install.sh. - Pins: earned-time 0.11.0, freedays 0.4.0, sickdays 0.1.0 (tags pending); pre-commit 4.7.0, ruff 0.17.1 (freshness gate). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xfj1sxKH9VBPqpcAni8Jry
228 lines
8.5 KiB
Python
228 lines
8.5 KiB
Python
"""Tests for _check_today_state_exits and scheduled-skip branches."""
|
|
|
|
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, create_locker_relaxed_day
|
|
|
|
_SKIP = MorningSkip(outcome="completed", exempt_until=datetime(2099, 1, 1).astimezone())
|
|
|
|
if TYPE_CHECKING:
|
|
from pathlib import Path
|
|
|
|
from screen_locker.screen_lock import ScreenLocker
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# _check_today_state_exits: return True/False branches
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
class TestCheckTodayStateExits:
|
|
"""Cover all return True/False paths in _check_today_state_exits.
|
|
|
|
sys.exit is mocked without side_effect so execution continues past it
|
|
and the 'return True' statements are reachable.
|
|
"""
|
|
|
|
def _make_locker(self, mock_tk: MagicMock, tmp_path: Path) -> ScreenLocker:
|
|
return create_locker(mock_tk, tmp_path)
|
|
|
|
def test_early_bird_upgrade_success_returns_true(
|
|
self,
|
|
mock_tk: MagicMock,
|
|
mock_sys_exit: MagicMock,
|
|
tmp_path: Path,
|
|
) -> None:
|
|
"""Early bird upgrade success returns true."""
|
|
locker = self._make_locker(mock_tk, tmp_path)
|
|
with (
|
|
patch.object(locker, "_is_early_bird_pending", return_value=True),
|
|
patch.object(locker, "_is_early_bird_time", return_value=False),
|
|
patch.object(locker, "_try_auto_upgrade_early_bird", return_value=True),
|
|
):
|
|
result = locker._check_today_state_exits()
|
|
assert result is True
|
|
|
|
def test_early_bird_upgrade_fail_returns_false(
|
|
self,
|
|
mock_tk: MagicMock,
|
|
mock_sys_exit: MagicMock,
|
|
tmp_path: Path,
|
|
) -> None:
|
|
"""Early bird upgrade fail returns false."""
|
|
locker = self._make_locker(mock_tk, tmp_path)
|
|
with (
|
|
patch.object(locker, "_is_early_bird_pending", return_value=True),
|
|
patch.object(locker, "_is_early_bird_time", return_value=False),
|
|
patch.object(locker, "_try_auto_upgrade_early_bird", return_value=False),
|
|
):
|
|
result = locker._check_today_state_exits()
|
|
assert result is False
|
|
|
|
def test_expired_early_bird_does_not_outrank_a_logged_workout(
|
|
self,
|
|
mock_tk: MagicMock,
|
|
mock_sys_exit: MagicMock,
|
|
tmp_path: Path,
|
|
) -> None:
|
|
"""2026-09-18: a manual walk logged at 09:32 must hold after 08:30.
|
|
|
|
The expired-marker branch used to return False (full lock) before
|
|
``has_logged_today`` was ever consulted, so every 5-minute tick after
|
|
the walk re-locked the PC for the rest of the day.
|
|
"""
|
|
locker = self._make_locker(mock_tk, tmp_path)
|
|
with (
|
|
patch.object(locker, "_is_early_bird_pending", return_value=True),
|
|
patch.object(locker, "_is_early_bird_time", return_value=False),
|
|
patch.object(locker, "_try_auto_upgrade_early_bird", return_value=False),
|
|
patch.object(locker, "has_logged_today", return_value=True),
|
|
patch("screen_locker._auto_upgrade.record_decision") as record,
|
|
):
|
|
result = locker._check_today_state_exits()
|
|
assert result is True
|
|
assert record.call_args.args[0].reason == "workout_logged_today"
|
|
|
|
def test_early_bird_window_active_returns_true(
|
|
self,
|
|
mock_tk: MagicMock,
|
|
mock_sys_exit: MagicMock,
|
|
tmp_path: Path,
|
|
) -> None:
|
|
"""Early bird window active returns true."""
|
|
locker = self._make_locker(mock_tk, tmp_path)
|
|
with (
|
|
patch.object(locker, "_is_early_bird_pending", return_value=True),
|
|
patch.object(locker, "_is_early_bird_time", return_value=True),
|
|
):
|
|
result = locker._check_today_state_exits()
|
|
assert result is True
|
|
|
|
def test_sick_day_no_upgrade_still_returns_true(
|
|
self,
|
|
mock_tk: MagicMock,
|
|
mock_sys_exit: MagicMock,
|
|
tmp_path: Path,
|
|
) -> None:
|
|
"""A sick day already marked today halts startup even when no real
|
|
workout is found to upgrade it - sick_day no longer lives in
|
|
log.json, so this halt must be explicit (see
|
|
_auto_upgrade.py's _check_today_state_exits), not an accidental
|
|
side effect of has_logged_today() catching a leftover log entry."""
|
|
locker = self._make_locker(mock_tk, tmp_path)
|
|
with (
|
|
patch.object(locker, "_is_early_bird_pending", return_value=False),
|
|
patch.object(locker, "_is_sick_day_today", return_value=True),
|
|
):
|
|
result = locker._check_today_state_exits()
|
|
assert result is True
|
|
|
|
def test_workout_skip_today_returns_true(
|
|
self,
|
|
mock_tk: MagicMock,
|
|
mock_sys_exit: MagicMock,
|
|
tmp_path: Path,
|
|
) -> None:
|
|
"""Workout skip today returns true."""
|
|
locker = self._make_locker(mock_tk, tmp_path)
|
|
with (
|
|
patch.object(locker, "_is_early_bird_pending", return_value=False),
|
|
patch.object(locker, "_is_sick_day_today", return_value=False),
|
|
patch.object(locker, "has_logged_today", return_value=False),
|
|
patch(
|
|
"screen_locker._early_bird.morning_skip_today",
|
|
return_value=_SKIP,
|
|
),
|
|
):
|
|
result = locker._check_today_state_exits()
|
|
assert result is True
|
|
|
|
def test_early_bird_time_returns_true(
|
|
self,
|
|
mock_tk: MagicMock,
|
|
mock_sys_exit: MagicMock,
|
|
tmp_path: Path,
|
|
) -> None:
|
|
"""Early bird time returns true."""
|
|
locker = self._make_locker(mock_tk, tmp_path)
|
|
with (
|
|
patch.object(locker, "_is_early_bird_pending", return_value=False),
|
|
patch.object(locker, "_is_sick_day_today", return_value=False),
|
|
patch.object(locker, "has_logged_today", return_value=False),
|
|
patch(
|
|
"screen_locker._early_bird.morning_skip_today",
|
|
return_value=None,
|
|
),
|
|
patch.object(locker, "_is_early_bird_time", return_value=True),
|
|
patch.object(locker, "_save_early_bird_pending"),
|
|
):
|
|
result = locker._check_today_state_exits()
|
|
assert result is True
|
|
|
|
def test_no_exit_conditions_returns_false(
|
|
self,
|
|
mock_tk: MagicMock,
|
|
mock_sys_exit: MagicMock,
|
|
tmp_path: Path,
|
|
) -> None:
|
|
"""No exit conditions returns false."""
|
|
locker = self._make_locker(mock_tk, tmp_path)
|
|
with (
|
|
patch.object(locker, "_is_early_bird_pending", return_value=False),
|
|
patch.object(locker, "_is_sick_day_today", return_value=False),
|
|
patch.object(locker, "has_logged_today", return_value=False),
|
|
patch(
|
|
"screen_locker._early_bird.morning_skip_today",
|
|
return_value=None,
|
|
),
|
|
patch.object(locker, "_is_early_bird_time", return_value=False),
|
|
):
|
|
result = locker._check_today_state_exits()
|
|
assert result is False
|
|
|
|
|
|
class TestCheckNonVerifyExitsScheduledSkip:
|
|
"""Cover the return after scheduled-skip sys.exit in _check_non_verify_exits."""
|
|
|
|
def test_scheduled_skip_return_reached(
|
|
self,
|
|
mock_tk: MagicMock,
|
|
mock_sys_exit: MagicMock,
|
|
tmp_path: Path,
|
|
) -> None:
|
|
"""Scheduled skip return reached."""
|
|
locker = create_locker(mock_tk, tmp_path)
|
|
with patch.object(locker, "_is_scheduled_skip_today", return_value=True):
|
|
locker._check_non_verify_exits()
|
|
mock_sys_exit.assert_called_once_with(0)
|
|
|
|
|
|
class TestRelaxedDayCloseAndRun:
|
|
"""No LockWindow is built on a relaxed day; close()/run() use root."""
|
|
|
|
def test_relaxed_day_close_and_run_use_root_directly(
|
|
self,
|
|
mock_tk: MagicMock,
|
|
mock_sys_exit: MagicMock,
|
|
tmp_path: Path,
|
|
) -> None:
|
|
"""Relaxed day close and run use root directly."""
|
|
locker = create_locker_relaxed_day(mock_tk, tmp_path)
|
|
assert locker._lock is None
|
|
|
|
locker.run()
|
|
locker.root.mainloop.assert_called_once()
|
|
|
|
locker.close()
|
|
locker.root.destroy.assert_called_once()
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# _check_non_verify_exits: heat-skip branch (reached after weekly minimum
|
|
# is not met — the only remaining same-day skip is genuine extreme heat)
|
|
# ---------------------------------------------------------------------------
|