Pass the gate: emu export typing, test split
Some checks are pending
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,free-days-interop,dependency-freshness) (push) Waiting to run
Tests / test (push) Waiting to run
Tests / free-days-interop (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Krzysztof Rudnicki 2026-11-22 16:36:06 +01:00
parent 032358cc03
commit 6be954afd4
3 changed files with 49 additions and 23 deletions

View File

@ -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: <String>['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, <String>['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, <String>['deadline:bathroomIn']);
});
}

View File

@ -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, <String>['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, <String>['deadline:bathroomIn']);
});
test('a miss with no re-rings left fails the session', () {
final s = fresh()..reRings = MorningSession.maxReRings;
expect(s.nextDeadline(), isNull);

24
scripts/emu_published.py Normal file → Executable file
View File

@ -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