screen-locker/stronglift_replacement/workout_app/test/flutter_test_config.dart
Krzysztof kuhy Rudnicki 74be875900 workout_app: offline-first workout sync
A finished workout's record now lands in a local crdt log
(workout_log.json) before any network call. Every sync tick pushes that
log, so a failed or unconfigured push goes out with the next tick (home
open, app resume, a 5-minute WorkoutResync retry). The re-push carries
the same record and clock; the PC credits once per type:date anyway.

Every tick and every live history read merges what it pulled into the
same log, so PC records stay readable offline and after a restart.
History shows local rows plus cached synced rows at once, then refreshes
from the live read in the background. Ticks run one at a time, each
cut off after 2 min so a hung request cannot block the queue.

Bug-class-check: stronglift_replacement/workout_app/test/services/workout_sync_offline_test.dart, test/screens/workout_finish_keeps_record_test.dart, test/screens/history_offline_test.dart
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 17:09:54 +01:00

41 lines
1.7 KiB
Dart

/// Suite-wide setup: applied by `flutter test` to every test file below.
///
/// The test host is Linux, so every `Platform.isLinux` desktop branch runs
/// here -- including the one that stores the Firebase refresh token in
/// `~/.config/screen_locker/firebase_auth.json`, the live credential the
/// screen-locker daemon signs in with. A sign-in test once overwrote it with
/// fixture values and still passed. Each test now gets its own throwaway
/// config root instead; `desktopConfigRoot` refuses the real one under
/// `flutter test`, so a test that slipped past this fails loudly.
library;
import 'dart:async';
import 'dart:io';
import 'package:flutter_test/flutter_test.dart';
import 'package:workout_app/services/desktop_config_dir.dart';
import 'package:workout_app/services/workout_log_store.dart';
import 'package:workout_app/services/workout_sync_session.dart';
Future<void> testExecutable(FutureOr<void> Function() testMain) async {
// Also set up front, so code that runs while tests are being declared is
// redirected too, not only code inside a test body.
final declarationRoot = _freshRoot();
desktopConfigRootOverride = declarationRoot.path;
// The workout log (outbox + cache) gets the same per-test root, so no test
// reads another's records or reaches the app support directory.
workoutLogDirOverride = declarationRoot.path;
tearDownAll(() => declarationRoot.deleteSync(recursive: true));
setUp(() {
final root = _freshRoot();
desktopConfigRootOverride = root.path;
workoutLogDirOverride = root.path;
WorkoutSyncSession.resetQueueForTesting();
addTearDown(() => root.deleteSync(recursive: true));
});
await testMain();
}
Directory _freshRoot() =>
Directory.systemTemp.createTempSync('workout_app_test_config_');