From 0e5a06ae88bfddf3d6324a0ffb68fc34ab1a4808 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Thu, 26 Nov 2026 01:58:57 +0000 Subject: [PATCH] Fix the 11 failing application tests: two product fixes, stale fixtures Product: - Settings jump index scrolls instead of overflowing a short wide window (overflowed by 48 px at 1200x800 once Open in chat added a section). - Chat: a route to the retained workspace's active pane shows it in the same frame again; ec3c1e4c deferred it a frame behind a post-frame callback. Tests updated to intended behaviour: - first-run walkthrough (30ba70ad): seed a device that has seen it and was offered it for the fixture server; - Output section open by default (22af093e); - chat page Back closes its own route explicitly (19b1d132); - open-chat sync (c48a1559): answer chat_open_workspace statefully; - keyed session list (0a51add9) no longer re-reads chat_sessions on open. Co-Authored-By: Claude Opus 5.5 --- app/lib/features/chat/screen.dart | 12 +- .../settings/settings_page_chrome.dart | 42 ++-- .../application/chat_registration_test.dart | 194 ++++++++++-------- .../application/chat_scroll_back_test.dart | 6 +- app/test/application/pipelines_app_test.dart | 10 + .../application/run_start_wiring_test.dart | 8 +- app/test/application/search_wiring_test.dart | 20 +- .../settings_registration_test.dart | 7 +- .../settings/settings_search_page_test.dart | 16 ++ 9 files changed, 201 insertions(+), 114 deletions(-) diff --git a/app/lib/features/chat/screen.dart b/app/lib/features/chat/screen.dart index 499e1476..50d1d6dd 100644 --- a/app/lib/features/chat/screen.dart +++ b/app/lib/features/chat/screen.dart @@ -407,7 +407,17 @@ class _ChatScreenState extends State id != null && id.isNotEmpty && (_workspace.activePane?.sessionId != id || !_workspaceVisible); - if (!reboundWorkspace && (routeChanged || targetIsNotActive)) { + if (!reboundWorkspace && + targetIsNotActive && + _workspace.activePane?.sessionId == id) { + // The routed chat is already the retained workspace's active pane (a + // Chats re-tap, or Back then forward): only its visibility changes, which + // notifies nothing, so it is shown in this frame and its entrance starts + // with the tap rather than a frame later. + _workspaceVisible = true; + _publishedWorkspaceSession = id; + _workspaceBinding?.changed(); + } else if (!reboundWorkspace && (routeChanged || targetIsNotActive)) { // The parent is rebuilding while didUpdateWidget runs. Opening a pane // notifies the workspace's ListenableBuilder, which must happen after // this build rather than during it. diff --git a/app/lib/features/settings/settings_page_chrome.dart b/app/lib/features/settings/settings_page_chrome.dart index 4868f96e..cd4adef8 100644 --- a/app/lib/features/settings/settings_page_chrome.dart +++ b/app/lib/features/settings/settings_page_chrome.dart @@ -41,7 +41,9 @@ class SettingsSearchField extends StatelessWidget { ); } -/// The wide layout's slim jump index: one link per visible section. +/// The wide layout's slim jump index: one link per visible section. It +/// scrolls on its own when a short window cannot fit every link, so the last +/// sections stay reachable instead of overflowing the page. class SettingsSectionIndex extends StatelessWidget { const SettingsSectionIndex({ super.key, @@ -56,24 +58,28 @@ class SettingsSectionIndex extends StatelessWidget { Widget build(BuildContext context) => Semantics( container: true, label: 'Settings sections', - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - mainAxisSize: MainAxisSize.min, - children: [ - for (final section in sections) - TextButton( - key: ValueKey('settings.index.${section.id}'), - onPressed: () => onJump(section.id), - style: TextButton.styleFrom( - alignment: AlignmentDirectional.centerStart, + child: SingleChildScrollView( + // The page's own list owns the primary controller. + primary: false, + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + mainAxisSize: MainAxisSize.min, + children: [ + for (final section in sections) + TextButton( + key: ValueKey('settings.index.${section.id}'), + onPressed: () => onJump(section.id), + style: TextButton.styleFrom( + alignment: AlignmentDirectional.centerStart, + ), + child: Text( + section.title, + textAlign: TextAlign.start, + overflow: TextOverflow.ellipsis, + ), ), - child: Text( - section.title, - textAlign: TextAlign.start, - overflow: TextOverflow.ellipsis, - ), - ), - ], + ], + ), ), ); } diff --git a/app/test/application/chat_registration_test.dart b/app/test/application/chat_registration_test.dart index 93b2e293..5aeb072c 100644 --- a/app/test/application/chat_registration_test.dart +++ b/app/test/application/chat_registration_test.dart @@ -47,6 +47,9 @@ Future> waitForRequest( // Automation metadata is independently requested before history. This // fixture has no provider schedules; answer unavailable rather than leave // the correlated transport blocked behind an unanswered request. + // The open-chat sync reads and writes `chat_open_workspace` around opening + // a chat; the serialized transport holds every later request behind it. + if (type != 'chat_open_workspace') answerOpenWorkspaceRequests(channel); if (type != 'chat_automations') { for (final raw in channel.outgoing.toList()) { final metadata = jsonDecode(raw as String) as Map; @@ -222,36 +225,53 @@ Future replyChatSessions( await tester.pump(); } -/// Answers the `chat_open_workspace` requests the app sends around opening a -/// chat (main's open-chat sync), so the chat can subscribe. A read gets an -/// empty set; a write is stored at the next revision with its own entries. -/// Each request is answered once. +/// The fixture server's open-chat set per channel, as the real +/// `chat_open_workspace` holds it: a revision and its entries. +final _openWorkspaces = Expando<({int revision, List entries})>(); + +/// Answers every unanswered `chat_open_workspace` request the app has sent +/// (the open-chat sync), so the chat can subscribe. A read gets the stored set +/// (empty at first); a write is stored at the next revision with its own +/// entries. Each request is answered once, sharing [waitForRequest]'s record +/// of replies. +void answerOpenWorkspaceRequests(FakeChannel channel) { + final answered = _fixtureAutomationReplies[channel] ??= {}; + for (final raw in channel.outgoing.toList()) { + final message = jsonDecode(raw as String) as Map; + if (message['type'] != 'chat_open_workspace' || + !answered.add('${message['id']}')) { + continue; + } + var stored = + _openWorkspaces[channel] ?? (revision: 0, entries: const []); + final write = message['chat_open_workspace_request'] as Map?; + if (write != null) { + stored = ( + revision: stored.revision + 1, + entries: List.of(write['entries'] as List), + ); + _openWorkspaces[channel] = stored; + } + channel.incoming.add( + jsonEncode({ + 'id': message['id'], + 'type': 'chat_open_workspace', + 'chat_open_workspace': { + 'revision': stored.revision, + 'entries': stored.entries, + }, + }), + ); + } +} + +/// Answers the `chat_open_workspace` requests sent over a few frames. Future answerOpenWorkspace( WidgetTester tester, FakeChannel channel, ) async { - final answered = {}; for (var attempt = 0; attempt < 20; attempt++) { - for (final raw in channel.outgoing.toList()) { - final message = jsonDecode(raw as String) as Map; - if (message['type'] != 'chat_open_workspace' || - !answered.add(message['id'])) { - continue; - } - final write = message['chat_open_workspace_request'] as Map?; - channel.incoming.add( - jsonEncode({ - 'id': message['id'], - 'type': 'chat_open_workspace', - 'chat_open_workspace': write == null - ? {'revision': 0, 'entries': const []} - : { - 'revision': (write['base_revision'] as num) + 1, - 'entries': write['entries'], - }, - }), - ); - } + answerOpenWorkspaceRequests(channel); await tester.pump(const Duration(milliseconds: 5)); } } @@ -381,74 +401,73 @@ void main() { }, ); - testWidgets( - 'a mounted chat notification route activates a different chat', - (tester) async { - tester.view.physicalSize = const Size(900, 900); - tester.view.devicePixelRatio = 1; - addTearDown(tester.view.resetPhysicalSize); - addTearDown(tester.view.resetDevicePixelRatio); + testWidgets('a mounted chat notification route activates a different chat', ( + tester, + ) async { + tester.view.physicalSize = const Size(900, 900); + tester.view.devicePixelRatio = 1; + addTearDown(tester.view.resetPhysicalSize); + addTearDown(tester.view.resetDevicePixelRatio); - final channel = FakeChannel()..readyCompleter.complete(); - final client = PipelinesClient(channelFactory: (_) => channel); - final provider = PlatformRouteInformationProvider( - initialRouteInformation: RouteInformation(uri: Uri.parse('/chat/old')), - ); - addTearDown(provider.dispose); + final channel = FakeChannel()..readyCompleter.complete(); + final client = PipelinesClient(channelFactory: (_) => channel); + final provider = PlatformRouteInformationProvider( + initialRouteInformation: RouteInformation(uri: Uri.parse('/chat/old')), + ); + addTearDown(provider.dispose); - await tester.pumpWidget( - PipelinesApp( - androidSupported: false, - server: webServer(), - client: client, - routeInformationProvider: provider, - ), - ); - await tester.pump(); + await tester.pumpWidget( + PipelinesApp( + androidSupported: false, + server: webServer(), + client: client, + routeInformationProvider: provider, + ), + ); + await tester.pump(); - await replyChatSessions(tester, channel, ['old', 'target']); - await replyChatHistory( - tester, - channel, - subscribeIndex: 0, - historyIndex: 0, - text: 'The retained chat.', - ); - expect(find.text('The retained chat.'), findsOneWidget); + await replyChatSessions(tester, channel, ['old', 'target']); + await replyChatHistory( + tester, + channel, + subscribeIndex: 0, + historyIndex: 0, + text: 'The retained chat.', + ); + expect(find.text('The retained chat.'), findsOneWidget); - // This is the route delivered by a native chat notification, not a - // direct ChatScreen replacement. - await provider.didPushRouteInformation( - RouteInformation(uri: Uri.parse('/chat/target')), - ); - await tester.pump(); - expect(provider.value.uri.path, '/chat/target'); + // This is the route delivered by a native chat notification, not a + // direct ChatScreen replacement. + await provider.didPushRouteInformation( + RouteInformation(uri: Uri.parse('/chat/target')), + ); + await tester.pump(); + expect(provider.value.uri.path, '/chat/target'); - await replyChatHistory( - tester, - channel, - subscribeIndex: 1, - historyIndex: 1, - text: 'The notified chat.', - ); - await tester.pumpAndSettle(); + await replyChatHistory( + tester, + channel, + subscribeIndex: 1, + historyIndex: 1, + text: 'The notified chat.', + ); + await tester.pumpAndSettle(); - expect(requestOf(channel, 'chat_subscribe', index: 1)!['chat_subscribe'], { - 'session_id': 'target', - }); - expect(requestOf(channel, 'chat_messages', index: 1)!['chat_query'], { - 'session_id': 'target', - 'limit': 200, - 'cursor': '', - }); - expect(find.text('The notified chat.'), findsOneWidget); - expect(find.text('The retained chat.'), findsNothing); - expect(provider.value.uri.path, '/chat/target'); + expect(requestOf(channel, 'chat_subscribe', index: 1)!['chat_subscribe'], { + 'session_id': 'target', + }); + expect(requestOf(channel, 'chat_messages', index: 1)!['chat_query'], { + 'session_id': 'target', + 'limit': 200, + 'cursor': '', + }); + expect(find.text('The notified chat.'), findsOneWidget); + expect(find.text('The retained chat.'), findsNothing); + expect(provider.value.uri.path, '/chat/target'); - await tester.pumpWidget(const SizedBox.shrink()); - await tester.pump(); - }, - ); + await tester.pumpWidget(const SizedBox.shrink()); + await tester.pump(); + }); testWidgets( 'mobile Chats retap reopens the retained multi-pane workspace after tabs', @@ -496,7 +515,8 @@ void main() { await tester.pump(); expect(provider.value.uri.path, '/chat/a'); expect(find.byType(ChatThreadView), findsOneWidget); - await replyChatSessions(tester, channel, ['a', 'b'], index: 1); + // The keyed session list moves beside the chat without remounting, so + // opening a chat issues no second list read. await replyChatHistory( tester, channel, diff --git a/app/test/application/chat_scroll_back_test.dart b/app/test/application/chat_scroll_back_test.dart index afe9ab63..74175663 100644 --- a/app/test/application/chat_scroll_back_test.dart +++ b/app/test/application/chat_scroll_back_test.dart @@ -124,10 +124,12 @@ void main() { reason: 'The main-screen Back interceptor must not block an open chat', ); + // The visible Back closes the chat page's own route explicitly (the + // same path the system gesture takes), never the nearest route. expect( tester.widget(findNativeBack()).onPressed, - isNull, - reason: 'Use the stock Navigator Back action without a chat override', + isNotNull, + reason: 'Back pops the chat page itself, not whichever route is near', ); final transcript = find.byKey(const ValueKey('chat-thread-s')); final scroll = tester diff --git a/app/test/application/pipelines_app_test.dart b/app/test/application/pipelines_app_test.dart index 7a46e08c..8c73ff0a 100644 --- a/app/test/application/pipelines_app_test.dart +++ b/app/test/application/pipelines_app_test.dart @@ -11,6 +11,7 @@ import 'package:pipelines_app/application/pipelines_app.dart'; import 'package:pipelines_app/application/server_endpoint.dart'; import 'package:pipelines_app/core/transport/pipelines_client.dart'; import 'package:pipelines_app/features/pipelines/screen.dart'; +import 'package:pipelines_app/features/walkthrough/walkthrough_store.dart'; import '../core/transport/pipelines_client_test.dart' show FakeChannel; import '../features/pipelines/fixtures.dart'; @@ -21,6 +22,15 @@ ServerEndpoint webServer() => ServerEndpoint.resolve( web: true, ); +/// Preferences for a device that has finished the first-run walkthrough and +/// was already offered it for [webServer]. With them the Pipelines page shows +/// no walkthrough dialog over its rows and bar, and issues no empty-server +/// check (whose unanswered reads would hold the serialized request queue). +Map walkthroughDonePreferences() => { + walkthroughSeenKey: true, + walkthroughOfferedKey: [webServer().uri.toString()], +}; + Map? requestOf(FakeChannel channel, String type) => channel .outgoing .map((frame) => jsonDecode(frame as String) as Map) diff --git a/app/test/application/run_start_wiring_test.dart b/app/test/application/run_start_wiring_test.dart index 97ad90f1..7eee7c6e 100644 --- a/app/test/application/run_start_wiring_test.dart +++ b/app/test/application/run_start_wiring_test.dart @@ -9,7 +9,7 @@ import 'package:pipelines_app/features/pipelines/ui/run_pipeline_wording.dart'; import '../core/transport/pipelines_client_test.dart' show FakeChannel; import '../features/pipelines/fixtures.dart'; -import 'pipelines_app_test.dart' show webServer; +import 'pipelines_app_test.dart' show walkthroughDonePreferences, webServer; import 'pipelines_replies.dart'; List> requestsOf(FakeChannel channel, String type) => @@ -55,7 +55,11 @@ Future reply( void main() { // The Run dialog reads the device's pending launch store before it opens. - setUp(() => SharedPreferences.setMockInitialValues({})); + // A device that has seen the first-run walkthrough has no dialog over the + // Pipelines page to absorb the row taps. + setUp( + () => SharedPreferences.setMockInitialValues(walkthroughDonePreferences()), + ); testWidgets('an accepted launch opens the returned run and re-reads the ' 'runs list exactly once', (tester) async { tester.view.physicalSize = const Size(1100, 900); diff --git a/app/test/application/search_wiring_test.dart b/app/test/application/search_wiring_test.dart index 6eb41471..c2a1a801 100644 --- a/app/test/application/search_wiring_test.dart +++ b/app/test/application/search_wiring_test.dart @@ -560,7 +560,8 @@ void main() { expect(find.byType(ArtifactViewerPage), findsOneWidget); // Leave the viewer for the Artifacts tab, then a retired field hit opens - // the plain Summary with no visit. + // the plain Summary with no visit, in its default sections (Output open, + // Input closed). await closeViewer(tester); expectArtifactsTabSelecting(tester, '/artifacts/7/2/report.txt'); await sendSearch(query: 'retired', index: 1, hit: retiredFieldHit()); @@ -579,6 +580,17 @@ void main() { findsOneWidget, ); expect(find.text('ship it'), findsNothing); + expect(find.text('ok'), findsOneWidget); + + // The operator closes Output, so the next hit must reopen it itself. + final outputTitle = find.descendant( + of: find.byKey(const ValueKey('run-detail-summary-output')), + matching: find.text('Output'), + ); + await tester.ensureVisible(outputTitle.first); + await tester.pumpAndSettle(); + await tester.tap(outputTitle.first); + await tester.pumpAndSettle(); expect(find.text('ok'), findsNothing); // A current field hit opens the same run at the Summary section holding the @@ -710,12 +722,16 @@ void main() { await replyRunDetailFor(tester, channel, searchSelectionDetail(), index: 1); await tester.pumpAndSettle(); + expect(find.byType(ArtifactViewerPage), findsNothing); expect(find.byKey(const Key('run-visit-pane')), findsNothing); expect( find.byKey(const Key('run-detail-tab-body-summary')), findsOneWidget, ); - expect(find.text('ok'), findsNothing); + // An ordinary visit shows the Summary's default sections: Output open, + // Input closed. + expect(find.text('ok'), findsOneWidget); + expect(find.text('ship it'), findsNothing); await tester.pumpWidget(const SizedBox.shrink()); await tester.pump(); diff --git a/app/test/application/settings_registration_test.dart b/app/test/application/settings_registration_test.dart index acaca0db..433ac368 100644 --- a/app/test/application/settings_registration_test.dart +++ b/app/test/application/settings_registration_test.dart @@ -9,13 +9,16 @@ import 'package:shared_preferences/shared_preferences.dart'; import '../core/transport/pipelines_client_test.dart' show FakeChannel; import '../features/pipelines/fixtures.dart'; -import 'pipelines_app_test.dart' show webServer, requestOf; +import 'pipelines_app_test.dart' + show walkthroughDonePreferences, webServer, requestOf; import 'pipelines_replies.dart'; import 'package:pipelines_app/ui/adaptive/segmented_bar.dart'; void main() { testWidgets('Settings shares socket and one native bar', (tester) async { - SharedPreferences.setMockInitialValues({}); + // A device that has seen the first-run walkthrough: no dialog over the + // Pipelines page absorbs the bar tap. + SharedPreferences.setMockInitialValues(walkthroughDonePreferences()); final channel = FakeChannel()..readyCompleter.complete(); var sockets = 0; final client = PipelinesClient( diff --git a/app/test/features/settings/settings_search_page_test.dart b/app/test/features/settings/settings_search_page_test.dart index 02da8d0f..cd9defa3 100644 --- a/app/test/features/settings/settings_search_page_test.dart +++ b/app/test/features/settings/settings_search_page_test.dart @@ -230,6 +230,22 @@ void main() { expect(tester.takeException(), isNull); }); + testWidgets('a short wide window scrolls the jump index to its last link', ( + tester, + ) async { + // More links than a 600 px tall index fits: it must scroll, not overflow. + await _pump(tester, _filler(30), size: const Size(1200, 600)); + expect(tester.takeException(), isNull); + + final last = find.byKey(const ValueKey('settings.index.filler-29')); + await tester.ensureVisible(last); + await tester.pumpAndSettle(); + await tester.tap(last); + await tester.pumpAndSettle(); + expect(find.text('Filler 29'), findsWidgets); + expect(tester.takeException(), isNull); + }); + testWidgets('a narrow layout has no jump index', (tester) async { await _pump(tester, [ SettingsSection(