mirror of
https://github.com/kuhyx/diet-guard.git
synced 2026-11-23 12:36:18 +01:00
e0d62e19a0
3 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
| af35eb20c8 |
feat: offer delivered dishes to the log form, one tap each
The phone now prefills the log form with today's delivered dishes, in the caterer's own meal order. It still never logs anything itself -- a delivered meal is not an eaten meal, so the user taps for each dish. Two guards carried over from the PC, both of which fail silently if dropped: - **The queue survives a submit.** `prefillNextDish` has two callers: the initial load and the post-submit advance. On the PC the second briefly did not exist, which made "(N more to go)" a dead letter -- every dish after the first waited behind another tap. The test asserts the *form controller* holds dish 2 after dish 1 is logged, not that a dish is "available"; the latter passes throughout that bug. - **The automatic refresh is guarded** by a device-local last-fetched date, mirroring `refresh_delivery_once`. The log-flow trigger can fire after every meal and each unguarded walk is a login plus three requests. The settings button deliberately stays unguarded: an explicit ask always goes and looks, matching `diet-guard kuchnia`. Only a clean fetch records the day, so an outage retries. Dishes are ordered against `MealScheduleService.current`, never a hardcoded four slots -- offering a dish for a slot the user's schedule does not have is the "checkpoint that can never be satisfied" failure in a new costume. Editing the description before submitting leaves the dish queued: what was logged was not the delivered dish, and marking it eaten would lose a real delivery silently. Two bugs the tests caught: - `dishesStillQueued` excluded the offered dish, so the status line read "0 more" while a real dish sat in the form. The offered dish is prefilled, not logged; it counts. - An end-to-end test through the real `LogMealScreen` never terminated -- that screen's `initState` fans out into sync, notifications and the food bank, and pumping it to quiescence hangs. Rather than keep fighting it, the behaviour is tested at the mixin that owns it, through a minimal host. The guarantee asserted is the same one: form contents after a submit. `log_meal_screen.dart` is back under the 250-line cap by moving the nutrition build into `log_meal_actions.dart` and inlining a one-line alias. 694 Dart tests, 1040 Python tests, 100% Python branch coverage. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QQpCiPaSbyRpwsLkH3dgsX |
|||
| 8905d072d0 |
feat: carry the catering credential to the phone
The Dart half of the credential sync: a `KuchniaCredentialService` that owns the value locally, a `sync_merge_kuchnia.dart` adapter mirroring the Python one, and a `_syncKuchniaCredential` tick alongside the banks and budget. The phone can now receive the panel password, which is the prerequisite for it fetching anything itself. One source of truth, per the answered question: the value lives in the synced document store and nowhere else. Deliberately *not* mirrored into `flutter_secure_storage` -- two homes for one value is how a stale password survives a change made on the other device, and the credential has to be readable synchronously at merge time anyway. Gated by a second shared fixture, `tests/fixtures/kuchnia_credential.json`, asserted by both suites. Two cases carry the weight: - an **unparsable** edit time must fall back to the same clock on both sides (Python catches `ValueError` from `fromisoformat`, Dart's `tryParse` returns null). Verified they agree on `wall_time_ms == 0`; mutating that expectation fails both suites. - a **blank half** contributes nothing, so a half-filled settings form cannot push an empty-string password that wins LWW against a real one. `KuchniaCredentialService.init()` is called in the WorkManager isolate as well as `main()`. A fresh isolate has its own static state and `_syncKuchniaCredential` no-ops when the singleton is missing, so without it a background tick would neither publish this device's credential nor receive a peer's -- and on the phone the background tick is most of the syncing there is. Same class of trap as the `initSyncDeviceId()` one already documented there. `.toDouble()` came off the bank record: the fields are already `double`, so it was a no-op the analyzer flags. The field *types* are what keep the encoding byte-identical to Python's, and `kuchnia_parity_test.dart` asserts that. 654 Dart tests, 1040 Python tests, 100% Python branch coverage. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QQpCiPaSbyRpwsLkH3dgsX |
|||
| 24be05b9c3 |
feat: mirror the catering parser and slot spread in Dart, gated by one fixture
The phone is getting its own Kuchnia Wikinga importer so the feature works with the PC switched off. That turns a risk `_kuchnia_spread.py` called "theoretical" into a live one: two implementations must now agree exactly on which dishes are dropped, which slot each lands on, and the JSON a banked record encodes to. Disagreement means each device re-adds what the other dropped, and since `add_manual_entry` restamps `t` unconditionally, the whole curated bank republishes to every peer on every refresh. A slot mismatch is worse -- a checkpoint one device offers and the other does not can never be satisfied. So the port lands with its gate rather than after it. One shared fixture, `tests/fixtures/kuchnia_day.json`, is asserted by both `pytest` and `flutter test`: same input, same expected dishes, drops, slots, bank keys and records. Two suites written independently from the same prose is not a gate. The fixture is five real dishes (a scrubbed 2026-08-22 capture) plus synthetic meals that each pin one drop or fallback path -- a per-100 g mix-up, an absurd portion, a stringly-typed number, a non-dict entry, a missing `nutrition`, a missing `mealPriority`, and a twin-dish pair. Without those, "the same meals are dropped" is a vacuous assertion against an all-happy-path capture. Both halves were mutation-checked: flipping an expected slot, drop count or record value fails each suite, and flipping `435.0` to `435` fails the byte-identity test while the value comparison still passes, which is why both exist. Three traps the port had to survive, each caught before it shipped: - `_ENERGY_TOLERANCE` is **0.35**. The prose said "~1%", which describes how closely the captured day agreed, not the threshold; porting 0.01 would drop dishes the PC keeps. That paragraph now says so. - `jsonEncode(435)` emits `435` where Python emits `435.0`, so every Dart macro is forced to `double` and a canonical-encoding test pins it. - Dart's `List.sort` is unstable where Python's `sorted` is stable, so the Dart comparator carries the payload index as a final tiebreak. The real dishes live in their own file rather than as a literal in the generator: transcribing them by hand corrupted three of the five, and the error was invisible until the generated fixture was diffed against the capture. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QQpCiPaSbyRpwsLkH3dgsX |