feat(mobile): add screen breadcrumbs to diagnostic reports (#9823)

feat(mobile): add screen breadcrumbs to diagnostic reports
Adds screen breadcrumbs to mobile diagnostic reports, so a hang or error
report shows which screens the person was on before it happened. Today
the only breadcrumbs are foreground and background changes.

## Changes

- **Observers:** one `DiagnosticScreenTrail` is shared by an observer on
the root navigator and one on each conversation pane's nested navigator,
where channels, threads, search and activity open. A breadcrumb is left
on push, replace, and when a page is shown again after a pop, a frame
later and only for the page that ends up visible.
- **The screen the person is on:** a route that hosts a pane with a page
open past its first (a phone conversation over the channel list, or a
wide conversation beside it) is named by that page. So closing a
full-screen cover, such as a huddle, over an open channel records
`channel`, not `channelList`.
- **No repeats:** a screen equal to the last one is skipped. A pane host
and its pane's empty first page both name the host, and wide Settings
sections all show Settings, so these leave one crumb. The empty first
page still gives Home its crumb after sign-in.
- **Names come from a fixed list owned by the app:**
`lib/diagnostic_screens.dart` maps page widgets to names such as
`channelList`, `channel`, `thread`, `settings` or `addCommunity`, and
reaches the observers through `diagnosticScreenClassifierProvider`,
which the root scope overrides. Any other page is `other`. Route
settings and page content are never read, so no channel name, ID or text
can reach a breadcrumb.
- **Dialogs, sheets and menus are skipped:** popup routes leave nothing,
and the Duo channel sheet, which is a page route, opts out with
`DiagnosticSheetRoute`.
- **Filter:** adds a `navigation` category to the breadcrumb list. A
navigation breadcrumb leaves with only its screen name, and it is
dropped if that name isn't on the list.
- **No destination:** a build without a reporting destination does
nothing; the observers don't even inspect routes.
- **Spec:** the breadcrumb list, user story 7, and the out-of-scope line
about behavior data.

## Regressions

- **Architecture:** the screen list lives with the app, so `shared/`
gains no imports from features. The shared conversation pane's import
closure is unchanged from main.
- **Performance:** the route walk costs well under a millisecond per
navigation (28 to 155 µs measured, against 58 to 143 ms for the push
frame). Rebuild counts are unchanged with reporting on and off, and
nothing new goes over the network.
- **Confined to reporting builds:** in a build without a destination the
observers return before touching a route.

## Validation

New tests in
[`diagnostic_navigation_test.dart`](https://github.com/block/buzz/blob/tomb/mobile-diag-screen-breadcrumbs/mobile/test/shared/diagnostics/diagnostic_navigation_test.dart):
- the app's list, including `addCommunity` for adding a community and an
unlisted page;
- a root journey: a route whose settings carry an ID records only the
plain name, a dialog and a sheet route leave nothing, and two pops at
once leave only where they end;
- a phone journey with the real pane: Home once, channel, thread and
back, a cover closing back onto the open channel, closing the channel,
and a page with its own pane named once;
- a wide Settings pane where changing sections adds nothing;
- a build with no reporting destination.

Plus filter rows for nameless, unlisted and valid navigation
breadcrumbs.


Full-app run on an iOS simulator at 85a72de, signed in to a test
community: channel list, a channel and its details page, a message's
actions sheet, a thread and back, Search, Activity, Agents, Settings and
its status sheet, the identity-to-desktop confirmation, and the
community switcher's Add Community page. Every flow opened and closed
normally with no Flutter exceptions or error screens.

---------

Signed-off-by: Tom Brow <tomb@block.xyz>
Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@localhost>
This commit is contained in:
Tom Brow
2026-11-22 09:10:13 -08:00
committed by GitHub
parent d29c679066
commit 42dc2a8c58
18 changed files with 958 additions and 23 deletions

View File

@@ -20,7 +20,7 @@ A build that is given a [reporting destination](../CONTEXT.md#reporting-destinat
4. As a developer, I want a report when the relay rejects something the app sent as invalid, so that client bugs in what we send are found.
5. As a developer, I want a report when a Builderlab or push gateway response cannot be understood, so that contract drift is caught.
6. As a developer, I want a report when data saved on the device cannot be read back, so that storage corruption and migration bugs surface.
7. As a developer, I want each report to carry the trail of recent networking events, so that I can see what the connection was doing before the fault.
7. As a developer, I want each report to carry the trail of recent networking events and the screens the person was on, so that I can see what the connection was doing and where the person was before the fault.
8. As a developer, I want each report to carry the member's public key, so that I can follow up with the person who hit it.
9. As a developer, I want timeouts, disconnects, being offline, rate limits and refused sign-ins counted and not reported as errors, so that the error list contains only bugs someone can fix.
10. As a developer, I want every network request and relay connection event counted with its backend, endpoint, outcome and kind of failure, so that I can see which backend and which operation is failing.
@@ -46,7 +46,7 @@ A build that is given a [reporting destination](../CONTEXT.md#reporting-destinat
- **Networking measurements.** Every request through the app's shared HTTP client and every relay connection event (connected, disconnected, reconnect attempt, request timed out, subscription closed by the relay) is counted with four attributes: backend, endpoint, outcome and kind of failure. The backend is the host name of the server the app was talking to when it is one of the app's own (a relay the app has used this run, the build's Builderlab and push gateway); any other host, such as a remote image's, is counted as `external`, so a host that names a person never leaves the phone. Endpoints are names from a fixed list, never raw paths. Durations are recorded for requests (to response headers) and for time to connect. A request the app gives up on at its own deadline is a timeout, including one whose successful response body is still arriving; one the app cancels (a view closing, an image scrolled away) is not counted. A request still in flight when the member signs out or switches is not counted for anyone. HTTP is measured where the app's shared HTTP client already classifies transport failures; relay connections are measured by hand in the relay session, since the SDK documents no WebSocket instrumentation.
- **Counts are handed to the SDK as they happen**, including while the network is down. The app does no buffering of its own, and the SDK's default limit on unsent data is kept. Accepted consequence: in a long outage the oldest unsent reports can be dropped.
- **No log lines in step one.** The counts carry the member and the time, and the destination can filter them by member (see Further notes), so the fallback of one log line per outage is not needed.
- **Breadcrumbs come from a fixed list:** networking events, written by the app, and the app moving to the foreground or background, written by the SDK. The SDK's other automatic breadcrumbs, which could carry content or addresses, are turned off or filtered. Leaving a member (switching or signing out) clears the trail, so one member's networking events never reach another member's reports.
- **Breadcrumbs come from a fixed list:** networking events and screen names, written by the app, and the app moving to the foreground or background, written by the SDK. A screen name comes from the app's own list of screens (such as the channel list, a channel, a thread or settings), with any other page called "other". A screen whose name alone would say something about the person, such as the age restriction, is also called "other". It is never a channel or community name, an ID, a route's settings or anything a screen shows, so a report shows which screens the person was on and not what they were looking at. A breadcrumb is left when the person moves to a page or back to one, unless it names the same screen as the one before. Dialogs, sheets and menus leave none. The SDK's other automatic breadcrumbs, which could carry content or addresses, are turned off or filtered. Leaving a member (switching or signing out) clears the trail, so one member's networking events never reach another member's reports.
- **Who a report is about.** The member's public key is set as the report's user when a session starts and cleared when it ends. When the session is a Builderlab account, the Builderlab's origin and the account's subject identifier are added, never its email address. Every report also carries the app's own random per-install identifier, created on first launch and kept in a file that device backups and transfers skip, so a phone restored from another gets its own, as a separate field, signed in or not, so reports from one device can be matched to the members who used it, and a member's reports to the devices they used. With no member set, for example before sign-in, the SDK fills the report's user with its own random per-install identifier, on Dart and native reports alike. On iOS, native crash and hang reports also carry the SDK's device app hash: a hash of the identifier iOS gives the app's vendor, the hardware model and the bundle identifier, stable across launches and across a reinstall while another app from the same vendor stays installed. The Dart filter drops it, so Dart reports don't carry it. The SDK also sends session records, so the destination can show a crash-free rate. A session begins each time the app starts or returns after 30 seconds or more in the background. The SDK sends a record when it begins, an update each time an error is counted, and a last record when it ends. Together they carry when the session started, how many errors it had, how it ended (normally, crashed or abnormally), the time from start to end (not time in active use), the release, the environment and the SDK's identifier.
- **One filter before anything leaves.** Errors, breadcrumbs and counts from Dart all pass through a single filter that removes URL query strings and fragments, drops any attribute not on the allowed list, replaces every error's own text with fixed wording, drops what the SDK adds about the failing widget or platform call, and keeps only the app, operating system, device and runtime details among the report's contexts, so the SDK's accessibility settings, locale and the device's own name stay on the device. An error keeps its type and stack trace. The SDK's options for sending personal data, screenshots, view hierarchies and session recordings stay off.
- **Main-thread hangs** are captured by the SDK's own hang detection, at the SDK's default thresholds. The app's Dart code runs on the platform's main thread, so Dart work that blocks it shows up here. On iOS, the SDK reports the main thread being blocked, fully or mostly, for 2 seconds or more while the app is active, with the main thread's stack taken during the hang, including freezes the app recovers from. A hang that is still going when the app is killed, for example by the system watchdog, is sent on the next launch as a fatal hang. The SDK's separate watchdog-termination tracking also reports, on the next launch, a run that ended while the app was in the foreground with nothing else to explain it; it never reports on simulators or for kills in the background. App hang detection is off while a debugger is attached ([sentry-cocoa 9.35.0](https://github.com/getsentry/sentry-cocoa/blob/9.35.0/Sources/Swift/Integrations/AppHangTracking/SentryHangTrackingIntegration.swift)). On Android the SDK reports only freezes the system itself declared "app not responding". On Android 11 and later it reports only one that ended the process, read from the system's exit records on the next launch: the most recent unreported one, and only when the system kept a usable thread dump. Before Android 11 it reports when the main thread has been blocked for 5 seconds and the system has marked the app not responding, never with a debugger attached ([sentry-java 8.64.0](https://github.com/getsentry/sentry-java/blob/8.64.0/sentry-android-core/src/main/java/io/sentry/android/core/AnrIntegrationFactory.java)). So with these defaults, a freeze the app recovers from is reported on iOS, and on Android only before Android 11 and only once the system has marked the app not responding. Dart frames in a hang's stack are readable only with the Dart code's debug symbols at the destination, the same as for crashes.
@@ -74,7 +74,7 @@ A build that is given a [reporting destination](../CONTEXT.md#reporting-destinat
- Requests that bypass the shared HTTP client, such as those made by native media players and image loaders.
- Alert rules, dashboards and the destination's own configuration, which belong to whoever owns the destination.
- Diagnostic reporting in a [public build](../CONTEXT.md#public-build). Nothing prevents it, but what a report carries was chosen for internal builds. Turning it on there first needs the member's public key and the server host names removed, the rest of the list reviewed, and a way to tell people ([ADR 0007](adr/0007-diagnostic-reporting-follows-the-destination.md)). Because identity and every attribute pass through one module, that is a small code change.
- Usage or behavior data of any kind, beyond the SDK's session records described above.
- Usage or behavior data of any kind, beyond the SDK's session records described above and the trail of screens in a report.
- Fixing the bugs the reports will reveal, including one found while planning: a catch-all in account requests presents every error as an outage.
## Further notes

View File

@@ -54,6 +54,8 @@ import 'shared/auth/auth.dart';
import 'shared/deeplink/pending_deep_link_provider.dart';
import 'shared/emoji/emoji_burst.dart';
import 'shared/relay/relay.dart';
import 'shared/diagnostics/diagnostic_navigation_observer.dart';
import 'shared/diagnostics/diagnostic_reporter.dart';
import 'shared/theme/theme.dart';
import 'shared/widgets/buzz_loading_indicator.dart';
import 'shared/read_state/failed_clear_notice.dart';
@@ -476,10 +478,34 @@ class App extends HookConsumerWidget {
},
);
final latestHome = useRef<Widget?>(null)..value = home;
final screenTrail = ref.read(diagnosticScreenTrailProvider);
final screenObserver = useMemoized(screenTrail.observer);
useEffect(() => screenObserver.dispose, [screenObserver]);
// The root page's content changes in place as auth settles (splash, then
// onboarding or Home) with no navigation, so name it again.
final homeKind = authState.when(
loading: () => null,
error: (_, _) => false,
data: (state) => state.status,
);
useEffect(() {
screenObserver.refresh();
return null;
}, [homeKind]);
// The age restriction replaces the navigator rather than covering a route.
// It is named only as `other`: its own name would reveal an age signal.
useEffect(() {
screenTrail.cover(
ageSignalState == AgeSignalState.restricted
? DiagnosticScreen.other
: null,
);
return null;
}, [ageSignalState]);
return MaterialApp(
navigatorKey: _mobileRootNavigatorKey,
navigatorObservers: [appRouteObserver],
navigatorObservers: [appRouteObserver, screenObserver],
title: 'Buzz',
debugShowCheckedModeBanner: false,
theme: lightTheme,

View File

@@ -0,0 +1,55 @@
import 'package:flutter/widgets.dart';
import 'features/activity/activity_page.dart';
import 'features/agents/agents_page.dart';
import 'features/agents/create_agent_page.dart';
import 'features/channels/channel_actions_sheet.dart';
import 'features/channels/channel_detail_page.dart';
import 'features/channels/channels_page.dart';
import 'features/channels/media_viewer_page.dart';
import 'features/channels/thread_detail_page.dart';
import 'features/forum/forum_thread_page.dart';
import 'features/home/home_page.dart';
import 'features/invites/invite_create_page.dart';
import 'features/onboarding/hosted_connect_page.dart';
import 'features/pairing/pairing_page.dart';
import 'features/profile/profile_edit_page.dart';
import 'features/search/search_page.dart';
import 'features/settings/settings_page.dart';
import 'features/settings/theme_picker_page.dart';
import 'onboarding_app_entry.dart';
import 'organization_app_entry.dart';
import 'shared/diagnostics/diagnostic_reporter.dart';
/// The app's pages that have a name in a report's trail of screens, for
/// `diagnosticScreenClassifierProvider`. Add a page here to name it. A route is
/// named by the first page below it that this names, so a page that wraps
/// another listed page names both.
DiagnosticScreen? diagnosticScreenOf(Widget page) => switch (page) {
HomePage() => DiagnosticScreen.channelList,
ChannelDetailPage() => DiagnosticScreen.channel,
ThreadDetailPage() => DiagnosticScreen.thread,
ForumThreadPage() => DiagnosticScreen.forumPost,
ChannelDetailsPage() => DiagnosticScreen.channelDetails,
SearchPage() => DiagnosticScreen.search,
ActivityPage() => DiagnosticScreen.activity,
SettingsPage() => DiagnosticScreen.settings,
ThemePickerPage() => DiagnosticScreen.appearance,
ProfileEditPage() => DiagnosticScreen.profile,
AgentsPage() => DiagnosticScreen.agents,
CreateAgentPage() => DiagnosticScreen.createAgent,
CommunityInvitePage() => DiagnosticScreen.invites,
CommunitySwitcherPage() => DiagnosticScreen.communitySwitcher,
OnboardingAppEntry(addingCommunity: true) ||
PairingPage(
addingCommunity: true,
identityRecoveryOnly: false,
) => DiagnosticScreen.addCommunity,
MediaImageViewerPage() ||
MediaVideoViewerPage() => DiagnosticScreen.mediaViewer,
OnboardingAppEntry() ||
OrganizationAppEntry() ||
PairingPage() ||
HostedSetupSteps() => DiagnosticScreen.onboarding,
_ => null,
};

View File

@@ -3,6 +3,7 @@ import 'package:duo_kit/duo_kit.dart';
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import '../../shared/diagnostics/diagnostic_navigation_observer.dart';
import '../../shared/widgets/adaptive_conversation_pane.dart';
import '../../shared/widgets/duo_toolbar.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
@@ -134,6 +135,10 @@ class _AgentsNavigation extends HookConsumerWidget {
Widget build(BuildContext context, WidgetRef ref) {
final communityId = ref.watch(activeCommunityProvider).asData?.value?.id;
final heroController = useMemoized(HeroController.new);
final screenObserver = useMemoized(
ref.read(diagnosticScreenTrailProvider).observer,
);
useEffect(() => screenObserver.dispose, [screenObserver]);
final navigator = useMemoized(() => GlobalKey<NavigatorState>(), [
communityId,
]);
@@ -154,7 +159,7 @@ class _AgentsNavigation extends HookConsumerWidget {
},
child: Navigator(
key: navigator,
observers: [heroController],
observers: [heroController, screenObserver],
onGenerateRoute: (_) => MaterialPageRoute<void>(
builder: (_) => _AgentsWorkspace(
child: Builder(

View File

@@ -11,6 +11,7 @@ import 'package:flutter/services.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:buzz/shared/theme/buzz_icons.dart';
import '../../shared/diagnostics/diagnostic_navigation_observer.dart';
import '../../shared/clipboard_utils.dart';
import '../../shared/relay/relay.dart';
import '../../shared/identity_archives/identity_archives.dart';
@@ -82,7 +83,8 @@ bool _usesNativeChannelSheet(BuildContext context) {
}
// Keep the result alive after retiring the invisible route for relay work.
class _NativeChannelSheetRoute extends PageRouteBuilder<bool> {
class _NativeChannelSheetRoute extends PageRouteBuilder<bool>
with DiagnosticSheetRoute<bool> {
_NativeChannelSheetRoute(WidgetBuilder builder)
: super(
opaque: false,

View File

@@ -40,7 +40,7 @@ class HostedConnectPage extends HookConsumerWidget {
onPopInvokedWithResult: (didPop, _) {
if (!didPop) stepsNavigator.currentState?.maybePop();
},
child: _HostedSteps(
child: HostedSetupSteps(
navigatorKey: stepsNavigator,
flow: flow,
onAddCommunity: onAddCommunity,
@@ -73,8 +73,10 @@ class HostedConnectPage extends HookConsumerWidget {
}
}
class _HostedSteps extends HookWidget {
const _HostedSteps({
/// The hosted setup steps, pushed as one screen above [HostedConnectPage].
class HostedSetupSteps extends HookWidget {
const HostedSetupSteps({
super.key,
required this.navigatorKey,
required this.flow,
this.onAddCommunity,

View File

@@ -7,11 +7,13 @@ import 'package:package_info_plus/package_info_plus.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'app.dart';
import 'diagnostic_screens.dart';
import 'features/age_gate/age_signal_push_bootstrap.dart';
import 'features/agents/agents_page.dart';
import 'features/invites/invite_join_provider.dart';
import 'shared/agents/agents_surface.dart';
import 'shared/diagnostics/diagnostic_member_binding.dart';
import 'shared/diagnostics/diagnostic_navigation_observer.dart';
import 'shared/diagnostics/diagnostic_reporter.dart';
import 'shared/diagnostics/diagnostic_startup.dart';
import 'shared/push/push_bridge.dart';
@@ -79,6 +81,7 @@ ProviderScope buildRootProviderScope({
(context, link) async => unawaited(showAgents(context, draft: link)),
),
diagnosticReporterProvider.overrideWithValue(reporter),
diagnosticScreenClassifierProvider.overrideWithValue(diagnosticScreenOf),
savedPrefsProvider.overrideWithValue(prefs),
if (mediaCacheRoot != null)
mediaCacheRootProvider.overrideWith((ref) => mediaCacheRoot()),

View File

@@ -1,5 +1,7 @@
import 'package:sentry_flutter/sentry_flutter.dart';
import 'diagnostic_reporter.dart';
/// The one filter every Dart report, breadcrumb and count passes through
/// before it leaves the device. Reports the native SDKs capture themselves
/// (native crashes, app hangs) do not pass through it.
@@ -12,6 +14,12 @@ abstract final class DiagnosticFilter {
/// Breadcrumb category the app writes for networking events.
static const networkCategory = 'network';
/// Breadcrumb category the app writes for the screen the person moved to.
static const navigationCategory = 'navigation';
/// The one data key of a navigation breadcrumb: a `DiagnosticScreen` name.
static const screenKey = 'screen';
/// Breadcrumb category of the SDK's foreground/background entries.
static const lifecycleCategory = 'app.lifecycle';
@@ -29,7 +37,11 @@ abstract final class DiagnosticFilter {
/// Fixed wording that replaces an error's own text.
static const removedText = 'Error text removed before sending.';
static const _breadcrumbCategories = {networkCategory, lifecycleCategory};
static const _breadcrumbCategories = {
networkCategory,
navigationCategory,
lifecycleCategory,
};
/// Device fields that may leave: the hardware and its state, never the
/// name a person gave it or its locale and timezone.
@@ -188,6 +200,7 @@ abstract final class DiagnosticFilter {
if (crumb == null || !_breadcrumbCategories.contains(crumb.category)) {
return null;
}
if (crumb.category == navigationCategory) return _screenCrumb(crumb);
crumb.message = switch (crumb.message) {
final message? => stripUrlTails(message),
null => null,
@@ -198,6 +211,18 @@ abstract final class DiagnosticFilter {
return crumb;
}
/// A navigation breadcrumb leaves as its screen name and nothing else, and
/// only when that name is on the app's list.
static Breadcrumb? _screenCrumb(Breadcrumb crumb) {
final screen = crumb.data?[screenKey];
if (!DiagnosticScreen.values.any((value) => value.name == screen)) {
return null;
}
crumb.message = null;
crumb.data = {screenKey: screen};
return crumb;
}
/// Filters a count.
static SentryMetric filterMetric(SentryMetric metric) {
metric.attributes.removeWhere((key, _) => !allowsAttribute(key));

View File

@@ -0,0 +1,226 @@
import 'package:flutter/widgets.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'diagnostic_reporter.dart';
/// Names the screen a page widget is, or null for a widget that is not a
/// listed page. The app supplies its list of pages
/// ([diagnosticScreenClassifierProvider]); an unlisted page is reported as
/// [DiagnosticScreen.other], never by its own type name, which release builds
/// can obfuscate.
typedef DiagnosticScreenClassifier = DiagnosticScreen? Function(Widget page);
/// The app's list of named pages. The root scope overrides it, so the list
/// lives with the app rather than below the features it names.
final diagnosticScreenClassifierProvider = Provider<DiagnosticScreenClassifier>(
(ref) => throw UnimplementedError('The app supplies its list of screens.'),
);
/// The trail shared by every navigator that holds screens.
final diagnosticScreenTrailProvider = Provider<DiagnosticScreenTrail>(
(ref) => DiagnosticScreenTrail(
ref.watch(diagnosticReporterProvider),
() => ref.read(diagnosticScreenClassifierProvider),
),
);
/// Leaves a breadcrumb for each screen the person moves to or back to, so a
/// report shows which screens they were on.
///
/// Give an [observer] to each navigator that holds screens: the app's root
/// navigator and the pane navigator that holds an open conversation. Only
/// pages ([PageRoute]) count. Dialogs, sheets and menus are popup routes or
/// [DiagnosticSheetRoute]s with no screen of their own: the screen they cover
/// is still the one shown, so opening or closing one leaves nothing new. A
/// screen equal to the last one left is skipped. A build
/// without a reporting destination does nothing, not even looking at routes.
class DiagnosticScreenTrail {
DiagnosticScreenTrail(this._reporter, this._classifier);
final DiagnosticReporter _reporter;
final DiagnosticScreenClassifier Function() _classifier;
final _observers = <DiagnosticNavigationObserver>{};
DiagnosticScreen? _last;
DiagnosticScreen? _cover;
/// How many elements a search below a route may look at. A page sits near
/// the top of its route; this keeps an unlisted page from costing a walk of
/// everything it shows.
static const _searchBudget = 3000;
/// A new observer for one navigator. [DiagnosticNavigationObserver.dispose]
/// it with its navigator.
DiagnosticNavigationObserver observer() {
final observer = DiagnosticNavigationObserver._(this);
_observers.add(observer);
return observer;
}
/// Shows [screen] in place of every navigator, such as the age restriction
/// that replaces the app, or with null takes it away. While a cover shows,
/// the navigators under it name nothing; taking it away names the screen
/// shown again.
void cover(DiagnosticScreen? screen) {
if (screen == _cover) return;
_cover = screen;
if (!_reporter.reporting) return;
if (screen != null) {
_leave(screen);
} else {
for (final observer in _observers) {
observer.refresh();
}
}
}
void _leave(DiagnosticScreen screen) {
if (screen == _last) return;
_last = screen;
_reporter.leaveBreadcrumb(DiagnosticBreadcrumb.screen(screen));
}
/// Names [route] once the frame has built it, if it is then what the person
/// sees. Several pops in one go, or a route replaced at once, leave only the
/// screen they end on.
void _announce(PageRoute<dynamic> route) {
if (!_reporter.reporting) return;
WidgetsBinding.instance.addPostFrameCallback((_) {
if (_cover != null || !_shown(route)) return;
_leave(screenOf(route));
});
}
/// The screen [route] shows, once it has been built.
///
/// A route has no name of its own here: the app pushes page widgets without
/// route settings, and where settings exist they can carry IDs. So a route
/// that hosts a navigator with a page open past its first, such as a
/// conversation over a list, shows that page. Otherwise it is named by the
/// first listed page widget below it, and a route showing none is
/// [DiagnosticScreen.other]. Nothing is read from a route's settings, its
/// arguments or what the page shows.
@visibleForTesting
DiagnosticScreen screenOf(ModalRoute<dynamic> route) {
if (_openPage(route) case final ModalRoute<dynamic> page) {
return screenOf(page);
}
if (route.subtreeContext case final BuildContext context) {
final classify = _classifier();
var budget = _searchBudget;
DiagnosticScreen? found;
void visit(Element element) {
if (found != null || budget-- <= 0) return;
found = classify(element.widget);
if (found == null) element.visitChildElements(visit);
}
(context as Element).visitChildElements(visit);
if (found != null) return found!;
}
// The first route of a nested navigator is its container, such as the
// empty list side of a pane, and shows whatever hosts that navigator.
// After sign-in this is what names Home.
if (route.isFirst) {
final navigator = route.navigator;
final host = navigator == null ? null : ModalRoute.of(navigator.context);
if (host != null) return screenOf(host);
}
return DiagnosticScreen.other;
}
/// The page open past the first in a navigator that [route] hosts.
ModalRoute<dynamic>? _openPage(ModalRoute<dynamic> route) {
for (final observer in _observers) {
final navigator = observer.navigator;
if (navigator == null || ModalRoute.of(navigator.context) != route) {
continue;
}
final page = observer._topPage;
if (page != null && !page.isFirst) return page;
}
return null;
}
/// Whether [route] is the top screen of its navigator and of every
/// navigator hosting it. A dialog or sheet over a screen leaves it shown.
bool _shown(Route<dynamic> route) {
final navigator = route.navigator;
if (navigator == null || !route.isActive) return false;
final top = _observerOf(navigator)?._topPage;
if (top == null ? !route.isCurrent : top != route) return false;
final host = ModalRoute.of(navigator.context);
return host == null || _shown(host);
}
DiagnosticNavigationObserver? _observerOf(NavigatorState navigator) {
for (final observer in _observers) {
if (observer.navigator == navigator) return observer;
}
return null;
}
}
/// A page route that presents a sheet rather than a screen, so it leaves no
/// breadcrumb opening or closing.
mixin DiagnosticSheetRoute<T> on PageRoute<T> {}
/// Reports one navigator's pages to a [DiagnosticScreenTrail].
class DiagnosticNavigationObserver extends NavigatorObserver {
DiagnosticNavigationObserver._(this._trail);
final DiagnosticScreenTrail _trail;
/// This navigator's screens, bottom first. Kept only while reporting.
final _pages = <PageRoute<dynamic>>[];
/// The top screen, which shows even under a dialog or sheet.
PageRoute<dynamic>? get _topPage {
_pages.removeWhere((page) => !page.isActive);
return _pages.lastOrNull;
}
/// Stops reporting this navigator.
void dispose() => _trail._observers.remove(this);
/// Names this navigator's current page again, once the frame has built it.
/// Call it when a page's content changes in place with no navigation, such
/// as the root page moving from the splash screen to onboarding or Home.
void refresh() {
if (_topPage case final page?) _trail._announce(page);
}
static bool _isScreen(Route<dynamic>? route) =>
route is PageRoute<dynamic> && route is! DiagnosticSheetRoute<dynamic>;
@override
void didPush(Route<dynamic> route, Route<dynamic>? previousRoute) =>
_arrived(route);
@override
void didReplace({Route<dynamic>? newRoute, Route<dynamic>? oldRoute}) {
_pages.remove(oldRoute);
_arrived(newRoute);
}
@override
void didPop(Route<dynamic> route, Route<dynamic>? previousRoute) =>
_revealed(route);
@override
void didRemove(Route<dynamic> route, Route<dynamic>? previousRoute) =>
_revealed(route);
void _arrived(Route<dynamic>? route) {
if (!_trail._reporter.reporting || !_isScreen(route)) return;
final page = route! as PageRoute<dynamic>;
_pages.add(page);
_trail._announce(page);
}
/// Names the top screen again after any route leaves, even a sheet: a
/// screen can leave while covered, such as a channel opened over a sheet.
void _revealed(Route<dynamic> left) {
_pages.remove(left);
if (_topPage case final page?) _trail._announce(page);
}
}

View File

@@ -147,14 +147,57 @@ class NetworkEvent {
final Duration? duration;
}
/// One entry in the trail of recent networking events.
class DiagnosticBreadcrumb {
const DiagnosticBreadcrumb(this.event);
/// A screen the person can be on, from a fixed list the app writes. Only
/// these names ever leave the device for navigation, never a channel or
/// community name, an ID, or anything else a route could carry.
enum DiagnosticScreen {
channelList,
channel,
thread,
forumPost,
channelDetails,
search,
activity,
settings,
appearance,
profile,
agents,
createAgent,
invites,
communitySwitcher,
addCommunity,
mediaViewer,
onboarding,
/// Any page the app does not name.
other,
}
/// One entry in the trail of recent events: a networking event or the screen
/// the person moved to.
sealed class DiagnosticBreadcrumb {
const DiagnosticBreadcrumb._();
/// A networking event.
const factory DiagnosticBreadcrumb(NetworkEvent event) = NetworkBreadcrumb;
/// The person moved to [screen].
const factory DiagnosticBreadcrumb.screen(DiagnosticScreen screen) =
ScreenBreadcrumb;
}
class NetworkBreadcrumb extends DiagnosticBreadcrumb {
const NetworkBreadcrumb(this.event) : super._();
/// Breadcrumbs from the fixed list are networking events.
final NetworkEvent event;
}
class ScreenBreadcrumb extends DiagnosticBreadcrumb {
const ScreenBreadcrumb(this.screen) : super._();
final DiagnosticScreen screen;
}
/// Used when the build has no reporting destination.
class NoopDiagnosticReporter implements DiagnosticReporter {
const NoopDiagnosticReporter();

View File

@@ -52,18 +52,22 @@ class SentryDiagnosticReporter implements DiagnosticReporter {
@override
void leaveBreadcrumb(DiagnosticBreadcrumb breadcrumb) => _drop(
() => _hub.addBreadcrumb(
Breadcrumb(
() => _hub.addBreadcrumb(switch (breadcrumb) {
NetworkBreadcrumb(:final event) => Breadcrumb(
category: DiagnosticFilter.networkCategory,
level: breadcrumb.event.outcome == NetworkOutcome.failure
level: event.outcome == NetworkOutcome.failure
? SentryLevel.warning
: SentryLevel.info,
data: {
for (final entry in _attributes(breadcrumb.event).entries)
for (final entry in _attributes(event).entries)
entry.key: entry.value.value,
},
),
),
ScreenBreadcrumb(:final screen) => Breadcrumb(
category: DiagnosticFilter.navigationCategory,
data: {DiagnosticFilter.screenKey: screen.name},
),
}),
);
@override

View File

@@ -4,6 +4,7 @@ import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:duo_kit/duo_kit.dart';
import '../diagnostics/diagnostic_navigation_observer.dart';
import 'duo_toolbar.dart';
import 'app_route_observer.dart';
import 'covered_route_keyboard_insets.dart';
@@ -206,6 +207,10 @@ class AdaptiveConversationPane extends HookConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final routeObserver = useMemoized(appRouteObserver.createNestedObserver);
final screenObserver = useMemoized(
ref.read(diagnosticScreenTrailProvider).observer,
);
useEffect(() => screenObserver.dispose, [screenObserver]);
final navigator = useMemoized(() => GlobalKey<NavigatorState>());
final ownerRoute = ModalRoute.of(context);
useEffect(() {
@@ -369,7 +374,10 @@ class AdaptiveConversationPane extends HookConsumerWidget {
child: Navigator(
requestFocus: selected != null,
key: navigator,
observers: [routeObserver],
observers: [
routeObserver,
screenObserver,
],
pages: [
if (!(wide &&
persistentSelection &&

View File

@@ -0,0 +1,134 @@
import 'dart:async';
import 'package:buzz/app.dart';
import 'package:buzz/diagnostic_screens.dart';
import 'package:buzz/features/age_gate/age_signal_provider.dart';
import 'package:buzz/shared/auth/auth.dart';
import 'package:buzz/shared/diagnostics/diagnostic_navigation_observer.dart';
import 'package:buzz/shared/diagnostics/diagnostic_reporter.dart';
import 'package:buzz/shared/theme/theme_provider.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:shared_preferences/shared_preferences.dart';
void main() {
testWidgets('the root screen is named again when auth settles in place', (
tester,
) async {
SharedPreferences.setMockInitialValues({});
final prefs = await SharedPreferences.getInstance();
final auth = Completer<AuthState>();
final reporter = _RecordingReporter();
await tester.pumpWidget(
ProviderScope(
overrides: [
authProvider.overrideWith(() => _PendingAuthNotifier(auth.future)),
ageSignalProvider.overrideWith(() => _AllowedAgeSignalNotifier()),
savedPrefsProvider.overrideWithValue(prefs),
diagnosticReporterProvider.overrideWithValue(reporter),
diagnosticScreenClassifierProvider.overrideWithValue(
diagnosticScreenOf,
),
],
child: const App(),
),
);
await tester.pump();
// The splash screen is not a listed page.
expect(reporter.screens, [DiagnosticScreen.other]);
// Auth swaps the root page's content for onboarding, with no navigation.
auth.complete(const AuthState(status: AuthStatus.unauthenticated));
await tester.pump();
await tester.pump();
expect(reporter.screens, [
DiagnosticScreen.other,
DiagnosticScreen.onboarding,
]);
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('the age restriction shows as an unnamed screen', (tester) async {
SharedPreferences.setMockInitialValues({});
final prefs = await SharedPreferences.getInstance();
final age = _MutableAgeSignalNotifier();
final reporter = _RecordingReporter();
await tester.pumpWidget(
ProviderScope(
overrides: [
authProvider.overrideWith(
() => _PendingAuthNotifier(
Future.value(const AuthState(status: AuthStatus.unauthenticated)),
),
),
ageSignalProvider.overrideWith(() => age),
savedPrefsProvider.overrideWithValue(prefs),
diagnosticReporterProvider.overrideWithValue(reporter),
diagnosticScreenClassifierProvider.overrideWithValue(
diagnosticScreenOf,
),
],
child: const App(),
),
);
await tester.pump();
await tester.pump();
expect(reporter.screens.last, DiagnosticScreen.onboarding);
final before = reporter.screens.length;
// The restriction replaces the navigator, with no auth change or route.
age.setState(AgeSignalState.restricted);
await tester.pump();
await tester.pump();
age.setState(AgeSignalState.allowed);
await tester.pump();
await tester.pump();
expect(reporter.screens.skip(before), [
DiagnosticScreen.other,
DiagnosticScreen.onboarding,
]);
await tester.pumpWidget(const SizedBox.shrink());
});
}
class _MutableAgeSignalNotifier extends AgeSignalNotifier {
@override
AgeSignalState build() => AgeSignalState.allowed;
@override
Future<void> request() async {}
void setState(AgeSignalState next) => state = next;
}
class _PendingAuthNotifier extends AuthNotifier {
_PendingAuthNotifier(this._state);
final Future<AuthState> _state;
@override
Future<AuthState> build() => _state;
}
class _AllowedAgeSignalNotifier extends AgeSignalNotifier {
@override
AgeSignalState build() => AgeSignalState.allowed;
@override
Future<void> request() async {}
}
class _RecordingReporter extends NoopDiagnosticReporter {
final screens = <DiagnosticScreen>[];
@override
bool get reporting => true;
@override
void leaveBreadcrumb(DiagnosticBreadcrumb breadcrumb) {
if (breadcrumb case ScreenBreadcrumb(:final screen)) screens.add(screen);
}
}

View File

@@ -0,0 +1,62 @@
import 'package:buzz/diagnostic_screens.dart';
import 'package:buzz/features/agents/agents_page.dart';
import 'package:buzz/features/agents/create_agent_page.dart';
import 'package:buzz/shared/diagnostics/diagnostic_navigation_observer.dart';
import 'package:buzz/shared/diagnostics/diagnostic_reporter.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'agents_harness.dart';
void main() {
testWidgets('creating an agent is its own screen in the trail', (
tester,
) async {
final reporter = _RecordingReporter();
final h = await AgentsHarness.create();
await h.open(
tester,
directory: const [],
overrides: [
diagnosticReporterProvider.overrideWithValue(reporter),
diagnosticScreenClassifierProvider.overrideWithValue(
diagnosticScreenOf,
),
],
);
expect(reporter.screens, [DiagnosticScreen.agents]);
// The Agents sheet pushes the create form on its own navigator.
final agents = Navigator.of(tester.element(find.byType(AgentsPage)));
agents.push(
MaterialPageRoute<void>(
builder: (_) => CreateAgentPage(
controller: h.controller,
community: h.community,
onCreated: () {},
),
),
);
await tester.pumpAndSettle();
agents.pop();
await tester.pumpAndSettle();
expect(reporter.screens, [
DiagnosticScreen.agents,
DiagnosticScreen.createAgent,
DiagnosticScreen.agents,
]);
});
}
class _RecordingReporter extends NoopDiagnosticReporter {
final screens = <DiagnosticScreen>[];
@override
bool get reporting => true;
@override
void leaveBreadcrumb(DiagnosticBreadcrumb breadcrumb) {
if (breadcrumb case ScreenBreadcrumb(:final screen)) screens.add(screen);
}
}

View File

@@ -1,5 +1,7 @@
import 'package:buzz/diagnostic_screens.dart';
import 'package:buzz/features/settings/settings_page.dart';
import 'package:buzz/shared/community/community_membership_provider.dart';
import 'package:buzz/shared/diagnostics/diagnostic_navigation_observer.dart';
import 'package:buzz/shared/diagnostics/diagnostic_reporter.dart';
import 'package:buzz/shared/theme/theme.dart';
import 'package:flutter/material.dart';
@@ -33,6 +35,9 @@ void main() {
const AsyncData<CommunityMemberRole?>(CommunityMemberRole.member),
),
diagnosticReporterProvider.overrideWithValue(reporter),
diagnosticScreenClassifierProvider.overrideWithValue(
diagnosticScreenOf,
),
],
child: MaterialApp(
theme: AppTheme.light(),

View File

@@ -4,6 +4,8 @@ import 'package:buzz/shared/diagnostics/diagnostic_reporter.dart';
/// was given.
class RecordingDiagnostics extends NoopDiagnosticReporter {
final counts = <({NetworkEvent event, String? member})>[];
/// The networking breadcrumbs left, in order.
final breadcrumbs = <NetworkEvent>[];
final errors = <(Type, DiagnosticOperation)>[];
String? _member;
@@ -39,8 +41,9 @@ class RecordingDiagnostics extends NoopDiagnosticReporter {
counts.add((event: event, member: _member));
@override
void leaveBreadcrumb(DiagnosticBreadcrumb breadcrumb) =>
breadcrumbs.add(breadcrumb.event);
void leaveBreadcrumb(DiagnosticBreadcrumb breadcrumb) {
if (breadcrumb case NetworkBreadcrumb(:final event)) breadcrumbs.add(event);
}
@override
void reportError(

View File

@@ -0,0 +1,314 @@
import 'package:buzz/diagnostic_screens.dart';
import 'package:buzz/features/pairing/pairing_page.dart';
import 'package:buzz/features/settings/theme_picker_page.dart';
import 'package:buzz/onboarding_app_entry.dart';
import 'package:buzz/shared/diagnostics/diagnostic_navigation_observer.dart';
import 'package:buzz/shared/diagnostics/diagnostic_reporter.dart';
import 'package:buzz/shared/widgets/adaptive_conversation_pane.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
void main() {
group('the screen a page is named', () {
final rows = <(Widget, DiagnosticScreen?)>[
(const ThemePickerPage(), DiagnosticScreen.appearance),
(const OnboardingAppEntry(), DiagnosticScreen.onboarding),
(
const OnboardingAppEntry(addingCommunity: true),
DiagnosticScreen.addCommunity,
),
(const PairingPage(addingCommunity: true), DiagnosticScreen.addCommunity),
// Send to Desktop recovers an identity; it adds no community.
(
const PairingPage(addingCommunity: true, identityRecoveryOnly: true),
DiagnosticScreen.onboarding,
),
// Not on the list: never named by its own type.
(const Text('unlisted'), null),
];
for (final (page, screen) in rows) {
test('$screen for $page', () {
expect(diagnosticScreenOf(page), screen);
});
}
});
group('screen breadcrumbs', () {
const channelId = 'c0ffee-secret-channel-id';
late _RecordingReporter reporter;
late GlobalKey<NavigatorState> root;
Future<void> pumpApp(
WidgetTester tester, {
bool reporting = true,
Widget home = const _Page(DiagnosticScreen.channelList),
}) async {
reporter = _RecordingReporter(reporting: reporting);
root = GlobalKey<NavigatorState>();
final container = ProviderContainer(
overrides: [
diagnosticReporterProvider.overrideWithValue(reporter),
diagnosticScreenClassifierProvider.overrideWithValue(
(page) => page is _Page ? page.screen : null,
),
],
);
addTearDown(container.dispose);
final observer = container.read(diagnosticScreenTrailProvider).observer();
addTearDown(observer.dispose);
await tester.pumpWidget(
UncontrolledProviderScope(
container: container,
child: MaterialApp(
navigatorKey: root,
navigatorObservers: [observer],
home: home,
),
),
);
await tester.pumpAndSettle();
}
List<String> trail() => [
for (final screen in reporter.screens) screen.name,
];
testWidgets('a push and a pop leave the screens the person was on', (
tester,
) async {
await pumpApp(tester);
// A route whose settings carry an ID is still named by its page.
root.currentState!.push(
MaterialPageRoute<void>(
settings: const RouteSettings(name: '/channels/$channelId'),
builder: (_) => const _Page(DiagnosticScreen.appearance),
),
);
await tester.pumpAndSettle();
// An unlisted page is "other", whatever its settings say.
root.currentState!.push(
MaterialPageRoute<void>(
settings: const RouteSettings(name: '/channels/$channelId'),
builder: (_) => const Scaffold(body: Text('unlisted')),
),
);
await tester.pumpAndSettle();
// A dialog is not a screen: opening and closing it leaves nothing.
final dialog = showDialog<void>(
context: root.currentContext!,
builder: (_) => const AlertDialog(content: Text('dialog')),
);
await tester.pumpAndSettle();
root.currentState!.pop();
await dialog;
await tester.pumpAndSettle();
// Nor is a sheet presented as a page route.
root.currentState!.push(_SheetRoute());
await tester.pumpAndSettle();
root.currentState!.pop();
await tester.pumpAndSettle();
// Two pops at once leave only the screen they end on.
root.currentState!.popUntil((route) => route.isFirst);
await tester.pumpAndSettle();
expect(trail(), ['channelList', 'appearance', 'other', 'channelList']);
expect(
reporter.crumbs.map((crumb) => crumb.toString()).join(),
isNot(contains(channelId)),
);
});
testWidgets('a page that leaves from under a sheet names the one shown', (
tester,
) async {
await pumpApp(tester);
// Like an Android notification opening a channel over Home's actions
// sheet: Back leaves the channel, revealing the sheet over Home.
final sheet = showModalBottomSheet<void>(
context: root.currentContext!,
builder: (_) => const Text('actions'),
);
await tester.pumpAndSettle();
root.currentState!.push(
MaterialPageRoute<void>(
builder: (_) => const _Page(DiagnosticScreen.channel),
),
);
await tester.pumpAndSettle();
root.currentState!.pop();
await tester.pumpAndSettle();
root.currentState!.pop();
await sheet;
await tester.pumpAndSettle();
expect(trail(), ['channelList', 'channel', 'channelList']);
});
testWidgets('a phone pane names the screen the person is on', (
tester,
) async {
tester.view.devicePixelRatio = 1;
tester.view.physicalSize = const Size(390, 844);
addTearDown(tester.view.reset);
final controller = ConversationPaneController();
addTearDown(controller.dispose);
final search = ConversationPaneController();
addTearDown(search.dispose);
await pumpApp(
tester,
home: _Page(
DiagnosticScreen.channelList,
child: AdaptiveConversationPane(
controller: controller,
list: const Text('list'),
),
),
);
NavigatorState pane() =>
Navigator.of(tester.element(find.text('channel')));
// The pane's empty first page shows its host, Home, once.
expect(trail(), ['channelList']);
controller.open('one', (_) => const _Page(DiagnosticScreen.channel));
await tester.pumpAndSettle();
pane().push(
MaterialPageRoute<void>(
builder: (_) => const _Page(DiagnosticScreen.thread),
),
);
await tester.pumpAndSettle();
Navigator.of(tester.element(find.text('thread'))).pop();
await tester.pumpAndSettle();
// A full-screen cover, such as a huddle, closes back onto the open
// channel rather than the list under it.
root.currentState!.push(
MaterialPageRoute<void>(builder: (_) => const Text('huddle')),
);
await tester.pumpAndSettle();
root.currentState!.pop();
await tester.pumpAndSettle();
pane().pop();
await tester.pumpAndSettle();
// A page that hosts its own pane is named once.
root.currentState!.push(
MaterialPageRoute<void>(
builder: (_) => _Page(
DiagnosticScreen.search,
child: AdaptiveConversationPane(
controller: search,
list: const Text('results'),
),
),
),
);
await tester.pumpAndSettle();
root.currentState!.pop();
await tester.pumpAndSettle();
expect(trail(), [
'channelList',
'channel',
'thread',
'channel',
'other',
'channel',
'channelList',
'search',
'channelList',
]);
});
testWidgets('a wide section change stays on its screen', (tester) async {
tester.view.devicePixelRatio = 1;
tester.view.physicalSize = const Size(1000, 800);
addTearDown(tester.view.reset);
final controller = ConversationPaneController();
addTearDown(controller.dispose);
await pumpApp(tester);
root.currentState!.push(
MaterialPageRoute<void>(
builder: (_) => _Page(
DiagnosticScreen.settings,
child: AdaptiveConversationPane(
controller: controller,
persistentSelection: true,
list: const Text('sections'),
),
),
),
);
await tester.pumpAndSettle();
controller.open('status', (_) => const Text('status'));
await tester.pumpAndSettle();
controller.open('profile', (_) => const Text('profile'));
await tester.pumpAndSettle();
controller.open(
'appearance',
(_) => const _Page(DiagnosticScreen.appearance),
);
await tester.pumpAndSettle();
expect(trail(), ['channelList', 'settings', 'appearance']);
});
testWidgets('a build without a destination looks at nothing', (
tester,
) async {
await pumpApp(tester, reporting: false);
root.currentState!.push(
MaterialPageRoute<void>(
builder: (_) => const _Page(DiagnosticScreen.appearance),
),
);
await tester.pumpAndSettle();
root.currentState!.pop();
await tester.pumpAndSettle();
expect(reporter.crumbs, isEmpty);
});
});
}
/// A page the test's list names [screen].
class _Page extends StatelessWidget {
const _Page(this.screen, {this.child});
final DiagnosticScreen screen;
final Widget? child;
@override
Widget build(BuildContext context) =>
Scaffold(body: child ?? Text(screen.name));
}
class _SheetRoute extends PageRouteBuilder<void>
with DiagnosticSheetRoute<void> {
_SheetRoute()
: super(
opaque: false,
pageBuilder: (_, _, _) => const _Page(DiagnosticScreen.channelDetails),
);
}
class _RecordingReporter extends NoopDiagnosticReporter {
_RecordingReporter({required this.reporting});
@override
final bool reporting;
final crumbs = <DiagnosticBreadcrumb>[];
Iterable<DiagnosticScreen> get screens =>
crumbs.whereType<ScreenBreadcrumb>().map((crumb) => crumb.screen);
@override
void leaveBreadcrumb(DiagnosticBreadcrumb breadcrumb) =>
crumbs.add(breadcrumb);
}

View File

@@ -67,10 +67,28 @@ void main() {
null,
),
(
'a navigation breadcrumb is dropped',
'a navigation breadcrumb that names no app screen is dropped',
() async => crumb(Breadcrumb(category: 'navigation', message: 'Chat')),
null,
),
(
'a navigation breadcrumb with an unlisted screen name is dropped',
() async => crumb(
Breadcrumb(category: 'navigation', data: {'screen': 'secret-room'}),
),
null,
),
(
'a navigation breadcrumb keeps only its screen name',
() async => crumb(
Breadcrumb(
category: 'navigation',
message: 'secret-room',
data: {'screen': 'channel', 'route': '/channels/secret-id'},
),
)?.data,
{'screen': 'channel'},
),
(
'a lifecycle breadcrumb is kept',
() async => crumb(