Keep chat activity stable in one live disclosure and distinguish unread attention
This commit is contained in:
@@ -123,10 +123,11 @@ void main() {
|
||||
|
||||
expect(rows.map((row) => row['kind']), ['activity', 'assistant']);
|
||||
final activity = rows.first;
|
||||
expect(activity['records'], hasLength(3));
|
||||
expect(activity['records'], hasLength(2));
|
||||
expect(activity['label'], 'Context compacted');
|
||||
expect(activity['state'], 'completed');
|
||||
expect((rows.last['parts'] as List).single['text'], 'answer');
|
||||
expect(rows.last['activityRecords'], hasLength(1));
|
||||
});
|
||||
|
||||
test('a sequence can span consecutive assistant messages', () {
|
||||
@@ -143,8 +144,8 @@ void main() {
|
||||
]),
|
||||
]);
|
||||
|
||||
expect(_activityRows(rows), hasLength(1));
|
||||
expect(_activityRows(rows).single['label'], 'Thought');
|
||||
expect(_activityRows(rows), isEmpty);
|
||||
expect(rows.single['activityRecords'], hasLength(2));
|
||||
});
|
||||
|
||||
test('separate turns keep separate lines', () {
|
||||
@@ -243,9 +244,8 @@ void main() {
|
||||
group('expanded detail', () {
|
||||
final recorded = <JsonMap>[
|
||||
{
|
||||
'type': 'activity',
|
||||
'type': 'compaction',
|
||||
'id': 'e1',
|
||||
'kind': 'tool',
|
||||
'state': 'completed',
|
||||
'label': 'Ran a tool',
|
||||
'input': {'command': 'ls'},
|
||||
|
||||
@@ -138,6 +138,8 @@ void main() {
|
||||
await tester.pump();
|
||||
await tester.tap(find.byKey(const Key('chat-composer-primary')));
|
||||
await tester.pumpAndSettle();
|
||||
final activity = find.byKey(const Key('chat-stable-turn-activity'));
|
||||
final activityElement = tester.element(activity);
|
||||
gateway.emitEvent({
|
||||
'session_id': 's',
|
||||
'message_id': 'live',
|
||||
@@ -145,8 +147,8 @@ void main() {
|
||||
'part': {'id': 'live-reasoning-0', 'type': 'reasoning'},
|
||||
'delta': 'Provided reasoning after the follow-up',
|
||||
});
|
||||
// The reasoning chip spins while its step is the newest part, so the
|
||||
// frames are pumped rather than settled.
|
||||
// The combined activity control remains keyed to the live turn while
|
||||
// the queued follow-up is a separate user row.
|
||||
Future<void> frames() async {
|
||||
for (var frame = 0; frame < 8; frame++) {
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
@@ -154,7 +156,11 @@ void main() {
|
||||
}
|
||||
|
||||
await frames();
|
||||
await tester.tap(find.text('Reasoning'));
|
||||
expect(tester.element(activity), same(activityElement));
|
||||
expect(find.byKey(const Key('chat-turn-activity')), findsOneWidget);
|
||||
await tester.tap(find.byKey(const Key('chat-turn-activity')));
|
||||
await frames();
|
||||
await tester.tap(find.text('Reasoning 1'));
|
||||
await frames();
|
||||
expect(
|
||||
find.text('Provided reasoning after the follow-up'),
|
||||
|
||||
@@ -24,8 +24,8 @@ Widget _host(Widget child, bool cupertino) => cupertino
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
|
||||
/// A streaming reasoning chip spins for as long as reasoning is the newest
|
||||
/// part, so pumpAndSettle would never return; this lets a sheet finish its
|
||||
/// The streaming activity control animates, so pumpAndSettle would never
|
||||
/// return; this lets its dialog finish its
|
||||
/// entrance or exit instead.
|
||||
Future<void> _settle(WidgetTester tester) async {
|
||||
for (var frame = 0; frame < 8; frame++) {
|
||||
@@ -33,69 +33,63 @@ Future<void> _settle(WidgetTester tester) async {
|
||||
}
|
||||
}
|
||||
|
||||
final _sheet = find.byKey(const Key('chat-reasoning-sheet'));
|
||||
final _activity = find.byKey(const Key('chat-turn-activity'));
|
||||
final _dialog = find.text('Activity details');
|
||||
|
||||
Finder _inSheet(String text) =>
|
||||
find.descendant(of: _sheet, matching: find.text(text));
|
||||
Finder _inDialog(String text) => find.text(text);
|
||||
|
||||
Future<void> _dismiss(WidgetTester tester) async {
|
||||
await tester.tapAt(const Offset(10, 10));
|
||||
await _settle(tester);
|
||||
expect(_sheet, findsNothing);
|
||||
expect(_dialog, findsNothing);
|
||||
}
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
final host = cupertino ? 'Cupertino' : 'Material';
|
||||
|
||||
testWidgets('reasoning arriving after text is a spinning chip ($host)', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = FakeChatGateway();
|
||||
addTearDown(gateway.close);
|
||||
gateway.history = (_) async => chatPage(const []);
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
ChatThreadView(gateway: gateway, sessionId: 's', onBack: () {}),
|
||||
cupertino,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
gateway.emitEvent(_delta('text', 'Answer first'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Reasoning'), findsNothing);
|
||||
testWidgets(
|
||||
'reasoning arriving after text keeps one streaming activity control ($host)',
|
||||
(tester) async {
|
||||
final gateway = FakeChatGateway();
|
||||
addTearDown(gateway.close);
|
||||
gateway.history = (_) async => chatPage(const []);
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
ChatThreadView(gateway: gateway, sessionId: 's', onBack: () {}),
|
||||
cupertino,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
gateway.emitEvent(_delta('text', 'Answer first'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Reasoning'), findsNothing);
|
||||
|
||||
gateway.emitEvent(_delta('reasoning', 'Only supplied reasoning'));
|
||||
await _settle(tester);
|
||||
// A chip in the footer like the tools chip, not an inline body.
|
||||
expect(find.text('Only supplied reasoning'), findsNothing);
|
||||
expect(find.text('Answer first'), findsOneWidget);
|
||||
final chip = find.byKey(const Key('chat-reasoning-chip'));
|
||||
final spinner = find.descendant(
|
||||
of: chip,
|
||||
matching: find.byType(
|
||||
cupertino ? CupertinoActivityIndicator : CircularProgressIndicator,
|
||||
),
|
||||
);
|
||||
expect(spinner, findsOneWidget);
|
||||
expect(
|
||||
find.bySemanticsLabel('Reasoning, expand for details'),
|
||||
findsOneWidget,
|
||||
);
|
||||
gateway.emitEvent(_delta('reasoning', 'Only supplied reasoning'));
|
||||
await _settle(tester);
|
||||
// Reasoning is private until the operator opens the combined activity.
|
||||
expect(find.text('Only supplied reasoning'), findsNothing);
|
||||
expect(find.text('Answer first'), findsOneWidget);
|
||||
expect(_activity, findsOneWidget);
|
||||
expect(find.textContaining('Thinking'), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-reasoning-chip')), findsNothing);
|
||||
|
||||
await tester.tap(find.text('Reasoning'));
|
||||
await _settle(tester);
|
||||
expect(_inSheet('Only supplied reasoning'), findsOneWidget);
|
||||
await _dismiss(tester);
|
||||
await tester.tap(_activity);
|
||||
await _settle(tester);
|
||||
await tester.tap(find.text('Reasoning 1'));
|
||||
await _settle(tester);
|
||||
expect(_inDialog('Only supplied reasoning'), findsOneWidget);
|
||||
await _dismiss(tester);
|
||||
|
||||
// The step ends: the chip settles to its icon.
|
||||
gateway.emitEvent(chatStepFrame('ended'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(spinner, findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
// The step ends: the chip settles to its icon.
|
||||
gateway.emitEvent(chatStepFrame('ended'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_activity, findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('an open reasoning sheet follows live deltas, paging and '
|
||||
testWidgets('an open activity dialog follows live deltas, paging and '
|
||||
'resync ($host)', (tester) async {
|
||||
final gateway = FakeChatGateway();
|
||||
addTearDown(gateway.close);
|
||||
@@ -112,21 +106,23 @@ void main() {
|
||||
gateway.emitEvent(_delta('reasoning', 'Provided thought'));
|
||||
await _settle(tester);
|
||||
final rowElement = tester.element(find.byType(ChatMessageView));
|
||||
await tester.tap(find.text('Reasoning'));
|
||||
await tester.tap(_activity);
|
||||
await _settle(tester);
|
||||
expect(_inSheet('Provided thought'), findsOneWidget);
|
||||
await tester.tap(find.text('Reasoning 1'));
|
||||
await _settle(tester);
|
||||
expect(_inDialog('Provided thought'), findsOneWidget);
|
||||
|
||||
// The open sheet repaints with each delta while the answer streams too;
|
||||
// the row and its chip are the same elements throughout.
|
||||
gateway.emitEvent(_delta('text', 'Answer'));
|
||||
gateway.emitEvent(_delta('reasoning', ' continues'));
|
||||
await _settle(tester);
|
||||
expect(_inSheet('Provided thought continues'), findsOneWidget);
|
||||
expect(_inDialog('Provided thought continues'), findsOneWidget);
|
||||
expect(find.text('Answer'), findsOneWidget);
|
||||
expect(tester.element(find.byType(ChatMessageView)), same(rowElement));
|
||||
gateway.emitEvent(_delta('reasoning', ' live'));
|
||||
await _settle(tester);
|
||||
expect(_inSheet('Provided thought continues live'), findsOneWidget);
|
||||
expect(_inDialog('Provided thought continues live'), findsOneWidget);
|
||||
await _dismiss(tester);
|
||||
|
||||
// A closed sheet draws nothing; reopening shows the newest text.
|
||||
@@ -135,16 +131,19 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.textContaining('while closed'), findsNothing);
|
||||
expect(find.text('Answer continues'), findsOneWidget);
|
||||
await tester.tap(find.text('Reasoning'));
|
||||
await tester.tap(_activity);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Reasoning 1'), findsOneWidget);
|
||||
await tester.tap(find.text('Reasoning 1'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
_inSheet('Provided thought continues live while closed'),
|
||||
_inDialog('Provided thought continues live while closed'),
|
||||
findsOneWidget,
|
||||
);
|
||||
await _dismiss(tester);
|
||||
|
||||
// Prepending another assistant message folds into the same turn without
|
||||
// replacing the row; the chip counts both steps.
|
||||
// replacing the row; the one activity control keeps both steps.
|
||||
gateway.history = (_) async => chatPage([
|
||||
chatMessage(
|
||||
'older',
|
||||
@@ -160,13 +159,19 @@ void main() {
|
||||
]);
|
||||
await tester.tap(find.text('Load older'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Reasoning · 2 steps'), findsOneWidget);
|
||||
expect(_activity, findsOneWidget);
|
||||
expect(tester.element(find.byType(ChatMessageView)), same(rowElement));
|
||||
await tester.tap(find.text('Reasoning · 2 steps'));
|
||||
await tester.tap(_activity);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_inSheet('Older provided thought'), findsOneWidget);
|
||||
expect(find.text('Reasoning 1'), findsOneWidget);
|
||||
expect(find.text('Reasoning 2'), findsOneWidget);
|
||||
await tester.tap(find.text('Reasoning 1'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Reasoning 2'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_inDialog('Older provided thought'), findsOneWidget);
|
||||
expect(
|
||||
_inSheet('Provided thought continues live while closed'),
|
||||
_inDialog('Provided thought continues live while closed'),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
@@ -188,7 +193,7 @@ void main() {
|
||||
]);
|
||||
gateway.emitEvent({'session_id': 's', 'kind': 'resync'});
|
||||
await tester.pumpAndSettle();
|
||||
expect(_inSheet('Stored provided thought'), findsOneWidget);
|
||||
expect(_inDialog('Stored provided thought'), findsOneWidget);
|
||||
expect(find.textContaining('while closed'), findsNothing);
|
||||
expect(find.text('Stored answer'), findsOneWidget);
|
||||
expect(tester.element(find.byType(ChatMessageView)), same(rowElement));
|
||||
@@ -205,9 +210,11 @@ void main() {
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Stored provided thought'), findsNothing);
|
||||
await tester.tap(find.text('Reasoning'));
|
||||
await tester.tap(_activity);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_inSheet('Stored provided thought'), findsOneWidget);
|
||||
await tester.tap(find.text('Reasoning 1'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_inDialog('Stored provided thought'), findsOneWidget);
|
||||
if (cupertino) expect(find.byType(Material), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
@@ -115,7 +115,7 @@ void main() {
|
||||
});
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('1 tool'), findsOneWidget);
|
||||
expect(find.text('Ran 1 command'), findsOneWidget);
|
||||
expect(find.text('1 permission'), findsOneWidget);
|
||||
expect(find.text('Rejected'), findsNothing);
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ void main() {
|
||||
await _send(tester);
|
||||
expect(find.byType(ChatResponsePending), findsOneWidget);
|
||||
expect(
|
||||
find.bySemanticsLabel('Assistant is responding'),
|
||||
find.bySemanticsLabel(RegExp(r'Thinking.*expand for details')),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.byType(ChatMessageView), findsNWidgets(2));
|
||||
@@ -131,20 +131,25 @@ void main() {
|
||||
});
|
||||
await _pump(tester);
|
||||
expect(find.byType(ChatResponsePending), findsOneWidget);
|
||||
expect(find.text('1 tool'), findsOneWidget);
|
||||
expect(find.textContaining('Thinking'), findsOneWidget);
|
||||
expect(find.byType(ChatMessageView), findsNWidgets(2));
|
||||
expect(
|
||||
tester.getTopLeft(find.byType(ChatResponsePending)).dy,
|
||||
lessThan(tester.getTopLeft(find.text('1 tool')).dy),
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('chat-turn-activity')),
|
||||
matching: find.byType(ChatResponsePending),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
gateway.emitEvent(chatTextFrame('Here is the answer.'));
|
||||
await _pump(tester);
|
||||
expect(find.byType(ChatResponsePending), findsNothing);
|
||||
expect(find.byType(ChatResponsePending), findsOneWidget);
|
||||
expect(find.text('Here is the answer.'), findsOneWidget);
|
||||
expect(find.text('1 tool'), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-turn-activity')), findsOneWidget);
|
||||
gateway.emitEvent(chatStepFrame('ended'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(ChatResponsePending), findsNothing);
|
||||
expect(find.text('Used 1 tool'), findsOneWidget);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
},
|
||||
);
|
||||
|
||||
@@ -168,30 +168,40 @@ void main() {
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// The turn's reasoning is one footer chip below its answer; it counts
|
||||
// the steps of every message folded into the turn.
|
||||
expect(find.text('Reasoning · 2 steps'), findsOneWidget);
|
||||
// The folded turn has one stable activity control, not one chip per
|
||||
// category. Its summary stays generic when only reasoning is known.
|
||||
expect(find.byKey(const Key('chat-turn-activity')), findsOneWidget);
|
||||
expect(find.text('Reasoning'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('Load older'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Reasoning · 4 steps'), findsOneWidget);
|
||||
await tester.tap(find.text('Reasoning · 4 steps'));
|
||||
expect(find.text('Reasoning'), findsOneWidget);
|
||||
await tester.tap(find.byKey(const Key('chat-turn-activity')));
|
||||
await tester.pumpAndSettle();
|
||||
for (var index = 1; index <= 4; index++) {
|
||||
final disclosure = find.text('Reasoning $index');
|
||||
if (tester.any(disclosure)) {
|
||||
await tester.tap(disclosure);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
}
|
||||
for (final body in [
|
||||
'NEWEST folded reasoning body.',
|
||||
'OLDEST folded reasoning body.',
|
||||
]) {
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('chat-reasoning-sheet')),
|
||||
of: cupertino
|
||||
? find.byType(CupertinoAlertDialog)
|
||||
: find.byType(AlertDialog),
|
||||
matching: find.text(body),
|
||||
),
|
||||
findsOneWidget,
|
||||
reason: body,
|
||||
);
|
||||
}
|
||||
await tester.tapAt(const Offset(10, 10));
|
||||
await tester.tap(find.text('Done'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('OLDEST folded reasoning body.'), findsNothing);
|
||||
expect(
|
||||
|
||||
Reference in New Issue
Block a user