mirror of
https://github.com/kuhyx/screen-locker.git
synced 2026-11-11 14:27:40 +01:00
The workout lock, its explanation, the status view and the workday penalty's penalised day now ask _sick.stands_down_workout: a sick day that keeps the workout locker behaves as a normal day. The penalty's ring day is judged by the alarm switch. Shutdown (20:00 floor, grace floor, base, target, preview scripts) keeps is_sick: the floor belongs to the day, not to a locker. The one-tap button still keeps nothing. Test pool fixture and preview harness now redirect every sickdays resolve_paths binding, so keep edits never reach the real pool. Pins bumped to sickdays-v0.2.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PAhbNszs5JKdtnD4uBi3xp
115 lines
4.3 KiB
Python
115 lines
4.3 KiB
Python
"""screen_locker._workday_penalty — the stick file, read and never re-derived."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
import json
|
|
from typing import TYPE_CHECKING
|
|
from unittest.mock import patch
|
|
|
|
from gatelock.log_integrity import compute_entry_hmac
|
|
import pytest
|
|
import sickdays
|
|
|
|
from screen_locker import _workday_penalty
|
|
from screen_locker._workday_penalty import workday_penalty_today
|
|
from screen_locker.tests._sick_helpers import mark_sick
|
|
|
|
if TYPE_CHECKING:
|
|
from pathlib import Path
|
|
|
|
NOW = datetime(2026, 9, 23, 9, 0).astimezone()
|
|
|
|
|
|
def _write(entry: dict[str, object], *, sign: bool = True) -> Path:
|
|
if sign:
|
|
entry["hmac"] = compute_entry_hmac(entry)
|
|
path = _workday_penalty.WORKDAY_PENALTY_FILE
|
|
path.write_text(json.dumps(entry))
|
|
return path
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _signing_key(tmp_path: Path) -> None:
|
|
key = tmp_path / "hmac.key"
|
|
key.write_bytes(b"1" * 32)
|
|
with patch("gatelock.log_integrity.DEFAULT_HMAC_KEY_FILE", key):
|
|
yield
|
|
|
|
|
|
class TestVerdict:
|
|
def test_todays_penalty_applies(self) -> None:
|
|
_write({"penalty_date": "2026-09-23", "issued_date": "2026-09-22"})
|
|
assert workday_penalty_today(NOW) is True
|
|
|
|
def test_a_different_dates_penalty_does_not_apply(self) -> None:
|
|
_write({"penalty_date": "2026-09-24", "issued_date": "2026-09-23"})
|
|
assert workday_penalty_today(NOW) is False
|
|
|
|
def test_missing_unreadable_tampered_are_all_no_penalty(
|
|
self, tmp_path: Path
|
|
) -> None:
|
|
assert workday_penalty_today(NOW) is False
|
|
path = _write({"penalty_date": "2026-09-23"}, sign=False)
|
|
assert workday_penalty_today(NOW) is False
|
|
path.write_text("not json")
|
|
assert workday_penalty_today(NOW) is False
|
|
path.write_text("[]")
|
|
assert workday_penalty_today(NOW) is False
|
|
path.unlink()
|
|
assert workday_penalty_today(NOW) is False
|
|
|
|
def test_default_now_is_used_when_unset(self) -> None:
|
|
# Not asserting a value -- just that omitting `now` does not raise.
|
|
assert workday_penalty_today() is False
|
|
|
|
|
|
class TestSickDayVoidsThePenalty:
|
|
"""Void when EITHER the missed ring's day OR the penalised day is sick."""
|
|
|
|
def test_a_sick_penalty_date_voids_it(self) -> None:
|
|
mark_sick("2026-09-23")
|
|
_write({"penalty_date": "2026-09-23", "issued_date": "2026-09-22"})
|
|
assert workday_penalty_today(NOW) is False
|
|
|
|
def test_a_sick_issued_date_voids_it(self) -> None:
|
|
"""Missed at 08:15, marked sick at 14:00: wake-alarm's retraction lags."""
|
|
mark_sick("2026-09-22")
|
|
_write({"penalty_date": "2026-09-23", "issued_date": "2026-09-22"})
|
|
assert workday_penalty_today(NOW) is False
|
|
|
|
def test_an_older_file_without_issued_date_still_applies(self) -> None:
|
|
_write({"penalty_date": "2026-09-23"})
|
|
assert workday_penalty_today(NOW) is True
|
|
|
|
def test_a_malformed_issued_date_is_logged_not_sick(
|
|
self, caplog: pytest.LogCaptureFixture
|
|
) -> None:
|
|
_write({"penalty_date": "2026-09-23", "issued_date": "yesterday"})
|
|
assert workday_penalty_today(NOW) is True
|
|
assert "not a date" in caplog.text
|
|
|
|
|
|
class TestKeptLockersDecideThePenalty:
|
|
"""Ring date -> the alarm switch; penalty date -> the workout lock."""
|
|
|
|
def test_a_kept_alarm_on_the_ring_day_keeps_the_penalty(self) -> None:
|
|
mark_sick("2026-09-22", keep=[sickdays.LOCKER_ALARM])
|
|
_write({"penalty_date": "2026-09-23", "issued_date": "2026-09-22"})
|
|
assert workday_penalty_today(NOW) is True
|
|
|
|
def test_a_kept_workout_on_the_ring_day_still_voids_it(self) -> None:
|
|
mark_sick("2026-09-22", keep=[sickdays.LOCKER_WORKOUT])
|
|
_write({"penalty_date": "2026-09-23", "issued_date": "2026-09-22"})
|
|
assert workday_penalty_today(NOW) is False
|
|
|
|
def test_a_kept_workout_on_the_penalty_day_keeps_it(self) -> None:
|
|
mark_sick("2026-09-23", keep=[sickdays.LOCKER_WORKOUT])
|
|
_write({"penalty_date": "2026-09-23", "issued_date": "2026-09-22"})
|
|
assert workday_penalty_today(NOW) is True
|
|
|
|
def test_a_kept_alarm_on_the_penalty_day_still_voids_it(self) -> None:
|
|
mark_sick("2026-09-23", keep=[sickdays.LOCKER_ALARM])
|
|
_write({"penalty_date": "2026-09-23", "issued_date": "2026-09-22"})
|
|
assert workday_penalty_today(NOW) is False
|