fix(chat): place per-message reasoning left of the tools count

This commit is contained in:
2026-10-24 11:47:07 +01:00
parent 8547a1527f
commit b355679507
5 changed files with 189 additions and 37 deletions
@@ -161,7 +161,80 @@ void main() {
});
for (final cupertino in [false, true]) {
testWidgets('reasoning disclosure and tool chip follow the answer '
testWidgets(
'each message keeps its reasoning beside its own tools ($cupertino)',
(tester) async {
_phone(tester);
final first = _assistant([
{'type': 'text', 'text': 'First message'},
{'type': 'reasoning', 'text': 'First reasoning'},
{
'type': 'tool',
'name': 'read',
'state': {'status': 'completed'},
},
]);
final second = _assistant([
{'type': 'text', 'text': 'Second message'},
{'type': 'reasoning', 'text': 'Second reasoning'},
{
'type': 'tool',
'name': 'read',
'state': {'status': 'completed'},
},
{
'type': 'tool',
'name': 'write',
'state': {'status': 'completed'},
},
]);
final body = ListView(
children: [
ChatMessageView(key: const Key('message-first'), row: first),
ChatMessageView(key: const Key('message-second'), row: second),
],
);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: body))
: MaterialApp(home: Scaffold(body: body)),
);
await tester.pumpAndSettle();
for (final (key, count) in [
('message-first', '1 tool'),
('message-second', '2 tools'),
]) {
final message = find.byKey(Key(key));
final reasoning = find.descendant(
of: message,
matching: find.text('Reasoning'),
);
final tools = find.descendant(
of: message,
matching: find.text(count),
);
expect(
tester.getRect(reasoning).right,
lessThan(tester.getRect(tools).left),
);
expect(
tester.getRect(reasoning).center.dy,
closeTo(tester.getRect(tools).center.dy, 2),
);
}
await tester.tap(
find.descendant(
of: find.byKey(const Key('message-first')),
matching: find.text('Reasoning'),
),
);
await tester.pumpAndSettle();
expect(find.text('First reasoning'), findsOneWidget);
expect(find.text('Second reasoning'), findsNothing);
},
);
testWidgets('reasoning sits immediately left of the tools count '
'(${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.
@@ -191,7 +264,8 @@ void main() {
reasoning.top,
greaterThan(tester.getRect(find.text('The answer')).bottom),
);
expect(reasoning.bottom, lessThan(tools.top));
expect(reasoning.center.dy, closeTo(tools.center.dy, 2));
expect(reasoning.right, lessThan(tools.left));
// The inline disclosure opens with every recorded step.
await tester.tap(find.text('Reasoning · 2 steps'));