fix(app): refresh visible lists on foreground resume

This commit is contained in:
2026-10-22 23:37:34 +01:00
parent 48eeb5fcbd
commit d0def10490
2 changed files with 85 additions and 4 deletions
+27 -3
View File
@@ -80,6 +80,10 @@ class _PipelinesAppState extends State<PipelinesApp>
/// list once; the run itself is then opened from its route.
int _runsRefresh = 0;
/// Prevents duplicate resumed notifications from refreshing twice before
/// the next background transition starts another foreground visit.
bool _foregroundVisitHandled = false;
/// One run detail request from Search, delivered through the shell so the
/// mounted run detail can resolve it once the named run's steps have loaded.
/// A field or artifact hit names no addressable URL of its own, so the request
@@ -198,9 +202,29 @@ class _PipelinesAppState extends State<PipelinesApp>
/// facts), so no screen re-subscribes on its own.
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state != AppLifecycleState.resumed) return;
if (!shouldReconnectOnForeground(_session.connection.kind)) return;
unawaited(_session.retry());
if (state != AppLifecycleState.resumed) {
_foregroundVisitHandled = false;
return;
}
if (_foregroundVisitHandled) return;
_foregroundVisitHandled = true;
final connection = _session.connection.kind;
if (shouldReconnectOnForeground(connection)) {
unawaited(_session.retry());
return;
}
if (connection != ConnectionKind.connected) return;
// A return to the foreground refreshes only the visible list. Detail routes
// (including pipeline definitions and run visits) keep their current data.
final route = _delegate.route;
if (route.kind == AppRouteKind.pipelines &&
route.pipelineId == null &&
route.stageKey == null) {
setState(() => _pipelinesRefresh++);
} else if (route.kind == AppRouteKind.runs && route.runId == null) {
setState(() => _runsRefresh++);
}
}
/// A replaced socket drops the attention status baseline so the gap cannot
@@ -48,6 +48,9 @@ List<String> types(FakeChannel channel) => <String>[
(jsonDecode(frame as String) as Map<String, dynamic>)['type'] as String,
];
int countType(FakeChannel channel, String type) =>
types(channel).where((value) => value == type).length;
void main() {
tearDown(() {
WidgetsBinding.instance.handleAppLifecycleStateChanged(
@@ -100,21 +103,75 @@ void main() {
},
);
testWidgets('foreground resume does not churn a still-connected socket', (
testWidgets('foreground resume refreshes the visible Pipelines list once', (
tester,
) async {
final channel = FakeChannel()..readyCompleter.complete();
final client = PipelinesClient(channelFactory: (_) => channel);
await pumpApp(tester, provider: routeProvider(), client: client);
await replyPipelines(tester, channel, PipelineFixture());
final before = countType(channel, 'list_pipelines');
expect(types(channel).where((type) => type == 'subscribe'), hasLength(1));
await resume(tester);
expect(countType(channel, 'list_pipelines'), before + 1);
expect(types(channel).where((type) => type == 'subscribe'), hasLength(1));
expect(client.state.kind, ConnectionKind.connected);
await tester.pumpWidget(const SizedBox.shrink());
await tester.pump();
});
testWidgets('foreground resume refreshes the visible Runs list once', (
tester,
) async {
final channel = FakeChannel()..readyCompleter.complete();
final provider = PlatformRouteInformationProvider(
initialRouteInformation: RouteInformation(uri: Uri.parse('/runs')),
);
addTearDown(provider.dispose);
final client = PipelinesClient(channelFactory: (_) => channel);
await pumpApp(tester, provider: provider, client: client);
await waitForRequest(tester, channel, 'list_runs');
final initialRuns = pipelineRequest(channel, 'list_runs')!;
channel.incoming.add(
jsonEncode({
'id': initialRuns['id'],
'type': 'runs',
'runs': PipelineFixture().runs,
}),
);
await tester.pump();
final before = countType(channel, 'list_runs');
await resume(tester);
expect(countType(channel, 'list_runs'), before + 1);
expect(countType(channel, 'subscribe'), 1);
await tester.pumpWidget(const SizedBox.shrink());
await tester.pump();
});
testWidgets('foreground resume does not refresh an open run detail', (
tester,
) async {
final channel = FakeChannel()..readyCompleter.complete();
final provider = routeProvider();
final client = PipelinesClient(channelFactory: (_) => channel);
await pumpApp(tester, provider: provider, client: client);
await replyPipelines(tester, channel, PipelineFixture());
provider.routerReportsNewRouteInformation(
RouteInformation(uri: Uri.parse('/runs/1')),
type: RouteInformationReportingType.navigate,
);
await tester.pump();
final before = countType(channel, 'list_runs');
await resume(tester);
expect(countType(channel, 'list_runs'), before);
await tester.pumpWidget(const SizedBox.shrink());
await tester.pump();
});
}