Files
pipelines/app/test/features/chat/conversation/chat_row_keys_test.dart
T

102 lines
2.6 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/chat/conversation/chat_row_keys.dart';
import 'package:pipelines_app/features/chat/domain/chat_transcript.dart';
import 'chat_thread_fixtures.dart';
JsonMap _assistant(String id) => chatMessage(
id,
'assistant',
parts: [
{'type': 'reasoning', 'id': 'r-$id', 'text': 'reasoning $id'},
{'type': 'text', 'id': 't-$id', 'text': 'answer $id'},
],
);
JsonMap _user(String id) => chatMessage(
id,
'user',
parts: [
{'type': 'text', 'text': 'question $id'},
],
);
void main() {
test('an older page prepended into a folded turn keeps its key', () {
final keys = ChatRowKeys();
final newest = keys.forRows(
transcriptRows([_assistant('msg_6'), _assistant('msg_4')]),
);
final paged = keys.forRows(
transcriptRows([
_assistant('msg_2'),
_assistant('msg_0'),
_assistant('msg_6'),
_assistant('msg_4'),
]),
);
expect(newest, hasLength(1));
expect(paged, hasLength(1));
expect(paged.single, newest.single);
});
test('a live assistant message appended to a folded turn keeps its key', () {
final keys = ChatRowKeys();
final newest = keys.forRows(transcriptRows([_assistant('msg_6')]));
final streamed = keys.forRows(
transcriptRows([_assistant('msg_6'), _assistant('msg_live')]),
);
expect(streamed.single, newest.single);
});
test('user rows keep their key and folded turns stay distinct', () {
final keys = ChatRowKeys();
final first = keys.forRows(
transcriptRows([
_user('u1'),
_assistant('a1'),
_user('u2'),
_assistant('a2'),
]),
);
final paged = keys.forRows(
transcriptRows([
_user('u0'),
_assistant('a0'),
_user('u1'),
_assistant('a1'),
_user('u2'),
_assistant('a2'),
]),
);
expect(first.toSet(), hasLength(4));
expect(paged.toSet(), hasLength(6));
expect(paged.sublist(2), first);
});
test('an id-less prepended turn never collides with a held key', () {
final keys = ChatRowKeys();
keys.forRows(transcriptRows([_assistant('a1')]));
final paged = keys.forRows(
transcriptRows([
// No id: only a positional fallback is possible.
chatMessage(
'',
'assistant',
parts: [
{'type': 'text', 'text': 'anonymous older answer'},
],
),
_user('u1'),
_assistant('a1'),
]),
);
expect(paged.toSet(), hasLength(paged.length));
});
}