bff7115e4e
A search with kind chat matches the operator-session registry's titles and directories and the newest messages of recent transcripts through the chat broker (bounded count, concurrency and one-second budget), answered off the connection's read loop. The all-kind search is unchanged for older clients. The app sends the chat search after its run search and shows a Chats group with title, harness, directory and snippet; a chat hit opens that chat in the Chat tab. The probe fixture answers chat searches over ?chats=N.
125 lines
4.3 KiB
Dart
125 lines
4.3 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/core/api_gateway.dart';
|
|
import 'package:pipelines_app/features/search/search_screen.dart';
|
|
import 'package:pipelines_app/features/search/ui/search_result_slivers.dart';
|
|
|
|
import 'search_screen_test.dart'
|
|
show ImmediateGateway, field, response, search, useNarrowSurface;
|
|
import 'search_test_support.dart' show chatHit;
|
|
|
|
/// Run hits for every kind but chat; chat hits for the chat request.
|
|
JsonMap replies(String query, String kind) => kind == 'chat'
|
|
? response([
|
|
chatHit('ses_a', title: 'API refactor', snippet: 'the release retry'),
|
|
chatHit('ses_b', title: 'Release notes'),
|
|
])
|
|
: response([field]);
|
|
|
|
Widget host(Widget child, {required bool cupertino}) =>
|
|
cupertino ? CupertinoApp(home: child) : MaterialApp(home: child);
|
|
|
|
void main() {
|
|
for (final cupertino in [false, true]) {
|
|
final platform = cupertino ? 'Cupertino' : 'Material';
|
|
|
|
testWidgets('$platform: chat hits lead as a Chats group with title, '
|
|
'harness, directory and snippet, and open their chat', (tester) async {
|
|
useNarrowSurface(tester);
|
|
final gateway = ImmediateGateway(replies);
|
|
JsonMap? opened;
|
|
await tester.pumpWidget(
|
|
host(
|
|
SearchScreen(
|
|
gateway: gateway,
|
|
onOpen: (value) => opened = value,
|
|
cupertino: cupertino,
|
|
),
|
|
cupertino: cupertino,
|
|
),
|
|
);
|
|
await search(tester, 'release');
|
|
|
|
expect(gateway.calls.single['search'], {
|
|
'query': 'release',
|
|
'kind': '',
|
|
'limit': 0,
|
|
});
|
|
expect(gateway.chatCalls.single['search'], {
|
|
'query': 'release',
|
|
'kind': 'chat',
|
|
'limit': 0,
|
|
});
|
|
expect(find.text('Chats (2)'), findsOneWidget);
|
|
expect(find.text('Pipelines and runs'), findsOneWidget);
|
|
final chats = tester.getTopLeft(find.byKey(searchChatsSectionKey));
|
|
final others = tester.getTopLeft(find.byKey(searchOthersSectionKey));
|
|
final chatRow = find.byKey(const ValueKey('search.result.chat:ses_a'));
|
|
final runRow = find.byKey(
|
|
const ValueKey('search.result.run:11:4:output'),
|
|
);
|
|
expect(chats.dy, lessThan(tester.getTopLeft(chatRow).dy));
|
|
expect(tester.getTopLeft(chatRow).dy, lessThan(others.dy));
|
|
expect(others.dy, lessThan(tester.getTopLeft(runRow).dy));
|
|
|
|
expect(find.text('API refactor'), findsOneWidget);
|
|
expect(find.text('Release notes'), findsOneWidget);
|
|
expect(
|
|
find.textContaining('Chat · Claude Code · /work/api'),
|
|
findsNWidgets(2),
|
|
);
|
|
expect(find.textContaining('the release retry'), findsOneWidget);
|
|
expect(tester.takeException(), isNull);
|
|
|
|
await tester.tap(chatRow);
|
|
await tester.pump();
|
|
expect(opened?['target'], 'chat:ses_a');
|
|
expect((opened?['chat'] as Map)['session_id'], 'ses_a');
|
|
});
|
|
}
|
|
|
|
testWidgets('Chats selected alone lists chats without group headings', (
|
|
tester,
|
|
) async {
|
|
useNarrowSurface(tester);
|
|
final gateway = ImmediateGateway(replies);
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: SearchScreen(gateway: gateway, onOpen: (_) {}, cupertino: false),
|
|
),
|
|
);
|
|
await search(tester, 't:chat release');
|
|
|
|
expect(gateway.calls, isEmpty);
|
|
expect(gateway.chatCalls, hasLength(1));
|
|
expect(find.text('API refactor'), findsOneWidget);
|
|
expect(find.byKey(searchChatsSectionKey), findsNothing);
|
|
expect(find.byKey(searchOthersSectionKey), findsNothing);
|
|
});
|
|
|
|
testWidgets('an older server without chat search keeps its run results and '
|
|
'says chats were not searched', (tester) async {
|
|
useNarrowSurface(tester);
|
|
final gateway = ImmediateGateway((query, kind) {
|
|
if (kind == 'chat') {
|
|
throw StateError('unknown search kind "chat"; use one of pipeline');
|
|
}
|
|
return response([field]);
|
|
});
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: SearchScreen(gateway: gateway, onOpen: (_) {}, cupertino: false),
|
|
),
|
|
);
|
|
await search(tester, 'release');
|
|
|
|
expect(
|
|
find.byKey(const ValueKey('search.result.run:11:4:output')),
|
|
findsOneWidget,
|
|
);
|
|
expect(find.byKey(searchChatsNoteKey), findsOneWidget);
|
|
expect(find.textContaining('does not search chats'), findsOneWidget);
|
|
});
|
|
}
|