Keep chat activity stable in one live disclosure and distinguish unread attention
This commit is contained in:
@@ -203,8 +203,8 @@ void main() {
|
||||
'cursor': '',
|
||||
});
|
||||
expect(find.text('The stored reply stays readable.'), findsOneWidget);
|
||||
expect(find.text('Reasoning'), findsOneWidget);
|
||||
expect(find.text('1 tool'), findsOneWidget);
|
||||
expect(find.text('Ran 1 command'), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-turn-activity')), findsOneWidget);
|
||||
expect(find.text('Kept behind a native disclosure.'), findsNothing);
|
||||
|
||||
// The shell bar stays over the list and rail; the open chat has its
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/session_attention.dart';
|
||||
|
||||
void main() {
|
||||
test('only final turn end clears working; a background shell cannot', () {
|
||||
for (final status in ['started', 'streamed', 'running', 'streaming']) {
|
||||
final effect = chatSessionFrameEffect({
|
||||
'type': 'chat_event',
|
||||
'chat_event': {
|
||||
'session_id': 's',
|
||||
'kind': 'step',
|
||||
'step': {'status': status},
|
||||
},
|
||||
});
|
||||
expect(effect!.running, isTrue);
|
||||
expect(effect.attention, isFalse);
|
||||
}
|
||||
for (final kind in ['shell', 'compaction']) {
|
||||
final effect = chatSessionFrameEffect({
|
||||
'type': 'chat_event',
|
||||
'chat_event': {
|
||||
'session_id': 's',
|
||||
'kind': kind,
|
||||
kind: {'status': kind == 'shell' ? 'exited' : 'completed'},
|
||||
},
|
||||
});
|
||||
expect(effect!.running, isNull);
|
||||
expect(effect.attention, isFalse);
|
||||
}
|
||||
final intermediate = chatSessionFrameEffect({
|
||||
'type': 'chat_event',
|
||||
'chat_event': {
|
||||
'session_id': 's',
|
||||
'kind': 'step',
|
||||
'step': {'status': 'ended', 'intermediate': true},
|
||||
},
|
||||
});
|
||||
expect(intermediate!.running, isNull);
|
||||
});
|
||||
}
|
||||
@@ -124,39 +124,31 @@ void main() {
|
||||
expect(find.textContaining('"payload": 7'), findsNothing);
|
||||
expect(find.text('plain future text'), findsOneWidget);
|
||||
|
||||
// The answer keeps its own order; the footer chips sit below it.
|
||||
// Answer content stays ordered, while reasoning and tools share one
|
||||
// stable activity control before the transcript body.
|
||||
double top(String text) => tester.getTopLeft(find.text(text)).dy;
|
||||
expect(top('First answer'), lessThan(top('Second answer')));
|
||||
expect(
|
||||
top('Second answer'),
|
||||
lessThan(top('Unrecognised part: future_part')),
|
||||
);
|
||||
expect(top('Unrecognised part: future_part'), lessThan(top('1 tool')));
|
||||
expect(top('Unrecognised part: future_part'), lessThan(top('Reasoning')));
|
||||
final activity = find.byKey(const Key('chat-turn-activity'));
|
||||
expect(activity, findsOneWidget);
|
||||
expect(find.text('Ran 1 command'), findsOneWidget);
|
||||
expect(top('Ran 1 command'), lessThan(top('First answer')));
|
||||
|
||||
// Reasoning is a chip like the tools chip: it opens a native sheet.
|
||||
await tester.ensureVisible(find.text('Reasoning'));
|
||||
// The combined activity control opens the recorded reasoning and tool.
|
||||
await tester.ensureVisible(activity);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Reasoning'));
|
||||
await tester.tap(activity);
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('chat-reasoning-sheet')),
|
||||
matching: find.text('private reasoning'),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
await tester.tapAt(const Offset(10, 10));
|
||||
await tester.tap(find.text('Reasoning 1'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('private reasoning'), findsNothing);
|
||||
|
||||
// The chip opens the calls; a call opens to its formatted input.
|
||||
await tester.ensureVisible(find.text('1 tool'));
|
||||
await tester.tap(find.text('1 tool'));
|
||||
expect(find.text('private reasoning'), findsOneWidget);
|
||||
final tool = find.textContaining('shell · ls');
|
||||
await tester.ensureVisible(tool);
|
||||
await tester.tap(tool);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('shell · ls'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('INPUT'), findsOneWidget);
|
||||
expect(find.textContaining('"command": "ls"'), findsOneWidget);
|
||||
await tester.tapAt(const Offset(10, 10));
|
||||
await tester.pumpAndSettle();
|
||||
@@ -170,7 +162,7 @@ void main() {
|
||||
|
||||
for (final cupertino in [false, true]) {
|
||||
testWidgets(
|
||||
'each message keeps its reasoning beside its own tools ($cupertino)',
|
||||
'each message keeps its combined activity with its own turn ($cupertino)',
|
||||
(tester) async {
|
||||
_phone(tester);
|
||||
final first = _assistant([
|
||||
@@ -209,40 +201,35 @@ void main() {
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
for (final (key, count) in [
|
||||
('message-first', '1 tool'),
|
||||
('message-second', '2 tools'),
|
||||
('message-first', 'Used 1 tool'),
|
||||
('message-second', 'Used 2 tools'),
|
||||
]) {
|
||||
final message = find.byKey(Key(key));
|
||||
final reasoning = find.descendant(
|
||||
final activity = find.descendant(
|
||||
of: message,
|
||||
matching: find.text('Reasoning'),
|
||||
);
|
||||
final tools = find.descendant(
|
||||
of: message,
|
||||
matching: find.text(count),
|
||||
matching: find.byKey(const Key('chat-turn-activity')),
|
||||
);
|
||||
expect(activity, findsOneWidget);
|
||||
expect(
|
||||
tester.getRect(reasoning).right,
|
||||
lessThan(tester.getRect(tools).left),
|
||||
);
|
||||
expect(
|
||||
tester.getRect(reasoning).center.dy,
|
||||
closeTo(tester.getRect(tools).center.dy, 2),
|
||||
find.descendant(of: activity, matching: find.text(count)),
|
||||
findsOneWidget,
|
||||
);
|
||||
}
|
||||
await tester.tap(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('message-first')),
|
||||
matching: find.text('Reasoning'),
|
||||
matching: find.byKey(const Key('chat-turn-activity')),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Reasoning 1'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('First reasoning'), findsOneWidget);
|
||||
expect(find.text('Second reasoning'), findsNothing);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('reasoning sits immediately left of the tools count '
|
||||
testWidgets('reasoning and tools are in one activity control '
|
||||
'(${cupertino ? 'cupertino' : 'material'})', (tester) async {
|
||||
// The test font draws every glyph as a full square, so the chips need
|
||||
// more room than real text does on a phone.
|
||||
@@ -266,29 +253,27 @@ void main() {
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final reasoning = tester.getRect(find.text('Reasoning · 2 steps'));
|
||||
final tools = tester.getRect(find.text('1 tool'));
|
||||
final activity = find.byKey(const Key('chat-turn-activity'));
|
||||
expect(activity, findsOneWidget);
|
||||
expect(
|
||||
reasoning.top,
|
||||
greaterThan(tester.getRect(find.text('The answer')).bottom),
|
||||
tester.getTopLeft(activity).dy,
|
||||
lessThan(tester.getRect(find.text('The answer')).top),
|
||||
);
|
||||
expect(reasoning.center.dy, closeTo(tools.center.dy, 2));
|
||||
expect(reasoning.right, lessThan(tools.left));
|
||||
expect(find.text('Ran 1 command'), findsOneWidget);
|
||||
|
||||
// The sheet lists every recorded step, in order.
|
||||
await tester.tap(find.text('Reasoning · 2 steps'));
|
||||
await tester.tap(activity);
|
||||
await tester.pumpAndSettle();
|
||||
final sheet = find.byKey(const Key('chat-reasoning-sheet'));
|
||||
Finder inSheet(String text) =>
|
||||
find.descendant(of: sheet, matching: find.text(text));
|
||||
expect(inSheet('first thought'), findsOneWidget);
|
||||
expect(inSheet('second thought'), findsOneWidget);
|
||||
expect(
|
||||
tester.getTopLeft(inSheet('first thought')).dy,
|
||||
lessThan(tester.getTopLeft(inSheet('second thought')).dy),
|
||||
);
|
||||
expect(inSheet('STEP 1'), findsOneWidget);
|
||||
expect(inSheet('STEP 2'), findsOneWidget);
|
||||
expect(find.text('Reasoning 1'), findsOneWidget);
|
||||
expect(find.text('Reasoning 2'), findsOneWidget);
|
||||
await tester.tap(find.text('Reasoning 1'));
|
||||
await tester.pumpAndSettle();
|
||||
final secondStep = find.text('Reasoning 2');
|
||||
await tester.ensureVisible(secondStep);
|
||||
await tester.tap(secondStep);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('first thought'), findsOneWidget);
|
||||
expect(find.text('second thought'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -369,7 +354,7 @@ void main() {
|
||||
expect(find.byType(SelectableText), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('Cupertino reasoning and tool chips open native popups', (
|
||||
testWidgets('Cupertino combined activity opens a native dialog', (
|
||||
tester,
|
||||
) async {
|
||||
final row = _assistant([
|
||||
@@ -384,16 +369,13 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('thought'), findsNothing);
|
||||
await tester.tap(find.text('Reasoning'));
|
||||
await tester.tap(find.byKey(const Key('chat-turn-activity')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(CupertinoAlertDialog), findsOneWidget);
|
||||
expect(find.text('Activity details'), findsOneWidget);
|
||||
await tester.tap(find.text('Reasoning 1'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(CupertinoPopupSurface), findsOneWidget);
|
||||
expect(find.text('thought'), findsOneWidget);
|
||||
await tester.tapAt(const Offset(10, 10));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('thought'), findsNothing);
|
||||
|
||||
await tester.tap(find.text('1 tool'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('read · failed'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('ERROR'), findsOneWidget);
|
||||
|
||||
@@ -5,14 +5,14 @@ import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/chat/domain/chat_transcript.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/chat_message_view.dart';
|
||||
|
||||
JsonMap _turn(List<JsonMap> parts, {String model = ''}) => transcriptRows([
|
||||
JsonMap _turn(List<JsonMap> parts, {bool streaming = false}) => transcriptRows([
|
||||
{
|
||||
'id': 'a1',
|
||||
'role': 'assistant',
|
||||
if (model.isNotEmpty) 'model': model,
|
||||
'parts': parts,
|
||||
if (streaming) 'streaming': true,
|
||||
},
|
||||
]).single;
|
||||
], running: streaming).single;
|
||||
|
||||
Widget _app(Widget body, bool cupertino) => cupertino
|
||||
? CupertinoApp(home: CupertinoPageScaffold(child: body))
|
||||
@@ -21,91 +21,60 @@ Widget _app(Widget body, bool cupertino) => cupertino
|
||||
home: Scaffold(body: body),
|
||||
);
|
||||
|
||||
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.descendant(
|
||||
of: find.byType(CupertinoAlertDialog).evaluate().isNotEmpty
|
||||
? find.byType(CupertinoAlertDialog)
|
||||
: find.byType(AlertDialog),
|
||||
matching: find.text(text),
|
||||
);
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
final host = cupertino ? 'Cupertino' : 'Material';
|
||||
|
||||
testWidgets('the footer reads reasoning, tools, permissions, model '
|
||||
testWidgets('one stable activity control combines reasoning and tools '
|
||||
'($host)', (tester) async {
|
||||
tester.view.physicalSize = const Size(900, 600);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final row = _turn([
|
||||
{'type': 'reasoning', 'id': 'r1', 'text': 'thought'},
|
||||
{
|
||||
'type': 'tool',
|
||||
'name': 'read',
|
||||
'state': {
|
||||
'status': 'completed',
|
||||
'input': {'path': '/tmp/a'},
|
||||
},
|
||||
},
|
||||
]);
|
||||
await tester.pumpWidget(
|
||||
_app(
|
||||
ListView(
|
||||
children: [
|
||||
ChatMessageView(
|
||||
row: _turn([
|
||||
{'type': 'text', 'text': 'Answer'},
|
||||
{'type': 'reasoning', 'text': 'thought'},
|
||||
{
|
||||
'type': 'tool',
|
||||
'name': 'read',
|
||||
'state': {'status': 'completed'},
|
||||
},
|
||||
], model: 'model-x'),
|
||||
footer: const [Text('permissions')],
|
||||
),
|
||||
],
|
||||
),
|
||||
cupertino,
|
||||
),
|
||||
_app(ListView(children: [ChatMessageView(row: row)]), cupertino),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
// The test font draws every glyph as a full square, so the row may wrap;
|
||||
// each item then follows the previous one in reading order.
|
||||
final rects = [
|
||||
for (final text in ['Reasoning', '1 tool', 'permissions', 'model-x'])
|
||||
tester.getRect(find.text(text)),
|
||||
];
|
||||
for (var index = 1; index < rects.length; index++) {
|
||||
final before = rects[index - 1];
|
||||
final after = rects[index];
|
||||
final sameLine = (after.center.dy - before.center.dy).abs() < 3;
|
||||
expect(
|
||||
sameLine ? after.left > before.right : after.top >= before.bottom,
|
||||
isTrue,
|
||||
reason: 'footer item $index follows item ${index - 1}',
|
||||
);
|
||||
}
|
||||
|
||||
expect(_activity, findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-reasoning-chip')), findsNothing);
|
||||
expect(find.byKey(const Key('chat-tool-chip')), findsNothing);
|
||||
expect(find.text('Used 1 tool'), findsOneWidget);
|
||||
expect(
|
||||
(rects[1].center.dy - rects[0].center.dy).abs(),
|
||||
lessThan(3),
|
||||
reason: 'reasoning and tools share a line',
|
||||
);
|
||||
// Same native chip as the tools: an icon and a chevron, one button node.
|
||||
final chip = find.byKey(const Key('chat-reasoning-chip'));
|
||||
expect(
|
||||
find.descendant(
|
||||
of: chip,
|
||||
matching: find.byIcon(
|
||||
cupertino ? CupertinoIcons.lightbulb : Icons.lightbulb_outline,
|
||||
),
|
||||
),
|
||||
find.bySemanticsLabel('Used 1 tool, expand for details'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: chip,
|
||||
matching: find.byIcon(
|
||||
cupertino ? CupertinoIcons.chevron_up : Icons.expand_less,
|
||||
),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
final semantics = tester.getSemantics(
|
||||
find.bySemanticsLabel('Reasoning, expand for details'),
|
||||
);
|
||||
expect(semantics.flagsCollection.isButton, isTrue);
|
||||
if (cupertino) expect(find.byType(Material), findsNothing);
|
||||
|
||||
await tester.tap(_activity);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_dialog, findsOneWidget);
|
||||
expect(_inDialog('Reasoning 1'), findsOneWidget);
|
||||
expect(_inDialog('thought'), findsNothing);
|
||||
await tester.tap(_inDialog('Reasoning 1'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_inDialog('thought'), findsOneWidget);
|
||||
expect(find.textContaining('read'), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('an open sheet follows a rebuilt turn and outlives its row '
|
||||
testWidgets('the activity dialog tracks rebuilt parts and closes with Done '
|
||||
'($host)', (tester) async {
|
||||
final row = ValueNotifier<JsonMap?>(
|
||||
_turn([
|
||||
@@ -117,7 +86,7 @@ void main() {
|
||||
_app(
|
||||
ValueListenableBuilder<JsonMap?>(
|
||||
valueListenable: row,
|
||||
builder: (context, value, _) => ListView(
|
||||
builder: (_, value, _) => ListView(
|
||||
children: [
|
||||
if (value != null)
|
||||
ChatMessageView(key: const Key('turn'), row: value),
|
||||
@@ -128,30 +97,91 @@ void main() {
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Reasoning'));
|
||||
await tester.tap(_activity);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_inSheet('Reasoning'), findsOneWidget);
|
||||
expect(_inSheet('first'), findsOneWidget);
|
||||
expect(_inDialog('first'), findsNothing);
|
||||
await tester.tap(_inDialog('Reasoning 1'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_inDialog('first'), findsOneWidget);
|
||||
|
||||
row.value = _turn([
|
||||
{'type': 'reasoning', 'id': 'r1', 'text': 'first, longer'},
|
||||
{'type': 'text', 'text': 'Answer'},
|
||||
{'type': 'reasoning', 'id': 'r1', 'text': 'first updated'},
|
||||
{'type': 'reasoning', 'id': 'r2', 'text': 'second'},
|
||||
{
|
||||
'type': 'tool',
|
||||
'name': 'read',
|
||||
'state': {'status': 'completed'},
|
||||
},
|
||||
]);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_inSheet('Reasoning · 2 steps'), findsOneWidget);
|
||||
expect(_inSheet('first, longer'), findsOneWidget);
|
||||
expect(_inSheet('second'), findsOneWidget);
|
||||
expect(_inDialog('first updated'), findsOneWidget);
|
||||
expect(_inDialog('Reasoning 2'), findsOneWidget);
|
||||
expect(_inDialog('read'), findsOneWidget);
|
||||
|
||||
// The row leaves the transcript while the sheet is open: the sheet keeps
|
||||
// its last steps and closes cleanly.
|
||||
final done = find.text('Done');
|
||||
await tester.tap(done);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_dialog, findsNothing);
|
||||
|
||||
await tester.tap(_activity);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.binding.handlePopRoute();
|
||||
await tester.pumpAndSettle();
|
||||
expect(_dialog, findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('a streaming turn keeps a generic activity control until tool '
|
||||
'activity is recorded ($host)', (tester) async {
|
||||
final row = _turn([
|
||||
{'type': 'reasoning', 'id': 'r1', 'text': 'secret reasoning'},
|
||||
], streaming: true);
|
||||
await tester.pumpWidget(
|
||||
_app(ListView(children: [ChatMessageView(row: row)]), cupertino),
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 50));
|
||||
expect(_activity, findsOneWidget);
|
||||
expect(find.textContaining('Thinking'), findsOneWidget);
|
||||
expect(find.text('secret reasoning'), findsNothing);
|
||||
final activityElement = tester.element(_activity);
|
||||
final height = tester.getSize(_activity).height;
|
||||
await tester.pump(const Duration(seconds: 2));
|
||||
expect(tester.element(_activity), same(activityElement));
|
||||
expect(tester.getSize(_activity).height, height);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('removing the owning turn closes its activity dialog ($host)', (
|
||||
tester,
|
||||
) async {
|
||||
final row = ValueNotifier<JsonMap?>(
|
||||
_turn([
|
||||
{'type': 'reasoning', 'id': 'r1', 'text': 'owned detail'},
|
||||
]),
|
||||
);
|
||||
addTearDown(row.dispose);
|
||||
await tester.pumpWidget(
|
||||
_app(
|
||||
ValueListenableBuilder<JsonMap?>(
|
||||
valueListenable: row,
|
||||
builder: (_, value, _) => ListView(
|
||||
children: [
|
||||
if (value != null)
|
||||
ChatMessageView(key: const Key('turn'), row: value),
|
||||
],
|
||||
),
|
||||
),
|
||||
cupertino,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(_activity);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_dialog, findsOneWidget);
|
||||
row.value = null;
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('turn')), findsNothing);
|
||||
expect(_inSheet('second'), findsOneWidget);
|
||||
await tester.tapAt(const Offset(10, 10));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_sheet, findsNothing);
|
||||
expect(_dialog, findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user