71 lines
2.0 KiB
Dart
71 lines
2.0 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/core/api_gateway.dart';
|
|
import 'package:pipelines_app/features/chat/domain/chat_transcript.dart';
|
|
|
|
void main() {
|
|
test('only the newest assistant turn is marked streaming', () {
|
|
final messages = <JsonMap>[
|
|
{
|
|
'id': 'old',
|
|
'role': 'assistant',
|
|
'parts': [
|
|
{'type': 'reasoning', 'text': 'Stored thought'},
|
|
],
|
|
},
|
|
{'id': 'user', 'role': 'user', 'parts': []},
|
|
];
|
|
expect(transcriptRows(messages, running: true).first['streaming'], isNull);
|
|
final activityOnly = <JsonMap>[
|
|
...messages,
|
|
{
|
|
'id': 'activity-only',
|
|
'role': 'assistant',
|
|
'parts': [
|
|
{'type': 'activity', 'kind': 'thinking', 'state': 'running'},
|
|
],
|
|
},
|
|
];
|
|
expect(
|
|
transcriptRows(activityOnly, running: true).first['streaming'],
|
|
isNull,
|
|
);
|
|
messages.add({
|
|
'id': 'new',
|
|
'role': 'assistant',
|
|
'parts': [
|
|
{'type': 'text', 'text': 'Answer'},
|
|
],
|
|
});
|
|
final rows = transcriptRows(messages, running: true);
|
|
expect(rows.first['streaming'], isNull);
|
|
expect(rows.last['streaming'], isTrue);
|
|
expect(transcriptRows(messages).last['streaming'], isNull);
|
|
});
|
|
|
|
test('same ordinal text and reasoning stay independent across deltas', () {
|
|
var thread = <String, dynamic>{'sessionId': 's', 'messages': <JsonMap>[]};
|
|
for (final (kind, delta) in [
|
|
('text', 'Answer'),
|
|
('reasoning', 'Provided thought'),
|
|
('text', ' continued'),
|
|
('reasoning', ' continued'),
|
|
]) {
|
|
thread = applyChatEvent(thread, {
|
|
'session_id': 's',
|
|
'message_id': 'a',
|
|
'kind': kind,
|
|
'part': {'type': kind, 'id': 'a#$kind#0'},
|
|
'delta': delta,
|
|
});
|
|
}
|
|
expect((thread['messages'] as List).single['parts'], [
|
|
{'type': 'text', 'id': 'a#text#0', 'text': 'Answer continued'},
|
|
{
|
|
'type': 'reasoning',
|
|
'id': 'a#reasoning#0',
|
|
'text': 'Provided thought continued',
|
|
},
|
|
]);
|
|
});
|
|
}
|