Compare commits

..

No commits in common. "6587258da90650e07e0a28391d97a5041cd50219" and "f2606fe0ca6a472f1c0362d1666bbbfe4869882f" have entirely different histories.

11 changed files with 26 additions and 117 deletions

View File

@ -107,9 +107,8 @@ repos:
# the manifest becomes an unresolvable hook environment rather
# than merely an old one.
- 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
- crdt-sync @ git+https://github.com/kuhyx/utils@crdt-sync-v0.9.1#subdirectory=crdt-sync
- freedays @ git+https://github.com/kuhyx/utils@freedays-v0.3.0#subdirectory=freedays
- mcp>=2,<3
- pydantic
- defusedxml==0.7.1

View File

@ -32,8 +32,8 @@ catch-up rule).
`diet-guard-gate.timer` is wall-clock (`OnCalendar=*-*-* *:00/15:00`,
`Persistent=true`), not boot-relative — a boot-relative timer collided with
fullscreen games grabbing input. `diet-guard-gate.service` is `Type=oneshot`
and exits 0 at once when no lock is due (free/sick day: [docs/DOCS-sick-days.md](docs/DOCS-sick-days.md)).
Needs `DISPLAY`/`XAUTHORITY`; see the unit file and `wait_for_display()`.
and exits 0 immediately when no lock is due. It needs `DISPLAY`/`XAUTHORITY`;
see the unit file's comments and `wait_for_display()`.
## Cross-device sync

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.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.8.0-all.zip

View File

@ -203,18 +203,18 @@ packages:
dependency: "direct main"
description:
name: flutter_local_notifications
sha256: "9ee28742343dd13df758bb4185e8ded37ac2d1aeca6648c3ba7862c99797517e"
sha256: "357be7ff996dc272e2037c69c1bdd5d1bd21172219d55f8bd2e11aeea602e6d3"
url: "https://pub.dev"
source: hosted
version: "22.3.2"
version: "22.3.1"
flutter_local_notifications_linux:
dependency: transitive
description:
name: flutter_local_notifications_linux
sha256: "3b89a4bf095fa5f8a99beeabf982c5bd506c3ad25e7b9e61da945e994dc5b615"
sha256: "9ca97e63776f29ab1b955725c09999fc2c150523269db150c39274f2a43c5a8b"
url: "https://pub.dev"
source: hosted
version: "8.0.2"
version: "8.0.1"
flutter_local_notifications_platform_interface:
dependency: transitive
description:
@ -390,10 +390,10 @@ packages:
dependency: "direct main"
description:
name: idb_shim
sha256: "4f32cd03ce97e2996b57cea03b2d098f5153ac55435a27cf2c89716db571728d"
sha256: "110fe0514a52dc8da5414df42405a8f9e880dfac3e84852fdab8e5559ee6ad07"
url: "https://pub.dev"
source: hosted
version: "2.10.1+1"
version: "2.9.11"
image:
dependency: transitive
description:

View File

@ -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.111+1
environment:
sdk: ^3.12.2
@ -17,7 +17,7 @@ dependencies:
fl_chart: 1.2.0
flutter:
sdk: flutter
flutter_local_notifications: 22.3.2
flutter_local_notifications: 22.3.1
flutter_secure_storage: 11.2.0
# One-tap sign-in for the sync account. App-side only: crdt_sync stays pure
@ -30,7 +30,7 @@ dependencies:
google_sign_in: 7.2.0
health: 13.3.2
http: 1.6.0
idb_shim: 2.10.1+1
idb_shim: 2.9.11
path: 1.9.1
path_provider: 2.1.6
permission_handler: 13.0.2

View File

@ -18,7 +18,6 @@ from __future__ import annotations
from typing import TYPE_CHECKING
import freedays
import sickdays
from diet_guard._meal_schedule_store import current_schedule
from diet_guard._slots import missing_slots, slot_label
@ -42,16 +41,13 @@ 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
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.
Empty on a shared free day, whatever the schedule says. The 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" -- 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(reference.date()):
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

View File

@ -11,7 +11,6 @@ from typing import TYPE_CHECKING
from unittest.mock import patch
import freedays
import sickdays
if TYPE_CHECKING:
from pathlib import Path
@ -29,12 +28,6 @@ def state_redirects(tmp_path: Path) -> list[_patch[object]]:
"freedays._api.resolve_paths",
lambda paths: paths or freedays.Paths.under(tmp_path / "freedays"),
),
# Same for the sick-day pool: a real sick day on this machine must not
# silently stand the gate down for the whole suite.
patch(
"sickdays._api.resolve_paths",
lambda paths: paths or sickdays.Paths.under(tmp_path / "sickdays"),
),
patch(
"diet_guard._budget.BUDGET_FILE",
tmp_path / ".budget",

View File

@ -6,17 +6,13 @@ here the logged set is mocked and ``now`` is injected to drive each decision.
from __future__ import annotations
from datetime import UTC, date, datetime, time, timedelta
from datetime import UTC, date, datetime
from typing import TYPE_CHECKING
from unittest.mock import patch
import freedays
import sickdays
from diet_guard._estimator import Nutrition
from diet_guard._gate import due_slots, gate_is_due, gate_message
from diet_guard._state import log_meal, now_local
from diet_guard._state_today import logged_slots_today, today_total_kcal
if TYPE_CHECKING:
from pathlib import Path
@ -120,55 +116,3 @@ class TestFreeDays:
(pool_dir / "free_days.json").write_text("{ not json", encoding="utf-8")
with _logged(set()):
assert gate_is_due(_at(20))
def _mark_sick(tmp_path: Path, day: date) -> None:
"""Put ``day`` in the (temp) sick-day pool; the redirect lives in conftest."""
sickdays.add_sick_day(
day,
is_free=lambda _day: False,
paths=sickdays.Paths.under(tmp_path / "sickdays"),
now=day,
)
class TestSickDays:
"""The sick-day pool stands the gate down, like a free day."""
def test_a_sick_day_leaves_nothing_due(self, tmp_path: Path) -> None:
with _logged(set()):
assert due_slots(_at(20)), "precondition: slots are due without a sick day"
_mark_sick(tmp_path, _at(20).date())
assert due_slots(_at(20)) == ()
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_on_another_date_changes_nothing(self, tmp_path: Path) -> None:
with _logged(set()):
_mark_sick(tmp_path, date(2026, 12, 24))
assert due_slots(_at(20))
assert gate_is_due(_at(20))
def test_the_day_after_a_sick_day_is_armed_again(self, tmp_path: Path) -> None:
_mark_sick(tmp_path, _at(20).date())
tomorrow = _at(20) + timedelta(days=1)
with _logged(set()):
assert gate_is_due(tomorrow)
def test_an_unreadable_pool_leaves_the_gate_armed(self, tmp_path: Path) -> None:
"""Fail closed: a corrupt pool must not switch the gate off."""
pool_dir = tmp_path / "sickdays"
pool_dir.mkdir(exist_ok=True)
(pool_dir / "sick_days.json").write_text("{ not json", encoding="utf-8")
with _logged(set()):
assert gate_is_due(_at(20))
def test_logging_still_works_on_a_sick_day(self, tmp_path: Path) -> None:
"""The gate stands down; the log does not: a meal is still recorded."""
today = now_local().date()
_mark_sick(tmp_path, today)
log_meal("soup", Nutrition(300, 10, 30, 5, 250, "manual"), slot=480)
assert logged_slots_today() == {480}
assert today_total_kcal() == 300
late = datetime.combine(today, time(23, 0), tzinfo=now_local().tzinfo)
assert not gate_is_due(late)

View File

@ -1,21 +0,0 @@
# 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,
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.
- 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.
- 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
sick day on the dev machine must not stand the suite's gate down.
- **Phone gap:** the companion app does not read either pool.
`due_slot_check.dart` (`checkAndNotify`) still posts "log your meal"
notifications on a free or sick day. It would need `crdt_sync_dart` syncing
`sickdays-sync/devices/*/sick_days.json` (see the sickdays README) and an
early return before `_reconcileNotifications` that cancels pending ones.

View File

@ -6,8 +6,7 @@ requires-python = ">=3.14"
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",
"freedays @ git+https://github.com/kuhyx/utils@freedays-v0.3.1#subdirectory=freedays",
"defusedxml==0.7.1",
"requests==2.34.2",
]

View File

@ -5,13 +5,13 @@ codespell==2.4.3
coverage==7.16.2
crdt-sync @ git+https://github.com/kuhyx/utils@crdt-sync-v0.9.2#subdirectory=crdt-sync
defusedxml==0.7.1
freedays @ git+https://github.com/kuhyx/utils@freedays-v0.4.0#subdirectory=freedays
freedays @ git+https://github.com/kuhyx/utils@freedays-v0.3.1#subdirectory=freedays
gatelock @ git+https://github.com/kuhyx/utils@gatelock-v0.9.0#subdirectory=gatelock
mcp==2.3.0
mypy==2.4.0
pre-commit==4.7.0
pydantic==2.14.1
pylint==4.1.3
pre-commit==4.6.2
pydantic==2.14.0
pylint==4.1.2
pytest==9.1.1
pytest-cov==7.1.0
pytest-randomly==5.0.0
@ -19,5 +19,4 @@ pytest-sugar==1.1.1
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
ruff==0.17.0