mirror of
https://github.com/kuhyx/diet-guard.git
synced 2026-11-21 20:02:18 +01:00
Sick days: diet stands down only when the day does not keep it
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
file-length / file length <= 250 lines (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint) (push) Waiting to run
Tests / test (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
file-length / file length <= 250 lines (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint) (push) Waiting to run
Tests / test (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
due_slots asks sickdays.stands_down(LOCKER_DIET, day) instead of is_sick_day, so a sick day that keeps diet is a normal day for the gate. Bump sickdays pins to v0.2.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PAhbNszs5JKdtnD4uBi3xp
This commit is contained in:
parent
6587258da9
commit
8b82faf8f9
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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))
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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",
|
||||
]
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user