diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2d524d7..f79caf4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -109,7 +109,7 @@ repos: - gatelock @ git+https://github.com/kuhyx/utils@gatelock-v0.9.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 - - sickdays @ git+https://github.com/kuhyx/utils@sickdays-v0.1.0#subdirectory=sickdays + - sickdays @ git+https://github.com/kuhyx/utils@sickdays-v0.2.0#subdirectory=sickdays - mcp>=2,<3 - pydantic - defusedxml==0.7.1 diff --git a/app/pubspec.yaml b/app/pubspec.yaml index 9342963..d0f8d9e 100644 --- a/app/pubspec.yaml +++ b/app/pubspec.yaml @@ -2,7 +2,7 @@ name: diet_guard_app description: "Companion phone app for diet_guard: log meals on the go." publish_to: 'none' -version: 1.0.113+1 +version: 1.0.114+1 environment: sdk: ^3.12.2 diff --git a/diet_guard/_gate.py b/diet_guard/_gate.py index 2263af8..2b9dcce 100644 --- a/diet_guard/_gate.py +++ b/diet_guard/_gate.py @@ -42,16 +42,18 @@ def due_slots(now: datetime | None = None) -> tuple[int, ...]: Returns: The slot minutes that still need a meal logged (empty == nothing due). - Empty on a shared free day or a sick day, whatever the schedule says: the - gate stands down, so no lock opens and nothing accrues -- unlogged meals - leave no debt, and logging a meal still works as on any day. Each pool is + Empty on a shared free day or a sick day that does not keep diet, whatever + the schedule says: the gate stands down, so no lock opens and nothing + accrues -- unlogged meals leave no debt, and logging a meal still works as + on any day. A sick day that keeps diet (``sickdays`` keep set) is a normal + day here: the slots are due and the lock opens. Each pool is read from a single local file and never the network, so this cannot hang the systemd-fired gate, and an unreadable pool reads as "not free" / "not sick" -- the normal rules apply rather than the gate switching itself off. """ reference = now if now is not None else now_local() day = reference.date() - if freedays.is_free_day(day) or sickdays.is_sick_day(day): + if freedays.is_free_day(day) or sickdays.stands_down(sickdays.LOCKER_DIET, day): return () # One schedule for both halves: snapping the log onto a different schedule # than the one deriving the due slots would leave a logged meal covering a diff --git a/diet_guard/tests/test_gate.py b/diet_guard/tests/test_gate.py index eef8a18..0fcc106 100644 --- a/diet_guard/tests/test_gate.py +++ b/diet_guard/tests/test_gate.py @@ -122,10 +122,11 @@ class TestFreeDays: assert gate_is_due(_at(20)) -def _mark_sick(tmp_path: Path, day: date) -> None: +def _mark_sick(tmp_path: Path, day: date, keep: tuple[str, ...] = ()) -> None: """Put ``day`` in the (temp) sick-day pool; the redirect lives in conftest.""" sickdays.add_sick_day( day, + keep=keep, is_free=lambda _day: False, paths=sickdays.Paths.under(tmp_path / "sickdays"), now=day, @@ -143,6 +144,24 @@ class TestSickDays: assert not gate_is_due(_at(20)) assert gate_message(_at(20)) == "All meals are logged. You're up to date." + def test_a_sick_day_that_keeps_diet_stays_armed(self, tmp_path: Path) -> None: + """A kept locker behaves exactly as on a normal day.""" + with _logged(set()): + _mark_sick(tmp_path, _at(20).date(), keep=(sickdays.LOCKER_DIET,)) + assert due_slots(_at(20)) + assert gate_is_due(_at(20)) + + def test_a_sick_day_keeping_another_locker_still_stands_down( + self, tmp_path: Path + ) -> None: + with _logged(set()): + _mark_sick( + tmp_path, + _at(20).date(), + keep=(sickdays.LOCKER_WORKOUT, sickdays.LOCKER_ALARM), + ) + assert due_slots(_at(20)) == () + def test_a_sick_day_on_another_date_changes_nothing(self, tmp_path: Path) -> None: with _logged(set()): _mark_sick(tmp_path, date(2026, 12, 24)) diff --git a/docs/DOCS-sick-days.md b/docs/DOCS-sick-days.md index f6a8be8..89da27c 100644 --- a/docs/DOCS-sick-days.md +++ b/docs/DOCS-sick-days.md @@ -1,7 +1,9 @@ # Free days and sick days `_gate.due_slots` returns `()` on a shared free day (`freedays`) or a sick day -(`sickdays` 0.1.0, one pool for every gate). Nothing is due, so no lock opens, +(`sickdays` 0.2.0, one pool for every gate) -- unless that sick day *keeps* +diet (`sickdays.stands_down(LOCKER_DIET, day)` is False): a kept locker behaves +exactly as on a normal day. Nothing is due, so no lock opens, nothing is said about missing meals and no debt accrues. Logging a meal works as on any other day (the log path never consults the gate); diet-guard earns nothing, so there is nothing to credit. @@ -9,7 +11,7 @@ nothing, so there is nothing to credit. - Each pool is one local file, never the network, so the systemd-fired gate cannot hang on it. - **Fail closed:** an unreadable pool reads as "not free" / "not sick", so the - gate stays armed. `sickdays.is_sick_day` never raises. + gate stays armed. `sickdays.stands_down` never raises for a data problem. - Only the calendar day of `now` is asked (the last slot is at most 22:00, so the gate never runs on yesterday's slots after midnight). - Tests: `tests/_state_redirects.py` points both pools into `tmp_path`; a real diff --git a/pyproject.toml b/pyproject.toml index 5f9d08c..85a0652 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ dependencies = [ "gatelock @ git+https://github.com/kuhyx/utils@gatelock-v0.9.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", - "sickdays @ git+https://github.com/kuhyx/utils@sickdays-v0.1.0#subdirectory=sickdays", + "sickdays @ git+https://github.com/kuhyx/utils@sickdays-v0.2.0#subdirectory=sickdays", "defusedxml==0.7.1", "requests==2.34.2", ] diff --git a/requirements.txt b/requirements.txt index 2e171b0..80746bc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,4 +20,4 @@ pytest-xdist==3.8.0 pytest-xvfb==3.1.1 requests==2.34.2 ruff==0.17.1 -sickdays @ git+https://github.com/kuhyx/utils@sickdays-v0.1.0#subdirectory=sickdays +sickdays @ git+https://github.com/kuhyx/utils@sickdays-v0.2.0#subdirectory=sickdays