fix(chat): use stock Navigator Back at every screen width

This commit is contained in:
2026-10-24 12:36:17 +01:00
parent 0ecd4a8487
commit f22afabd94
16 changed files with 262 additions and 53 deletions
@@ -846,7 +846,6 @@ class _ChatThreadViewState extends State<ChatThreadView> {
final title = widget.title.trim(); final title = widget.title.trim();
return ShellBar( return ShellBar(
title: title.isEmpty ? null : title, title: title.isEmpty ? null : title,
onBack: widget.onBack,
actions: [ actions: [
if (hasModel) if (hasModel)
ConstrainedBox( ConstrainedBox(
+6 -13
View File
@@ -165,7 +165,7 @@ class _ChatScreenState extends State<ChatScreen> {
} }
} }
/// 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(); final DetailPageHost _page = DetailPageHost();
@override @override
@@ -200,12 +200,11 @@ class _ChatScreenState extends State<ChatScreen> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final selected = _selected; final selected = _selected;
// On a phone an open chat is its own page over the tabs; a wide window // Chats are real Navigator pages at every width. Do not swap a conversation
// keeps it in the tab, beside the destination rail. // into the home page and manually emulate Back on tablets/foldables.
final narrow = MediaQuery.sizeOf(context).width < kDetailPageMaxWidth;
_page.sync( _page.sync(
context, context,
selected: selected != null && narrow, selected: selected != null,
destination: AppDestination.chat, destination: AppDestination.chat,
onClosed: _back, onClosed: _back,
builder: (context) => selected == null builder: (context) => selected == null
@@ -220,14 +219,8 @@ class _ChatScreenState extends State<ChatScreen> {
onOpen: _open, onOpen: _open,
onSessions: _adoptRows, onSessions: _adoptRows,
activeSessionId: selected, activeSessionId: selected,
publishShellBar: narrow || selected == null, publishShellBar: true,
);
if (narrow) return list;
return Stack(
children: [
Offstage(offstage: selected != null, child: list),
if (selected != null) _thread(selected, _back),
],
); );
return list;
} }
} }
+2 -12
View File
@@ -111,8 +111,6 @@ class _DetailPageState extends State<_DetailPage> {
super.dispose(); super.dispose();
} }
void _back() => Navigator.of(context).maybePop();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final body = ShellBarScope( final body = ShellBarScope(
@@ -129,11 +127,7 @@ class _DetailPageState extends State<_DetailPage> {
if (usesCupertinoHost(context)) { if (usesCupertinoHost(context)) {
return CupertinoPageScaffold( return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar( navigationBar: CupertinoNavigationBar(
leading: CupertinoNavigationBarBackButton( automaticallyImplyLeading: true,
key: const ValueKey('shell.back'),
onPressed: _back,
),
automaticallyImplyLeading: false,
middle: Text(title), middle: Text(title),
trailing: actions.isEmpty trailing: actions.isEmpty
? null ? null
@@ -144,11 +138,7 @@ class _DetailPageState extends State<_DetailPage> {
} }
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
automaticallyImplyLeading: false, automaticallyImplyLeading: true,
leading: BackButton(
key: const ValueKey('shell.back'),
onPressed: _back,
),
title: Text(title), title: Text(title),
actions: actions, actions: actions,
), ),
@@ -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.
@@ -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 'package:pipelines_app/features/chat/ui/sessions/chat_sessions_screen.dart';
import '../core/transport/pipelines_client_test.dart' show FakeChannel; import '../core/transport/pipelines_client_test.dart' show FakeChannel;
import '../native_back.dart';
ServerEndpoint webServer() => ServerEndpoint.resolve( ServerEndpoint webServer() => ServerEndpoint.resolve(
base: Uri.parse('http://127.0.0.1:8096/'), base: Uri.parse('http://127.0.0.1:8096/'),
@@ -188,6 +189,7 @@ void main() {
await replySessions(tester, channel); await replySessions(tester, channel);
await replySubscribe(tester, channel); await replySubscribe(tester, channel);
await replyHistory(tester, channel); await replyHistory(tester, channel);
await tester.pumpAndSettle();
expect(provider.value.uri.path, '/chat/s1'); expect(provider.value.uri.path, '/chat/s1');
expect(find.byType(ChatThreadView), findsOneWidget); expect(find.byType(ChatThreadView), findsOneWidget);
@@ -234,10 +236,9 @@ void main() {
// The open chat takes over the app bar: one Back there, and no // The open chat takes over the app bar: one Back there, and no
// second header row under it. // second header row under it.
expect(find.byKey(const Key('chat-thread-header')), findsNothing); expect(find.byKey(const Key('chat-thread-header')), findsNothing);
await tester.tap(find.byKey(const ValueKey('shell.back'))); await tester.tap(findNativeBack());
await tester.pump(); // A real Navigator pop finishes its native reverse transition.
// The bar hands back to the list on the next frame. await tester.pumpAndSettle();
await tester.pump();
expect(provider.value.uri.path, '/chat'); expect(provider.value.uri.path, '/chat');
expect(find.byType(ChatThreadView), findsNothing); expect(find.byType(ChatThreadView), findsNothing);
expect(find.byType(ChatSessionsScreen), findsOneWidget); expect(find.byType(ChatSessionsScreen), findsOneWidget);
@@ -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<JsonMap> 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 = <String>[];
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<NavigatorState>(find.byType(Navigator));
expect(
navigator.canPop(),
isTrue,
reason: 'Chat must be pushed, not swapped into the main page',
);
expect(
tester.widget<BackButton>(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<ListView>(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();
},
);
}
}
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import '../native_back.dart';
import 'package:pipelines_app/application/app_router.dart'; import 'package:pipelines_app/application/app_router.dart';
import 'package:pipelines_app/core/transport/pipelines_client.dart'; import 'package:pipelines_app/core/transport/pipelines_client.dart';
@@ -122,7 +123,7 @@ void main() {
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('Navigation dialog'), findsNothing); expect(find.text('Navigation dialog'), findsNothing);
expect(provider.value.uri.path, detailPath); expect(provider.value.uri.path, detailPath);
expect(find.byKey(const ValueKey('shell.back')), findsOneWidget); expect(findNativeBack(), findsOneWidget);
if (predictive) { if (predictive) {
await backGesture(tester, 'startBackGesture'); await backGesture(tester, 'startBackGesture');
+6 -5
View File
@@ -3,6 +3,7 @@ import 'dart:convert';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.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_route.dart';
import 'package:pipelines_app/application/app_router.dart'; import 'package:pipelines_app/application/app_router.dart';
import 'package:pipelines_app/application/pipelines_app.dart'; import 'package:pipelines_app/application/pipelines_app.dart';
@@ -160,11 +161,11 @@ void main() {
await replyDetail(tester, channel, 1); await replyDetail(tester, channel, 1);
expect(find.text('Run 1'), findsWidgets); 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(provider.value.uri.path, '/runs/1');
expect(find.text('Pipelines — Not implemented'), findsNothing); expect(find.text('Pipelines — Not implemented'), findsNothing);
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'); expect(provider.value.uri.path, '/runs');
expect(find.text('Deep-linked run'), findsWidgets); expect(find.text('Deep-linked run'), findsWidgets);
@@ -267,7 +268,7 @@ void main() {
await tester.pump(); await tester.pump();
expect(provider.value.uri.path, '/runs/2'); expect(provider.value.uri.path, '/runs/2');
await replyDetail(tester, channel, 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. // The engine's browser Back arrives as new route information.
await provider.didPushRouteInformation( await provider.didPushRouteInformation(
@@ -277,7 +278,7 @@ void main() {
// The bar returns to the tab's own after the closed run hands it back. // The bar returns to the tab's own after the closed run hands it back.
await tester.pump(); await tester.pump();
expect(find.text('Beta run'), findsWidgets); expect(find.text('Beta run'), findsWidgets);
expect(find.byKey(const ValueKey('shell.back')), findsNothing); expect(findNativeBack(), findsNothing);
// Forward re-opens the same run. // Forward re-opens the same run.
await provider.didPushRouteInformation( await provider.didPushRouteInformation(
@@ -286,7 +287,7 @@ void main() {
await tester.pump(); await tester.pump();
await replyDetail(tester, channel, 2); await replyDetail(tester, channel, 2);
await tester.pump(); await tester.pump();
expect(find.byKey(const ValueKey('shell.back')), findsOneWidget); expect(findNativeBack(), findsOneWidget);
}); });
testWidgets('a malformed boot path is corrected to /pipelines', ( testWidgets('a malformed boot path is corrected to /pipelines', (
+6 -5
View File
@@ -3,6 +3,7 @@ import 'dart:convert';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter_test/flutter_test.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_route.dart';
import 'package:pipelines_app/application/app_router.dart'; import 'package:pipelines_app/application/app_router.dart';
import 'package:pipelines_app/application/pipelines_app.dart'; import 'package:pipelines_app/application/pipelines_app.dart';
@@ -323,7 +324,7 @@ void main() {
expect(provider.value.uri.path, '/runs/2'); expect(provider.value.uri.path, '/runs/2');
expect(find.byType(SearchScreen), findsNothing); expect(find.byType(SearchScreen), findsNothing);
expect(find.byKey(const ValueKey('shell.back')), findsOneWidget); expect(findNativeBack(), findsOneWidget);
expect(find.text('Run 2'), findsWidgets); expect(find.text('Run 2'), findsWidgets);
// The shell was never remounted, so the open run was not re-read. // The shell was never remounted, so the open run was not re-read.
expect(requestsOf(channel, 'get_run'), hasLength(1)); expect(requestsOf(channel, 'get_run'), hasLength(1));
@@ -408,7 +409,7 @@ void main() {
expect(provider.value.uri.path, '/runs/7'); expect(provider.value.uri.path, '/runs/7');
await replyRunDetail(tester, channel, 7, index: 1); await replyRunDetail(tester, channel, 7, index: 1);
expect(find.byType(SearchScreen), findsNothing); expect(find.byType(SearchScreen), findsNothing);
expect(find.byKey(const ValueKey('shell.back')), findsOneWidget); expect(findNativeBack(), findsOneWidget);
expect(find.text('Run 7'), findsWidgets); expect(find.text('Run 7'), findsWidgets);
// One app socket carried the search and the run reads. // One app socket carried the search and the run reads.
expect(sockets, 1); expect(sockets, 1);
@@ -650,8 +651,8 @@ void main() {
// leaves from the loading placeholder instead. // leaves from the loading placeholder instead.
await openArtifactHit(tester, channel); await openArtifactHit(tester, channel);
expect(provider.value.uri.path, '/runs/7'); expect(provider.value.uri.path, '/runs/7');
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.pump(); await tester.pump();
await tester.pump(); await tester.pump();
expect(provider.value.uri.path, '/runs'); expect(provider.value.uri.path, '/runs');
@@ -710,7 +711,7 @@ void main() {
await tester.tap(find.byKey(const Key('run-visit-back'))); await tester.tap(find.byKey(const Key('run-visit-back')));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
await tester.tap(find.byKey(const ValueKey('shell.back'))); await tester.tap(findNativeBack());
await tester.pump(); await tester.pump();
await tester.pump(); await tester.pump();
expect(provider.value.uri.path, '/runs'); expect(provider.value.uri.path, '/runs');
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import '../../native_back.dart';
import 'package:pipelines_app/core/api_gateway.dart'; import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/chat/screen.dart'; import 'package:pipelines_app/features/chat/screen.dart';
@@ -89,7 +90,7 @@ void main() {
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('model-b'), findsOneWidget); expect(find.text('model-b'), findsOneWidget);
await tester.tap(find.byKey(const Key('chat-back'))); await tester.tap(findNativeBack());
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('model-b'), findsNothing); expect(find.text('model-b'), findsNothing);
@@ -2,6 +2,7 @@ import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import '../../native_back.dart';
import 'package:pipelines_app/core/api_gateway.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/definition_graph_view.dart';
import 'package:pipelines_app/features/graph/widgets/stage_definition_view.dart'; import 'package:pipelines_app/features/graph/widgets/stage_definition_view.dart';
@@ -243,7 +244,7 @@ void main() {
await tester.pageBack(); await tester.pageBack();
await tester.pumpAndSettle(); await tester.pumpAndSettle();
await tester.tap(find.byKey(const ValueKey('shell.back'))); await tester.tap(findNativeBack());
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.byKey(const Key('pipeline-list')), findsOneWidget); expect(find.byKey(const Key('pipeline-list')), findsOneWidget);
@@ -282,7 +283,7 @@ void main() {
await tester.pageBack(); await tester.pageBack();
await tester.pumpAndSettle(); await tester.pumpAndSettle();
await tester.tap(find.byKey(const ValueKey('shell.back'))); await tester.tap(findNativeBack());
await tester.pumpAndSettle(); await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('pipeline-row-1'))); await tester.tap(find.byKey(const Key('pipeline-row-1')));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
@@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.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/graph/widgets/definition_graph_view.dart';
import 'package:pipelines_app/features/pipelines/pipeline_repository.dart'; import 'package:pipelines_app/features/pipelines/pipeline_repository.dart';
import 'package:pipelines_app/features/pipelines/pipelines_controller.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. // The open pipeline is its own page: its bar names it and Back closes it.
expect(find.text('Alpha review'), findsWidgets); expect(find.text('Alpha review'), findsWidgets);
await tester.tap(find.byKey(const ValueKey('shell.back'))); await tester.tap(findNativeBack());
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.byKey(const Key('pipeline-list')), findsOneWidget); expect(find.byKey(const Key('pipeline-list')), findsOneWidget);
expect(find.byKey(const Key('pipeline-detail')), findsNothing); expect(find.byKey(const Key('pipeline-detail')), findsNothing);
@@ -3,6 +3,7 @@ import 'dart:async';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import '../../../native_back.dart';
import 'package:pipelines_app/core/api_gateway.dart'; import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/runs/screen.dart'; import 'package:pipelines_app/features/runs/screen.dart';
@@ -323,9 +324,9 @@ void main() {
await tester.pumpAndSettle(); await tester.pumpAndSettle();
// The run covers the list as a page with its own Back. // The run covers the list as a page with its own Back.
expect(find.text('Alpha run'), findsNothing); 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(); await tester.pumpAndSettle();
expect(backs, 1); expect(backs, 1);
expect(find.text('Alpha run'), findsOneWidget); expect(find.text('Alpha run'), findsOneWidget);
+9
View File
@@ -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,
);
+2 -1
View File
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import '../native_back.dart';
import 'package:pipelines_app/shell/destination.dart'; import 'package:pipelines_app/shell/destination.dart';
import 'package:pipelines_app/shell/detail_page.dart'; import 'package:pipelines_app/shell/detail_page.dart';
import 'package:pipelines_app/shell/shell_bar.dart'; import 'package:pipelines_app/shell/shell_bar.dart';
@@ -64,7 +65,7 @@ void main() {
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('detail 8'), findsOneWidget); expect(find.text('detail 8'), findsOneWidget);
await tester.tap(find.byKey(const ValueKey('shell.back'))); await tester.tap(findNativeBack());
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('the list'), findsOneWidget); expect(find.text('the list'), findsOneWidget);
expect(selection.value, isNull); expect(selection.value, isNull);
+22 -5
View File
@@ -11,12 +11,13 @@ import { launchChrome, waitForPort, waitForPage, connect, sleep } from './pipeli
import { axNodes, waitFor, capture } from './pipelines_probe_cdp_input.mjs'; import { axNodes, waitFor, capture } from './pipelines_probe_cdp_input.mjs';
const pairs = Number(process.env.CHAT_PAIRS ?? 100); const pairs = Number(process.env.CHAT_PAIRS ?? 100);
const width = Number(process.env.PROBE_WIDTH ?? 390);
const text = '# Recorded answer\n\n' + 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') + 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'; '\n```dart\n' + Array.from({ length: 25 }, (_, i) => `final value${i} = ${i};`).join('\n') + '\n```\n';
const turns = Array.from({ length: pairs }, (_, i) => [ const turns = Array.from({ length: pairs }, (_, i) => [
{ id: `u${i}`, role: 'user', parts: [{ type: 'text', text: `Recorded question ${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(); ]).flat();
const folded = process.env.CHAT_FOLDED === '1'; const folded = process.env.CHAT_FOLDED === '1';
const messages = folded ? [turns[0], ...turns.filter(m => m.role === 'assistant')] : turns; 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 fixture = await startFixture({ root: resolve(process.argv[2]), chatMessages: messages });
const profile = await mkdtemp(join(tmpdir(), 'chat-back-latency-')); const profile = await mkdtemp(join(tmpdir(), 'chat-back-latency-'));
const chrome = launchChrome('/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', profile, 'about:blank'); 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 c;
let streamTimer; let streamTimer;
const requests = new Set(); const requests = new Set();
@@ -38,21 +39,37 @@ try {
if (log.host === 'material') await c.send('Emulation.setUserAgentOverride', { 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', 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 }); await c.send('Emulation.setCPUThrottlingRate', { rate: log.cpuRate });
const opened = performance.now(); 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)); assert.ok(await waitFor(() => c.evaluate("Boolean(document.querySelector('flt-semantics-placeholder'))"), 30000));
// Mobile semantics activation requires a real pointer at the placeholder's // Mobile semantics activation requires a real pointer at the placeholder's
// centre; element.click() at (0,0) does not enable Android web semantics. // 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}; })()"); 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: '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 }); 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'); assert.ok(await waitFor(async () => (await axNodes(c)).some(n => n.name?.value === 'Back'), 45000), 'chat Back ready');
await sleep(1800); await sleep(1800);
await c.evaluate('new Promise(r => requestAnimationFrame(() => requestAnimationFrame(r)))'); await c.evaluate('new Promise(r => requestAnimationFrame(() => requestAnimationFrame(r)))');
log.openAndSettleMs = performance.now() - opened; log.openAndSettleMs = performance.now() - opened;
await capture(c, output, log, 'chat-before-back'); 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) { if (log.streaming) {
streamTimer = setInterval(() => { streamTimer = setInterval(() => {
const request = fetch(fixture.url + '/fixture/chat-event', { method: 'POST', body: JSON.stringify({ 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 ?? '')); 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})); 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'); assert.ok(back, 'native Back control');
const { model } = await c.send('DOM.getBoxModel', { backendNodeId: back.backendDOMNodeId }); const { model } = await c.send('DOM.getBoxModel', { backendNodeId: back.backendDOMNodeId });
const [x1, y1, , , x3, y3] = model.content; const [x1, y1, , , x3, y3] = model.content;