wake-alarm/phone_app/test/free_day_interop_writer_test.dart
Krzysztof kuhy Rudnicki 758b2976b8 Gate the free-day rules against the Python package, and fix two picker paths
showDatePicker asserts that initialDate satisfies selectableDayPredicate,
so with today already free the picker asserted in debug and, in release,
pre-selected a disabled day. The cursor now starts on the first non-free
day. And the reason dialog had no Cancel: a barrier tap marked the day
anyway. Both covered by widget tests; the first fails without the fix.

The cross-language check that proved the Dart port was a one-off probe,
deleted after it ran. It is now scripts/free_days_interop/check.sh, a
pre-commit hook on both inputs: Dart writes one pool through every policy
branch, Python replays the same edits into a scratch pool, and every
semantic reading has to agree. The Python package is the oracle -- Dart's
own count compared to what Python reads from Dart's file cannot see a
drift in what Dart writes. Proved by dropping the sticky consumed flag
from release: remaining dart=33 python=32.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019pBgaXSJKyY3DarYpDatDF
2026-09-11 13:53:56 +02:00

45 lines
1.6 KiB
Dart

import 'dart:io';
import 'package:crdt_sync/crdt_sync.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:wake_alarm_sync/services/free_day_pool.dart';
/// Half of the cross-language gate (`scripts/free_days_interop/check.sh`).
///
/// Writes a pool through the Dart rules to `FREE_DAYS_INTEROP_OUT`, then the
/// script replays the same edits through the Python package and compares. Under a plain
/// `flutter test` the variable is unset and this does nothing: the point is
/// the comparison, and only the script can make it.
class _FilePersistence implements LogPersistence {
_FilePersistence(this.file);
final File file;
@override
Future<String?> read() async =>
file.existsSync() ? file.readAsStringSync() : null;
@override
Future<void> write(String text) async => file.writeAsStringSync(text);
}
void main() {
test('writes the interop fixture when asked', () async {
final out = Platform.environment['FREE_DAYS_INTEROP_OUT'];
if (out == null) return;
final pool = await FreeDayPool.open(
persistence: _FilePersistence(File(out)),
deviceId: 'dart-interop',
);
final now = DateTime(2026, 9, 11);
// One of each policy branch: future, today (consumed on the spot),
// future then refunded, and released only after it had arrived.
await pool.mark(DateTime(2026, 9, 12), reason: 'from dart', now: now);
await pool.mark(now, now: now);
await pool.mark(DateTime(2026, 9, 13), now: now);
await pool.release(DateTime(2026, 9, 13), now: now);
await pool.mark(DateTime(2026, 9, 14), now: now);
await pool.release(DateTime(2026, 9, 14), now: DateTime(2026, 9, 14));
});
}