Since 2.10.0 the whole app sits behind one all-or-nothing initialization gate, and that gate discarded the only evidence of its own failure. It caught the error, logged nothing but `error.runtimeType`, rendered an icon plus the word "Error" plus Retry, and never reported the error because catching it kept the crash reporter from ever seeing it. There is no log file on any platform, the buffer is in memory only, a double-clicked Windows release build has no console, and the log viewer lives in Settings, behind the gate that just failed. #1732 is the result: a Windows 11 user whose app will not boot and who cannot produce a single byte of diagnostic detail. The gate now names its phases. Each step is wrapped so a throw carries the phase it came from, replacing a `Future.wait` that discarded every error but the first and could not attribute it to any of four concurrent steps. The failure screen renders the phase, the exception type, the message and an expandable stack, plus copy and upload actions that reuse the existing log-relay flow. The record is persisted next to the database so the next successful launch can surface it in Settings > Logs, and it is reported to the crash reporter explicitly. Only preferences and the database still gate the launch. Window chrome, locale, crash-reporting init, TV/performance detection, the image-cache budget and download storage are best-effort and time-bounded, so a stalled platform thread degrades instead of holding the splash forever. Sentry no longer receives the startup work as its `appRunner`: that made a startup failure indistinguishable from a Sentry failure, and the guard would then have re-run migrations and the database open a second time. The two remaining fatal steps become recoverable. Preference reads tolerate a value whose stored type no longer matches, dropping the key and defaulting instead of failing the boot. A store that cannot be parsed is detected before either desktop plugin backend can memoise it, which is what makes an in-process repair possible at all. Repair is never automatic: it states what it will cost, salvages the credential-vault key and every tracker and Seerr session it can validate out of the damaged bytes, reseeds them, and moves the original aside rather than deleting it. Servers and profiles survive a salvaged key because their tokens are ciphertext in the database; tracker and Seerr sessions are plaintext preference entries, so the copy says they may still need reconnecting. Nothing derived from the store reaches a diagnostic. `FormatException` prints an excerpt of whatever it failed to parse, and during startup that document holds the vault key, refresh tokens and session cookies while the redaction manager still has nothing registered, so the wrapper keeps only the cause's type and offset and the record is an allowlist of already-redacted fields. The quarantined copy is labelled as containing credentials, is never offered for upload, and can be deleted from the dialog. Also self-heals orphaned WAL/SHM sidecars on desktop rather than only tvOS, makes every `createTable` migration step idempotent, keeps MSVC link by-products out of the Windows bundle, and asserts bundle contents in CI. Refs #1732
122 lines
4.1 KiB
Dart
122 lines
4.1 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:plezy/i18n/strings.g.dart';
|
|
import 'package:plezy/main.dart';
|
|
import 'package:plezy/services/prefs_recovery.dart';
|
|
|
|
Future<void> _openDialog(
|
|
WidgetTester tester,
|
|
PrefsRepairOutcome outcome, {
|
|
Future<void> Function(String path)? deleteBackup,
|
|
}) async {
|
|
await tester.pumpWidget(
|
|
TranslationProvider(
|
|
child: MaterialApp(
|
|
home: Builder(
|
|
builder: (context) => Scaffold(
|
|
body: Center(
|
|
child: ElevatedButton(
|
|
onPressed: () =>
|
|
showRepairOutcomeDialog(context, outcome, deleteBackup: deleteBackup ?? PrefsRecovery.deleteBackup),
|
|
child: const Text('open'),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.tap(find.text('open'));
|
|
await tester.pumpAndSettle();
|
|
}
|
|
|
|
void main() {
|
|
setUpAll(() => LocaleSettings.setLocaleSync(AppLocale.en));
|
|
|
|
late Directory tempDir;
|
|
late File backup;
|
|
|
|
setUp(() async {
|
|
tempDir = await Directory.systemTemp.createTemp('plezy-repair-outcome');
|
|
backup = File('${tempDir.path}/shared_preferences.corrupt-x.json');
|
|
await backup.writeAsString('{"credential_vault_key_v1":"secret"}');
|
|
});
|
|
|
|
tearDown(() async {
|
|
if (await tempDir.exists()) await tempDir.delete(recursive: true);
|
|
});
|
|
|
|
testWidgets('warns that the backup holds credentials and must not be shared', (tester) async {
|
|
await _openDialog(
|
|
tester,
|
|
PrefsRepairOutcome(backupPath: backup.path, vaultKeySalvaged: true, sessionsSalvaged: 0, sessionsLost: 0),
|
|
);
|
|
|
|
expect(find.text(t.startup.backupTitle), findsOneWidget);
|
|
expect(find.text(t.startup.backupWarning), findsOneWidget);
|
|
expect(find.text(backup.path), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('deleting the backup removes the file and stops showing its path', (tester) async {
|
|
final deleted = <String>[];
|
|
await _openDialog(
|
|
tester,
|
|
PrefsRepairOutcome(backupPath: backup.path, vaultKeySalvaged: true, sessionsSalvaged: 0, sessionsLost: 0),
|
|
// The widget-test binding's fake-async zone never completes a `dart:io`
|
|
// future, so the real delete is covered in prefs_recovery_test.dart and
|
|
// this test owns the UI state that follows it.
|
|
deleteBackup: (path) async => deleted.add(path),
|
|
);
|
|
|
|
await tester.tap(find.text(t.startup.deleteBackup));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(deleted, [backup.path]);
|
|
// Regression: the flag lived inside the StatefulBuilder closure, so the
|
|
// rebuild it triggered reset it and the sensitive path stayed on screen.
|
|
expect(find.text(t.startup.backupDeleted), findsOneWidget);
|
|
expect(find.text(backup.path), findsNothing);
|
|
expect(find.text(t.startup.deleteBackup), findsNothing);
|
|
});
|
|
|
|
testWidgets('says sign-ins are kept only when the vault key survived', (tester) async {
|
|
await _openDialog(
|
|
tester,
|
|
PrefsRepairOutcome(backupPath: null, vaultKeySalvaged: true, sessionsSalvaged: 2, sessionsLost: 0),
|
|
);
|
|
|
|
expect(find.text(t.startup.repairKeptSignIns), findsOneWidget);
|
|
expect(find.text(t.startup.repairLostSignIns), findsNothing);
|
|
});
|
|
|
|
testWidgets('states the full credential loss when the vault key is gone', (tester) async {
|
|
await _openDialog(
|
|
tester,
|
|
PrefsRepairOutcome(backupPath: null, vaultKeySalvaged: false, sessionsSalvaged: 0, sessionsLost: 3),
|
|
);
|
|
|
|
expect(find.text(t.startup.repairLostSignIns), findsOneWidget);
|
|
// Tracker/Seerr sessions are plaintext preference entries, so they are
|
|
// reported separately from the vault-protected server tokens.
|
|
expect(find.text(t.startup.repairLostSessions), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('asks for a restart when the store could not be reopened', (tester) async {
|
|
await _openDialog(
|
|
tester,
|
|
PrefsRepairOutcome(
|
|
backupPath: null,
|
|
vaultKeySalvaged: true,
|
|
sessionsSalvaged: 1,
|
|
sessionsLost: 0,
|
|
requiresRestart: true,
|
|
),
|
|
);
|
|
|
|
expect(find.text(t.startup.repairNeedsRestart), findsOneWidget);
|
|
expect(find.text(t.startup.repairSucceeded), findsNothing);
|
|
});
|
|
}
|