4a85a12cf7
The open conversation draws its own bar of separate rounded pieces: the platform Back in a circle, a title pill with the folder that opens the chat information, and a pill with the model and mode controls. Detail pages drop only their app bar for it, keeping the body mounted.
279 lines
8.5 KiB
Dart
279 lines
8.5 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
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/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/'),
|
|
web: true,
|
|
);
|
|
|
|
Map<String, dynamic>? requestOf(
|
|
FakeChannel channel,
|
|
String type, {
|
|
int index = 0,
|
|
}) => channel.outgoing
|
|
.map((frame) => jsonDecode(frame as String) as Map<String, dynamic>)
|
|
.where((frame) => frame['type'] == type)
|
|
.skip(index)
|
|
.firstOrNull;
|
|
|
|
Future<Map<String, dynamic>> waitForRequest(
|
|
WidgetTester tester,
|
|
FakeChannel channel,
|
|
String type, {
|
|
int index = 0,
|
|
}) async {
|
|
for (var attempt = 0; attempt < 80; attempt++) {
|
|
final request = requestOf(channel, type, index: index);
|
|
if (request != null) return request;
|
|
await tester.pump(const Duration(milliseconds: 5));
|
|
}
|
|
fail('Timed out waiting for $type #$index');
|
|
}
|
|
|
|
Future<void> replySessions(
|
|
WidgetTester tester,
|
|
FakeChannel channel, {
|
|
int index = 0,
|
|
}) async {
|
|
final request = await waitForRequest(
|
|
tester,
|
|
channel,
|
|
'chat_sessions',
|
|
index: index,
|
|
);
|
|
channel.incoming.add(
|
|
jsonEncode({
|
|
'id': request['id'],
|
|
'type': 'chat_sessions',
|
|
'chat_sessions': [
|
|
{'id': 's1', 'title': 'Wire chat', 'directory': '/workspace/demo'},
|
|
],
|
|
}),
|
|
);
|
|
await tester.pump();
|
|
}
|
|
|
|
Future<void> replySubscribe(
|
|
WidgetTester tester,
|
|
FakeChannel channel, {
|
|
int index = 0,
|
|
}) async {
|
|
final request = await waitForRequest(
|
|
tester,
|
|
channel,
|
|
'chat_subscribe',
|
|
index: index,
|
|
);
|
|
channel.incoming.add(
|
|
jsonEncode({'id': request['id'], 'type': 'chat_subscribe'}),
|
|
);
|
|
await tester.pump();
|
|
await tester.pump();
|
|
}
|
|
|
|
/// The mounted thread also reads the session's running background tasks. The
|
|
/// client serializes requests, so this snapshot is answered (no running task)
|
|
/// before the history page behind it can leave the queue.
|
|
Future<void> replyShells(
|
|
WidgetTester tester,
|
|
FakeChannel channel, {
|
|
int index = 0,
|
|
}) async {
|
|
final request = await waitForRequest(
|
|
tester,
|
|
channel,
|
|
'chat_shells',
|
|
index: index,
|
|
);
|
|
channel.incoming.add(
|
|
jsonEncode({
|
|
'id': request['id'],
|
|
'type': 'chat_shells',
|
|
'chat_shells': const [],
|
|
}),
|
|
);
|
|
await tester.pump();
|
|
}
|
|
|
|
Future<void> replyHistory(
|
|
WidgetTester tester,
|
|
FakeChannel channel, {
|
|
int index = 0,
|
|
String text = 'The stored reply stays readable.',
|
|
bool shells = true,
|
|
}) async {
|
|
if (shells) await replyShells(tester, channel, index: index);
|
|
final request = await waitForRequest(
|
|
tester,
|
|
channel,
|
|
'chat_messages',
|
|
index: index,
|
|
);
|
|
channel.incoming.add(
|
|
jsonEncode({
|
|
'id': request['id'],
|
|
'type': 'chat_history',
|
|
'chat_history': {
|
|
'messages': [
|
|
{
|
|
'id': 'u1',
|
|
'role': 'user',
|
|
'parts': [
|
|
{'type': 'text', 'text': 'Open this chat from its route.'},
|
|
],
|
|
},
|
|
{
|
|
'id': 'a1',
|
|
'role': 'assistant',
|
|
'parts': [
|
|
{'type': 'text', 'text': text},
|
|
{'type': 'reasoning', 'text': 'Kept behind a native disclosure.'},
|
|
{'type': 'tool', 'name': 'shell'},
|
|
],
|
|
},
|
|
],
|
|
'next_cursor': '',
|
|
'has_more': false,
|
|
},
|
|
}),
|
|
);
|
|
await tester.pump();
|
|
await tester.pump();
|
|
}
|
|
|
|
void main() {
|
|
for (final cupertino in [false, true]) {
|
|
testWidgets(
|
|
'a wide /chat/s1 deep link shows that thread beside the list and route Back returns to /chat ($cupertino)',
|
|
(tester) async {
|
|
tester.view.physicalSize = const Size(900, 900);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.resetPhysicalSize);
|
|
addTearDown(tester.view.resetDevicePixelRatio);
|
|
if (cupertino) {
|
|
tester.platformDispatcher.platformBrightnessTestValue =
|
|
Brightness.dark;
|
|
addTearDown(
|
|
tester.platformDispatcher.clearPlatformBrightnessTestValue,
|
|
);
|
|
}
|
|
|
|
final channel = FakeChannel()..readyCompleter.complete();
|
|
final client = PipelinesClient(channelFactory: (_) => channel);
|
|
final provider = PlatformRouteInformationProvider(
|
|
initialRouteInformation: RouteInformation(uri: Uri.parse('/chat/s1')),
|
|
);
|
|
addTearDown(provider.dispose);
|
|
|
|
await tester.pumpWidget(
|
|
PipelinesApp(
|
|
server: webServer(),
|
|
client: client,
|
|
cupertino: cupertino,
|
|
routeInformationProvider: provider,
|
|
),
|
|
);
|
|
await tester.pump();
|
|
|
|
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);
|
|
// The exact route names the session; the request carries the same id.
|
|
expect(requestOf(channel, 'chat_subscribe')!['chat_subscribe'], {
|
|
'session_id': 's1',
|
|
});
|
|
expect(requestOf(channel, 'chat_messages')!['chat_query'], {
|
|
'session_id': 's1',
|
|
'limit': 200,
|
|
'cursor': '',
|
|
});
|
|
expect(find.text('The stored reply stays readable.'), findsOneWidget);
|
|
expect(find.text('Ran 1 command'), findsOneWidget);
|
|
expect(find.byKey(const Key('chat-turn-activity')), findsOneWidget);
|
|
expect(find.text('Kept behind a native disclosure.'), findsNothing);
|
|
|
|
// The shell bar stays over the list and rail; the open chat draws its
|
|
// own floating bar in its pane, with no Back: the list beside it is the
|
|
// way out.
|
|
expect(find.byType(ChatSessionsScreen), findsOneWidget);
|
|
expect(
|
|
find.byType(NavigationRail),
|
|
cupertino ? findsNothing : findsOneWidget,
|
|
);
|
|
if (cupertino) {
|
|
expect(find.byType(CupertinoNavigationBar), findsOneWidget);
|
|
expect(find.byType(AppBar), findsNothing);
|
|
} else {
|
|
expect(find.byType(AppBar), findsOneWidget);
|
|
expect(find.byType(CupertinoNavigationBar), findsNothing);
|
|
}
|
|
expect(find.byKey(const Key('chat-thread-header')), findsOneWidget);
|
|
expect(findNativeBack(), findsNothing);
|
|
|
|
// A live frame updates the held thread.
|
|
channel.incoming.add(
|
|
jsonEncode({
|
|
'type': 'chat_event',
|
|
'chat_event': {
|
|
'session_id': 's1',
|
|
'message_id': 'a1',
|
|
'kind': 'text',
|
|
'part': {'id': 'p2', 'type': 'text'},
|
|
'delta': 'A live line arrived.',
|
|
},
|
|
}),
|
|
);
|
|
await tester.pump();
|
|
await tester.pump();
|
|
expect(find.text('A live line arrived.'), findsOneWidget);
|
|
|
|
// The thread's own bar carries its controls once: no second bar.
|
|
expect(find.byKey(const Key('chat-thread-header')), findsOneWidget);
|
|
// Browser Back to /chat clears the open pane and keeps the list.
|
|
await provider.didPushRouteInformation(
|
|
RouteInformation(uri: Uri.parse('/chat')),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
expect(provider.value.uri.path, '/chat');
|
|
expect(find.byType(ChatThreadView), findsNothing);
|
|
expect(find.byType(ChatSessionsScreen), findsOneWidget);
|
|
expect(find.text('Wire chat'), findsOneWidget);
|
|
expect(find.text('Select a chat to open it here.'), findsOneWidget);
|
|
|
|
// Browser Forward re-opens the same session through its route.
|
|
await provider.didPushRouteInformation(
|
|
RouteInformation(uri: Uri.parse('/chat/s1')),
|
|
);
|
|
await tester.pump();
|
|
expect(provider.value.uri.path, '/chat/s1');
|
|
await replySubscribe(tester, channel, index: 1);
|
|
await replyHistory(
|
|
tester,
|
|
channel,
|
|
index: 1,
|
|
text: 'Reopened from the route.',
|
|
);
|
|
expect(find.text('Reopened from the route.'), findsOneWidget);
|
|
|
|
await tester.pumpWidget(const SizedBox.shrink());
|
|
await tester.pump();
|
|
},
|
|
);
|
|
}
|
|
}
|