Files
pipelines/app/test/features/chat/domain/chat_find_test.dart
T
alan 8bd219e636 Chat: find in chat (Ctrl+F / Cmd+F)
A find bar over the transcript: query, Match case, n of N (counted from
the newest), Enter for an older match and Shift+Enter for a newer one.
Matches are painted over the rendered text, code blocks included, without
restyling it; the current match is scrolled into view. Matches in history
not loaded yet come from the server's chat:<id>-scoped search and are
reached by loading older pages. Esc closes and returns to the composer.
The key is the pane's, so a focused terminal keeps Ctrl+F. Fixture answers
scoped searches for captures; cheatsheet lists the key. The scoped search
matches the query as typed, spaces included, like the client.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 00:41:39 +00:00

79 lines
2.3 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/domain/chat_find.dart';
void main() {
final rows = [
{
'kind': 'user',
'key': 'u1',
'message': {
'id': 'u1',
'parts': [
{'type': 'text', 'text': 'Find the Needle'},
{'type': 'text', 'text': 'and another needle'},
],
},
},
{'kind': 'activity', 'key': 'x', 'label': 'needle in activity'},
{
'kind': 'assistant',
'key': 'a1',
'messageIds': ['a1', 'a2'],
'parts': [
{'type': 'reasoning', 'text': 'needle thoughts'},
{'type': 'text', 'text': 'A **needle** here, needle there'},
{'type': 'text', 'text': ' '},
],
},
];
test('units are user turns and answer text parts as rendered', () {
final units = chatFindUnits(rows, ['k0', 'k1', 'k2']);
expect(units.map((u) => u.text), [
'Find the Needle\nand another needle',
'A **needle** here, needle there',
]);
expect(units.map((u) => u.rowKey), ['k0', 'k2']);
expect(units.first.messageIds, ['u1']);
expect(units.last.messageIds, ['a1', 'a2']);
});
test('matches fold case unless asked, in display order', () {
final units = chatFindUnits(rows, ['k0', 'k1', 'k2']);
final folded = chatFindMatches(units, 'needle', caseSensitive: false);
expect(folded.length, 4);
expect(folded.first.start, 'Find the '.length);
expect(folded.map((m) => m.ordinal), [0, 1, 0, 1]);
final exact = chatFindMatches(units, 'Needle', caseSensitive: true);
expect(exact.length, 1);
});
test('regex characters in the query are literal', () {
expect(chatFindRanges('a.b axb (c)', '.', caseSensitive: false), [
(start: 1, end: 2),
]);
expect(chatFindRanges('a.b axb (c)', '(c)', caseSensitive: false), [
(start: 8, end: 11),
]);
});
test('server hits parse from a scoped reply', () {
final hits = ChatFindRemoteHit.fromReply({
'search_results': {
'results': [
{
'chat': {'message_id': 'm9', 'part': 1, 'offset': 4},
},
{
'chat': {'message_id': 'm8'},
},
],
},
});
expect(hits.map((h) => (h.messageId, h.part, h.offset)), [
('m9', 1, 4),
('m8', 0, 0),
]);
});
}