Compare commits

...

4 Commits

Author SHA1 Message Date
e0a4f71953 Mirror test: wait for the sync cue, bounded
Some checks are pending
file-length / file length <= 250 lines (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint,dependency-freshness) (push) Waiting to run
Tests / test (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Same fixed-200 ms flake as the log screen tests: under load the
Sync now tick outlasted it. settle() now pumps until the expected
cue appears, at most 5 s.

Todo: 7808ee0a

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 06:57:52 +01:00
1190e2d079 Log screen tests: await work, not a fixed sleep
The 200 ms settle flaked under load on origin/main too: the open
chain or a tap's I/O outlasted it. The screen keeps its open chain
in openChain; tests await it, or poll a bounded condition.

Todo: 7808ee0a

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 06:50:31 +01:00
9d63c33fa7 Cover place_logo with a real-Tk test
Todo: 7808ee0a

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 06:39:11 +01:00
6c2c365a69 Put my logo everywhere
Todo: 7808ee0a
2026-11-21 06:36:21 +01:00
19 changed files with 189 additions and 33 deletions

2
.fvmrc
View File

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

View File

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

View File

@ -115,6 +115,7 @@ 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,6 +22,11 @@ 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);
@ -57,12 +62,15 @@ 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) {
unawaited(onOpenedOrResumed());
startOpenChain();
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());
unawaited(onOpenedOrResumed());
startOpenChain();
}
@override

View File

@ -27,6 +27,7 @@ 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';
@ -241,6 +242,10 @@ 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: "8dd9625c9c26379a5753ad24c33af1d3dc5ce1f36f19c03e17c676c2f8fdbb80"
sha256: "683d15fdde49a942bacce871faf3090bda3c1f5dad995725337aeb1dfd348e6d"
url: "https://pub.dev"
source: hosted
version: "13.3.2"
version: "14.0.0"
hooks:
dependency: transitive
description:
@ -682,6 +682,15 @@ 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.186+1
version: 1.0.190+1
environment:
sdk: ^3.12.2
@ -48,11 +48,16 @@ dependencies:
url: https://github.com/kuhyx/utils
ref: google_account_token-v0.1.0
path: google_account_token
health: 13.3.2
health: 14.0.0
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,13 +65,20 @@ 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.
Future<void> settle(WidgetTester tester) async {
// [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 {
tester.view.physicalSize = const Size(800, 1400);
tester.view.devicePixelRatio = 1.0;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
await Future<void>.delayed(const Duration(milliseconds: 200));
await tester.pumpAndSettle();
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));
}
/// Drains the device flow's real `Future.delayed` poll (GitHubDeviceAuth
@ -167,7 +174,7 @@ void main() {
await settle(tester);
await tester.tap(controlByLabel('Sync now'));
await settle(tester);
await settle(tester, until: cueLabelled('Synced.'));
expect(cueLabelled('Synced.'), findsOneWidget);
});
@ -197,7 +204,7 @@ void main() {
await settle(tester);
await tester.tap(controlByLabel('Sync now'));
await settle(tester);
await settle(tester, until: cueLabelled('Synced.'));
expect(cueLabelled('Synced.'), findsOneWidget);
final status = await SyncHealth.read();
@ -228,7 +235,7 @@ void main() {
await settle(tester);
await tester.tap(controlByLabel('Sync now'));
await settle(tester);
await settle(tester, until: cueOfKind(CueKind.error));
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 settle(tester);
await settleOpen(tester);
}
testWidgets('opening in due mode logs the due dishes with no tap', (
@ -72,7 +72,11 @@ void main() {
await tester.runAsync(() async {
await open(tester);
await tester.tap(byIconLabel('Undo').first);
await settle(tester);
await settleUntil(
tester,
() async =>
(await LogStorageService.instance.todayEntries()).length == 1,
);
expect(find.byIcon(Icons.restaurant), findsOneWidget);
var live = await LogStorageService.instance.todayEntries();
expect(live.map((e) => e.desc), ['Danie 2']);
@ -130,7 +134,7 @@ void main() {
(state as WidgetsBindingObserver).didChangeAppLifecycleState(
AppLifecycleState.resumed,
);
await settle(tester);
await settleOpen(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 settle(tester);
await settleOpen(tester);
}
testWidgets('the request id is a ULID and the mode follows due mode', (
@ -75,7 +75,12 @@ void main() {
await settle(tester);
await tester.tap(controlByLabel('Log meal'));
await settle(tester);
await settleUntil(
tester,
() async =>
relay.cancelled.isNotEmpty &&
byIconLabel('Ask Claude').evaluate().isNotEmpty,
);
expect(relay.cancelled, [relay.sent.single.requestId]);
expect(byIconLabel('Ask Claude'), findsOneWidget);
@ -88,7 +93,12 @@ void main() {
_claudeEntry(claudeEntryId(relay.sent.single.requestId)),
),
);
await settle(tester);
await settleUntil(
tester,
() async =>
(await LogStorageService.instance.todayEntries()).length ==
(claimed ? 2 : 1),
);
final live = await LogStorageService.instance.todayEntries();
expect(live, hasLength(claimed ? 2 : 1));
});

View File

@ -4,6 +4,8 @@ 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';
@ -51,3 +53,28 @@ 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,6 +10,7 @@ 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';
@ -224,4 +225,17 @@ 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,6 +58,7 @@ 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
@ -127,8 +128,7 @@ 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's defaults are the design-system palette
# and _gatelock_ui reads them too (an override drifted once).
# No colour overrides: LockConfig defaults are the palette (one drifted).
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)
# 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.
# A returning output gets its bindings; re-wiring the rest is a no-op.
self._wire_events()
def teardown_surface(self, surface: SurfaceInfo) -> None:

View File

@ -0,0 +1,27 @@
"""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,6 +202,8 @@ 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

@ -0,0 +1,35 @@
"""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,9 +7,10 @@ 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.5#subdirectory=sickdays",
"claude-agent-sdk==0.2.185",
"sickdays @ git+https://github.com/kuhyx/utils@sickdays-v0.5.6#subdirectory=sickdays",
"claude-agent-sdk==0.2.187",
"defusedxml==0.7.1",
"httpx==0.28.1",
"requests==2.34.2",
@ -25,7 +26,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.15"]
dev = ["hypothesis==6.170.17"]
# 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,20 +1,21 @@
# 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.185
claude-agent-sdk==0.2.187
codespell==2.4.3
coverage==7.17.3
coverage==7.17.4
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.15
hypothesis==6.170.17
kuhy-credit @ git+https://github.com/kuhyx/utils@kuhy-credit-v0.3.0#subdirectory=kuhy_credit
mcp==2.3.0
mypy==2.4.1
pre-commit==4.7.0
pydantic==2.14.3
pydantic==2.14.4
pylint==4.1.4
pytest==9.2.0
pytest-cov==7.1.0
@ -24,5 +25,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.5
sickdays @ git+https://github.com/kuhyx/utils@sickdays-v0.5.5#subdirectory=sickdays
ruff==0.17.6
sickdays @ git+https://github.com/kuhyx/utils@sickdays-v0.5.6#subdirectory=sickdays