fix(chat): keep provided reasoning visible during live replies
This commit is contained in:
@@ -0,0 +1,165 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/chat_message_view.dart';
|
||||
|
||||
import 'chat_thread_fixtures.dart';
|
||||
|
||||
// Matches the normalized OpenCode V2 protocol: text and reasoning each start
|
||||
// at ordinal zero but have distinct stable IDs (ChatDeltaPartID in Go).
|
||||
JsonMap _delta(String kind, String text) => {
|
||||
'session_id': 's',
|
||||
'message_id': 'a',
|
||||
'kind': kind,
|
||||
'part': {'id': 'a#$kind#0', 'type': kind},
|
||||
'delta': text,
|
||||
};
|
||||
|
||||
Widget _host(Widget child, bool cupertino) => cupertino
|
||||
? CupertinoApp(home: CupertinoPageScaffold(child: child))
|
||||
: MaterialApp(
|
||||
theme: ThemeData(platform: TargetPlatform.android),
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
testWidgets('reasoning arriving after text opens live ($cupertino)', (
|
||||
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 tester.pumpAndSettle();
|
||||
expect(find.text('Only supplied reasoning'), findsOneWidget);
|
||||
expect(find.text('Answer first'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('live reasoning survives text, collapse, paging and resync '
|
||||
'(${cupertino ? 'Cupertino' : 'Material'})', (tester) async {
|
||||
final gateway = FakeChatGateway();
|
||||
addTearDown(gateway.close);
|
||||
gateway.history = (_) async =>
|
||||
chatPage(const [], hasMore: true, cursor: 'old');
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
ChatThreadView(gateway: gateway, sessionId: 's', onBack: () {}),
|
||||
cupertino,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
gateway.emitEvent(_delta('reasoning', 'Provided thought'));
|
||||
await tester.pumpAndSettle();
|
||||
// No opening tap required for a newly streaming reply.
|
||||
expect(find.text('Provided thought'), findsOneWidget);
|
||||
final rowElement = tester.element(find.byType(ChatMessageView));
|
||||
|
||||
gateway.emitEvent(_delta('text', 'Answer'));
|
||||
gateway.emitEvent(_delta('reasoning', ' continues'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Provided thought continues'), findsOneWidget);
|
||||
expect(find.text('Answer'), findsOneWidget);
|
||||
expect(tester.element(find.byType(ChatMessageView)), same(rowElement));
|
||||
|
||||
await tester.tap(find.text('Reasoning'));
|
||||
await tester.pumpAndSettle();
|
||||
gateway.emitEvent(_delta('reasoning', ' while collapsed'));
|
||||
gateway.emitEvent(_delta('text', ' continues'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.textContaining('while collapsed'), findsNothing);
|
||||
expect(find.text('Answer continues'), findsOneWidget);
|
||||
await tester.tap(find.text('Reasoning'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
find.text('Provided thought continues while collapsed'),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
// Prepending another assistant message folds into the same turn without
|
||||
// replacing the row or closing the already-open reasoning disclosure.
|
||||
gateway.history = (_) async => chatPage([
|
||||
chatMessage(
|
||||
'older',
|
||||
'assistant',
|
||||
parts: [
|
||||
{
|
||||
'type': 'reasoning',
|
||||
'id': 'older-r',
|
||||
'text': 'Older provided thought',
|
||||
},
|
||||
],
|
||||
),
|
||||
]);
|
||||
await tester.tap(find.text('Load older'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Older provided thought'), findsOneWidget);
|
||||
expect(
|
||||
find.text('Provided thought continues while collapsed'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(tester.element(find.byType(ChatMessageView)), same(rowElement));
|
||||
|
||||
gateway.emitEvent(chatStepFrame('ended'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
find.text('Provided thought continues while collapsed'),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
gateway.history = (_) async => chatPage([
|
||||
chatMessage(
|
||||
'a',
|
||||
'assistant',
|
||||
parts: [
|
||||
{
|
||||
'type': 'reasoning',
|
||||
'id': 'a#reasoning#0',
|
||||
'text': 'Stored provided thought',
|
||||
},
|
||||
{'type': 'text', 'id': 'a#text#0', 'text': 'Stored answer'},
|
||||
],
|
||||
),
|
||||
]);
|
||||
gateway.emitEvent({'session_id': 's', 'kind': 'resync'});
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Stored provided thought'), findsOneWidget);
|
||||
expect(find.text('Stored answer'), findsOneWidget);
|
||||
expect(find.textContaining('while collapsed'), findsNothing);
|
||||
expect(tester.element(find.byType(ChatMessageView)), same(rowElement));
|
||||
await tester.tap(find.text('Reasoning'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Stored provided thought'), findsNothing);
|
||||
|
||||
// A fresh history visit starts collapsed; missing reasoning is never
|
||||
// fabricated. Cupertino keeps only its native controls.
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
ChatThreadView(gateway: gateway, sessionId: 's', onBack: () {}),
|
||||
cupertino,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Stored provided thought'), findsNothing);
|
||||
await tester.tap(find.text('Reasoning'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Stored provided thought'), findsOneWidget);
|
||||
if (cupertino) expect(find.byType(Material), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -168,7 +168,7 @@ void main() {
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// The turn's reasoning is one chip below its answer; it counts the
|
||||
// The turn's reasoning is one disclosure below its answer; it counts the
|
||||
// steps of every message folded into the turn.
|
||||
expect(find.text('Reasoning · 2 steps'), findsOneWidget);
|
||||
|
||||
@@ -184,9 +184,7 @@ void main() {
|
||||
]) {
|
||||
expect(find.text(body), findsOneWidget, reason: body);
|
||||
}
|
||||
Navigator.of(
|
||||
tester.element(find.text('NEWEST folded reasoning body.')),
|
||||
).pop();
|
||||
await tester.tap(find.text('Reasoning · 4 steps'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
find.text('Load older'),
|
||||
|
||||
Reference in New Issue
Block a user