mirror of
https://github.com/kuhyx/wake-alarm.git
synced 2026-11-21 18:22:18 +01:00
The dismiss gate was an OR — NFC tag *or* QR *or* (25 steps + 2 min) —
followed by one challenge. QR never worked at ring time (no scanner
package, no CAMERA permission, `onQrScanned` had no caller), so the real
bar was "walk 25 steps, wait 2 minutes, answer one question" and the NFC
tag was already fully bypassable.
It is now a strict, latched sequence owned by `DismissGate`:
tag 1 -> 25 steps + 2 min -> tag 2 -> 3 challenges
Every stage is required, in that order, and a stage once passed never
reverts. That last part also fixes a real bug: `_onNfcTag` and `_trySteps`
both assigned the room-proof result straight onto `_inRoom`, so a wrong
tag tapped after the gate had passed sent the user back to the start.
Two *distinct* tags are required; the same id in both slots is refused at
registration, since one tag satisfying both stages removes the walk that
is the whole point. The existing single-tag registration migrates into
slot 1 rather than being stranded.
Answers are cumulative, not consecutive: a wrong one costs the attempt and
nothing else.
The bypass is the only fallback and is deliberately narrow. After 5 minutes
of ringing, or immediately when NFC is off or fewer than two distinct tags
are registered, the two *tag* stages are skipped and the count rises to 6.
The walk is never skipped — jumping straight to the challenges would let
someone lie in bed for five minutes and answer questions without standing
up, which is weaker than the gate this replaces. Without some such hatch a
dead tag at 06:00 leaves an alarm that cannot be switched off at all.
Also deletes the `flash` challenge outright, along with the now-orphaned
`generateCode`/`kDismissCodeLength`/`_dismissChars`. It was the only kind
that removed its prompt from the screen, which is unsolvable for someone
who has just walked in from another room.
The ring screen takes an injectable clock: `Stopwatch` reads the wall
clock, which `tester.pump()` does not advance, so without that seam no
widget test could reach the two-minute floor or the five-minute bypass.
Verified on the Pixel 6a: the existing tag migrated into slot 1 and both
rows render. 102 Dart tests pass; analyzer clean.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PcdngP688mW6rJye3LRkSN
71 lines
2.7 KiB
Dart
71 lines
2.7 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import 'package:wake_alarm_sync/services/room_proof_settings.dart';
|
|
|
|
void main() {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
setUp(() => SharedPreferences.setMockInitialValues(<String, Object>{}));
|
|
|
|
test('an unconfigured install registers no tags', () async {
|
|
final settings = await RoomProofSettings.load();
|
|
expect(settings.tagAt(0), isNull);
|
|
expect(settings.tagAt(1), isNull);
|
|
expect(settings.isComplete, isFalse);
|
|
});
|
|
|
|
test('each slot round-trips independently', () async {
|
|
await RoomProofSettings.saveNfcTagAt(0, '04a2b3c4');
|
|
expect((await RoomProofSettings.load()).tagAt(0), '04a2b3c4');
|
|
expect((await RoomProofSettings.load()).tagAt(1), isNull);
|
|
|
|
await RoomProofSettings.saveNfcTagAt(1, '04ffee11');
|
|
final both = await RoomProofSettings.load();
|
|
expect(both.tagAt(0), '04a2b3c4', reason: 'slot 0 must survive');
|
|
expect(both.tagAt(1), '04ffee11');
|
|
expect(both.isComplete, isTrue);
|
|
});
|
|
|
|
test('re-registering one slot leaves the other alone', () async {
|
|
await RoomProofSettings.saveNfcTagAt(0, 'aaa');
|
|
await RoomProofSettings.saveNfcTagAt(1, 'bbb');
|
|
await RoomProofSettings.saveNfcTagAt(0, 'ccc');
|
|
final settings = await RoomProofSettings.load();
|
|
expect(settings.tagAt(0), 'ccc');
|
|
expect(settings.tagAt(1), 'bbb');
|
|
});
|
|
|
|
test('a legacy single tag migrates into slot 1', () async {
|
|
// An existing install has one tag under the pre-two-tag key. Losing it
|
|
// would leave the user bypass-only on the first morning after updating.
|
|
SharedPreferences.setMockInitialValues(<String, Object>{
|
|
RoomProofSettings.kLegacyNfcTagKey: '0465dab3ce2a81',
|
|
});
|
|
final settings = await RoomProofSettings.load();
|
|
expect(settings.tagAt(0), '0465dab3ce2a81');
|
|
expect(settings.tagAt(1), isNull);
|
|
expect(settings.isComplete, isFalse);
|
|
});
|
|
|
|
test('the same tag in both slots is not a complete configuration', () async {
|
|
// One physical tag satisfying both stages would remove the walk.
|
|
await RoomProofSettings.saveNfcTagAt(0, 'same');
|
|
await RoomProofSettings.saveNfcTagAt(1, 'same');
|
|
expect((await RoomProofSettings.load()).isComplete, isFalse);
|
|
});
|
|
|
|
test('a malformed stored value degrades to unregistered', () async {
|
|
SharedPreferences.setMockInitialValues(<String, Object>{
|
|
RoomProofSettings.kNfcTagsKey: 'not json',
|
|
});
|
|
final settings = await RoomProofSettings.load();
|
|
expect(settings.tagAt(0), isNull);
|
|
expect(settings.isComplete, isFalse);
|
|
});
|
|
|
|
test('an out-of-range slot write is ignored', () async {
|
|
await RoomProofSettings.saveNfcTagAt(5, 'nope');
|
|
expect((await RoomProofSettings.load()).isComplete, isFalse);
|
|
});
|
|
}
|