Compare commits

..

3 Commits

Author SHA1 Message Date
c4d2bbcd7d Bump deps: fln 23, gradle 9.9, astro, jsdom 31
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
release-apk / release (APK) (push) Has been cancelled
repo-contract / repo contract (push) Has been cancelled
Tests / flutter-coverage (push) Has been cancelled
Pin @emnapi core/runtime to stable 1.11.3: astro's peers
otherwise resolve to 2.0.0-beta.2 and astro check crashes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWZd3smuxDGmEgXkYP8
2026-11-07 08:44:45 +01:00
595c5f41e6 Pin gatelock v0.12.0
Also bump coverage 7.17.2 and ruff 0.17.4 for the freshness gate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWZd3smuxDGmEgXkYP8
2026-11-07 08:31:14 +01:00
856f0c0774 Lift armed lock when carrot lands late
Poll morning_session every 15s (05:00-11:00) while the lock is
up; on a signed skip bank the early-bird marker, record
wake_alarm_skip_late and leave through the normal close().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWZd3smuxDGmEgXkYP8
2026-11-07 08:11:39 +01:00
12 changed files with 761 additions and 281 deletions

View File

@ -136,7 +136,7 @@ repos:
# direct URLs for one distribution, so any pin that drifts from
# the manifest becomes an unresolvable hook environment rather
# than merely an old one.
- gatelock @ git+https://github.com/kuhyx/utils@gatelock-v0.11.0#subdirectory=gatelock
- gatelock @ git+https://github.com/kuhyx/utils@gatelock-v0.12.0#subdirectory=gatelock
- 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.21.0#subdirectory=earned_time
- freedays @ git+https://github.com/kuhyx/utils@freedays-v0.4.0#subdirectory=freedays
@ -159,7 +159,7 @@ repos:
# direct URLs for one distribution, so any pin that drifts from
# the manifest becomes an unresolvable hook environment rather
# than merely an old one.
- gatelock @ git+https://github.com/kuhyx/utils@gatelock-v0.11.0#subdirectory=gatelock
- gatelock @ git+https://github.com/kuhyx/utils@gatelock-v0.12.0#subdirectory=gatelock
- 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.21.0#subdirectory=earned_time
- freedays @ git+https://github.com/kuhyx/utils@freedays-v0.4.0#subdirectory=freedays

View File

@ -7,7 +7,7 @@ requires-python = ">=3.14"
# crdt-sync: shared CRDT merge scheme + sync transports, also used by
# diet_guard; here for phone-workout sync, Firebase RTDB only since 2026-10-09
dependencies = [
"gatelock @ git+https://github.com/kuhyx/utils@gatelock-v0.11.0#subdirectory=gatelock",
"gatelock @ git+https://github.com/kuhyx/utils@gatelock-v0.12.0#subdirectory=gatelock",
"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",
"earned-time @ git+https://github.com/kuhyx/utils@earned-time-v0.21.0#subdirectory=earned_time",

View File

@ -2,11 +2,11 @@
# Runtime: tkinter/subprocess/socket/sqlite3 (stdlib) plus gatelock (below).
bandit==1.9.4
codespell==2.4.3
coverage==7.17.1
coverage==7.17.2
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.21.0#subdirectory=earned_time
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.12.0#subdirectory=gatelock
holds @ git+https://github.com/kuhyx/utils@holds-v0.1.0#subdirectory=holds
mcp==2.3.0
mypy==2.4.1
@ -21,7 +21,7 @@ pytest-xdist==3.8.0
# token over the REST endpoint; crdt-sync already pulls requests in, but this
# module imports it itself, so it is declared rather than assumed.
requests==2.34.2
ruff==0.17.3
ruff==0.17.4
sickdays @ git+https://github.com/kuhyx/utils@sickdays-v0.4.0#subdirectory=sickdays
types-requests==2.33.0.20261030
# Direct dependency since the Firebase session stream (_session_stream) catches

View File

@ -25,7 +25,7 @@ import sys
from screen_locker._decision_log import LockDecision, record_decision
from screen_locker._decision_reasons import reasons_extra
from screen_locker._hold import workout_hold_active
from screen_locker._morning_session import has_workout_skip_today
from screen_locker._morning_session import MorningSkip, has_workout_skip_today
from screen_locker._night_lockdown import has_evening_lockdown_today
from screen_locker._sick import stands_down_workout
from screen_locker._weekly_check import has_weekly_minimum, is_relaxed_day
@ -153,6 +153,34 @@ class AutoUpgradeMixin(_ReasonsMixin):
return False
return True
def _stand_down_for_carrot(self, skip: MorningSkip) -> None:
"""Take an armed lock down because the carrot landed after it armed.
Does what the ``wake_alarm_skip`` rung above does -- bank the pending
marker so the post-carrot run still tries the phone workout, record the
decision -- then leaves through the locker's normal ``close`` (the same
one a credited workout and a test hold use): lock window released,
instance lock dropped, exit 0. Nothing is credited or penalised.
"""
self._save_early_bird_pending()
record_decision(
LockDecision(
locked=False,
reason="wake_alarm_skip_late",
detail=f"Morning session carrot landed after the lock armed: {skip}.",
extra={
"exempt_until": skip.exempt_until.isoformat(),
"outcome": skip.outcome,
},
)
)
_logger.warning(
"Morning-session carrot appeared while the lock was up (%s) — "
"taking the lock down; the early-bird marker is banked.",
skip,
)
self.close()
def _try_auto_upgrade_early_bird(self) -> bool:
"""Try phone then RunnerUp to upgrade an early_bird log entry."""
try:

View File

@ -0,0 +1,76 @@
"""An armed lock stands down when wake-alarm's signed carrot lands late.
2026-11-07: the lock armed at 07:49:17 because today's signed
``morning_session.json`` had not landed yet (the refresher lost a network
race). It landed at 07:50:00 (``in_progress``, exempt until 09:13) and nothing
ever re-read it, so the morning session ran under a fullscreen lock. The
startup ladder reads the file once; this is the same verdict, re-asked every
``POLL_MS`` while the window is up.
The decision stays wake-alarm's (signature ok, dated today, now < exempt_until);
this module only decides *when to ask* -- 05:00-11:00 local, the hours the
refresher runs -- and never waits, since it sits on the Tk loop. The file is
read through the ``_morning_session`` module attribute so the test suite's
redirected path applies.
"""
from __future__ import annotations
from datetime import UTC, datetime
import logging
from typing import TYPE_CHECKING
from screen_locker import _morning_session
if TYPE_CHECKING:
from collections.abc import Callable
from tkinter import Misc
__all__ = ["POLL_MS", "watch_for_carrot"]
_logger = logging.getLogger(__name__)
POLL_MS = 15_000
# Local minutes after midnight; mirrors gatelock.morning_session.MORNING_WINDOW.
_WINDOW_START_MIN = 5 * 60
_WINDOW_END_MIN = 11 * 60
def _local_now() -> datetime:
return datetime.now(tz=UTC).astimezone()
def _in_window(now: datetime) -> bool:
return _WINDOW_START_MIN <= now.hour * 60 + now.minute < _WINDOW_END_MIN
def watch_for_carrot(
root: Misc, on_carrot: Callable[[_morning_session.MorningSkip], None]
) -> None:
"""Hand a late-landing signed carrot to ``on_carrot`` within one poll.
``on_carrot`` is the locker's own stand-down (bank the early-bird marker,
record the decision, then the normal ``close``). Polls on the Tk loop (no
thread) and stops re-arming once it fires. A failed read is logged and the
poll goes on: one bad read must not end the only thing watching.
"""
def _tick() -> None:
now = _local_now()
if _in_window(now):
try:
skip = _morning_session.morning_skip_today(now, wait=False)
except (OSError, ValueError, TypeError, KeyError) as exc:
_logger.warning(
"Could not read the morning session while the lock is up "
"(%s) — keeping the lock and trying again in %d s",
exc,
POLL_MS // 1000,
)
skip = None
if skip is not None:
on_carrot(skip)
return
root.after(POLL_MS, _tick)
root.after(POLL_MS, _tick)

View File

@ -22,6 +22,7 @@ from gatelock import (
from screen_locker import _instance
from screen_locker._auto_upgrade import AutoUpgradeMixin
from screen_locker._carrot_watch import watch_for_carrot
from screen_locker._constants import (
EARLY_BIRD_END_HOUR,
EARLY_BIRD_END_MINUTE,
@ -210,6 +211,7 @@ class ScreenLocker(
if self._lock is not None: # pragma: no branch
self._lock.grab_input()
watch_for_hold(self.root, self.close)
watch_for_carrot(self.root, self._stand_down_for_carrot)
def close(self) -> None:
"""Close the application and exit."""

View File

@ -0,0 +1,193 @@
"""An armed lock takes itself down when wake-alarm's signed carrot lands late.
2026-11-07: the lock armed at 07:49 because today's morning_session.json had
not landed; it landed at 07:50 and nothing re-read it, so the morning session
ran under a fullscreen lock.
"""
from __future__ import annotations
from datetime import datetime, timedelta
import json
import logging
from typing import TYPE_CHECKING
from unittest.mock import MagicMock, patch
from gatelock.log_integrity import compute_entry_hmac
import pytest
from screen_locker import _carrot_watch, _morning_session
from screen_locker._carrot_watch import POLL_MS, watch_for_carrot
from screen_locker._morning_session import MorningSkip
from screen_locker.tests.conftest import create_locker
if TYPE_CHECKING:
from collections.abc import Iterator
from pathlib import Path
_EIGHT = datetime(2026, 11, 7, 8, 0).astimezone()
@pytest.fixture(autouse=True)
def _signing_key(tmp_path: Path) -> Iterator[None]:
key = tmp_path / "hmac.key"
key.write_bytes(b"1" * 32)
with patch("gatelock.log_integrity.DEFAULT_HMAC_KEY_FILE", key):
yield
def _sign(date: str, until: datetime) -> None:
"""Write a signed session file into the conftest-redirected path."""
entry: dict[str, object] = {
"date": date,
"outcome": "in_progress",
"exempt_until": until.isoformat(),
}
entry["hmac"] = compute_entry_hmac(entry)
_morning_session.MORNING_SESSION_FILE.write_text(json.dumps(entry))
def _tick(now: datetime) -> tuple[MagicMock, MagicMock]:
"""Arm the watch, run its first poll at ``now``; return (root, on_carrot)."""
root, on_carrot = MagicMock(), MagicMock()
watch_for_carrot(root, on_carrot)
with patch.object(_carrot_watch, "_local_now", return_value=now):
root.after.call_args.args[1]()
return root, on_carrot
class TestWatchForCarrot:
"""The poll on the Tk loop."""
def test_local_now_is_timezone_aware_local_time(self) -> None:
"""The poll's clock is the real, aware local time."""
assert abs(_carrot_watch._local_now() - datetime.now().astimezone()) < (
timedelta(seconds=5)
)
def test_arms_a_fifteen_second_poll(self) -> None:
"""Arming schedules the first check 15 s out and releases nothing."""
root, on_carrot = MagicMock(), MagicMock()
watch_for_carrot(root, on_carrot)
assert POLL_MS == 15_000
assert root.after.call_args.args[0] == POLL_MS
on_carrot.assert_not_called()
def test_signed_todays_skip_releases_once_and_stops_polling(self) -> None:
"""A skip that landed after arming is handed over; no re-arm."""
until = _EIGHT + timedelta(hours=1, minutes=13)
_sign("2026-11-07", until)
root, on_carrot = _tick(_EIGHT)
on_carrot.assert_called_once_with(MorningSkip("in_progress", until))
assert root.after.call_count == 1
def test_no_file_keeps_the_lock_and_reschedules(self) -> None:
"""No file: the lock stays and the next poll is scheduled."""
root, on_carrot = _tick(_EIGHT)
on_carrot.assert_not_called()
assert root.after.call_count == 2
assert root.after.call_args.args[0] == POLL_MS
def test_expired_skip_keeps_the_lock(self) -> None:
"""A carrot whose exempt_until has passed is no skip."""
_sign("2026-11-07", _EIGHT - timedelta(minutes=1))
root, on_carrot = _tick(_EIGHT)
on_carrot.assert_not_called()
assert root.after.call_count == 2
def test_yesterdays_file_keeps_the_lock(self) -> None:
"""A file dated another day is no skip."""
_sign("2026-11-06", _EIGHT + timedelta(hours=3))
_root, on_carrot = _tick(_EIGHT)
on_carrot.assert_not_called()
@pytest.mark.parametrize(("hour", "minute"), [(4, 59), (11, 0), (23, 30)])
def test_outside_05_to_11_never_reads_or_releases(
self, hour: int, minute: int
) -> None:
"""Outside 05:00-11:00 local the poll neither reads nor releases."""
now = _EIGHT.replace(hour=hour, minute=minute)
_sign("2026-11-07", now + timedelta(hours=1))
with patch.object(_carrot_watch._morning_session, "morning_skip_today") as read:
root, on_carrot = _tick(now)
read.assert_not_called()
on_carrot.assert_not_called()
assert root.after.call_count == 2
def test_inside_window_reads_without_waiting(self) -> None:
"""The poll never waits: it must not block the Tk loop."""
with patch.object(
_carrot_watch._morning_session, "morning_skip_today", return_value=None
) as read:
_tick(_EIGHT)
read.assert_called_once_with(_EIGHT, wait=False)
def test_reader_failure_is_logged_and_the_poll_survives(
self, caplog: pytest.LogCaptureFixture
) -> None:
"""A read error warns and re-arms; one bad read must not end the watch."""
with (
patch.object(
_carrot_watch._morning_session,
"morning_skip_today",
side_effect=OSError("disk gone"),
),
caplog.at_level(logging.WARNING, logger="screen_locker._carrot_watch"),
):
root, on_carrot = _tick(_EIGHT)
on_carrot.assert_not_called()
assert root.after.call_count == 2
assert "disk gone" in caplog.text
class TestLockerStandsDown:
"""The locker side: marker, decision, warning, then the real close."""
def test_construction_arms_the_watch(
self, mock_tk: MagicMock, tmp_path: Path
) -> None:
"""A built locker watches on its own root and its own stand-down."""
with patch("screen_locker.screen_lock.watch_for_carrot") as watch:
locker = create_locker(mock_tk, tmp_path)
watch.assert_called_once_with(locker.root, locker._stand_down_for_carrot)
def test_stand_down_banks_marker_records_decision_then_closes(
self,
mock_tk: MagicMock,
tmp_path: Path,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Marker first, decision lock=no, warning, and only then close()."""
locker = create_locker(mock_tk, tmp_path)
until = _EIGHT + timedelta(hours=1)
order = MagicMock()
with (
patch.object(locker, "_save_early_bird_pending", order.save),
patch("screen_locker._auto_upgrade.record_decision", order.record),
patch.object(locker, "close", order.close),
caplog.at_level(logging.WARNING, logger="screen_locker._auto_upgrade"),
):
locker._stand_down_for_carrot(MorningSkip("in_progress", until))
assert [c[0] for c in order.mock_calls] == ["save", "record", "close"]
decision = order.record.call_args.args[0]
assert decision.locked is False
assert decision.reason == "wake_alarm_skip_late"
assert decision.extra["exempt_until"] == until.isoformat()
assert decision.extra["outcome"] == "in_progress"
assert "carrot" in caplog.text.lower()
def test_stand_down_goes_through_the_real_close_and_exits_zero(
self, mock_tk: MagicMock, mock_sys_exit: MagicMock, tmp_path: Path
) -> None:
"""The real ``close``: lock window released, instance lock dropped, exit 0."""
locker = create_locker(mock_tk, tmp_path)
with (
patch.object(locker, "_save_early_bird_pending"),
patch("screen_locker._auto_upgrade.record_decision"),
patch.object(locker, "_lock") as lock,
patch.object(locker._instance_lock, "release") as release,
):
locker._stand_down_for_carrot(MorningSkip("completed", _EIGHT))
lock.close.assert_called_once_with()
release.assert_called_once_with()
mock_sys_exit.assert_called_once_with(0)

View File

@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.8.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.9.0-all.zip

View File

@ -380,42 +380,42 @@ packages:
dependency: "direct main"
description:
name: flutter_local_notifications
sha256: fd5fc8966a8b34337ac182dc394f3506139b69d8138d4e9e174a13d6468adcd4
sha256: e99e9c6078d1359ba131b2c1eb8d68837170836a01bf2cea3cf2fa13e62ac2ac
url: "https://pub.dev"
source: hosted
version: "22.3.3"
version: "23.0.0"
flutter_local_notifications_linux:
dependency: transitive
description:
name: flutter_local_notifications_linux
sha256: "3b89a4bf095fa5f8a99beeabf982c5bd506c3ad25e7b9e61da945e994dc5b615"
sha256: bcbcf3c15e33b6866805092308f5f6ef27e1191874f6a92ef59213a0812a79a2
url: "https://pub.dev"
source: hosted
version: "8.0.2"
version: "9.0.0"
flutter_local_notifications_platform_interface:
dependency: transitive
description:
name: flutter_local_notifications_platform_interface
sha256: "43c3761d916c9bd3d5c7ebbc44d82f4990329840c0c5d62ad5260cc1b5d399bd"
sha256: "4a49db4ce3d633ebc85c85b5fa959572600ec10bd097419c454579444308a0a0"
url: "https://pub.dev"
source: hosted
version: "12.2.0"
version: "13.0.0"
flutter_local_notifications_web:
dependency: transitive
description:
name: flutter_local_notifications_web
sha256: "516afaf97a2d1e67a036c6617321b00d205d72f7a67b6eccf936cd565f985878"
sha256: ef117694fbfcd82308ab0e324cfc9282fa50c192e24ec54a58173ae327ebc544
url: "https://pub.dev"
source: hosted
version: "1.0.0"
version: "2.0.0"
flutter_local_notifications_windows:
dependency: transitive
description:
name: flutter_local_notifications_windows
sha256: "6f43bdd03b171b7a90f22647506fea33e2bb12294b7c7c7a3d690e960a382945"
sha256: c2d6efe9ba585d5f560d8b329131f00fe745834848e6221b22d1f62e0f0b16e2
url: "https://pub.dev"
source: hosted
version: "3.1.1"
version: "4.0.0"
flutter_secure_storage:
dependency: "direct main"
description:

View File

@ -31,7 +31,7 @@ dependencies:
flutter_foreground_task: 11.0.3
# The break-end alert itself, on its own high-importance channel so the OS
# rings even if the Flutter isolate is busy.
flutter_local_notifications: 22.3.3
flutter_local_notifications: 23.0.0
flutter_secure_storage: 11.2.0
# One-tap sign-in for the sync account. App-side only: crdt_sync stays pure

View File

@ -2,7 +2,7 @@
"name": "screen-locker-web",
"private": true,
"version": "0.0.0",
"packageManager": "pnpm@12.16.1",
"packageManager": "pnpm@12.18.0",
"type": "module",
"scripts": {
"dev": "astro dev",
@ -16,10 +16,12 @@
},
"dependencies": {
"@kuhyx/web-ui": "github:kuhyx/utils#web_ui-v0.5.0&path:/web_ui",
"astro": "7.4.5"
"astro": "7.4.7"
},
"devDependencies": {
"@astrojs/check": "0.9.12",
"@emnapi/core": "1.11.3",
"@emnapi/runtime": "1.11.3",
"@eslint/js": "10.0.1",
"@testing-library/dom": "10.4.2",
"@testing-library/jest-dom": "7.0.1",
@ -29,7 +31,7 @@
"eslint": "10.14.0",
"eslint-plugin-astro": "3.2.1",
"globals": "17.14.0",
"jsdom": "30.1.3",
"jsdom": "31.0.0",
"typescript": "6.0.3",
"typescript-eslint": "8.72.1",
"vitest": "5.1.0"

File diff suppressed because it is too large Load Diff