Show an animated assistant bubble before response tokens
This commit is contained in:
@@ -253,7 +253,12 @@ void main() {
|
||||
await typeAndSend(tester, 'plain text');
|
||||
|
||||
expect(find.text('plain text'), findsOneWidget);
|
||||
expect(find.byType(ChatMessageView), findsOneWidget);
|
||||
expect(
|
||||
find.byWidgetPredicate(
|
||||
(widget) => widget is ChatMessageView && widget.row['kind'] == 'user',
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text('screen.png'), findsNothing);
|
||||
expect(find.text('notes.txt'), findsNothing);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_composer_controller.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_draft_store.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_thread_controller.dart';
|
||||
import 'package:pipelines_app/features/chat/domain/chat_transcript.dart';
|
||||
|
||||
import 'chat_composer_fixtures.dart';
|
||||
import 'chat_thread_fixtures.dart' as thread;
|
||||
|
||||
class _SlowDraftStore extends MemoryChatDraftStore {
|
||||
final clear = Completer<bool>();
|
||||
|
||||
@override
|
||||
Future<bool> write(String sessionId, String text) =>
|
||||
text.isEmpty ? clear.future : super.write(sessionId, text);
|
||||
}
|
||||
|
||||
void main() {
|
||||
test(
|
||||
'optimistic response starts before disk persistence or server reply',
|
||||
() async {
|
||||
final drafts = _SlowDraftStore();
|
||||
final gateway = FakeComposerGateway();
|
||||
var optimistic = false;
|
||||
final composer = ChatComposerController(
|
||||
gateway,
|
||||
's',
|
||||
drafts: drafts,
|
||||
onOptimistic: (_) => optimistic = true,
|
||||
);
|
||||
addTearDown(composer.dispose);
|
||||
addTearDown(gateway.close);
|
||||
await composer.setDraft('hello');
|
||||
final sending = composer.send();
|
||||
expect(optimistic, isTrue);
|
||||
expect(gateway.calls, isEmpty);
|
||||
drafts.clear.complete(true);
|
||||
expect(await sending, isTrue);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'local waiting survives a user echo and acceptance, then ends',
|
||||
() async {
|
||||
final gateway = thread.FakeChatGateway();
|
||||
final controller = ChatThreadController(gateway, 's');
|
||||
addTearDown(controller.dispose);
|
||||
addTearDown(gateway.close);
|
||||
controller.insertLocal({
|
||||
'id': 'local',
|
||||
'role': 'user',
|
||||
'operation_id': 'op',
|
||||
'parts': [],
|
||||
});
|
||||
expect(controller.awaitingResponse, isTrue);
|
||||
controller.promptAccepted('op', queued: false);
|
||||
gateway.emitEvent({
|
||||
'session_id': 's',
|
||||
'kind': 'user',
|
||||
'message_id': 'echo',
|
||||
'part': {'text': 'hello'},
|
||||
});
|
||||
await pumpEventQueue();
|
||||
expect(controller.awaitingResponse, isTrue);
|
||||
gateway.emitEvent(thread.chatStepFrame('ended'));
|
||||
await pumpEventQueue();
|
||||
expect(controller.awaitingResponse, isFalse);
|
||||
controller.promptAccepted('op', queued: false);
|
||||
expect(
|
||||
controller.awaitingResponse,
|
||||
isFalse,
|
||||
reason: 'a late ack cannot restart it',
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
test('a queued follow-up does not create a second assistant shell', () {
|
||||
final rows = transcriptRows(
|
||||
[
|
||||
thread.chatMessage('u', 'user'),
|
||||
thread.chatMessage(
|
||||
'a',
|
||||
'assistant',
|
||||
parts: [
|
||||
{'id': 't', 'type': 'tool', 'name': 'read'},
|
||||
],
|
||||
),
|
||||
thread.chatMessage('queued', 'user'),
|
||||
],
|
||||
running: true,
|
||||
liveMessageId: 'a',
|
||||
awaitingResponse: true,
|
||||
);
|
||||
expect(rows.where((row) => row['kind'] == 'assistant'), hasLength(1));
|
||||
expect(rows[1]['streaming'], isTrue);
|
||||
expect(rows.last['kind'], 'user');
|
||||
});
|
||||
|
||||
test('a response shell is display-only and absent from settled history', () {
|
||||
final messages = [thread.chatMessage('u', 'user')];
|
||||
final pending = transcriptRows(messages, awaitingResponse: true);
|
||||
expect(pending.last['kind'], 'assistant');
|
||||
expect(pending.last['streaming'], isTrue);
|
||||
expect(messages, hasLength(1));
|
||||
expect(transcriptRows(messages), hasLength(1));
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_draft_store.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/chat_message_view.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/chat_response_pending.dart';
|
||||
|
||||
import 'chat_thread_fixtures.dart';
|
||||
|
||||
class _Gateway extends FakeChatGateway {
|
||||
Completer<JsonMap> prompt = Completer();
|
||||
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
|
||||
if (type == 'chat_prompt') return prompt.future;
|
||||
return super.call(type, fields);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _pump(WidgetTester tester) async {
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
Future<void> _host(
|
||||
WidgetTester tester,
|
||||
_Gateway gateway, {
|
||||
bool cupertino = false,
|
||||
}) async {
|
||||
gateway.history = (_) async => chatPage([]);
|
||||
final thread = ChatThreadView(
|
||||
gateway: gateway,
|
||||
sessionId: 's',
|
||||
onBack: () {},
|
||||
drafts: MemoryChatDraftStore(),
|
||||
newOperationId: () => 'test-pending',
|
||||
);
|
||||
Widget animations(BuildContext context, Widget? child) => MediaQuery(
|
||||
data: MediaQuery.of(context).copyWith(disableAnimations: false),
|
||||
child: child!,
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? CupertinoApp(
|
||||
builder: animations,
|
||||
home: CupertinoPageScaffold(child: thread),
|
||||
)
|
||||
: MaterialApp(
|
||||
builder: animations,
|
||||
home: Scaffold(body: thread),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
Future<void> _send(WidgetTester tester) async {
|
||||
await tester.enterText(find.byKey(const Key('chat-composer-field')), 'Hello');
|
||||
await tester.pump();
|
||||
await tester.tap(find.byKey(const Key('chat-composer-primary')));
|
||||
await _pump(tester);
|
||||
}
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
testWidgets(
|
||||
'response bubble exists before frames, through tools, then text '
|
||||
'($cupertino)',
|
||||
(tester) async {
|
||||
final gateway = _Gateway();
|
||||
addTearDown(gateway.close);
|
||||
await _host(tester, gateway, cupertino: cupertino);
|
||||
expect(find.byType(ChatResponsePending), findsNothing);
|
||||
await _send(tester);
|
||||
expect(find.byType(ChatResponsePending), findsOneWidget);
|
||||
expect(
|
||||
find.bySemanticsLabel('Assistant is responding'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.byType(ChatMessageView), findsNWidgets(2));
|
||||
final opacities = tester
|
||||
.widgetList<Opacity>(
|
||||
find.descendant(
|
||||
of: find.byType(ChatResponsePending),
|
||||
matching: find.byType(Opacity),
|
||||
),
|
||||
)
|
||||
.map((widget) => widget.opacity)
|
||||
.toList();
|
||||
await tester.pump(const Duration(milliseconds: 200));
|
||||
expect(
|
||||
tester
|
||||
.widgetList<Opacity>(
|
||||
find.descendant(
|
||||
of: find.byType(ChatResponsePending),
|
||||
matching: find.byType(Opacity),
|
||||
),
|
||||
)
|
||||
.map((widget) => widget.opacity)
|
||||
.toList(),
|
||||
isNot(opacities),
|
||||
);
|
||||
gateway.prompt.complete({});
|
||||
await _pump(tester);
|
||||
expect(find.byType(ChatResponsePending), findsOneWidget);
|
||||
|
||||
gateway.emitEvent(chatStepFrame('running'));
|
||||
gateway.emitEvent({
|
||||
'session_id': 's',
|
||||
'kind': 'reasoning',
|
||||
'message_id': 'a',
|
||||
'part': {'id': 'reasoning', 'type': 'reasoning'},
|
||||
'delta': 'Thinking through this.',
|
||||
});
|
||||
await _pump(tester);
|
||||
expect(find.byType(ChatResponsePending), findsOneWidget);
|
||||
gateway.emitEvent({
|
||||
'session_id': 's',
|
||||
'kind': 'tool',
|
||||
'message_id': 'a',
|
||||
'part': {
|
||||
'id': 'tool-1',
|
||||
'type': 'tool',
|
||||
'name': 'read',
|
||||
'state': {'status': 'completed'},
|
||||
},
|
||||
});
|
||||
await _pump(tester);
|
||||
expect(find.byType(ChatResponsePending), findsOneWidget);
|
||||
expect(find.text('1 tool'), findsOneWidget);
|
||||
expect(find.byType(ChatMessageView), findsNWidgets(2));
|
||||
expect(
|
||||
tester.getTopLeft(find.byType(ChatResponsePending)).dy,
|
||||
lessThan(tester.getTopLeft(find.text('1 tool')).dy),
|
||||
);
|
||||
|
||||
gateway.emitEvent(chatTextFrame('Here is the answer.'));
|
||||
await _pump(tester);
|
||||
expect(find.byType(ChatResponsePending), findsNothing);
|
||||
expect(find.text('Here is the answer.'), findsOneWidget);
|
||||
expect(find.text('1 tool'), findsOneWidget);
|
||||
gateway.emitEvent(chatStepFrame('ended'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
for (final result in ['refused', 'queued', 'ended']) {
|
||||
testWidgets(
|
||||
'$result clears a response shell without leaving fake history',
|
||||
(tester) async {
|
||||
final gateway = _Gateway();
|
||||
addTearDown(gateway.close);
|
||||
await _host(tester, gateway);
|
||||
await _send(tester);
|
||||
expect(find.byType(ChatResponsePending), findsOneWidget);
|
||||
if (result == 'refused') {
|
||||
gateway.prompt.completeError(StateError('Send refused'));
|
||||
} else {
|
||||
gateway.prompt.complete({'chat_queued': result == 'queued'});
|
||||
if (result == 'ended') gateway.emitEvent(chatStepFrame('ended'));
|
||||
}
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(ChatResponsePending), findsNothing);
|
||||
expect(
|
||||
tester
|
||||
.widgetList<ChatMessageView>(find.byType(ChatMessageView))
|
||||
.where((view) => view.row['kind'] == 'assistant'),
|
||||
isEmpty,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('reduced motion keeps a static accessible ellipsis', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: MediaQuery(
|
||||
data: MediaQueryData(disableAnimations: true),
|
||||
child: ChatResponsePending(),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('.'), findsNWidgets(3));
|
||||
expect(find.bySemanticsLabel('Assistant is responding'), findsOneWidget);
|
||||
expect(tester.binding.hasScheduledFrame, isFalse);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user