mirror of
https://github.com/kuhyx/screen-locker.git
synced 2026-11-11 14:07:41 +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
125 lines
4.7 KiB
Python
125 lines
4.7 KiB
Python
"""Minute-precision shutdown schedule: legacy keys and the real command line.
|
|
|
|
The schedule moved from whole hours to minutes after midnight. Pinned here:
|
|
``read_shutdown_config`` still understands a file with only the old ``*_HOUR``
|
|
keys, the sick-day state still loads its old ``original_*_hour`` keys, and a
|
|
value that is not a whole hour (a 30-minute earner) reaches the helper script
|
|
as ``HH:MM`` rather than being floored.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
import pytest
|
|
|
|
from screen_locker._shutdown import read_shutdown_config
|
|
from screen_locker.tests.conftest import create_locker
|
|
|
|
if TYPE_CHECKING:
|
|
from pathlib import Path
|
|
|
|
|
|
class TestReadShutdownConfigKeys:
|
|
"""``*_MINUTES`` is authoritative; ``*_HOUR`` is only a fallback."""
|
|
|
|
def _read(self, tmp_path: Path, body: str) -> tuple[int, int, int] | None:
|
|
conf = tmp_path / "shutdown.conf"
|
|
conf.write_text(body)
|
|
return read_shutdown_config(conf)
|
|
|
|
def test_minutes_keys_are_read_exactly(self, tmp_path: Path) -> None:
|
|
body = "MON_WED_MINUTES=1110\nTHU_SUN_MINUTES=1230\nMORNING_END_MINUTES=330\n"
|
|
assert self._read(tmp_path, body) == (1110, 1230, 330)
|
|
|
|
def test_legacy_hour_only_file_reads_as_hours_times_sixty(
|
|
self, tmp_path: Path
|
|
) -> None:
|
|
body = "MON_WED_HOUR=21\nTHU_SUN_HOUR=20\nMORNING_END_HOUR=5\n"
|
|
assert self._read(tmp_path, body) == (1260, 1200, 300)
|
|
|
|
def test_minutes_win_over_the_rounded_hour_copy(self, tmp_path: Path) -> None:
|
|
"""A dual-key file's *_HOUR is strict-rounded: 18:30 -> 18, 05:30 -> 6."""
|
|
body = (
|
|
"MON_WED_MINUTES=1110\nTHU_SUN_MINUTES=1110\nMORNING_END_MINUTES=330\n"
|
|
"MON_WED_HOUR=18\nTHU_SUN_HOUR=18\nMORNING_END_HOUR=6\n"
|
|
)
|
|
assert self._read(tmp_path, body) == (1110, 1110, 330)
|
|
|
|
def test_keys_resolve_independently(self, tmp_path: Path) -> None:
|
|
"""One key in minutes, the others only in hours: each falls back alone."""
|
|
body = "MON_WED_MINUTES=1110\nTHU_SUN_HOUR=20\nMORNING_END_HOUR=5\n"
|
|
assert self._read(tmp_path, body) == (1110, 1200, 300)
|
|
|
|
def test_a_missing_value_is_none(self, tmp_path: Path) -> None:
|
|
body = "MON_WED_MINUTES=1110\nTHU_SUN_MINUTES=1110\n"
|
|
assert self._read(tmp_path, body) is None
|
|
|
|
def test_non_numeric_values_and_comments_are_ignored(self, tmp_path: Path) -> None:
|
|
body = (
|
|
"# MON_WED_MINUTES=1\nMON_WED_MINUTES=oops\nMON_WED_HOUR=21\n"
|
|
"THU_SUN_HOUR=20\nMORNING_END_HOUR=5\nno-equals-sign\n"
|
|
)
|
|
assert self._read(tmp_path, body) == (1260, 1200, 300)
|
|
|
|
|
|
@pytest.mark.usefixtures("pre_ladder")
|
|
class TestMinutesReachTheHelperScript:
|
|
"""The helper receives HH:MM, so a half hour is not floored on the way."""
|
|
|
|
def _run(
|
|
self,
|
|
mock_tk: MagicMock,
|
|
tmp_path: Path,
|
|
config: tuple[int, int, int],
|
|
action: str,
|
|
*args: int,
|
|
) -> list[str]:
|
|
locker = create_locker(mock_tk, tmp_path)
|
|
script = tmp_path / "adjust.sh"
|
|
script.write_text("")
|
|
done = MagicMock(stdout="ok")
|
|
with (
|
|
patch.object(locker, "_read_shutdown_config", return_value=config),
|
|
patch("screen_locker._shutdown.ADJUST_SHUTDOWN_SCRIPT", script),
|
|
patch("screen_locker._shutdown.subprocess.run", return_value=done) as run,
|
|
):
|
|
assert getattr(locker, action)(*args) is True
|
|
cmd: list[str] = run.call_args.args[0]
|
|
return cmd[2:]
|
|
|
|
def test_a_30_minute_bonus_becomes_18_30(
|
|
self, mock_tk: MagicMock, mock_sys_exit: MagicMock, tmp_path: Path
|
|
) -> None:
|
|
args = self._run(
|
|
mock_tk, tmp_path, (1080, 1080, 300), "_adjust_shutdown_time_by", 30
|
|
)
|
|
assert args == ["--restore", "18:30", "18:30", "05:00"]
|
|
|
|
def test_the_bonus_is_capped_at_24_00(
|
|
self, mock_tk: MagicMock, mock_sys_exit: MagicMock, tmp_path: Path
|
|
) -> None:
|
|
args = self._run(
|
|
mock_tk, tmp_path, (1380, 1380, 300), "_adjust_shutdown_time_by", 90
|
|
)
|
|
assert args == ["--restore", "24:00", "24:00", "05:00"]
|
|
|
|
@pytest.mark.parametrize(
|
|
("config", "expected"),
|
|
[
|
|
((1290, 1260, 300), ["--restore", "23:00", "23:00", "05:00"]),
|
|
((1080, 1080, 300), ["--restore", "20:00", "20:00", "05:00"]),
|
|
],
|
|
)
|
|
def test_workout_reward_is_clamped_to_23_00(
|
|
self,
|
|
mock_tk: MagicMock,
|
|
mock_sys_exit: MagicMock,
|
|
tmp_path: Path,
|
|
config: tuple[int, int, int],
|
|
expected: list[str],
|
|
) -> None:
|
|
args = self._run(mock_tk, tmp_path, config, "_adjust_shutdown_time_later")
|
|
assert args == expected
|