mirror of
https://github.com/kuhyx/screen-locker.git
synced 2026-11-28 16:29:07 +01:00
LeetCode bonus needs the day paid in full (earned_time 0.18.0); gate_off asked live
Some checks failed
dependency freshness / dependencies on newest stable (push) Has been cancelled
md-naming / markdown naming convention (push) Has been cancelled
pre-commit / pre-commit (${{ matrix.group }}) (flutter, flutter-analyze, ) (push) Has been cancelled
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Has been cancelled
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Has been cancelled
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint,flutter-analyze) (push) Has been cancelled
Tests / test (push) Has been cancelled
Tests / lock-popup-safety (push) Has been cancelled
Tests / flutter test (shard ${{ matrix.shard }}) (0) (push) Has been cancelled
Tests / flutter test (shard ${{ matrix.shard }}) (1) (push) Has been cancelled
Tests / flutter test (shard ${{ matrix.shard }}) (2) (push) Has been cancelled
Tests / flutter test (shard ${{ matrix.shard }}) (3) (push) Has been cancelled
Tests / flutter test (shard ${{ matrix.shard }}) (4) (push) Has been cancelled
Tests / flutter test (shard ${{ matrix.shard }}) (5) (push) Has been cancelled
Tests / flutter test (shard ${{ matrix.shard }}) (6) (push) Has been cancelled
Tests / flutter test (shard ${{ matrix.shard }}) (7) (push) Has been cancelled
Tests / flutter test (shard ${{ matrix.shard }}) (8) (push) Has been cancelled
Tests / flutter test (shard ${{ matrix.shard }}) (9) (push) Has been cancelled
Tests / web-coverage (push) Has been cancelled
repo-contract / repo contract (push) Has been cancelled
Tests / flutter-coverage (push) Has been cancelled
Some checks failed
dependency freshness / dependencies on newest stable (push) Has been cancelled
md-naming / markdown naming convention (push) Has been cancelled
pre-commit / pre-commit (${{ matrix.group }}) (flutter, flutter-analyze, ) (push) Has been cancelled
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Has been cancelled
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Has been cancelled
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint,flutter-analyze) (push) Has been cancelled
Tests / test (push) Has been cancelled
Tests / lock-popup-safety (push) Has been cancelled
Tests / flutter test (shard ${{ matrix.shard }}) (0) (push) Has been cancelled
Tests / flutter test (shard ${{ matrix.shard }}) (1) (push) Has been cancelled
Tests / flutter test (shard ${{ matrix.shard }}) (2) (push) Has been cancelled
Tests / flutter test (shard ${{ matrix.shard }}) (3) (push) Has been cancelled
Tests / flutter test (shard ${{ matrix.shard }}) (4) (push) Has been cancelled
Tests / flutter test (shard ${{ matrix.shard }}) (5) (push) Has been cancelled
Tests / flutter test (shard ${{ matrix.shard }}) (6) (push) Has been cancelled
Tests / flutter test (shard ${{ matrix.shard }}) (7) (push) Has been cancelled
Tests / flutter test (shard ${{ matrix.shard }}) (8) (push) Has been cancelled
Tests / flutter test (shard ${{ matrix.shard }}) (9) (push) Has been cancelled
Tests / web-coverage (push) Has been cancelled
repo-contract / repo contract (push) Has been cancelled
Tests / flutter-coverage (push) Has been cancelled
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
814ad87301
commit
06c50a9231
@ -10,7 +10,7 @@ dependencies = [
|
|||||||
"gatelock @ git+https://github.com/kuhyx/utils@gatelock-v0.11.0#subdirectory=gatelock",
|
"gatelock @ git+https://github.com/kuhyx/utils@gatelock-v0.11.0#subdirectory=gatelock",
|
||||||
"crdt-sync @ git+https://github.com/kuhyx/utils@crdt-sync-v0.9.2#subdirectory=crdt-sync",
|
"crdt-sync @ git+https://github.com/kuhyx/utils@crdt-sync-v0.9.2#subdirectory=crdt-sync",
|
||||||
"freedays @ git+https://github.com/kuhyx/utils@freedays-v0.4.0#subdirectory=freedays",
|
"freedays @ git+https://github.com/kuhyx/utils@freedays-v0.4.0#subdirectory=freedays",
|
||||||
"earned-time @ git+https://github.com/kuhyx/utils@earned-time-v0.17.0#subdirectory=earned_time",
|
"earned-time @ git+https://github.com/kuhyx/utils@earned-time-v0.18.0#subdirectory=earned_time",
|
||||||
"sickdays @ git+https://github.com/kuhyx/utils@sickdays-v0.3.0#subdirectory=sickdays",
|
"sickdays @ git+https://github.com/kuhyx/utils@sickdays-v0.3.0#subdirectory=sickdays",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,7 @@ bandit==1.9.4
|
|||||||
codespell==2.4.3
|
codespell==2.4.3
|
||||||
coverage==7.17.0
|
coverage==7.17.0
|
||||||
crdt-sync @ git+https://github.com/kuhyx/utils@crdt-sync-v0.9.2#subdirectory=crdt-sync
|
crdt-sync @ git+https://github.com/kuhyx/utils@crdt-sync-v0.9.2#subdirectory=crdt-sync
|
||||||
earned-time @ git+https://github.com/kuhyx/utils@earned-time-v0.17.0#subdirectory=earned_time
|
earned-time @ git+https://github.com/kuhyx/utils@earned-time-v0.18.0#subdirectory=earned_time
|
||||||
freedays @ git+https://github.com/kuhyx/utils@freedays-v0.4.0#subdirectory=freedays
|
freedays @ git+https://github.com/kuhyx/utils@freedays-v0.4.0#subdirectory=freedays
|
||||||
gatelock @ git+https://github.com/kuhyx/utils@gatelock-v0.11.0#subdirectory=gatelock
|
gatelock @ git+https://github.com/kuhyx/utils@gatelock-v0.11.0#subdirectory=gatelock
|
||||||
mcp==2.3.0
|
mcp==2.3.0
|
||||||
|
|||||||
@ -16,7 +16,7 @@ midnight, so a 30-minute earner is applied exactly.
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from datetime import date, datetime
|
from datetime import UTC, date, datetime
|
||||||
import functools
|
import functools
|
||||||
import logging
|
import logging
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@ -26,6 +26,7 @@ import earned_time
|
|||||||
|
|
||||||
from screen_locker._constants import HMAC_KEY_FILE
|
from screen_locker._constants import HMAC_KEY_FILE
|
||||||
from screen_locker._day import today_str
|
from screen_locker._day import today_str
|
||||||
|
from screen_locker._gate_off import gate_off
|
||||||
|
|
||||||
_logger: Final = logging.getLogger(__name__)
|
_logger: Final = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -105,12 +106,25 @@ def earned_today(
|
|||||||
earner: earned_time.Earner, now: datetime | None = None
|
earner: earned_time.Earner, now: datetime | None = None
|
||||||
) -> bool | None:
|
) -> bool | None:
|
||||||
"""Whether ``earner``'s gate recorded today's credit; ``None`` if unknown."""
|
"""Whether ``earner``'s gate recorded today's credit; ``None`` if unknown."""
|
||||||
return earned_time.done_today(earner, ledger_file(earner), HMAC_KEY_FILE, now=now)
|
day = (now or datetime.now(tz=UTC)).astimezone().date()
|
||||||
|
return earned_time.done_today(
|
||||||
|
earner,
|
||||||
|
ledger_file(earner),
|
||||||
|
HMAC_KEY_FILE,
|
||||||
|
now=now,
|
||||||
|
gate_off=gate_off(earner, day),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def earned_units(earner: earned_time.Earner, day: date) -> int | None:
|
def earned_units(earner: earned_time.Earner, day: date) -> int | None:
|
||||||
"""How many of a counted earner's units count for ``day``; ``None`` if unknown."""
|
"""How many of a counted earner's units count for ``day``; ``None`` if unknown."""
|
||||||
return earned_time.credit_units(earner, ledger_file(earner), HMAC_KEY_FILE, day)
|
return earned_time.credit_units(
|
||||||
|
earner,
|
||||||
|
ledger_file(earner),
|
||||||
|
HMAC_KEY_FILE,
|
||||||
|
day,
|
||||||
|
gate_off=gate_off(earner, day),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def gate_answers(day: date | None = None) -> dict[str, int | bool | None]:
|
def gate_answers(day: date | None = None) -> dict[str, int | bool | None]:
|
||||||
@ -179,7 +193,9 @@ def first_credit_time(earner: earned_time.Earner, day: date) -> float | None:
|
|||||||
if fn is None:
|
if fn is None:
|
||||||
_warn_no_first_credit()
|
_warn_no_first_credit()
|
||||||
return None
|
return None
|
||||||
stamp: float | None = fn(earner, ledger_file(earner), HMAC_KEY_FILE, day)
|
stamp: float | None = fn(
|
||||||
|
earner, ledger_file(earner), HMAC_KEY_FILE, day, gate_off=gate_off(earner, day)
|
||||||
|
)
|
||||||
return stamp
|
return stamp
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
28
screen_locker/_gate_off.py
Normal file
28
screen_locker/_gate_off.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
"""Whether an earner's gate stands down today, asked live (earned_time 0.18.0).
|
||||||
|
|
||||||
|
Only LeetCode has a price: while its gate is on, earned_time pays only the
|
||||||
|
signed charge that covers the whole day, never one solve of five (kuhy,
|
||||||
|
2026-10-24). A free day or a sick day not keeping ``leetcode`` has no price,
|
||||||
|
so one verified solve earns. Never stored: clearing the sick day takes the
|
||||||
|
exception back on the next read.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
import earned_time
|
||||||
|
import freedays
|
||||||
|
import sickdays
|
||||||
|
|
||||||
|
from screen_locker._sick import stands_down
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from datetime import date
|
||||||
|
|
||||||
|
|
||||||
|
def gate_off(earner: earned_time.Earner, day: date) -> bool:
|
||||||
|
"""Whether ``earner``'s gate is off on ``day`` (always False but LeetCode)."""
|
||||||
|
if earner.name != earned_time.LEETCODE.name:
|
||||||
|
return False
|
||||||
|
return freedays.is_free_day(day) or stands_down(sickdays.LOCKER_LEETCODE, day)
|
||||||
@ -10,8 +10,10 @@ other. ``_isolate_home`` covers paths resolved at *call* time from
|
|||||||
``Path.home()``; ``_no_free_days_by_default`` covers paths bound into module
|
``Path.home()``; ``_no_free_days_by_default`` covers paths bound into module
|
||||||
constants at *import* time, which redirecting home afterwards cannot reach.
|
constants at *import* time, which redirecting home afterwards cannot reach.
|
||||||
|
|
||||||
``pre_ladder`` is the one opt-in fixture here: it keeps a test off the real
|
``pre_ladder`` and ``leetcode_gate_off`` are the opt-in fixtures here:
|
||||||
calendar's ladder cutover, the date-dependent half of the same question.
|
``pre_ladder`` keeps a test off the real calendar's ladder cutover, the
|
||||||
|
date-dependent half of the same question; ``leetcode_gate_off`` keeps
|
||||||
|
ledger-plumbing tests off LeetCode's paid-in-full rule.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
@ -172,6 +174,17 @@ def pre_ladder(monkeypatch: pytest.MonkeyPatch) -> None:
|
|||||||
monkeypatch.setattr("earned_time._ladder.LADDER_FROM", date.max)
|
monkeypatch.setattr("earned_time._ladder.LADDER_FROM", date.max)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def leetcode_gate_off(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||||
|
"""Let a bare LeetCode credit earn, as on a free or stood-down sick day.
|
||||||
|
|
||||||
|
These tests pin the shared ledger plumbing with one credit row per earner.
|
||||||
|
Since earned_time 0.18.0 a LeetCode credit alone earns only while the gate
|
||||||
|
is off; the paid-in-full rule itself is ``test_leetcode_gate_off.py``.
|
||||||
|
"""
|
||||||
|
monkeypatch.setattr("screen_locker._earned.gate_off", lambda _earner, _day: True)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def _no_real_night_lockdown(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
def _no_real_night_lockdown(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||||
"""Never let the lock chain read the machine's real night-lockdown stamp.
|
"""Never let the lock chain read the machine's real night-lockdown stamp.
|
||||||
|
|||||||
@ -133,6 +133,7 @@ class TestFlatEarners:
|
|||||||
assert f"{earner.name}_bonus_date" in seeded
|
assert f"{earner.name}_bonus_date" in seeded
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("leetcode_gate_off")
|
||||||
class TestEarnedToday:
|
class TestEarnedToday:
|
||||||
@_LEDGERED
|
@_LEDGERED
|
||||||
def test_signed_credit_today_earns(
|
def test_signed_credit_today_earns(
|
||||||
@ -215,6 +216,7 @@ class TestCannotCheck:
|
|||||||
assert "not valid JSON" in caplog.text
|
assert "not valid JSON" in caplog.text
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("leetcode_gate_off")
|
||||||
class TestFlatAnswers:
|
class TestFlatAnswers:
|
||||||
def test_every_flat_earner_answers_by_name(self, key: Path) -> None:
|
def test_every_flat_earner_answers_by_name(self, key: Path) -> None:
|
||||||
write_ledger(earned_time.LEETCODE, [credit(earned_time.LEETCODE)])
|
write_ledger(earned_time.LEETCODE, [credit(earned_time.LEETCODE)])
|
||||||
|
|||||||
66
screen_locker/tests/test_leetcode_gate_off.py
Normal file
66
screen_locker/tests/test_leetcode_gate_off.py
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
"""The LeetCode shutdown hour needs the day paid in full (earned_time 0.18.0).
|
||||||
|
|
||||||
|
kuhy, 2026-10-24: Saturday cost 5 credits, one problem was solved, and the
|
||||||
|
+1 h shutdown paid anyway. earned_time now counts only the signed ``leetcode``
|
||||||
|
charge while the gate is on; screen-locker has to say, live, when the gate is
|
||||||
|
off (a free day, or a sick day not keeping ``leetcode``), because only then
|
||||||
|
does one verified solve earn on its own.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from datetime import date
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
import earned_time
|
||||||
|
import freedays
|
||||||
|
import pytest
|
||||||
|
import sickdays
|
||||||
|
|
||||||
|
from screen_locker import _earned, _gate_off
|
||||||
|
|
||||||
|
SAT = date(2026, 10, 24)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def pools(monkeypatch: pytest.MonkeyPatch) -> dict[str, bool]:
|
||||||
|
"""Fake the free-day and sick-day pools; flip the returned flags."""
|
||||||
|
flags = {"free": False, "sick_off": False}
|
||||||
|
monkeypatch.setattr(freedays, "is_free_day", lambda _day=None: flags["free"])
|
||||||
|
|
||||||
|
def stands_down(locker: str, _day: date | None = None) -> bool:
|
||||||
|
return locker == sickdays.LOCKER_LEETCODE and flags["sick_off"]
|
||||||
|
|
||||||
|
monkeypatch.setattr(sickdays, "stands_down", stands_down)
|
||||||
|
return flags
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("free", "sick_off", "expected"),
|
||||||
|
[(False, False, False), (True, False, True), (False, True, True)],
|
||||||
|
)
|
||||||
|
def test_gate_off_follows_the_pools(
|
||||||
|
pools: dict[str, bool], *, free: bool, sick_off: bool, expected: bool
|
||||||
|
) -> None:
|
||||||
|
pools.update(free=free, sick_off=sick_off)
|
||||||
|
assert _gate_off.gate_off(earned_time.LEETCODE, SAT) is expected
|
||||||
|
|
||||||
|
|
||||||
|
def test_only_leetcode_has_a_gate_to_switch_off(pools: dict[str, bool]) -> None:
|
||||||
|
pools.update(free=True, sick_off=True)
|
||||||
|
assert _gate_off.gate_off(earned_time.READING, SAT) is False
|
||||||
|
|
||||||
|
|
||||||
|
def test_every_ledger_read_passes_it(pools: dict[str, bool]) -> None:
|
||||||
|
pools.update(free=True)
|
||||||
|
leet = earned_time.LEETCODE
|
||||||
|
with (
|
||||||
|
patch.object(earned_time, "done_today", return_value=True) as done,
|
||||||
|
patch.object(earned_time, "first_credit_at", return_value=1.0) as first,
|
||||||
|
patch.object(earned_time, "credit_units", return_value=1) as units,
|
||||||
|
):
|
||||||
|
_earned.earned_today(leet)
|
||||||
|
_earned.first_credit_time(leet, SAT)
|
||||||
|
_earned.earned_units(leet, SAT)
|
||||||
|
for mock in (done, first, units):
|
||||||
|
assert mock.call_args.kwargs["gate_off"] is True
|
||||||
@ -145,6 +145,7 @@ class TestANewlyRegisteredEarner:
|
|||||||
assert (base_minutes(eve), base_minutes(cut)) == (before[0], before[1] - 60)
|
assert (base_minutes(eve), base_minutes(cut)) == (before[0], before[1] - 60)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("leetcode_gate_off")
|
||||||
class TestRealLedgers:
|
class TestRealLedgers:
|
||||||
@pytest.mark.usefixtures("pre_ladder")
|
@pytest.mark.usefixtures("pre_ladder")
|
||||||
def test_signed_credits_on_disk_reach_the_reset(self, tmp_path: Path) -> None:
|
def test_signed_credits_on_disk_reach_the_reset(self, tmp_path: Path) -> None:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user