Watch
1
0
Fork
You've already forked arc
0
forked from hesabix/arc
arc/hesabixUI/hesabix_ui/test/ai_channel_assist_stream_test.dart
2026-08-21 14:14:21 +00:00

47 lines
1.6 KiB
Dart
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:flutter_test/flutter_test.dart';
import 'package:hesabix_ui/models/ai_stream_event.dart';
import 'package:hesabix_ui/widgets/ai/ai_channel_assist_stream.dart';
void main() {
test('consumeChannelAssistStream accumulates deltas and done fields', () async {
final stream = Stream<AIStreamChunk>.fromIterable([
const AIStreamChunk(
statusEvent: AIStreamStatusEvent(phase: 'thinking'),
),
const AIStreamChunk(contentDelta: 'سلام '),
const AIStreamChunk(
toolEvent: AIStreamToolEvent(type: 'tool_end', tool: 'get_crm_summary'),
),
const AIStreamChunk(
contentDelta: 'دنیا',
),
const AIStreamChunk(
done: true,
finalContent: 'سلام دنیا کامل',
functionResults: {
kAgentCitationsStorageKey: [
{'title': 'فاکتور ۱'},
],
},
),
]);
final outcome = await consumeChannelAssistStream(stream);
expect(outcome.text, 'سلام دنیا کامل');
expect(outcome.toolsUsed, ['get_crm_summary']);
expect(outcome.citations, [
{'title': 'فاکتور ۱'},
]);
expect(outcome.error, isNull);
});
test('consumeChannelAssistStream keeps partial text on error', () async {
final stream = Stream<AIStreamChunk>.fromIterable([
const AIStreamChunk(contentDelta: 'نیمه‌کاره'),
const AIStreamChunk(error: 'قطع ارتباط', done: true),
]);
final outcome = await consumeChannelAssistStream(stream);
expect(outcome.text, 'نیمه‌کاره');
expect(outcome.error, 'قطع ارتباط');
});
}