diff --git a/app/lib/models/food_entry.dart b/app/lib/models/food_entry.dart index ec76b47..a35e898 100644 --- a/app/lib/models/food_entry.dart +++ b/app/lib/models/food_entry.dart @@ -81,6 +81,13 @@ class FoodEntry { /// The meal-slot hour this entry satisfies (8/12/16/20), or null for a /// snack that counts toward calories but satisfies no slot. + /// + /// Nothing writes null any more -- the "Snack" chip was removed on + /// 2026-08-14 and every remaining writer resolves a concrete hour through + /// `slotForLog`/`slot_for_log` -- but entries already on disk and arriving + /// over sync still carry no `slot` key, so the null case and every + /// `slot != null` filter built on it are load-bearing. Dropping them would + /// make those historical entries retroactively satisfy meal slots. final int? slot; /// HMAC signature, present on entries that have passed through the PC's diff --git a/app/lib/widgets/slot_selector_row.dart b/app/lib/widgets/slot_selector_row.dart index 4532c6d..6cf4403 100644 --- a/app/lib/widgets/slot_selector_row.dart +++ b/app/lib/widgets/slot_selector_row.dart @@ -7,10 +7,15 @@ import 'package:diet_guard_app/models/slot.dart'; import 'package:diet_guard_app/ui/theme.dart'; import 'package:flutter/material.dart'; -/// One row of [ChoiceChip]s: one per today's slot hour plus a fixed -/// "Snack" chip. Each hour chip is simultaneously selectable (tap to log -/// for that slot) and status-colored (green+check = logged, red = due, -/// grey = upcoming), so no separate status bar or caption text is needed. +/// One row of [ChoiceChip]s, one per today's slot hour. Each chip is +/// simultaneously selectable (tap to log for that slot) and status-colored +/// (green+check = logged, red = due, grey = upcoming), so no separate status +/// bar or caption text is needed. +/// +/// There used to be a fifth "Snack" chip that selected no slot at all, +/// removed 2026-08-14. Entries with a null slot still exist in storage and +/// still arrive over sync, so the nullable types below are deliberate -- but +/// this widget no longer produces one. class SlotSelectorRow extends StatelessWidget { /// Creates a [SlotSelectorRow]. const SlotSelectorRow({ @@ -27,10 +32,11 @@ class SlotSelectorRow extends StatelessWidget { /// Slot hours already satisfied by today's log. final Set loggedSlots; - /// The slot currently chosen to log for, or null for "Snack". + /// The slot currently chosen to log for. Nullable for historical reasons + /// (see the class doc); no chip in this row selects null any more. final int? selectedSlot; - /// Called with the tapped slot's hour, or null for the "Snack" chip. + /// Called with the tapped slot's hour. Never called with null. final ValueChanged onSlotSelected; @override @@ -43,14 +49,6 @@ class SlotSelectorRow extends StatelessWidget { final statusColors = Theme.of(context).extension() ?? AppStatusColors.dark; final elapsed = elapsedSlots(now).toSet(); - // Snack has no logged/due/upcoming status like the hour chips, so it - // uses `accent` as its "color" instead of a status color -- but still - // needs every property below set explicitly like the hour chips are. - // Leaving any of them unset falls through to Flutter's own ChoiceChip - // default, a literal pure-white border (the one banned value in this - // system) -- the open finding the unified-design-system doc flagged. - final snackSelected = selectedSlot == null; - final snackColor = snackSelected ? scheme.primary : scheme.onSurfaceVariant; return Wrap( spacing: AppSpacing.xs + 2, runSpacing: AppSpacing.xs, @@ -86,27 +84,6 @@ class SlotSelectorRow extends StatelessWidget { onSelected: (_) => onSlotSelected(slot), ); }), - ChoiceChip( - label: const Text('Snack'), - // Icon reads lighter than the label text (rule 28): reduced - // opacity instead of the label's full-strength color. - avatar: Icon( - Icons.fastfood, - size: 14, - color: snackColor.withValues(alpha: 0.72), - ), - selected: snackSelected, - backgroundColor: scheme.onSurfaceVariant.withValues(alpha: 0.15), - selectedColor: scheme.primary.withValues(alpha: 0.35), - labelStyle: TextStyle(color: snackColor), - side: BorderSide( - width: snackSelected ? 2 : 1, - color: snackSelected - ? snackColor - : snackColor.withValues(alpha: 0.4), - ), - onSelected: (_) => onSlotSelected(null), - ), ], ); } diff --git a/app/pubspec.yaml b/app/pubspec.yaml index c6c553d..719b527 100644 --- a/app/pubspec.yaml +++ b/app/pubspec.yaml @@ -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.8+1 +version: 1.0.9+1 environment: sdk: ^3.12.2 diff --git a/app/test/widgets/slot_selector_row_test.dart b/app/test/widgets/slot_selector_row_test.dart new file mode 100644 index 0000000..42ab431 --- /dev/null +++ b/app/test/widgets/slot_selector_row_test.dart @@ -0,0 +1,90 @@ +import 'package:diet_guard_app/models/slot.dart'; +import 'package:diet_guard_app/widgets/slot_selector_row.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +Future _pump( + WidgetTester tester, { + required DateTime now, + Set loggedSlots = const {}, + int? selectedSlot, + ValueChanged? onSlotSelected, +}) => tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: SlotSelectorRow( + now: now, + loggedSlots: loggedSlots, + selectedSlot: selectedSlot, + onSlotSelected: onSlotSelected ?? (_) {}, + ), + ), + ), +); + +void main() { + group('SlotSelectorRow', () { + testWidgets('renders exactly one chip per day slot', (tester) async { + await _pump(tester, now: DateTime(2026, 8, 14, 13)); + + expect(find.byType(ChoiceChip), findsNWidgets(daySlots().length)); + for (final slot in daySlots()) { + expect(find.text(slotLabel(slot)), findsOneWidget); + } + }); + + // The "Snack" chip was removed on 2026-08-14; it was the only control + // that logged a meal against no slot at all. + testWidgets('has no Snack chip', (tester) async { + await _pump(tester, now: DateTime(2026, 8, 14, 13)); + + expect(find.text('Snack'), findsNothing); + expect(find.byIcon(Icons.fastfood), findsNothing); + }); + + testWidgets('tapping a chip reports that slot, never null', ( + tester, + ) async { + final selected = []; + await _pump( + tester, + now: DateTime(2026, 8, 14, 13), + onSlotSelected: selected.add, + ); + + for (final slot in daySlots()) { + await tester.tap(find.text(slotLabel(slot))); + } + + expect(selected, daySlots()); + expect(selected, isNot(contains(null))); + }); + + testWidgets('a logged slot gets a check avatar', (tester) async { + await _pump( + tester, + now: DateTime(2026, 8, 14, 13), + loggedSlots: {daySlots().first}, + ); + + expect(find.byIcon(Icons.check), findsOneWidget); + }); + + testWidgets('marks the selected slot', (tester) async { + final slot = daySlots().first; + await _pump( + tester, + now: DateTime(2026, 8, 14, 13), + selectedSlot: slot, + ); + + final chip = tester.widget( + find.ancestor( + of: find.text(slotLabel(slot)), + matching: find.byType(ChoiceChip), + ), + ); + expect(chip.selected, isTrue); + }); + }); +} diff --git a/diet_guard/_mcp.py b/diet_guard/_mcp.py index 9cfc9e5..16c1ec6 100644 --- a/diet_guard/_mcp.py +++ b/diet_guard/_mcp.py @@ -290,8 +290,9 @@ def log_meal( macros: Manually-entered nutrition (``kcal`` plus optional protein/carbs/fat). When given, lookups are skipped and the meal is logged exactly as specified. - slot: The meal-slot hour to satisfy; defaults to the current elapsed - slot (may be ``None`` early in the day, logging calories only). + slot: The meal-slot hour to satisfy; when omitted (or None) it falls + back to ``slot_for_log``, which clamps to a real hour rather than + returning None, so the entry always satisfies some slot. confirm: Set ``True`` to actually append the entry; otherwise preview. Returns: diff --git a/diet_guard/_state.py b/diet_guard/_state.py index a34970e..bcbd8ea 100644 --- a/diet_guard/_state.py +++ b/diet_guard/_state.py @@ -233,6 +233,15 @@ def logged_slots_today() -> set[int]: direction. An entry without a ``slot`` field (e.g. a snack logged with no checkpoint) contributes calories but satisfies no slot. + Nothing produces a slot-less entry any more: the phone's "Snack" chip was + removed on 2026-08-14, and every remaining writer resolves a concrete hour + through ``slot_for_log`` -- the CLI (:mod:`_cli`), the gate + (:mod:`_gatelock_mealflow`) and the MCP tool (:mod:`_mcp`, which falls back + to it whenever its ``slot`` argument is omitted or None). The check below + is still load-bearing for entries already on disk and arriving over sync -- + removing it would make every historical snack retroactively satisfy a meal + slot. + Returns: The distinct integer slot hours logged today (possibly empty). """