feat(app): chat turns show reasoning above the answer and tool calls as one chip with a formatted call sheet, as the web
This commit is contained in:
@@ -283,22 +283,28 @@ void main() {
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Before paging the turn holds two messages, so two disclosures.
|
||||
expect(find.text('Reasoning'), findsNWidgets(2));
|
||||
await tester.tap(find.text('Reasoning').first);
|
||||
// The turn's reasoning is one quiet block above its answer, as on
|
||||
// the web; it counts the steps it holds.
|
||||
expect(find.text('Reasoning · 2 steps'), findsOneWidget);
|
||||
await tester.tap(find.text('Reasoning · 2 steps'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('NEWEST folded reasoning body.'), findsOneWidget);
|
||||
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. The
|
||||
// newest block stays open; no older block may open.
|
||||
expect(find.text('Reasoning'), findsNWidgets(4));
|
||||
expect(find.text('NEWEST folded reasoning body.'), findsOneWidget);
|
||||
expect(find.text('FOURTH folded reasoning body.'), findsNothing);
|
||||
expect(find.text('SECOND folded reasoning body.'), findsNothing);
|
||||
expect(find.text('OLDEST folded reasoning body.'), findsNothing);
|
||||
// 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);
|
||||
for (final body in [
|
||||
'NEWEST folded reasoning body.',
|
||||
'OLDEST folded reasoning body.',
|
||||
]) {
|
||||
expect(find.textContaining(body), findsOneWidget, reason: body);
|
||||
}
|
||||
expect(
|
||||
find.text('Load older'),
|
||||
keepsControl ? findsOneWidget : findsNothing,
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/domain/chat_tool_calls.dart';
|
||||
|
||||
void main() {
|
||||
final shell = <String, dynamic>{
|
||||
'type': 'tool',
|
||||
'name': 'shell',
|
||||
'state': {
|
||||
'status': 'completed',
|
||||
'input': {'command': 'ls -la\n /srv'},
|
||||
'content': [
|
||||
{'type': 'text', 'text': 'a.txt'},
|
||||
],
|
||||
},
|
||||
'time': {'ran': 1000, 'completed': 2200},
|
||||
};
|
||||
|
||||
test('labels and counts follow the web', () {
|
||||
expect(chatToolLabel(shell), 'shell');
|
||||
expect(chatToolLabel({'type': 'tool'}), 'tool');
|
||||
expect(chatToolCallsLabel(1), '1 tool');
|
||||
expect(chatToolCallsLabel(3), '3 tools');
|
||||
});
|
||||
|
||||
test('the detail is the first command-like input, one line, elided', () {
|
||||
expect(chatToolDetail(shell), 'ls -la /srv');
|
||||
final long = {
|
||||
'type': 'tool',
|
||||
'state': {
|
||||
'input': {'description': 'x' * 100},
|
||||
},
|
||||
};
|
||||
expect(chatToolDetail(long)!.length, 72);
|
||||
expect(chatToolDetail(long), endsWith('…'));
|
||||
expect(
|
||||
chatToolDetail({
|
||||
'type': 'tool',
|
||||
'state': {'input': '{"par'},
|
||||
}),
|
||||
isNull,
|
||||
);
|
||||
});
|
||||
|
||||
test('duration, running and failure states', () {
|
||||
expect(chatToolDurationMillis(shell), 1200);
|
||||
expect(formatChatToolDuration(340), '340ms');
|
||||
expect(formatChatToolDuration(1200), '1.2s');
|
||||
expect(formatChatToolDuration(123000), '2m 3s');
|
||||
expect(chatToolRunning(shell), isFalse);
|
||||
expect(
|
||||
chatToolRunning({
|
||||
'type': 'tool',
|
||||
'state': {'status': 'running'},
|
||||
}),
|
||||
isTrue,
|
||||
);
|
||||
expect(
|
||||
chatToolFailed({
|
||||
'state': {'status': 'error'},
|
||||
}),
|
||||
isTrue,
|
||||
);
|
||||
});
|
||||
|
||||
test('input is pretty JSON and output is the text content', () {
|
||||
expect(chatToolInputText(shell), '{\n "command": "ls -la\\n /srv"\n}');
|
||||
expect(chatToolOutputText(shell), 'a.txt');
|
||||
expect(
|
||||
chatToolOutputText({
|
||||
'state': {'status': 'completed'},
|
||||
}),
|
||||
'(no output)',
|
||||
);
|
||||
expect(
|
||||
chatToolOutputText({
|
||||
'state': {'status': 'running'},
|
||||
}),
|
||||
'',
|
||||
);
|
||||
expect(
|
||||
chatToolErrorText({
|
||||
'state': {
|
||||
'status': 'error',
|
||||
'error': {'message': 'denied'},
|
||||
},
|
||||
}),
|
||||
'denied',
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -124,14 +124,16 @@ 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.
|
||||
double top(String text) => tester.getTopLeft(find.text(text)).dy;
|
||||
expect(top('First answer'), lessThan(top('Reasoning')));
|
||||
expect(top('Reasoning'), lessThan(top('shell')));
|
||||
expect(top('shell'), lessThan(top('Second answer')));
|
||||
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')));
|
||||
|
||||
await tester.ensureVisible(find.text('Reasoning'));
|
||||
await tester.pumpAndSettle();
|
||||
@@ -139,11 +141,16 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('private reasoning'), findsOneWidget);
|
||||
|
||||
await tester.ensureVisible(find.text('shell'));
|
||||
// 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'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('shell'));
|
||||
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();
|
||||
|
||||
await tester.ensureVisible(find.text('Unrecognised part: future_part'));
|
||||
await tester.pumpAndSettle();
|
||||
@@ -247,9 +254,12 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('thought'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('read'));
|
||||
await tester.tap(find.text('1 tool'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.textContaining('"status": "error"'), findsOneWidget);
|
||||
await tester.tap(find.text('read · failed'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('ERROR'), findsOneWidget);
|
||||
expect(find.text('(no output)'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('Cupertino disclosure announces its expanded state', (
|
||||
|
||||
Reference in New Issue
Block a user