screen-locker/stronglift_replacement/workout_app/test/flutter_test_config.dart
Krzysztof kuhy Rudnicki 0921146044 Tests can no longer write the live desktop Firebase credential
`flutter test` runs on a Linux host, so credentialStore()'s Platform.isLinux
branch wrote $HOME/.config/screen_locker/firebase_auth.json -- the refresh
token the screen-locker daemon signs in with. firebase_backend_google_test's
"stores the account under the email Firebase reports" case overwrote it with
the fixture token 'refresh' on every local run; the daemon only survived by
self-healing from a cached token.

Dart:
- lib/services/desktop_config_dir.dart: one resolver, desktopConfigRoot(),
  for every desktop path (the credential file's read/write/delete and the
  ~/.config/crdt-sync account read). @visibleForTesting override; under
  FLUTTER_TEST it throws StateError if the root is, or is inside, the real
  $HOME/.config -- so a test that bypasses the override fails loudly instead
  of writing. HOME unset now yields null instead of a cwd-relative .config.
- The crdt-sync read resolves the root outside its catch-all, so the guard
  cannot be swallowed as "not connected".
- test/flutter_test_config.dart gives every test its own temp config root.
- The Google sign-in test now asserts the token landed in that temp root.
- path_provider is unbound under flutter test (MissingPluginException), so
  the getApplicationSupportDirectory callers cannot reach live dirs.

Python (tests only): isolate_sync_token now patches every import-time
binding of SYNC_TOKEN_FILE (_constants, _manual_push, _sync_status were
missed), and test_home_isolation scans all runtime modules for any Path
still bound inside the real ~/.config/screen_locker.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KFwA9nymhUdTrVF65kigTV
2026-09-27 08:35:18 +02:00

34 lines
1.4 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';
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;
tearDownAll(() => declarationRoot.deleteSync(recursive: true));
setUp(() {
final root = _freshRoot();
desktopConfigRootOverride = root.path;
addTearDown(() => root.deleteSync(recursive: true));
});
await testMain();
}
Directory _freshRoot() =>
Directory.systemTemp.createTempSync('workout_app_test_config_');