mirror of
https://github.com/kuhyx/wake-alarm.git
synced 2026-11-23 11:46:30 +01:00
On 2026-09-19 the phone was powered off after the bathroom tag and nothing on the PC noticed: every finished session was published and nothing read it. Now wake-alarm distils the phone's morning into an HMAC-signed ~/.local/state/wake_alarm/morning_session.json (wake-alarm-session.timer, 07:00-11:00 every 2 min) that screen-locker and leetcode-guard read to defer their locks -- provisionally until min(start + 90 min, 09:30) while the session is live, until 11:00 once it completed inside that cutoff, and not at all for a session finished later (the phone switched on at noon completes the legs then; that must un-lock nothing). The phone publishes the session at start as well as at finish (current_session, cleared with the finish stamp), so the PC can tell "started, not finished" from "never started". A required 1-5 energy tap joins the weigh-in and ships as latest_energy with a PC reader mirroring _weight (the shared half is _field_reader). Also fixes the vmbox harness, red since the 2026-09-11 home-tidy: the guest tree lives at ~/wake-alarm, and the INSTALL-OK grep matched vm's echo of the command line. Takes Flutter 3.47.5. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tp54ewdXRLaimUuT8LgYyn
82 lines
2.8 KiB
Dart
82 lines
2.8 KiB
Dart
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:wake_alarm_sync/services/alarm_scheduler.dart';
|
|
import 'package:wake_alarm_sync/services/morning_session.dart';
|
|
import 'package:wake_alarm_sync/services/session_notice.dart';
|
|
import 'package:wake_alarm_sync/services/session_rules.dart';
|
|
import 'package:wake_alarm_sync/services/session_tag_settings.dart';
|
|
|
|
final DateTime t0 = DateTime(2026, 9, 17, 8, 5);
|
|
const SessionTagSettings allTags = SessionTagSettings(
|
|
tagIds: <String>['bath', 'ward', 'desk'],
|
|
);
|
|
|
|
MorningSession fresh() =>
|
|
SessionRules.start(now: t0, tags: allTags, nfcAvailable: true);
|
|
|
|
void main() {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
late List<MethodCall> calls;
|
|
late AlarmScheduler scheduler;
|
|
|
|
setUp(() {
|
|
calls = <MethodCall>[];
|
|
const channel = MethodChannel(AlarmScheduler.channelName);
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
|
.setMockMethodCallHandler(channel, (call) async {
|
|
calls.add(call);
|
|
return null;
|
|
});
|
|
scheduler = AlarmScheduler(channel: channel);
|
|
});
|
|
|
|
test('the label is the live leg', () {
|
|
expect(noticeLabel(fresh()), 'Tap the bathroom tag');
|
|
});
|
|
|
|
test('a leg whose re-ring is spent says it will pass by itself', () {
|
|
final s = fresh()..deadlineRung.add(SessionLeg.bathroomIn);
|
|
expect(noticeLabel(s), 'Tap the bathroom tag — passes by itself soon');
|
|
});
|
|
|
|
test('a finished session drops the deadline and posts no notice', () async {
|
|
final s = fresh()
|
|
..enterCheckIn(72, 3, t0)
|
|
..onTag(SessionTagSlot.bathroom, t0)
|
|
..onTag(SessionTagSlot.bathroom, t0.add(const Duration(minutes: 9)))
|
|
..onTag(SessionTagSlot.wardrobe, t0)
|
|
..onTag(SessionTagSlot.desk, t0);
|
|
expect(s.isActive, isFalse);
|
|
await pointNativeAtLeg(scheduler, s);
|
|
expect(calls.map((c) => c.method), <String>['armReRing']);
|
|
expect(calls.single.arguments, <String, int?>{'atMillis': null});
|
|
});
|
|
|
|
test('pointNativeAtLeg arms the deadline and the notice together', () async {
|
|
final s = fresh();
|
|
await pointNativeAtLeg(scheduler, s);
|
|
expect(calls.map((c) => c.method), <String>[
|
|
'armReRing',
|
|
'updateSessionNotice',
|
|
]);
|
|
final deadline = s.nextDeadline()!.millisecondsSinceEpoch;
|
|
expect(calls[0].arguments, <String, int?>{'atMillis': deadline});
|
|
expect(calls[1].arguments, <String, Object?>{
|
|
'date': '2026-09-17',
|
|
'label': 'Tap the bathroom tag',
|
|
'deadlineMillis': deadline,
|
|
});
|
|
});
|
|
|
|
test('a spent re-ring sends no deadline to either side', () async {
|
|
final s = fresh()..deadlineRung.add(SessionLeg.bathroomIn);
|
|
await pointNativeAtLeg(scheduler, s);
|
|
expect(calls[0].arguments, <String, int?>{'atMillis': null});
|
|
expect(
|
|
(calls[1].arguments as Map<Object?, Object?>)['deadlineMillis'],
|
|
isNull,
|
|
);
|
|
});
|
|
}
|