diff --git a/app/lib/features/chat/conversation/chat_thread_view.dart b/app/lib/features/chat/conversation/chat_thread_view.dart index a0eb6a70..20c030c5 100644 --- a/app/lib/features/chat/conversation/chat_thread_view.dart +++ b/app/lib/features/chat/conversation/chat_thread_view.dart @@ -846,7 +846,6 @@ class _ChatThreadViewState extends State { final title = widget.title.trim(); return ShellBar( title: title.isEmpty ? null : title, - onBack: widget.onBack, actions: [ if (hasModel) ConstrainedBox( diff --git a/app/lib/features/chat/screen.dart b/app/lib/features/chat/screen.dart index 3ebaa7cc..a55314d0 100644 --- a/app/lib/features/chat/screen.dart +++ b/app/lib/features/chat/screen.dart @@ -165,7 +165,7 @@ class _ChatScreenState extends State { } } - /// The open chat is its own page over the tabs on a phone. + /// The open chat is a real page above the main screen at every window width. final DetailPageHost _page = DetailPageHost(); @override @@ -200,12 +200,11 @@ class _ChatScreenState extends State { @override Widget build(BuildContext context) { final selected = _selected; - // On a phone an open chat is its own page over the tabs; a wide window - // keeps it in the tab, beside the destination rail. - final narrow = MediaQuery.sizeOf(context).width < kDetailPageMaxWidth; + // Chats are real Navigator pages at every width. Do not swap a conversation + // into the home page and manually emulate Back on tablets/foldables. _page.sync( context, - selected: selected != null && narrow, + selected: selected != null, destination: AppDestination.chat, onClosed: _back, builder: (context) => selected == null @@ -220,14 +219,8 @@ class _ChatScreenState extends State { onOpen: _open, onSessions: _adoptRows, activeSessionId: selected, - publishShellBar: narrow || selected == null, - ); - if (narrow) return list; - return Stack( - children: [ - Offstage(offstage: selected != null, child: list), - if (selected != null) _thread(selected, _back), - ], + publishShellBar: true, ); + return list; } } diff --git a/app/lib/shell/detail_page.dart b/app/lib/shell/detail_page.dart index 371fe874..dbacc938 100644 --- a/app/lib/shell/detail_page.dart +++ b/app/lib/shell/detail_page.dart @@ -111,8 +111,6 @@ class _DetailPageState extends State<_DetailPage> { super.dispose(); } - void _back() => Navigator.of(context).maybePop(); - @override Widget build(BuildContext context) { final body = ShellBarScope( @@ -129,11 +127,7 @@ class _DetailPageState extends State<_DetailPage> { if (usesCupertinoHost(context)) { return CupertinoPageScaffold( navigationBar: CupertinoNavigationBar( - leading: CupertinoNavigationBarBackButton( - key: const ValueKey('shell.back'), - onPressed: _back, - ), - automaticallyImplyLeading: false, + automaticallyImplyLeading: true, middle: Text(title), trailing: actions.isEmpty ? null @@ -144,11 +138,7 @@ class _DetailPageState extends State<_DetailPage> { } return Scaffold( appBar: AppBar( - automaticallyImplyLeading: false, - leading: BackButton( - key: const ValueKey('shell.back'), - onPressed: _back, - ), + automaticallyImplyLeading: true, title: Text(title), actions: actions, ), diff --git a/app/notes/chat-scroll-roundtrip-stock-back.md b/app/notes/chat-scroll-roundtrip-stock-back.md new file mode 100644 index 00000000..66165969 --- /dev/null +++ b/app/notes/chat-scroll-roundtrip-stock-back.md @@ -0,0 +1,34 @@ +# Stock chat Back after scrolling + +User supplied exact reproduction: chat list → open chat → scroll to top → scroll +to bottom → Android Back. The previous rendering benchmark did not exercise this +sequence and did not establish the device-specific cause. + +## Navigation correction + +- Chat is now a real pushed Navigator page at **all widths**, including tablets + and unfolded devices. The old wide layout swapped a thread into the main page + and manually stepped the route back instead of popping a page. +- Detail page bars let Material/Cupertino supply Back automatically. No custom + Back callback, forced leading button, chat PopScope, timer or extra press. +- Chat no longer publishes an onBack override into shell chrome. Normal route + completion still clears selection and keeps the re-push safety guard. +- Home double-back remains home-only. New regression performs the user's scroll + sequence at 390/840 logical pixels, verifies a real route and a stock Back + action, pops with one system Back, and only then verifies two presses to exit. +- Existing navigation tests find native Back controls rather than an app-specific + key; deep-link tests await the actual reverse transition, not two zero-time frames. + +## Evidence and limits + +- 12 focused chat/deep-link/detail tests pass. +- Browser probe now supports OPEN_FROM_LIST, SCROLL_ROUNDTRIP, CHAT_VARIANCE and + PROBE_WIDTH. Screenshots prove top/bottom were reached; fixtures remain loopback. +- Quiet browser samples did not reproduce a multi-second delay: phone was about + 481ms before; wide previously used an immediate manual route change. After the + real wide-page push, it pops in about 501ms with the native transition. + These numbers are NOT evidence that the reported physical-device delay is fixed. +- Captures: `build/scroll-back-repro-before/`, `build/scroll-back-wide-before/`, + `build/scroll-back-wide-after/`. +- No scroll-workaround, transition-duration change, backend mutation, service + restart or device testing. Full acceptance and deployment pending. diff --git a/app/test/application/chat_registration_test.dart b/app/test/application/chat_registration_test.dart index 48d3d879..a43996f9 100644 --- a/app/test/application/chat_registration_test.dart +++ b/app/test/application/chat_registration_test.dart @@ -10,6 +10,7 @@ import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart'; import 'package:pipelines_app/features/chat/ui/sessions/chat_sessions_screen.dart'; import '../core/transport/pipelines_client_test.dart' show FakeChannel; +import '../native_back.dart'; ServerEndpoint webServer() => ServerEndpoint.resolve( base: Uri.parse('http://127.0.0.1:8096/'), @@ -188,6 +189,7 @@ void main() { await replySessions(tester, channel); await replySubscribe(tester, channel); await replyHistory(tester, channel); + await tester.pumpAndSettle(); expect(provider.value.uri.path, '/chat/s1'); expect(find.byType(ChatThreadView), findsOneWidget); @@ -234,10 +236,9 @@ void main() { // The open chat takes over the app bar: one Back there, and no // second header row under it. expect(find.byKey(const Key('chat-thread-header')), findsNothing); - await tester.tap(find.byKey(const ValueKey('shell.back'))); - await tester.pump(); - // The bar hands back to the list on the next frame. - await tester.pump(); + await tester.tap(findNativeBack()); + // A real Navigator pop finishes its native reverse transition. + await tester.pumpAndSettle(); expect(provider.value.uri.path, '/chat'); expect(find.byType(ChatThreadView), findsNothing); expect(find.byType(ChatSessionsScreen), findsOneWidget); diff --git a/app/test/application/chat_scroll_back_test.dart b/app/test/application/chat_scroll_back_test.dart new file mode 100644 index 00000000..77f9bc39 --- /dev/null +++ b/app/test/application/chat_scroll_back_test.dart @@ -0,0 +1,158 @@ +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:shared_preferences/shared_preferences.dart'; +import 'package:pipelines_app/application/app_route.dart'; +import 'package:pipelines_app/application/app_router.dart'; +import 'package:pipelines_app/core/api_gateway.dart'; +import 'package:pipelines_app/features/chat/screen.dart'; +import 'package:pipelines_app/shell/adaptive_shell.dart'; +import 'package:pipelines_app/shell/destination.dart'; +import 'package:pipelines_app/ui/theme/app_theme.dart'; + +import '../features/chat/conversation/chat_thread_fixtures.dart'; +import '../native_back.dart'; + +class _Gateway extends FakeChatGateway { + @override + Future call(String type, [JsonMap fields = const {}]) { + if (type == 'chat_sessions') { + return Future.value({ + 'chat_sessions': [ + {'id': 's', 'title': 'Scroll and return'}, + ], + }); + } + if (type == 'chat_shells') return Future.value({'chat_shells': []}); + return super.call(type, fields); + } +} + +void main() { + for (final width in [390.0, 840.0]) { + testWidgets( + 'list → chat → top → bottom → one system Back pops a real route at $width', + (tester) async { + SharedPreferences.setMockInitialValues({}); + tester.view.physicalSize = Size(width, 844); + tester.view.devicePixelRatio = 1; + addTearDown(tester.view.reset); + final exits = []; + tester.binding.defaultBinaryMessenger.setMockMethodCallHandler( + SystemChannels.platform, + (call) async { + if (call.method == 'SystemNavigator.pop') exits.add(call.method); + return null; + }, + ); + addTearDown( + () => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler( + SystemChannels.platform, + null, + ), + ); + final gateway = _Gateway() + ..history = (_) async => chatPage([ + for (var i = 0; i < 30; i++) + chatMessage( + 'm$i', + i.isEven ? 'user' : 'assistant', + parts: [ + { + 'type': 'text', + 'text': + 'Message $i. ${List.filled(12 + i % 5, 'Recorded text that wraps across the screen.').join(' ')}', + }, + ], + ), + ]); + addTearDown(gateway.close); + late final AppRouterDelegate router; + router = AppRouterDelegate( + initial: AppRoute.chat, + cupertino: false, + onPopToChat: () => router.goTo(AppRoute.chat), + onPopToRuns: () {}, + builder: (_, route) => AdaptiveShell( + destination: AppDestination.chat, + destinationBodies: { + AppDestination.chat: (_) => ChatScreen( + gateway: gateway, + initialSessionId: route.chatSessionId, + onSessionSelected: (id) => + router.goTo(AppRoute.chatSession(id)), + onBack: () => router.goTo(AppRoute.chat), + ), + }, + ), + ); + var routerDisposed = false; + void disposeRouter() { + if (routerDisposed) return; + routerDisposed = true; + router.dispose(); + } + + addTearDown(disposeRouter); + final provider = PlatformRouteInformationProvider( + initialRouteInformation: RouteInformation(uri: Uri.parse('/chat')), + ); + addTearDown(provider.dispose); + await tester.pumpWidget( + MaterialApp.router( + theme: appLightTheme(), + routerDelegate: router, + routeInformationParser: const AppRouteParser(), + routeInformationProvider: provider, + ), + ); + await tester.pumpAndSettle(); + await tester.tap(find.text('Scroll and return')); + await tester.pumpAndSettle(); + final navigator = tester.state(find.byType(Navigator)); + expect( + navigator.canPop(), + isTrue, + reason: 'Chat must be pushed, not swapped into the main page', + ); + expect( + tester.widget(findNativeBack()).onPressed, + isNull, + reason: 'Use the stock Navigator Back action without a chat override', + ); + final transcript = find.byKey(const ValueKey('chat-thread-s')); + final scroll = tester.widget(transcript).controller!; + await tester.drag( + transcript, + Offset(0, scroll.position.maxScrollExtent + 500), + ); + await tester.pumpAndSettle(); + expect(scroll.offset, closeTo(scroll.position.minScrollExtent, 1)); + await tester.drag( + transcript, + Offset(0, -scroll.position.maxScrollExtent - 500), + ); + await tester.pumpAndSettle(); + expect(scroll.offset, closeTo(scroll.position.maxScrollExtent, 1)); + await tester.binding.handlePopRoute(); + await tester.pump(); + await tester.pump(const Duration(milliseconds: 500)); + await tester.pump(); + expect(router.route, AppRoute.chat); + expect(find.text('Scroll and return'), findsOneWidget); + expect(find.byKey(const ValueKey('chat-thread-s')), findsNothing); + expect(find.text('Press back again to close'), findsNothing); + expect(exits, isEmpty); + await tester.binding.handlePopRoute(); + await tester.pumpAndSettle(); + expect(find.text('Press back again to close'), findsOneWidget); + expect(exits, isEmpty); + await tester.binding.handlePopRoute(); + await tester.pump(); + expect(exits, ['SystemNavigator.pop']); + await tester.pumpWidget(const SizedBox.shrink()); + disposeRouter(); + }, + ); + } +} diff --git a/app/test/application/detail_navigation_test.dart b/app/test/application/detail_navigation_test.dart index ca62d82d..0d72e50a 100644 --- a/app/test/application/detail_navigation_test.dart +++ b/app/test/application/detail_navigation_test.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; +import '../native_back.dart'; import 'package:pipelines_app/application/app_router.dart'; import 'package:pipelines_app/core/transport/pipelines_client.dart'; @@ -122,7 +123,7 @@ void main() { await tester.pumpAndSettle(); expect(find.text('Navigation dialog'), findsNothing); expect(provider.value.uri.path, detailPath); - expect(find.byKey(const ValueKey('shell.back')), findsOneWidget); + expect(findNativeBack(), findsOneWidget); if (predictive) { await backGesture(tester, 'startBackGesture'); diff --git a/app/test/application/pipelines_app_test.dart b/app/test/application/pipelines_app_test.dart index 07a91adc..251659e2 100644 --- a/app/test/application/pipelines_app_test.dart +++ b/app/test/application/pipelines_app_test.dart @@ -3,6 +3,7 @@ import 'dart:convert'; import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; +import '../native_back.dart'; import 'package:pipelines_app/application/app_route.dart'; import 'package:pipelines_app/application/app_router.dart'; import 'package:pipelines_app/application/pipelines_app.dart'; @@ -160,11 +161,11 @@ void main() { await replyDetail(tester, channel, 1); expect(find.text('Run 1'), findsWidgets); - expect(find.byKey(const ValueKey('shell.back')), findsOneWidget); + expect(findNativeBack(), findsOneWidget); expect(provider.value.uri.path, '/runs/1'); expect(find.text('Pipelines — Not implemented'), findsNothing); - await tester.tap(find.byKey(const ValueKey('shell.back'))); + await tester.tap(findNativeBack()); await tester.pump(); expect(provider.value.uri.path, '/runs'); expect(find.text('Deep-linked run'), findsWidgets); @@ -267,7 +268,7 @@ void main() { await tester.pump(); expect(provider.value.uri.path, '/runs/2'); await replyDetail(tester, channel, 2); - expect(find.byKey(const ValueKey('shell.back')), findsOneWidget); + expect(findNativeBack(), findsOneWidget); // The engine's browser Back arrives as new route information. await provider.didPushRouteInformation( @@ -277,7 +278,7 @@ void main() { // The bar returns to the tab's own after the closed run hands it back. await tester.pump(); expect(find.text('Beta run'), findsWidgets); - expect(find.byKey(const ValueKey('shell.back')), findsNothing); + expect(findNativeBack(), findsNothing); // Forward re-opens the same run. await provider.didPushRouteInformation( @@ -286,7 +287,7 @@ void main() { await tester.pump(); await replyDetail(tester, channel, 2); await tester.pump(); - expect(find.byKey(const ValueKey('shell.back')), findsOneWidget); + expect(findNativeBack(), findsOneWidget); }); testWidgets('a malformed boot path is corrected to /pipelines', ( diff --git a/app/test/application/search_wiring_test.dart b/app/test/application/search_wiring_test.dart index f0e20723..a45bd6eb 100644 --- a/app/test/application/search_wiring_test.dart +++ b/app/test/application/search_wiring_test.dart @@ -3,6 +3,7 @@ import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter_test/flutter_test.dart'; +import '../native_back.dart'; import 'package:pipelines_app/application/app_route.dart'; import 'package:pipelines_app/application/app_router.dart'; import 'package:pipelines_app/application/pipelines_app.dart'; @@ -323,7 +324,7 @@ void main() { expect(provider.value.uri.path, '/runs/2'); expect(find.byType(SearchScreen), findsNothing); - expect(find.byKey(const ValueKey('shell.back')), findsOneWidget); + expect(findNativeBack(), findsOneWidget); expect(find.text('Run 2'), findsWidgets); // The shell was never remounted, so the open run was not re-read. expect(requestsOf(channel, 'get_run'), hasLength(1)); @@ -408,7 +409,7 @@ void main() { expect(provider.value.uri.path, '/runs/7'); await replyRunDetail(tester, channel, 7, index: 1); expect(find.byType(SearchScreen), findsNothing); - expect(find.byKey(const ValueKey('shell.back')), findsOneWidget); + expect(findNativeBack(), findsOneWidget); expect(find.text('Run 7'), findsWidgets); // One app socket carried the search and the run reads. expect(sockets, 1); @@ -650,8 +651,8 @@ void main() { // leaves from the loading placeholder instead. await openArtifactHit(tester, channel); expect(provider.value.uri.path, '/runs/7'); - expect(find.byKey(const ValueKey('shell.back')), findsOneWidget); - await tester.tap(find.byKey(const ValueKey('shell.back'))); + expect(findNativeBack(), findsOneWidget); + await tester.tap(findNativeBack()); await tester.pump(); await tester.pump(); expect(provider.value.uri.path, '/runs'); @@ -710,7 +711,7 @@ void main() { await tester.tap(find.byKey(const Key('run-visit-back'))); await tester.pumpAndSettle(); - await tester.tap(find.byKey(const ValueKey('shell.back'))); + await tester.tap(findNativeBack()); await tester.pump(); await tester.pump(); expect(provider.value.uri.path, '/runs'); diff --git a/app/test/features/chat/chat_screen_model_test.dart b/app/test/features/chat/chat_screen_model_test.dart index 59336ef9..daed8cff 100644 --- a/app/test/features/chat/chat_screen_model_test.dart +++ b/app/test/features/chat/chat_screen_model_test.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; +import '../../native_back.dart'; import 'package:pipelines_app/core/api_gateway.dart'; import 'package:pipelines_app/features/chat/screen.dart'; @@ -89,7 +90,7 @@ void main() { await tester.pumpAndSettle(); expect(find.text('model-b'), findsOneWidget); - await tester.tap(find.byKey(const Key('chat-back'))); + await tester.tap(findNativeBack()); await tester.pumpAndSettle(); expect(find.text('model-b'), findsNothing); diff --git a/app/test/features/pipelines/pipeline_deep_link_test.dart b/app/test/features/pipelines/pipeline_deep_link_test.dart index 6f711b27..5f3017bd 100644 --- a/app/test/features/pipelines/pipeline_deep_link_test.dart +++ b/app/test/features/pipelines/pipeline_deep_link_test.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; +import '../../native_back.dart'; import 'package:pipelines_app/core/api_gateway.dart'; import 'package:pipelines_app/features/graph/widgets/definition_graph_view.dart'; import 'package:pipelines_app/features/graph/widgets/stage_definition_view.dart'; @@ -243,7 +244,7 @@ void main() { await tester.pageBack(); await tester.pumpAndSettle(); - await tester.tap(find.byKey(const ValueKey('shell.back'))); + await tester.tap(findNativeBack()); await tester.pumpAndSettle(); expect(find.byKey(const Key('pipeline-list')), findsOneWidget); @@ -282,7 +283,7 @@ void main() { await tester.pageBack(); await tester.pumpAndSettle(); - await tester.tap(find.byKey(const ValueKey('shell.back'))); + await tester.tap(findNativeBack()); await tester.pumpAndSettle(); await tester.tap(find.byKey(const Key('pipeline-row-1'))); await tester.pumpAndSettle(); diff --git a/app/test/features/pipelines/pipelines_adaptive_test.dart b/app/test/features/pipelines/pipelines_adaptive_test.dart index b2bde403..1066cf1a 100644 --- a/app/test/features/pipelines/pipelines_adaptive_test.dart +++ b/app/test/features/pipelines/pipelines_adaptive_test.dart @@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; +import '../../native_back.dart'; import 'package:pipelines_app/features/graph/widgets/definition_graph_view.dart'; import 'package:pipelines_app/features/pipelines/pipeline_repository.dart'; import 'package:pipelines_app/features/pipelines/pipelines_controller.dart'; @@ -35,7 +36,7 @@ void main() { // The open pipeline is its own page: its bar names it and Back closes it. expect(find.text('Alpha review'), findsWidgets); - await tester.tap(find.byKey(const ValueKey('shell.back'))); + await tester.tap(findNativeBack()); await tester.pumpAndSettle(); expect(find.byKey(const Key('pipeline-list')), findsOneWidget); expect(find.byKey(const Key('pipeline-detail')), findsNothing); diff --git a/app/test/features/runs/ui/runs_screen_test.dart b/app/test/features/runs/ui/runs_screen_test.dart index f97e8dad..aac3597f 100644 --- a/app/test/features/runs/ui/runs_screen_test.dart +++ b/app/test/features/runs/ui/runs_screen_test.dart @@ -3,6 +3,7 @@ import 'dart:async'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; +import '../../../native_back.dart'; import 'package:pipelines_app/core/api_gateway.dart'; import 'package:pipelines_app/features/runs/screen.dart'; @@ -323,9 +324,9 @@ void main() { await tester.pumpAndSettle(); // The run covers the list as a page with its own Back. expect(find.text('Alpha run'), findsNothing); - expect(find.byKey(const ValueKey('shell.back')), findsOneWidget); + expect(findNativeBack(), findsOneWidget); - await tester.tap(find.byKey(const ValueKey('shell.back'))); + await tester.tap(findNativeBack()); await tester.pumpAndSettle(); expect(backs, 1); expect(find.text('Alpha run'), findsOneWidget); diff --git a/app/test/native_back.dart b/app/test/native_back.dart new file mode 100644 index 00000000..15f67bd4 --- /dev/null +++ b/app/test/native_back.dart @@ -0,0 +1,9 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +/// Find the platform's actual Back control, not an app-specific button key. +Finder findNativeBack() => find.byWidgetPredicate( + (widget) => + widget is BackButton || widget is CupertinoNavigationBarBackButton, +); diff --git a/app/test/shell/detail_page_test.dart b/app/test/shell/detail_page_test.dart index 79d9d6bb..abe8a4d1 100644 --- a/app/test/shell/detail_page_test.dart +++ b/app/test/shell/detail_page_test.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; +import '../native_back.dart'; import 'package:pipelines_app/shell/destination.dart'; import 'package:pipelines_app/shell/detail_page.dart'; import 'package:pipelines_app/shell/shell_bar.dart'; @@ -64,7 +65,7 @@ void main() { await tester.pumpAndSettle(); expect(find.text('detail 8'), findsOneWidget); - await tester.tap(find.byKey(const ValueKey('shell.back'))); + await tester.tap(findNativeBack()); await tester.pumpAndSettle(); expect(find.text('the list'), findsOneWidget); expect(selection.value, isNull); diff --git a/app/tool/chat_back_latency_probe.mjs b/app/tool/chat_back_latency_probe.mjs index 4120a213..7ad5df57 100644 --- a/app/tool/chat_back_latency_probe.mjs +++ b/app/tool/chat_back_latency_probe.mjs @@ -11,12 +11,13 @@ import { launchChrome, waitForPort, waitForPage, connect, sleep } from './pipeli import { axNodes, waitFor, capture } from './pipelines_probe_cdp_input.mjs'; const pairs = Number(process.env.CHAT_PAIRS ?? 100); +const width = Number(process.env.PROBE_WIDTH ?? 390); const text = '# Recorded answer\n\n' + Array.from({ length: 12 }, (_, i) => `Paragraph ${i}: This is recorded fixture content with **formatting**, an [inert link](https://example.test), and enough text to wrap naturally on a phone.\n`).join('\n') + '\n```dart\n' + Array.from({ length: 25 }, (_, i) => `final value${i} = ${i};`).join('\n') + '\n```\n'; const turns = Array.from({ length: pairs }, (_, i) => [ { id: `u${i}`, role: 'user', parts: [{ type: 'text', text: `Recorded question ${i}` }] }, - { id: `a${i}`, role: 'assistant', parts: [{ id: `p${i}`, type: 'text', text }] }, + { id: `a${i}`, role: 'assistant', parts: [{ id: `p${i}`, type: 'text', text: process.env.CHAT_VARIANCE === '1' ? text.repeat(1 + i % 4) : text }] }, ]).flat(); const folded = process.env.CHAT_FOLDED === '1'; const messages = folded ? [turns[0], ...turns.filter(m => m.role === 'assistant')] : turns; @@ -25,7 +26,7 @@ await mkdir(output, { recursive: true }); const fixture = await startFixture({ root: resolve(process.argv[2]), chatMessages: messages }); const profile = await mkdtemp(join(tmpdir(), 'chat-back-latency-')); const chrome = launchChrome('/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', profile, 'about:blank'); -const log = { pairs, folded, streaming: process.env.CHAT_STREAM === '1', cpuRate: Number(process.env.CPU_RATE ?? 1), host: process.env.PROBE_PLATFORM ?? 'cupertino', checks: [], captures: [] }; +const log = { pairs, width, folded, roundTrip: process.env.SCROLL_ROUNDTRIP === '1', fromList: process.env.OPEN_FROM_LIST === '1', streaming: process.env.CHAT_STREAM === '1', cpuRate: Number(process.env.CPU_RATE ?? 1), host: process.env.PROBE_PLATFORM ?? 'cupertino', checks: [], captures: [] }; let c; let streamTimer; const requests = new Set(); @@ -38,21 +39,37 @@ try { if (log.host === 'material') await c.send('Emulation.setUserAgentOverride', { userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/155.0.0.0 Safari/537.36', platform: 'Win32', }); - await c.send('Emulation.setDeviceMetricsOverride', { width: 390, height: 844, deviceScaleFactor: 1, mobile: true }); + await c.send('Emulation.setDeviceMetricsOverride', { width, height: 844, deviceScaleFactor: 1, mobile: true }); await c.send('Emulation.setCPUThrottlingRate', { rate: log.cpuRate }); const opened = performance.now(); - await c.send('Page.navigate', { url: fixture.url + '/chat/ses_probechat' }); + await c.send('Page.navigate', { url: fixture.url + (log.fromList ? '/chat' : '/chat/ses_probechat') }); assert.ok(await waitFor(() => c.evaluate("Boolean(document.querySelector('flt-semantics-placeholder'))"), 30000)); // Mobile semantics activation requires a real pointer at the placeholder's // centre; element.click() at (0,0) does not enable Android web semantics. const rect = await c.evaluate("(() => { const r = document.querySelector('flt-semantics-placeholder').getBoundingClientRect(); return {x:(r.left+r.right)/2,y:(r.top+r.bottom)/2}; })()"); await c.send('Input.dispatchMouseEvent', { type: 'mousePressed', x: rect.x, y: rect.y, button: 'left', clickCount: 1 }); await c.send('Input.dispatchMouseEvent', { type: 'mouseReleased', x: rect.x, y: rect.y, button: 'left', clickCount: 1 }); + if (log.fromList) { + const row = await waitFor(async () => (await axNodes(c)).find(n => n.name?.value?.startsWith('Probe conversation') && n.backendDOMNodeId && ['group', 'button'].includes(n.role?.value)), 30000); + assert.ok(row, 'chat list row'); + const { model } = await c.send('DOM.getBoxModel', { backendNodeId: row.backendDOMNodeId }); + const [x1, y1, , , x3, y3] = model.content; + await c.send('Input.dispatchMouseEvent', { type: 'mousePressed', x: (x1+x3)/2, y: (y1+y3)/2, button: 'left', clickCount: 1 }); + await c.send('Input.dispatchMouseEvent', { type: 'mouseReleased', x: (x1+x3)/2, y: (y1+y3)/2, button: 'left', clickCount: 1 }); + } assert.ok(await waitFor(async () => (await axNodes(c)).some(n => n.name?.value === 'Back'), 45000), 'chat Back ready'); await sleep(1800); await c.evaluate('new Promise(r => requestAnimationFrame(() => requestAnimationFrame(r)))'); log.openAndSettleMs = performance.now() - opened; await capture(c, output, log, 'chat-before-back'); + if (log.roundTrip) { + await c.send('Input.dispatchMouseEvent', { type: 'mouseWheel', x: width - 10, y: 400, deltaX: 0, deltaY: -1000000 }); + await sleep(900); + await capture(c, output, log, 'chat-scrolled-top'); + await c.send('Input.dispatchMouseEvent', { type: 'mouseWheel', x: width - 10, y: 400, deltaX: 0, deltaY: 1000000 }); + await sleep(Number(process.env.SCROLL_SETTLE_MS ?? 300)); + await capture(c, output, log, 'chat-scrolled-bottom'); + } if (log.streaming) { streamTimer = setInterval(() => { const request = fetch(fixture.url + '/fixture/chat-event', { method: 'POST', body: JSON.stringify({ @@ -65,7 +82,7 @@ try { } const backNodes = (await axNodes(c)).filter(n => /^Back(?:\s|$)/.test(n.name?.value ?? '')); log.backControlNodes = backNodes.map(n => ({name:n.name?.value, role:n.role?.value, backend:n.backendDOMNodeId})); - const back = backNodes.find(n => n.backendDOMNodeId); + const back = backNodes.find(n => n.backendDOMNodeId && n.role?.value === 'button') ?? backNodes.find(n => n.backendDOMNodeId); assert.ok(back, 'native Back control'); const { model } = await c.send('DOM.getBoxModel', { backendNodeId: back.backendDOMNodeId }); const [x1, y1, , , x3, y3] = model.content;