mirror of
https://github.com/kuhyx/diet-guard.git
synced 2026-11-11 13:47:38 +01:00
Without this the schedule would be device-local, which is the failure this
whole feature has to avoid: the phone sets five meals, the PC still derives
four, and the PC's gate nags for a 12:00 checkpoint the phone never offered
and can never satisfy. So sync lands before either edit surface, not after.
The history rides the existing `budget` CRDT record as one
`sched:<YYYY-MM-DD>` field per entry, exactly like the budget's own `hist:`
fields. merge_record is per-field LWW over the *union* of field names and both
devices push the merged record, so a device that predates the feature relays
the fields untouched -- no coordinated release. There is a test for precisely
that: merging our push with a budget-only peer keeps both schedule entries.
Verified the two languages agree on the wire, not just in their own suites --
Python and Dart both emit
{"sched:1970-01-01":{"f":8,"l":20,"n":4},"sched:2026-08-16":{"f":8,"l":20,"n":5}}
The Hlc is derived from the *parsed* timestamp on both sides, which matters
because the epoch fallback formats differently in each language
(1970-01-01T00:00:00+00:00 vs ...000Z) and a string comparison would diverge.
Two guards worth naming:
- A device with no history contributes no `sched:` fields at all, so an unset
default can never outrank a peer's real schedule; and an empty merge result
is never written back, so a pre-feature peer cannot erase a real history.
- Dart's `_syncBudget` synthesises a local record when the schedule has been
edited but the budget never has -- `budgetToLog(null, ...)` returns an empty
Log and would otherwise drop the schedule fields too. Its budget value
carries an epoch stamp, so it loses every LWW race against a real edit.
sync_merge/_schedule.py and sync_merge_schedule.dart are separate modules
rather than additions to the budget adapters, which were at 186 and 170 lines
against the 250 cap. Each declares its own record-id constant so the Dart
pair does not import each other.
772 Python tests at 100% branch coverage, 619 Dart.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0159b4E5hh512jYUeaJVNxfM
|
||
|---|---|---|
| .. | ||
| __init__.py | ||
| _gate_fixtures.py | ||
| _gate_focus_probe.py | ||
| _gate_keyboard_probe.py | ||
| _gate_layout_probe.py | ||
| _gate_measurement.py | ||
| _sync_fakes.py | ||
| _tk_fakes_canvas.py | ||
| _tk_fakes_containers.py | ||
| _tk_fakes.py | ||
| conftest.py | ||
| test_averages_report.py | ||
| test_averages.py | ||
| test_budget_history_io.py | ||
| test_budget_history.py | ||
| test_budget.py | ||
| test_calendar_averages.py | ||
| test_calendar_view.py | ||
| test_cli_averages.py | ||
| test_cli_gate.py | ||
| test_cli_sync.py | ||
| test_cli.py | ||
| test_daystatus.py | ||
| test_estimator.py | ||
| test_foodbank_manual.py | ||
| test_foodbank_rebuild.py | ||
| test_foodbank.py | ||
| test_fuzzy.py | ||
| test_gate_layout_fits.py | ||
| test_gate_tk_modules.py | ||
| test_gate.py | ||
| test_gatelock_calendar.py | ||
| test_gatelock_dashboard.py | ||
| test_gatelock_fanout.py | ||
| test_gatelock_form.py | ||
| test_gatelock_groups.py | ||
| test_gatelock_keyboard.py | ||
| test_gatelock_mealflow.py | ||
| test_gatelock.py | ||
| test_main.py | ||
| test_mcp_averages.py | ||
| test_mcp.py | ||
| test_meal_schedule_store.py | ||
| test_meal_schedule.py | ||
| test_portions.py | ||
| test_resolve.py | ||
| test_slots.py | ||
| test_state_redirect.py | ||
| test_state_sync.py | ||
| test_state_today.py | ||
| test_state.py | ||
| test_sync_backend.py | ||
| test_sync_banks.py | ||
| test_sync_budget.py | ||
| test_sync_device_id.py | ||
| test_sync_events.py | ||
| test_sync_merge_banks.py | ||
| test_sync_merge_budget.py | ||
| test_sync_merge_schedule.py | ||
| test_sync_merge.py | ||
| test_sync_pull.py | ||
| test_sync.py | ||
| test_test_guard.py | ||