Files
pipelines/app/test/features/search/search_test_support.dart
T
alan bff7115e4e Search: find operator chats by title, directory and message text
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.
2026-11-03 13:01:53 +00:00

82 lines
2.5 KiB
Dart

import 'dart:async';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/search/data/search_repository.dart';
import 'package:pipelines_app/features/search/domain/search_controller.dart';
/// Queues run/artifact searches in [calls]/[pending]. A `kind: chat` search
/// (sent beside every all-kind search) is recorded in [chatCalls] and, unless
/// [holdChats] is set, answered at once with no chats.
class QueuedGateway implements ApiGateway {
QueuedGateway({this.holdChats = false});
final bool holdChats;
final calls = <JsonMap>[];
final pending = <Completer<JsonMap>>[];
final chatCalls = <JsonMap>[];
final chatPending = <Completer<JsonMap>>[];
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
final search = fields['search'];
if (search is Map && search['kind'] == 'chat') {
chatCalls.add(Map.of(fields));
if (!holdChats) return Future.value(envelope(const []));
final completer = Completer<JsonMap>();
chatPending.add(completer);
return completer.future;
}
calls.add(Map.of(fields));
final completer = Completer<JsonMap>();
pending.add(completer);
return completer.future;
}
@override
Stream<JsonMap> get frames => const Stream.empty();
void succeed(int index, JsonMap reply) => pending[index].complete(reply);
void fail(int index, Object error) => pending[index].completeError(error);
JsonMap get lastSearch =>
Map<String, dynamic>.from((calls.last['search'] as Map));
}
JsonMap envelope(
List<JsonMap> results, {
bool truncated = false,
int scannedSteps = 0,
int scannedBytes = 0,
int cap = 50,
int scanBoundBytes = 1 << 20,
}) => {
'search_results': {
'results': results,
'truncated': truncated,
'scanned_steps': scannedSteps,
'scanned_bytes': scannedBytes,
'cap': cap,
'scan_bound_bytes': scanBoundBytes,
},
};
OmniSearchController controllerFor(ApiGateway gateway) => OmniSearchController(
repository: SearchRepository(gateway),
debounce: Duration.zero,
);
/// A server-shaped `kind: chat` hit; a [snippet] makes it a message match.
JsonMap chatHit(String id, {String title = 'Fix CI', String? snippet}) => {
'kind': 'chat',
'target': 'chat:$id',
'score': snippet == null ? 3 : 1,
'matched_field': snippet == null ? 'title' : 'message',
'chat': {
'session_id': id,
'title': title,
'directory': '/work/api',
'backend': 'claude',
'snippet': ?snippet,
},
};