feat: 优化 Agent 运行时与聊天设置体验

This commit is contained in:
qzl
2026-03-16 18:32:09 +08:00
parent 3f79cf0df7
commit 5a34616287
41 changed files with 2603 additions and 1263 deletions
@@ -87,5 +87,32 @@ void main() {
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');
});
});
}
@@ -0,0 +1,27 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:social_app/features/chat/presentation/bloc/agent_stage.dart';
void main() {
group('agent stage mapping', () {
test('maps protocol step router to intent stage label', () {
final stage = stageFromStepName('router');
expect(stage, AgentStage.intent);
expect(stageLabel(stage), '意图识别中');
});
test('maps protocol step worker to execution stage label', () {
final stage = stageFromStepName('worker');
expect(stage, AgentStage.execution);
expect(stageLabel(stage), '任务执行中');
});
test('uses processing label when step is unknown', () {
final stage = stageFromStepName('unexpected');
expect(stage, isNull);
expect(stageLabel(stage), '任务处理中');
});
});
}
@@ -0,0 +1,84 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';
import 'package:social_app/core/di/injection.dart';
import 'package:social_app/features/auth/data/auth_repository.dart';
import 'package:social_app/features/auth/presentation/bloc/auth_bloc.dart';
import 'package:social_app/features/auth/presentation/bloc/auth_event.dart';
import 'package:social_app/features/auth/presentation/bloc/auth_state.dart';
import 'package:social_app/features/settings/ui/screens/change_password_screen.dart';
class MockAuthRepository extends Mock implements AuthRepository {}
void main() {
late MockAuthRepository mockAuthRepository;
late AuthBloc authBloc;
setUp(() async {
mockAuthRepository = MockAuthRepository();
await sl.reset();
sl.registerSingleton<AuthRepository>(mockAuthRepository);
authBloc = AuthBloc(mockAuthRepository);
authBloc.add(
const AuthLoggedIn(
user: AuthUser(id: 'user-1', email: 'tester@example.com'),
),
);
});
tearDown(() async {
await authBloc.close();
await sl.reset();
});
Future<void> pumpScreen(WidgetTester tester) async {
await tester.pumpWidget(
BlocProvider<AuthBloc>.value(
value: authBloc,
child: const MaterialApp(home: ChangePasswordScreen()),
),
);
await tester.pump();
}
testWidgets('确认修改按钮在验证码发送前不可点击', (tester) async {
when(
() => mockAuthRepository.requestPasswordReset(any()),
).thenAnswer((_) async {});
await pumpScreen(tester);
final confirmButton = tester.widget<ElevatedButton>(
find.widgetWithText(ElevatedButton, '确认修改'),
);
expect(confirmButton.onPressed, isNull);
expect(find.text('完成验证码验证后可提交密码修改'), findsOneWidget);
});
testWidgets('发送验证码倒计时期间不会重复触发请求', (tester) async {
final completer = Completer<void>();
when(
() => mockAuthRepository.requestPasswordReset(any()),
).thenAnswer((_) => completer.future);
await pumpScreen(tester);
await tester.tap(find.text('发送验证码'));
await tester.pump();
expect(find.text('60 秒后可重发'), findsOneWidget);
await tester.tap(find.text('60 秒后可重发'));
await tester.pump();
verify(
() => mockAuthRepository.requestPasswordReset('tester@example.com'),
).called(1);
completer.complete();
});
}
@@ -0,0 +1,47 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:social_app/features/settings/ui/widgets/account_section_card.dart';
import 'package:social_app/features/settings/ui/widgets/account_surface_scaffold.dart';
void main() {
testWidgets('AccountSectionCard renders title and description', (
tester,
) async {
await tester.pumpWidget(
const MaterialApp(
home: Scaffold(
body: AccountSectionCard(
title: '基础信息',
description: '请填写公开展示资料',
child: Text('内容区'),
),
),
),
);
expect(find.text('基础信息'), findsOneWidget);
expect(find.text('请填写公开展示资料'), findsOneWidget);
expect(find.text('内容区'), findsOneWidget);
});
testWidgets('AccountSurfaceScaffold renders header and footer', (
tester,
) async {
await tester.pumpWidget(
MaterialApp(
home: AccountSurfaceScaffold(
title: '编辑资料',
subtitle: '管理账户公开信息',
body: const Text('主体内容'),
footer: const Text('底部操作区'),
onBack: () {},
),
),
);
expect(find.text('编辑资料'), findsOneWidget);
expect(find.text('管理账户公开信息'), findsOneWidget);
expect(find.text('主体内容'), findsOneWidget);
expect(find.text('底部操作区'), findsOneWidget);
});
}