diff --git a/phone_app/test/services/session_bypass_rering_test.dart b/phone_app/test/services/session_bypass_rering_test.dart new file mode 100644 index 0000000..9373097 --- /dev/null +++ b/phone_app/test/services/session_bypass_rering_test.dart @@ -0,0 +1,31 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:wake_alarm_sync/services/morning_session.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); + +MorningSession fresh() => SessionRules.start( + now: t0, + tags: const SessionTagSettings(tagIds: ['bath', 'ward', 'desk']), + nfcAvailable: true, +); + +void main() { + test('a bypass re-ring is named for its cause and counted once', () { + final s = fresh() + ..markReRing('deadline:bathroomIn', t0) + ..adoptBypassReRing('fsi_revoked') + ..recordReRing(t0.add(const Duration(minutes: 3))); + expect(s.reRings, 1); + expect(s.reRingReasons, ['bypass:fsi_revoked']); + }); + + test('no bypass stamped keeps the deadline reason', () { + final s = fresh() + ..markReRing('deadline:bathroomIn', t0) + ..adoptBypassReRing(null) + ..recordReRing(t0.add(const Duration(minutes: 3))); + expect(s.reRingReasons, ['deadline:bathroomIn']); + }); +} diff --git a/phone_app/test/services/session_rules_test.dart b/phone_app/test/services/session_rules_test.dart index 567a9bf..f8b9958 100644 --- a/phone_app/test/services/session_rules_test.dart +++ b/phone_app/test/services/session_rules_test.dart @@ -188,23 +188,6 @@ void main() { }, ); - test('a bypass re-ring is named for its cause and counted once', () { - final s = fresh() - ..markReRing('deadline:bathroomIn', t0) - ..adoptBypassReRing('fsi_revoked') - ..recordReRing(t0.add(const Duration(minutes: 3))); - expect(s.reRings, 1); - expect(s.reRingReasons, ['bypass:fsi_revoked']); - }); - - test('no bypass stamped keeps the deadline reason', () { - final s = fresh() - ..markReRing('deadline:bathroomIn', t0) - ..adoptBypassReRing(null) - ..recordReRing(t0.add(const Duration(minutes: 3))); - expect(s.reRingReasons, ['deadline:bathroomIn']); - }); - test('a miss with no re-rings left fails the session', () { final s = fresh()..reRings = MorningSession.maxReRings; expect(s.nextDeadline(), isNull); diff --git a/scripts/emu_published.py b/scripts/emu_published.py old mode 100644 new mode 100755 index c3239c4..e458dab --- a/scripts/emu_published.py +++ b/scripts/emu_published.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -"""Export what the emulator phone published to the Firebase RTDB emulator. +r"""Export what the emulator phone published to the Firebase RTDB emulator. The emulator live checks (a ``bypass`` reaching "the test backend") use a probe build that syncs to the PC's RTDB emulator instead of prod @@ -28,13 +28,24 @@ import json from pathlib import Path import sys -from crdt_sync import FirebaseSyncClient +from crdt_sync import ( + FirebaseSyncClient, + FirebaseTokenProvider, + MemoryCredentialStore, +) from wake_alarm._sync_transport import _read_published -class _OwnerToken: - """The emulator's admin token; the RTDB emulator accepts ``auth=owner``.""" +class _OwnerToken(FirebaseTokenProvider): + """The emulator's admin token; the RTDB emulator accepts ``auth=owner``. + + Never signs in: no API key, an empty store, and ``id_token`` overridden. + """ + + def __init__(self) -> None: + """A provider with nothing to refresh.""" + super().__init__("", MemoryCredentialStore()) def id_token(self) -> str: """Every request's ``auth`` parameter.""" @@ -47,11 +58,12 @@ def main(argv: list[str] | None = None) -> int: parser.add_argument("url", help="the RTDB emulator's origin") parser.add_argument("out", type=Path, help="where to write the JSON list") args = parser.parse_args(argv) - client = FirebaseSyncClient(args.url, _OwnerToken()) # type: ignore[arg-type] + client = FirebaseSyncClient(args.url, _OwnerToken()) published = _read_published(client) pairs = [[device, json.loads(raw)] for device, raw in published] args.out.write_text(json.dumps(pairs, indent=1), encoding="utf-8") - print(f"{len(pairs)} device(s): {' '.join(device for device, _ in pairs)}") + devices = " ".join(device for device, _ in pairs) + sys.stdout.write(f"{len(pairs)} device(s): {devices}\n") return 0 if pairs else 1