Compare commits

..

No commits in common. "e0a4f71953c83b0612a950428b7bf568e6caf7d5" and "3cd04e60dc6069ba0e4dfa0ed2f22cab220c8b6c" have entirely different histories.

19 changed files with 33 additions and 189 deletions

2
.fvmrc
View File

@ -1,3 +1,3 @@
{
"flutter": "3.50.1"
"flutter": "3.50.0"
}

View File

@ -60,7 +60,7 @@ jobs:
- uses: subosito/flutter-action@v2
with:
flutter-version: 3.50.1
flutter-version: 3.50.0
channel: stable
cache: true

View File

@ -115,7 +115,6 @@ repos:
- crdt-sync @ git+https://github.com/kuhyx/utils@crdt-sync-v0.11.1#subdirectory=crdt-sync
- freedays @ git+https://github.com/kuhyx/utils@freedays-v0.4.3#subdirectory=freedays
- sickdays @ git+https://github.com/kuhyx/utils@sickdays-v0.5.5#subdirectory=sickdays
- kuhy-credit @ git+https://github.com/kuhyx/utils@kuhy-credit-v0.3.0#subdirectory=kuhy_credit
- rtdb-relay @ git+https://github.com/kuhyx/utils@rtdb-relay-v0.2.1#subdirectory=rtdb_relay
- claude-agent-sdk==0.2.184
- httpx==0.28.1

View File

@ -22,11 +22,6 @@ mixin LogMealLoggedMixin<T extends StatefulWidget>
/// The rows under the action row, oldest first.
List<LoggedMeal> loggedRows = const [];
/// The latest open-or-resume chain. Tests await it instead of guessing how
/// long real file I/O takes (a fixed sleep flaked under load).
@visibleForTesting
Future<void> openChain = Future<void>.value();
/// Replaces the rows with [meals]: a new log retires the previous ones.
void showLogged(List<LoggedMeal> meals) {
if (mounted) setState(() => loggedRows = meals);
@ -62,15 +57,12 @@ mixin LogMealLoggedMixin<T extends StatefulWidget>
// single-flight, so calling super too would let the auto-log run before
// the pull finished). Pause still pushes through the sync mixin.
if (state == AppLifecycleState.resumed) {
startOpenChain();
unawaited(onOpenedOrResumed());
return;
}
super.didChangeAppLifecycleState(state);
}
/// Starts [onOpenedOrResumed] and keeps its future in [openChain].
void startOpenChain() => openChain = onOpenedOrResumed();
/// What a fresh open or a resume does: show the screen from the local log,
/// pull what other devices logged, then auto-log what is still due.
Future<void> onOpenedOrResumed() async {

View File

@ -90,7 +90,7 @@ class _LogMealScreenState extends State<LogMealScreen>
unawaited(_onDescChanged());
// Health first, so a device that stalled earlier says so before a tick.
unawaited(refreshSyncHealth());
startOpenChain();
unawaited(onOpenedOrResumed());
}
@override

View File

@ -27,7 +27,6 @@ import 'package:diet_guard_app/widgets/meal_schedule_editor.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:http/http.dart' as http;
import 'package:kuhy_credit/kuhy_credit.dart';
import 'package:material_ui/material_ui.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:sync_settings_ui/sync_settings_ui.dart';
@ -242,10 +241,6 @@ class _SettingsScreenState extends State<SettingsScreen>
const SizedBox(height: 16),
Align(alignment: Alignment.centerLeft, child: _status),
],
const SizedBox(height: 24),
const Divider(),
const SizedBox(height: 8),
const Align(alignment: Alignment.centerLeft, child: KuhyCredit()),
],
),
),

View File

@ -542,10 +542,10 @@ packages:
dependency: "direct main"
description:
name: health
sha256: "683d15fdde49a942bacce871faf3090bda3c1f5dad995725337aeb1dfd348e6d"
sha256: "8dd9625c9c26379a5753ad24c33af1d3dc5ce1f36f19c03e17c676c2f8fdbb80"
url: "https://pub.dev"
source: hosted
version: "14.0.0"
version: "13.3.2"
hooks:
dependency: transitive
description:
@ -682,15 +682,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.12.0"
kuhy_credit:
dependency: "direct main"
description:
path: "kuhy_credit/flutter"
ref: "kuhy-credit-v0.3.0"
resolved-ref: c3946412729991bf1e9c3b6a5cc55dbe80419fc0
url: "https://github.com/kuhyx/utils"
source: git
version: "0.3.0"
leak_tracker:
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.190+1
version: 1.0.186+1
environment:
sdk: ^3.12.2
@ -48,16 +48,11 @@ dependencies:
url: https://github.com/kuhyx/utils
ref: google_account_token-v0.1.0
path: google_account_token
health: 14.0.0
health: 13.3.2
http: 1.6.0
idb_shim: 2.11.3
# Camera/gallery photo as transient input to Claude (never stored or synced).
image_picker: 1.2.4
kuhy_credit:
git:
url: https://github.com/kuhyx/utils
ref: kuhy-credit-v0.3.0
path: kuhy_credit/flutter
material_ui: 1.11.1
path: 1.9.1
path_provider: 2.1.6

View File

@ -65,20 +65,13 @@ void main() {
// GitHubMirrorScreen loads its settings via a fire-and-forget Future in
// initState that Flutter's frame scheduler does not track -- same pitfall
// as HistoryScreen/LogMealScreen.
// [until]: keep pumping (max 5 s) until it is found -- a sync tick's real
// I/O outlasts the fixed 200 ms on a loaded machine.
Future<void> settle(WidgetTester tester, {Finder? until}) async {
Future<void> settle(WidgetTester tester) async {
tester.view.physicalSize = const Size(800, 1400);
tester.view.devicePixelRatio = 1.0;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final deadline = DateTime.now().add(const Duration(seconds: 5));
do {
await Future<void>.delayed(const Duration(milliseconds: 200));
await tester.pumpAndSettle();
} while (until != null &&
until.evaluate().isEmpty &&
DateTime.now().isBefore(deadline));
await Future<void>.delayed(const Duration(milliseconds: 200));
await tester.pumpAndSettle();
}
/// Drains the device flow's real `Future.delayed` poll (GitHubDeviceAuth
@ -174,7 +167,7 @@ void main() {
await settle(tester);
await tester.tap(controlByLabel('Sync now'));
await settle(tester, until: cueLabelled('Synced.'));
await settle(tester);
expect(cueLabelled('Synced.'), findsOneWidget);
});
@ -204,7 +197,7 @@ void main() {
await settle(tester);
await tester.tap(controlByLabel('Sync now'));
await settle(tester, until: cueLabelled('Synced.'));
await settle(tester);
expect(cueLabelled('Synced.'), findsOneWidget);
final status = await SyncHealth.read();
@ -235,7 +228,7 @@ void main() {
await settle(tester);
await tester.tap(controlByLabel('Sync now'));
await settle(tester, until: cueOfKind(CueKind.error));
await settle(tester);
expect(cueOfKind(CueKind.error), findsOneWidget);
});

View File

@ -47,7 +47,7 @@ void main() {
Future<void> open(WidgetTester tester) async {
await tester.pumpWidget(const MaterialApp(home: LogMealScreen()));
await settleOpen(tester);
await settle(tester);
}
testWidgets('opening in due mode logs the due dishes with no tap', (
@ -72,11 +72,7 @@ void main() {
await tester.runAsync(() async {
await open(tester);
await tester.tap(byIconLabel('Undo').first);
await settleUntil(
tester,
() async =>
(await LogStorageService.instance.todayEntries()).length == 1,
);
await settle(tester);
expect(find.byIcon(Icons.restaurant), findsOneWidget);
var live = await LogStorageService.instance.todayEntries();
expect(live.map((e) => e.desc), ['Danie 2']);
@ -134,7 +130,7 @@ void main() {
(state as WidgetsBindingObserver).didChangeAppLifecycleState(
AppLifecycleState.resumed,
);
await settleOpen(tester);
await settle(tester);
final entries = await LogStorageService.instance.todayEntries();
expect(entries.map((e) => e.desc), ['Danie 1', 'Danie 2']);

View File

@ -38,7 +38,7 @@ void main() {
Future<void> open(WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(home: LogMealScreen(relay: relay)));
await settleOpen(tester);
await settle(tester);
}
testWidgets('the request id is a ULID and the mode follows due mode', (
@ -75,12 +75,7 @@ void main() {
await settle(tester);
await tester.tap(controlByLabel('Log meal'));
await settleUntil(
tester,
() async =>
relay.cancelled.isNotEmpty &&
byIconLabel('Ask Claude').evaluate().isNotEmpty,
);
await settle(tester);
expect(relay.cancelled, [relay.sent.single.requestId]);
expect(byIconLabel('Ask Claude'), findsOneWidget);
@ -93,12 +88,7 @@ void main() {
_claudeEntry(claudeEntryId(relay.sent.single.requestId)),
),
);
await settleUntil(
tester,
() async =>
(await LogStorageService.instance.todayEntries()).length ==
(claimed ? 2 : 1),
);
await settle(tester);
final live = await LogStorageService.instance.todayEntries();
expect(live, hasLength(claimed ? 2 : 1));
});

View File

@ -4,8 +4,6 @@ library;
import 'dart:io';
import 'package:diet_guard_app/screens/log_meal_due_mixin.dart';
import 'package:diet_guard_app/screens/log_meal_logged_mixin.dart';
import 'package:diet_guard_app/screens/log_meal_screen.dart';
import 'package:diet_guard_app/services/app_settings_service.dart';
import 'package:diet_guard_app/services/budget_history_service.dart';
import 'package:diet_guard_app/services/document_store_io.dart';
@ -53,28 +51,3 @@ Future<void> settle(WidgetTester tester) async {
await Future<void>.delayed(const Duration(milliseconds: 200));
await tester.pumpAndSettle();
}
/// Waits for the screen's open-or-resume chain (sync, slots, catering
/// auto-log) to finish, then [settle]s.
Future<void> settleOpen(WidgetTester tester) async {
final state = tester.state(find.byType(LogMealScreen));
await (state as LogMealLoggedMixin).openChain;
await settle(tester);
}
/// [settle]s, then keeps pumping until [done] holds or [timeout] passes.
///
/// For chains a tap starts and nothing exposes: real file I/O outlasts the
/// fixed sleep in [settle] when the machine is loaded.
Future<void> settleUntil(
WidgetTester tester,
Future<bool> Function() done, {
Duration timeout = const Duration(seconds: 5),
}) async {
final deadline = DateTime.now().add(timeout);
await settle(tester);
while (!await done() && DateTime.now().isBefore(deadline)) {
await Future<void>.delayed(const Duration(milliseconds: 50));
await tester.pumpAndSettle();
}
}

View File

@ -10,7 +10,6 @@ import 'package:diet_guard_app/services/firebase_backend.dart';
import 'package:diet_guard_app/services/foodbank_service.dart';
import 'package:diet_guard_app/services/log_storage_service.dart';
import 'package:diet_guard_app/services/meal_schedule_service.dart';
import 'package:kuhy_credit/kuhy_credit.dart';
import 'package:material_ui/material_ui.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:permission_handler/permission_handler.dart';
@ -225,17 +224,4 @@ void main() {
});
},
);
testWidgets('shows the KuhyCredit logo at the bottom', (tester) async {
await tester.runAsync(() async {
await tester.pumpWidget(const MaterialApp(home: SettingsScreen()));
await settle(tester);
// Scroll to the bottom where KuhyCredit is placed.
await tester.ensureVisible(find.byType(KuhyCredit, skipOffstage: false));
await tester.pumpAndSettle();
expect(find.byType(KuhyCredit, skipOffstage: false), findsOneWidget);
});
});
}

View File

@ -58,7 +58,6 @@ from diet_guard._gatelock_core import _GateState
from diet_guard._gatelock_credit import arm_credit_watch
from diet_guard._gatelock_groups import GateWidgetsGroup
from diet_guard._gatelock_lockfile import acquire_gate_lock, release_gate_lock
from diet_guard._gatelock_logo import place_logo
from diet_guard._gatelock_peerpull import arm_peer_pull
from diet_guard._gatelock_ui import GateCallbacks, make_vars
from diet_guard._hold import watch_hold
@ -128,7 +127,8 @@ class MealGate(_GateCalendar):
self.root = GateRoot()
self.root.on_callback_error = self.on_callback_error
self.root.title("Diet Gate") # OS-level app name: the one kept noun
# No colour overrides: LockConfig defaults are the palette (one drifted).
# No colour overrides: LockConfig's defaults are the design-system palette
# and _gatelock_ui reads them too (an override drifted once).
config = LockConfig(
mode="soft" if demo_mode else "hard",
app_name="diet_guard",
@ -172,9 +172,9 @@ class MealGate(_GateCalendar):
monitor the user is actually looking at.
"""
widgets = self._build_tabs(parent, self._callbacks)
place_logo(parent)
self._widgets.add(widgets, surface.output_name)
# A returning output gets its bindings; re-wiring the rest is a no-op.
# An output coming back mid-lock gets its bindings too; tk's bind
# replaces rather than stacks, so re-wiring the others is a no-op.
self._wire_events()
def teardown_surface(self, surface: SurfaceInfo) -> None:

View File

@ -1,27 +0,0 @@
"""The kuhy logo in a corner of each gate surface (shared ``kuhy_credit``).
Uses the Tk widget from kuhy_credit (kuhy-credit-v0.3.0). A click opens the
credit panel; the site opens only on a further click, so the lock cannot be
escaped by accident. This module imports tkinter and builds widgets, so it
belongs in ``_GATE_TK_MODULES`` (see ``_gatelock_layout``).
"""
from __future__ import annotations
from typing import TYPE_CHECKING
from kuhy_credit.tk import KuhyCredit
if TYPE_CHECKING:
import tkinter as tk
__all__ = ["place_logo"]
_MARGIN = 16
def place_logo(parent: tk.Misc) -> KuhyCredit:
"""Overlay the logo on ``parent``'s bottom-right corner."""
credit = KuhyCredit(parent, theme="dark")
credit.place(relx=1, rely=1, x=-_MARGIN, y=-_MARGIN, anchor="se")
return credit

View File

@ -202,8 +202,6 @@ def fake_tk() -> Iterator[None]:
with ExitStack() as stack:
for module in _GATE_TK_MODULES:
stack.enter_context(patch.object(module, "tk", _FAKE_TK))
# The logo is a real Canvas subclass; it cannot take a fake parent.
stack.enter_context(patch.object(_gatelock, "place_logo"))
stack.enter_context(patch.object(_gatelock_calendar, "ttk", _FAKE_TTK))
stack.enter_context(patch.object(_gatelock_calendar_ui, "ttk", _FAKE_TTK))
# The schedule row's HH:MM spinboxes are ttk widgets; left real, they

View File

@ -1,35 +0,0 @@
"""The kuhy logo sits in the bottom-right corner of every gate surface."""
from __future__ import annotations
import os
import tkinter as tk
from typing import TYPE_CHECKING
from kuhy_credit.tk import KuhyCredit
import pytest
from diet_guard._gatelock_logo import place_logo
if TYPE_CHECKING:
from pytest_xvfb import Xvfb
def test_place_logo_anchors_bottom_right(xvfb: Xvfb | None) -> None:
# Real Tk, so only ever on pytest-xvfb's private display -- never the user's.
if xvfb is None:
pytest.skip("needs pytest-xvfb's private display")
assert os.environ["DISPLAY"] == f":{xvfb.display}"
root = tk.Tk()
try:
root.withdraw()
frame = tk.Frame(root)
credit = place_logo(frame)
assert isinstance(credit, KuhyCredit)
assert credit.master is frame
info = credit.place_info()
assert info["anchor"] == "se"
assert (info["relx"], info["rely"]) == ("1", "1")
assert (info["x"], info["y"]) == ("-16", "-16")
finally:
root.destroy()

View File

@ -7,10 +7,9 @@ dependencies = [
"gatelock @ git+https://github.com/kuhyx/utils@gatelock-v0.16.0#subdirectory=gatelock",
"crdt-sync @ git+https://github.com/kuhyx/utils@crdt-sync-v0.11.1#subdirectory=crdt-sync",
"freedays @ git+https://github.com/kuhyx/utils@freedays-v0.4.3#subdirectory=freedays",
"kuhy-credit @ git+https://github.com/kuhyx/utils@kuhy-credit-v0.3.0#subdirectory=kuhy_credit",
"holds @ git+https://github.com/kuhyx/utils@holds-v0.1.0#subdirectory=holds",
"sickdays @ git+https://github.com/kuhyx/utils@sickdays-v0.5.6#subdirectory=sickdays",
"claude-agent-sdk==0.2.187",
"sickdays @ git+https://github.com/kuhyx/utils@sickdays-v0.5.5#subdirectory=sickdays",
"claude-agent-sdk==0.2.185",
"defusedxml==0.7.1",
"httpx==0.28.1",
"requests==2.34.2",
@ -26,7 +25,7 @@ dependencies = [
mcp = ["mcp==2.3.0"]
# Test-only: the property tests (test_claude_log.py) need it; same pin as
# requirements.txt.
dev = ["hypothesis==6.170.17"]
dev = ["hypothesis==6.170.15"]
# Without this, setuptools' flat-layout auto-discovery treats the Flutter
# app/ directory as a second top-level package and refuses to build.

View File

@ -1,21 +1,20 @@
# Diet Guard — runtime + development dependencies
# Runtime: tkinter/json/hmac/fcntl (stdlib) plus gatelock and requests below.
bandit==1.9.4
claude-agent-sdk==0.2.187
claude-agent-sdk==0.2.185
codespell==2.4.3
coverage==7.17.4
coverage==7.17.3
crdt-sync @ git+https://github.com/kuhyx/utils@crdt-sync-v0.11.1#subdirectory=crdt-sync
defusedxml==0.7.1
freedays @ git+https://github.com/kuhyx/utils@freedays-v0.4.3#subdirectory=freedays
gatelock @ git+https://github.com/kuhyx/utils@gatelock-v0.16.0#subdirectory=gatelock
holds @ git+https://github.com/kuhyx/utils@holds-v0.1.0#subdirectory=holds
httpx==0.28.1
hypothesis==6.170.17
kuhy-credit @ git+https://github.com/kuhyx/utils@kuhy-credit-v0.3.0#subdirectory=kuhy_credit
hypothesis==6.170.15
mcp==2.3.0
mypy==2.4.1
pre-commit==4.7.0
pydantic==2.14.4
pydantic==2.14.3
pylint==4.1.4
pytest==9.2.0
pytest-cov==7.1.0
@ -25,5 +24,5 @@ pytest-xdist==3.8.0
pytest-xvfb==3.1.1
requests==2.34.2
rtdb-relay @ git+https://github.com/kuhyx/utils@rtdb-relay-v0.2.1#subdirectory=rtdb_relay
ruff==0.17.6
sickdays @ git+https://github.com/kuhyx/utils@sickdays-v0.5.6#subdirectory=sickdays
ruff==0.17.5
sickdays @ git+https://github.com/kuhyx/utils@sickdays-v0.5.5#subdirectory=sickdays