feat(app): chat reasoning is a chip beside the tool chip, opening its own sheet

This commit is contained in:
2026-10-23 16:22:31 +01:00
parent 7539a7a552
commit f2aa559d0e
5 changed files with 202 additions and 174 deletions
@@ -132,125 +132,10 @@ void main() {
expect(find.text('Load older'), findsNothing);
});
// Paging prepends messages, so an unkeyed transcript would reuse the element
// at a message's old index: the operator's open reasoning would move to the
// previous answer, or be dropped when `Load older` disappears.
for (final cupertino in [false, true]) {
testWidgets(
'an open reasoning block stays on its answer while has_more remains '
'($cupertino)',
(tester) async {
final gateway = FakeChatGateway();
addTearDown(gateway.close);
var reads = 0;
gateway.history = (_) async => ++reads == 1
? pagedChatPage(
'a2',
'NEWEST reasoning body that belongs to the newest answer.',
cursor: 'opaque/older',
hasMore: true,
)
: pagedChatPage(
'a1',
'OLDER reasoning body that must not steal the newest disclosure.',
cursor: 'opaque/older-2',
hasMore: true,
);
await tester.pumpWidget(
(cupertino ? cupertinoHost : host)(
ChatThreadView(gateway: gateway, sessionId: 's', onBack: () {}),
),
);
await tester.pumpAndSettle();
await tester.tap(find.text('Reasoning'));
await tester.pumpAndSettle();
expect(
find.text('NEWEST reasoning body that belongs to the newest answer.'),
findsOneWidget,
);
await tester.tap(find.text('Load older'));
await tester.pumpAndSettle();
// Both answers are present; only the one the operator opened is open.
expect(find.text('Reasoning'), findsNWidgets(2));
expect(find.text('Load older'), findsOneWidget);
expect(
find.text('NEWEST reasoning body that belongs to the newest answer.'),
findsOneWidget,
);
expect(
find.text(
'OLDER reasoning body that must not steal the newest disclosure.',
),
findsNothing,
);
},
);
testWidgets(
'an open reasoning block survives the removal of Load older ($cupertino)',
(tester) async {
final gateway = FakeChatGateway();
addTearDown(gateway.close);
var reads = 0;
gateway.history = (_) async => ++reads == 1
? pagedChatPage(
'a2',
'NEWEST reasoning body that belongs to the newest answer.',
cursor: 'opaque/older',
hasMore: true,
)
: pagedChatPage(
'a1',
'OLDER reasoning body that must not steal the newest disclosure.',
cursor: '',
hasMore: false,
);
await tester.pumpWidget(
(cupertino ? cupertinoHost : host)(
ChatThreadView(gateway: gateway, sessionId: 's', onBack: () {}),
),
);
await tester.pumpAndSettle();
await tester.tap(find.text('Reasoning'));
await tester.pumpAndSettle();
expect(
find.text('NEWEST reasoning body that belongs to the newest answer.'),
findsOneWidget,
);
await tester.tap(find.text('Load older'));
await tester.pumpAndSettle();
expect(find.text('Reasoning'), findsNWidgets(2));
expect(find.text('Load older'), findsNothing);
expect(
find.text('NEWEST reasoning body that belongs to the newest answer.'),
findsOneWidget,
);
expect(
find.text(
'OLDER reasoning body that must not steal the newest disclosure.',
),
findsNothing,
);
},
);
}
// The repository's own paged-history fixture pages consecutive assistant
// messages, so an older page can prepend into the one folded turn. Its first
// message id changes; the row must still be the same element and keep the
// operator's open disclosure.
for (final cupertino in [false, true]) {
for (final keepsControl in [true, false]) {
testWidgets(
'an open reasoning block in a folded assistant turn survives paging '
'a folded assistant turn counts every reasoning step across paging '
'(keeps Load older: $keepsControl, $cupertino)',
(tester) async {
final gateway = FakeChatGateway();
@@ -283,28 +168,24 @@ void main() {
);
await tester.pumpAndSettle();
// The turn's reasoning is one quiet block above its answer, as on
// the web; it counts the steps it holds.
// The turn's reasoning is one chip below its answer; it counts the
// steps of every message folded into the turn.
expect(find.text('Reasoning · 2 steps'), findsOneWidget);
await tester.tap(find.text('Reasoning · 2 steps'));
await tester.pumpAndSettle();
expect(
find.textContaining('NEWEST folded reasoning body.'),
findsOneWidget,
);
await tester.tap(find.text('Load older'));
await tester.pumpAndSettle();
// All four assistant messages now fold into the same turn, and the
// open block stays open while it grows.
expect(find.text('Reasoning · 4 steps'), findsOneWidget);
await tester.tap(find.text('Reasoning · 4 steps'));
await tester.pumpAndSettle();
for (final body in [
'NEWEST folded reasoning body.',
'OLDEST folded reasoning body.',
]) {
expect(find.textContaining(body), findsOneWidget, reason: body);
expect(find.text(body), findsOneWidget, reason: body);
}
Navigator.of(tester.element(find.text('NEWEST folded reasoning body.'))).pop();
await tester.pumpAndSettle();
expect(
find.text('Load older'),
keepsControl ? findsOneWidget : findsNothing,
@@ -124,22 +124,24 @@ void main() {
expect(find.textContaining('"payload": 7'), findsNothing);
expect(find.text('plain future text'), findsOneWidget);
// As the web: reasoning is a quiet line above the answer, the answer
// keeps its own order in the bubble, and the tool calls are one chip below.
// The answer keeps its own order in the bubble; reasoning and the tool
// calls are two chips in one row below it.
double top(String text) => tester.getTopLeft(find.text(text)).dy;
expect(top('Reasoning'), lessThan(top('First answer')));
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')));
await tester.ensureVisible(find.text('Reasoning'));
await tester.pumpAndSettle();
await tester.tap(find.text('Reasoning'));
await tester.pumpAndSettle();
expect(find.text('private reasoning'), findsOneWidget);
await tester.tapAt(const Offset(10, 10));
await tester.pumpAndSettle();
// The chip opens the calls; a call opens to its formatted input.
await tester.ensureVisible(find.text('1 tool'));
@@ -159,6 +161,48 @@ void main() {
expect(find.textContaining('"payload": 7'), findsOneWidget);
});
for (final cupertino in [false, true]) {
testWidgets('reasoning and tool chips share one row below the answer '
'(${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.
tester.view.physicalSize = const Size(800, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
await tester.pumpWidget(
_host(
_assistant([
{'type': 'reasoning', 'text': 'first thought'},
{'type': 'text', 'text': 'The answer'},
{'type': 'reasoning', 'text': 'second thought'},
{
'type': 'tool',
'name': 'shell',
'state': {'status': 'completed'},
},
]),
cupertino: cupertino,
),
);
await tester.pumpAndSettle();
final reasoning = tester.getRect(find.text('Reasoning · 2 steps'));
final tools = tester.getRect(find.text('1 tool'));
expect(
reasoning.top,
greaterThan(tester.getRect(find.text('The answer')).bottom),
);
expect(reasoning.center.dy, moreOrLessEquals(tools.center.dy));
expect(reasoning.right, lessThan(tools.left));
// Like the tool chip, it opens a sheet with every step.
await tester.tap(find.text('Reasoning · 2 steps'));
await tester.pumpAndSettle();
expect(find.text('first thought'), findsOneWidget);
expect(find.text('second thought'), findsOneWidget);
});
}
testWidgets(
'Material disclosure bodies start at the label edge at 1x and 2x',
(tester) async {
@@ -169,19 +213,20 @@ void main() {
await tester.pumpWidget(
_host(
_assistant([
{'type': 'reasoning', 'text': 'short thought'},
{'type': 'future_part', 'payload': 'short thought'},
]),
scale: scale,
),
);
await tester.pumpAndSettle();
await tester.tap(find.text('Reasoning'));
await tester.tap(find.text('Unrecognised part: future_part'));
await tester.pumpAndSettle();
final label = tester.getTopLeft(find.text('Reasoning'));
final body = tester.getTopLeft(find.text('short thought'));
expect(body.dx, label.dx, reason: 'short reasoning body at ${scale}x');
expect(find.text('short thought'), findsOneWidget);
final label = tester.getTopLeft(
find.text('Unrecognised part: future_part'),
);
final body = tester.getTopLeft(find.textContaining('short thought'));
expect(body.dx, label.dx, reason: 'disclosure body at ${scale}x');
}
},
);
@@ -253,6 +298,8 @@ void main() {
await tester.tap(find.text('Reasoning'));
await tester.pumpAndSettle();
expect(find.text('thought'), findsOneWidget);
await tester.tapAt(const Offset(10, 10));
await tester.pumpAndSettle();
await tester.tap(find.text('1 tool'));
await tester.pumpAndSettle();
@@ -269,7 +316,7 @@ void main() {
await tester.pumpWidget(
_host(
_assistant([
{'type': 'reasoning', 'text': 'thought'},
{'type': 'future_part', 'payload': 'thought'},
]),
cupertino: true,
),
@@ -277,13 +324,13 @@ void main() {
await tester.pumpAndSettle();
Tristate state() => tester
.getSemantics(find.bySemanticsLabel('Reasoning'))
.getSemantics(find.bySemanticsLabel('Unrecognised part: future_part'))
.getSemanticsData()
.flagsCollection
.isExpanded;
expect(state(), Tristate.isFalse);
await tester.tap(find.text('Reasoning'));
await tester.tap(find.text('Unrecognised part: future_part'));
await tester.pumpAndSettle();
expect(state(), Tristate.isTrue);
handle.dispose();
@@ -335,10 +382,9 @@ void main() {
await tester.pumpAndSettle();
final row = tester.getRect(find.byType(ChatMessageView));
final bubble = tester.getRect(
find.ancestor(
of: find.text('Ada phone'),
matching: find.byType(Material),
).first,
find
.ancestor(of: find.text('Ada phone'), matching: find.byType(Material))
.first,
);
expect(bubble.width, lessThanOrEqualTo(row.width * 0.85 + 0.5));
expect(bubble.right, closeTo(row.right, 1));