Files
social-app/apps/test/features/chat/ag_ui_event_test.dart
T
qzl aa30fe0ce6 refactor: 重构 Tool Result 契约,移除 ui_hints 统一使用 result 字段
- ToolAgentOutput 移除 result_summary 和 ui_hints,统一使用 result 字段
- 日历/用户查找工具移除 ui_hints 输出,改为机器可读的结构化结果
- Agent History 移除 tool 消息的 ui_hints 处理逻辑
- App 版本检查改为 manifest.json 方式,支持多渠道发布
- 更新 settings 配置和测试用例适配新结构
2026-03-17 12:18:09 +08:00

110 lines
3.3 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:social_app/features/chat/data/models/ag_ui_event.dart';
void main() {
group('AgUiEvent parsing', () {
test('parses TEXT_MESSAGE_END with ui_schema payload', () {
final event = AgUiEvent.fromJson({
'type': 'TEXT_MESSAGE_END',
'messageId': 'msg_1',
'answer': '你好',
'role': 'assistant',
'status': 'success',
'ui_schema': {
'version': '2.0',
'root': {
'type': 'stack',
'direction': 'vertical',
'appearance': 'card',
'children': [
{'type': 'text', 'role': 'title', 'content': '创建成功'},
],
},
},
});
expect(event, isA<TextMessageEndEvent>());
final textEnd = event as TextMessageEndEvent;
expect(textEnd.messageId, 'msg_1');
expect(textEnd.answer, '你好');
expect(textEnd.uiSchema?['version'], '2.0');
});
test('parses TOOL_CALL_RESULT snake_case fields', () {
final event = AgUiEvent.fromJson({
'type': 'TOOL_CALL_RESULT',
'messageId': 'tool_1',
'tool_call_id': 'call_1',
'tool_name': 'calendar_read',
'status': 'success',
'result_summary': '找到 2 条结果',
});
expect(event, isA<ToolCallResultEvent>());
final result = event as ToolCallResultEvent;
expect(result.toolCallId, 'call_1');
expect(result.toolName, 'calendar_read');
expect(result.resultSummary, '找到 2 条结果');
expect(result.uiSchema, isNull);
});
test('parses history snapshot with ui_schema', () {
final snapshot = HistorySnapshot.fromJson({
'scope': 'history_day',
'threadId': 'thread_1',
'day': '2026-03-16',
'hasMore': false,
'messages': [
{
'id': 'm1',
'seq': 1,
'role': 'assistant',
'content': '已处理',
'ui_schema': {
'version': '2.0',
'root': {
'type': 'stack',
'direction': 'vertical',
'appearance': 'card',
'children': [],
},
},
'timestamp': '2026-03-16T10:00:00Z',
},
],
});
expect(snapshot.scope, 'history_day');
expect(snapshot.messages, hasLength(1));
expect(snapshot.messages.first.uiSchema, isNotNull);
});
test('parses history user attachments list', () {
final snapshot = HistorySnapshot.fromJson({
'scope': 'history_day',
'threadId': 'thread_1',
'day': '2026-03-16',
'hasMore': false,
'messages': [
{
'id': 'm1',
'seq': 1,
'role': 'user',
'content': '请看图',
'attachments': [
{'url': 'https://signed.example/a.png', 'mimeType': 'image/png'},
{'url': 'https://signed.example/b.jpg', 'mimeType': 'image/jpeg'},
],
'timestamp': '2026-03-16T10:00:00Z',
},
],
});
final userMessage = snapshot.messages.first;
expect(userMessage.attachments, hasLength(2));
expect(userMessage.attachments.first.url, 'https://signed.example/a.png');
expect(userMessage.attachments.last.mimeType, 'image/jpeg');
});
});
}