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
230 lines
8.0 KiB
Dart
230 lines
8.0 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:device_info_plus/device_info_plus.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:http/http.dart' as http;
|
|
import 'package:http/testing.dart';
|
|
import 'package:package_info_plus/package_info_plus.dart';
|
|
import 'package:plezy/focus/focusable_action_bar.dart';
|
|
import 'package:plezy/focus/input_mode_tracker.dart';
|
|
import 'package:plezy/i18n/strings.g.dart';
|
|
import 'package:plezy/screens/settings/logs_screen.dart';
|
|
import 'package:plezy/services/log_upload_service.dart';
|
|
import 'package:plezy/services/startup_diagnostics.dart';
|
|
import 'package:plezy/utils/app_logger.dart';
|
|
import 'package:plezy/utils/media_server_http_client.dart';
|
|
|
|
void main() {
|
|
setUpAll(() {
|
|
LocaleSettings.setLocaleSync(AppLocale.en);
|
|
});
|
|
|
|
setUp(() {
|
|
MemoryLogOutput.clearLogs();
|
|
});
|
|
|
|
tearDown(() {
|
|
MemoryLogOutput.clearLogs();
|
|
});
|
|
test('log upload payload preserves the header and newest complete lines', () {
|
|
const header = 'Plezy test device\n---\n';
|
|
const logs = 'oldest line that should be removed\nmiddle line that should be removed\nnewest 🚀 line';
|
|
|
|
final payload = constrainLogUploadPayload(header: header, logs: logs, maxBytes: 52);
|
|
|
|
expect(utf8.encode(payload).length, lessThanOrEqualTo(52));
|
|
expect(payload, startsWith(header));
|
|
expect(payload, endsWith('newest 🚀 line'));
|
|
expect(payload, isNot(contains('oldest line')));
|
|
});
|
|
|
|
test('log upload payload remains unchanged below the server limit', () {
|
|
const header = 'device\n---\n';
|
|
const logs = 'one\ntwo';
|
|
|
|
expect(constrainLogUploadPayload(header: header, logs: logs, maxBytes: 128), '$header$logs');
|
|
});
|
|
|
|
testWidgets('long upload capability displays and copies at narrow width', (tester) async {
|
|
const capability = 'abcdefghijklmnopqrstuvwxy';
|
|
String? uploadedBody;
|
|
http.Request? uploadedRequest;
|
|
String? clipboardText;
|
|
|
|
PackageInfo.setMockInitialValues(
|
|
appName: 'Plezy',
|
|
packageName: 'com.plezy.test',
|
|
version: '1.2.3',
|
|
buildNumber: '45',
|
|
buildSignature: '',
|
|
);
|
|
final deviceInfo = DeviceInfoPlugin.setMockInitialValues(
|
|
linuxDeviceInfo: LinuxDeviceInfo(
|
|
name: 'Test Linux',
|
|
id: 'test-linux',
|
|
prettyName: 'Test Linux',
|
|
machineId: 'test-machine',
|
|
),
|
|
);
|
|
const deviceInfoChannel = MethodChannel('dev.fluttercommunity.plus/device_info');
|
|
final messenger = TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger;
|
|
messenger.setMockMethodCallHandler(deviceInfoChannel, (call) async {
|
|
expect(call.method, 'getDeviceInfo');
|
|
return <String, dynamic>{
|
|
'computerName': 'test-mac',
|
|
'hostName': 'test-mac.local',
|
|
'arch': 'arm64',
|
|
'model': 'Mac15,3',
|
|
'modelName': 'Mac',
|
|
'kernelVersion': 'test',
|
|
'osRelease': '15.0',
|
|
'majorVersion': 15,
|
|
'minorVersion': 0,
|
|
'patchVersion': 0,
|
|
'activeCPUs': 8,
|
|
'memorySize': 16 * 1024 * 1024 * 1024,
|
|
'cpuFrequency': 0,
|
|
'systemGUID': 'test-guid',
|
|
};
|
|
});
|
|
messenger.setMockMethodCallHandler(SystemChannels.platform, (call) async {
|
|
if (call.method == 'Clipboard.setData') {
|
|
clipboardText = (call.arguments as Map<Object?, Object?>)['text'] as String?;
|
|
}
|
|
return null;
|
|
});
|
|
addTearDown(() {
|
|
messenger.setMockMethodCallHandler(deviceInfoChannel, null);
|
|
messenger.setMockMethodCallHandler(SystemChannels.platform, null);
|
|
});
|
|
|
|
final client = MediaServerHttpClient(
|
|
client: MockClient((request) async {
|
|
uploadedRequest = request;
|
|
uploadedBody = request.body;
|
|
return http.Response(
|
|
jsonEncode(<String, String>{'id': capability}),
|
|
200,
|
|
headers: {'content-type': 'application/json'},
|
|
);
|
|
}),
|
|
);
|
|
addTearDown(client.close);
|
|
appLogger.i('widget upload seed');
|
|
|
|
tester.view.physicalSize = const Size(320, 640);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.resetPhysicalSize);
|
|
addTearDown(tester.view.resetDevicePixelRatio);
|
|
await tester.pumpWidget(
|
|
TranslationProvider(
|
|
child: InputModeTracker(
|
|
child: MaterialApp(
|
|
home: LogsScreen(httpClient: client, deviceInfoPlugin: deviceInfo),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
|
|
await tester.tap(find.byTooltip(t.logs.uploadLogs));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(tester.takeException(), isNull);
|
|
expect(find.text(capability, findRichText: true), findsOneWidget);
|
|
expect(utf8.encode(uploadedBody!).length, lessThanOrEqualTo(maxLogUploadBytes));
|
|
expect(uploadedRequest!.method, 'POST');
|
|
expect(uploadedRequest!.url, Uri.parse('https://ice.plezy.app/logs'));
|
|
final contentType = uploadedRequest!.headers.entries
|
|
.singleWhere((entry) => entry.key.toLowerCase() == 'content-type')
|
|
.value;
|
|
expect(contentType, startsWith('text/plain'));
|
|
expect(uploadedBody, contains('widget upload seed'));
|
|
|
|
final dialog = find.byType(AlertDialog);
|
|
final copyButton = find.descendant(of: dialog, matching: find.byType(IconButton));
|
|
expect(copyButton, findsOneWidget);
|
|
await tester.tap(copyButton);
|
|
await tester.pump();
|
|
expect(clipboardText, capability);
|
|
|
|
clipboardText = null;
|
|
await tester.sendKeyDownEvent(LogicalKeyboardKey.shiftLeft);
|
|
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
|
|
await tester.sendKeyUpEvent(LogicalKeyboardKey.shiftLeft);
|
|
await tester.pump();
|
|
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
|
|
await tester.pump();
|
|
expect(clipboardText, capability);
|
|
expect(tester.takeException(), isNull);
|
|
});
|
|
|
|
group('previous startup failure', () {
|
|
late StartupFailureRecord record;
|
|
|
|
Future<void> pumpLogs(WidgetTester tester) async {
|
|
PackageInfo.setMockInitialValues(
|
|
appName: 'Plezy',
|
|
packageName: 'com.plezy.test',
|
|
version: '2.11.0',
|
|
buildNumber: '124',
|
|
buildSignature: '',
|
|
);
|
|
await tester.pumpWidget(
|
|
TranslationProvider(
|
|
child: InputModeTracker(child: MaterialApp(home: const LogsScreen())),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
}
|
|
|
|
setUp(() {
|
|
StartupDiagnosticsStore.resetForTesting();
|
|
record = StartupFailureRecord.fromError(
|
|
phase: StartupPhase.database,
|
|
error: StateError('sqlite could not open'),
|
|
stackTrace: StackTrace.empty,
|
|
appVersion: '2.11.0+124',
|
|
platform: 'windows 11',
|
|
);
|
|
});
|
|
|
|
tearDown(StartupDiagnosticsStore.resetForTesting);
|
|
|
|
testWidgets('renders nothing when no launch has failed', (tester) async {
|
|
await pumpLogs(tester);
|
|
|
|
expect(find.byKey(previousStartupFailureKey), findsNothing);
|
|
});
|
|
|
|
testWidgets('shows the recorded failure so the user can see and act on it', (tester) async {
|
|
// The failing process left no in-memory log at all; this banner is the
|
|
// only surface that failure ever reaches (#1732).
|
|
StartupDiagnosticsStore.setPendingForTesting(record);
|
|
|
|
await pumpLogs(tester);
|
|
|
|
expect(find.byKey(previousStartupFailureKey), findsOneWidget);
|
|
expect(find.textContaining('sqlite could not open'), findsOneWidget);
|
|
expect(find.textContaining('Phase: database'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('enables upload and copy with a record but an empty log buffer', (tester) async {
|
|
MemoryLogOutput.clearLogs();
|
|
StartupDiagnosticsStore.setPendingForTesting(record);
|
|
|
|
await pumpLogs(tester);
|
|
|
|
// Gating these on the log buffer alone would show the record and then
|
|
// refuse to let the user do anything with it.
|
|
final bar = tester.widget<FocusableActionBar>(find.byType(FocusableActionBar));
|
|
for (final tooltip in [t.logs.uploadLogs, t.logs.copyLogs, t.logs.clearLogs]) {
|
|
final action = bar.actions.singleWhere((candidate) => candidate.tooltip == tooltip);
|
|
expect(action.onPressed, isNotNull, reason: tooltip);
|
|
}
|
|
});
|
|
});
|
|
}
|