diet-guard/diet_guard
Krzysztof kuhy Rudnicki e23f7ac3b4
Some checks are pending
pre-commit / pre-commit (push) Waiting to run
Tests / test (3.10) (push) Waiting to run
Tests / test (3.11) (push) Waiting to run
Tests / test (3.12) (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
Push under a persisted per-install uuid, not a fixed role id
diet_guard pushed as "pc" (Python), "phone" (Android) and "desktop" (web).
A role constant collides the moment a second machine takes the same role,
and after a reinstall the new install inherits the previous one's CRDT
identity -- the same reasoning home_inventory already records for choosing a
uuid. Both halves now mint a uuid once and persist it: the PC in
~/.local/share/diet_guard/.device_id, the app under SharedPreferences
'crdt.nodeId' (the key todo and home_inventory already use).

The old constant survives as the legacy id and is passed to sync_log /
syncLog, so devices/<legacy>/ is skipped as this device's own. Without that
every tick would re-download and re-merge this device's own pre-migration
log as though a peer had written it -- idempotent under LWW, but hundreds of
KB, 96 times a day. It drops to None once that path is reclaimed; a test
covers both states, including a negative control proving the skip is the
legacy id's doing.

All four documents move together (food_log, food_bank, food_bank_manual,
budget), and the hist:<date> fields riding on the budget record are
untouched -- merge_record unions field names, so they relay through
unchanged.

The resolver lives in its own module (_device.py / sync_device_id.dart)
because _sync_merge needs it for HLC stamping too and importing _sync there
would be a cycle. Dart resolves it asynchronously at startup, before
LogStorageService.init(); currentSyncDeviceId falls back to the compile-time
role constant until then, so a too-early Hlc stamp gets a valid id rather
than crashing.

conftest redirects the new id file in the same change that introduces it --
without that a test mints a uuid into the real state dir and this machine's
live sync identity is decided by whichever test ran first. Verified by
checking ~/.local/share/diet_guard/ before and after: untouched.

Verified live, not just against mocks: the sync timer ran mid-change and
migrated this machine to f8f46da6. All 358 food_log records and all 100
food_bank records are present under the new path (0 missing vs devices/pc/),
and the new log's HLCs carry only its own id -- confirming it did not
re-merge the old path as a peer.

Python: 687 tests, 100% branch coverage. App: 518 tests, analyzer clean.
Pins bumped to crdt-sync-v0.6.0 / crdt_sync_dart-v0.7.0 (pyproject,
requirements.txt, .pre-commit-config.yaml, pubspec), and the new library is
installed into /usr/bin/python's user site-packages so the production timer
does not ImportError on its next tick.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GZH89WEqAjuJT8WZdqc7AP
2026-08-09 17:18:42 +02:00
..
tests Push under a persisted per-install uuid, not a fixed role id 2026-08-09 17:18:42 +02:00
__init__.py Remove unused features; fix reminder false alarms; share all state 2026-07-26 16:39:52 +02:00
__main__.py Extract diet_guard from testsAndMisc as a standalone repo 2026-06-22 12:18:39 +02:00
_averages.py Show weekly and monthly average intake on both devices 2026-08-09 14:59:40 +02:00
_budget_history.py Remove unused features; fix reminder false alarms; share all state 2026-07-26 16:39:52 +02:00
_budget.py Remove unused features; fix reminder false alarms; share all state 2026-07-26 16:39:52 +02:00
_calendar_view.py Show weekly and monthly average intake on both devices 2026-08-09 14:59:40 +02:00
_cli_averages.py Show weekly and monthly average intake on both devices 2026-08-09 14:59:40 +02:00
_cli_gate.py Review fixes: specific sync exceptions, clearer names 2026-07-11 18:33:43 +02:00
_cli_sync.py Migrate sync to shared crdt_sync library (Python + Dart) 2026-07-10 23:49:43 +02:00
_cli.py Show weekly and monthly average intake on both devices 2026-08-09 14:59:40 +02:00
_coerce.py Extract diet_guard from testsAndMisc as a standalone repo 2026-06-22 12:18:39 +02:00
_constants.py Push under a persisted per-install uuid, not a fixed role id 2026-08-09 17:18:42 +02:00
_daystatus.py Show weekly and monthly average intake on both devices 2026-08-09 14:59:40 +02:00
_device.py Push under a persisted per-install uuid, not a fixed role id 2026-08-09 17:18:42 +02:00
_estimator.py Extract diet_guard from testsAndMisc as a standalone repo 2026-06-22 12:18:39 +02:00
_foodbank_manual.py Remove unused features; fix reminder false alarms; share all state 2026-07-26 16:39:52 +02:00
_foodbank.py Remove unused features; fix reminder false alarms; share all state 2026-07-26 16:39:52 +02:00
_fuzzy.py feat(diet_guard): add meal-logging screen-lock gate with trigger fix 2026-06-10 22:32:39 +02:00
_gate.py Extract diet_guard from testsAndMisc as a standalone repo 2026-06-22 12:18:39 +02:00
_gatelock_buttons.py Make the meal gate usable without a pointer on a 1366x768 screen 2026-07-30 16:21:27 +02:00
_gatelock_calendar_ui.py Show weekly and monthly average intake on both devices 2026-08-09 14:59:40 +02:00
_gatelock_calendar.py Show weekly and monthly average intake on both devices 2026-08-09 14:59:40 +02:00
_gatelock_core.py Remove unused features; fix reminder false alarms; share all state 2026-07-26 16:39:52 +02:00
_gatelock_groups.py Remove unused features; fix reminder false alarms; share all state 2026-07-26 16:39:52 +02:00
_gatelock_mealflow.py Remove unused features; fix reminder false alarms; share all state 2026-07-26 16:39:52 +02:00
_gatelock_nutrition.py Add budget-adherence calendar, streaks, and freely-editable synced budget 2026-07-13 21:31:45 +02:00
_gatelock_spacing.py Migrate diet_guard to gatelock v0.2.0 per-output locking 2026-07-25 16:56:13 +02:00
_gatelock_support.py feat: split oversized modules for 500-line limit, fix kasa coverage gap 2026-06-14 07:19:37 +02:00
_gatelock_typography.py Make the meal gate usable without a pointer on a 1366x768 screen 2026-07-30 16:21:27 +02:00
_gatelock_ui_types.py Remove unused features; fix reminder false alarms; share all state 2026-07-26 16:39:52 +02:00
_gatelock_ui.py Fit the meal gate on 1366x768 with a full day logged, and stop the auto-scroll 2026-08-03 16:00:13 +02:00
_gatelock.py Remove unused features; fix reminder false alarms; share all state 2026-07-26 16:39:52 +02:00
_mcp.py Show weekly and monthly average intake on both devices 2026-08-09 14:59:40 +02:00
_portions.py Extract diet_guard from testsAndMisc as a standalone repo 2026-06-22 12:18:39 +02:00
_resolve.py Extract diet_guard from testsAndMisc as a standalone repo 2026-06-22 12:18:39 +02:00
_slots.py Remove unused features; fix reminder false alarms; share all state 2026-07-26 16:39:52 +02:00
_state.py Add budget-adherence calendar, streaks, and freely-editable synced budget 2026-07-13 21:31:45 +02:00
_sync_merge.py Push under a persisted per-install uuid, not a fixed role id 2026-08-09 17:18:42 +02:00
_sync.py Push under a persisted per-install uuid, not a fixed role id 2026-08-09 17:18:42 +02:00
_test_guard.py Remove unused features; fix reminder false alarms; share all state 2026-07-26 16:39:52 +02:00