Remove Cupertino chat transcript branches

Keep the existing Material transcript path while preserving public Cupertino parameters for callers. Narrow transcript tests to the Material-only behavior and remove Cupertino-only fixtures.
This commit is contained in:
2026-11-11 11:46:13 +00:00
parent 1c2bb8733a
commit fbe1928f59
52 changed files with 1524 additions and 2947 deletions
@@ -1,4 +1,3 @@
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';
@@ -174,7 +173,6 @@ void main() {
group('recorded activity rendering', () {
Future<FakeChatGateway> pumpThread(
WidgetTester tester, {
required bool cupertino,
List<JsonMap>? activityParts,
}) async {
final gateway = FakeChatGateway();
@@ -209,15 +207,10 @@ void main() {
onBack: () {},
);
await tester.pumpWidget(
cupertino
? CupertinoApp(
theme: const CupertinoThemeData(brightness: Brightness.dark),
home: CupertinoPageScaffold(child: view),
)
: MaterialApp(
theme: ThemeData(),
home: Scaffold(body: view),
),
MaterialApp(
theme: ThemeData(),
home: Scaffold(body: view),
),
);
await tester.pumpAndSettle();
return gateway;
@@ -226,15 +219,7 @@ void main() {
testWidgets('Material shows the recorded line once beside the answer', (
tester,
) async {
await pumpThread(tester, cupertino: false);
expect(find.text('Compacting context…'), findsOneWidget);
expect(find.text('Answer'), findsOneWidget);
expect(find.textContaining('Unrecognised part'), findsNothing);
});
testWidgets('Cupertino shows the same recorded line', (tester) async {
await pumpThread(tester, cupertino: true);
await pumpThread(tester);
expect(find.text('Compacting context…'), findsOneWidget);
expect(find.text('Answer'), findsOneWidget);
@@ -302,81 +287,64 @@ void main() {
await tester.pumpAndSettle();
}
for (final cupertino in [false, true]) {
final host = cupertino ? 'Cupertino' : 'Material';
testWidgets('shows only the recorded detail values', (tester) async {
await pumpThread(tester, activityParts: recorded);
await toggle(tester);
testWidgets('$host shows only the recorded detail values', (
tester,
) async {
await pumpThread(
tester,
cupertino: cupertino,
activityParts: recorded,
);
await toggle(tester);
expect(
find.byKey(const ValueKey<String>('chat-activity-details')),
findsOneWidget,
);
expect(find.text('Lifecycle'), findsOneWidget);
expect(find.text('completed'), findsOneWidget);
expect(find.textContaining('"command": "ls"'), findsOneWidget);
expect(find.text('two files'), findsOneWidget);
expect(find.text('exit 1'), findsOneWidget);
expect(find.text('1.2s'), findsOneWidget);
expect(find.text('lib/main.dart\n+1 -1\n- old\n+ new'), findsOneWidget);
for (final absent in const [
'No lifecycle recorded.',
'No input recorded.',
'No output recorded.',
'No error recorded.',
'No duration recorded.',
'No edit diff recorded.',
]) {
expect(find.text(absent), findsNothing, reason: absent);
}
});
expect(
find.byKey(const ValueKey<String>('chat-activity-details')),
findsOneWidget,
);
expect(find.text('Lifecycle'), findsOneWidget);
expect(find.text('completed'), findsOneWidget);
expect(find.textContaining('"command": "ls"'), findsOneWidget);
expect(find.text('two files'), findsOneWidget);
expect(find.text('exit 1'), findsOneWidget);
expect(find.text('1.2s'), findsOneWidget);
expect(
find.text('lib/main.dart\n+1 -1\n- old\n+ new'),
findsOneWidget,
);
for (final absent in const [
'No lifecycle recorded.',
'No input recorded.',
'No output recorded.',
'No error recorded.',
'No duration recorded.',
'No edit diff recorded.',
]) {
expect(find.text(absent), findsNothing, reason: absent);
}
});
testWidgets('words every absent field exactly', (tester) async {
await pumpThread(tester, activityParts: sparse);
await toggle(tester);
testWidgets('$host words every absent field exactly', (tester) async {
await pumpThread(tester, cupertino: cupertino, activityParts: sparse);
await toggle(tester);
expect(find.text('running'), findsOneWidget);
expect(find.text('No input recorded.'), findsOneWidget);
expect(find.text('No output recorded.'), findsOneWidget);
expect(find.text('No error recorded.'), findsOneWidget);
expect(find.text('No duration recorded.'), findsOneWidget);
expect(find.text('No edit diff recorded.'), findsOneWidget);
expect(find.text('No lifecycle recorded.'), findsNothing);
});
expect(find.text('running'), findsOneWidget);
expect(find.text('No input recorded.'), findsOneWidget);
expect(find.text('No output recorded.'), findsOneWidget);
expect(find.text('No error recorded.'), findsOneWidget);
expect(find.text('No duration recorded.'), findsOneWidget);
expect(find.text('No edit diff recorded.'), findsOneWidget);
expect(find.text('No lifecycle recorded.'), findsNothing);
});
testWidgets('collapses back to the single line', (tester) async {
await pumpThread(tester, activityParts: recorded);
await toggle(tester);
expect(
find.byKey(const ValueKey<String>('chat-activity-details')),
findsOneWidget,
);
testWidgets('$host collapses back to the single line', (tester) async {
await pumpThread(
tester,
cupertino: cupertino,
activityParts: recorded,
);
await toggle(tester);
expect(
find.byKey(const ValueKey<String>('chat-activity-details')),
findsOneWidget,
);
await toggle(tester);
await toggle(tester);
expect(
find.byKey(const ValueKey<String>('chat-activity-details')),
findsNothing,
);
expect(find.text('Input'), findsNothing);
expect(find.text('Ran a tool'), findsOneWidget);
expect(find.text('Answer'), findsOneWidget);
});
}
expect(
find.byKey(const ValueKey<String>('chat-activity-details')),
findsNothing,
);
expect(find.text('Input'), findsNothing);
expect(find.text('Ran a tool'), findsOneWidget);
expect(find.text('Answer'), findsOneWidget);
});
});
});
}
@@ -1,7 +1,6 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
import 'package:pipelines_app/features/chat/ui/transcript/chat_injected_rows.dart';
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
import 'package:pipelines_app/ui/adaptive/glass_surface.dart';
import 'chat_composer_bar_fixtures.dart';
@@ -16,71 +15,8 @@ double _contrast(Color foreground, Color background) {
(ink > paper ? paper + .05 : ink + .05);
}
const _report = {
'message': {
'parts': [
{'type': 'text', 'text': 'Report summary', 'name': 'reviewer'},
],
},
};
const _notice = {
'message': {
'parts': [
{'type': 'text', 'text': 'Background task finished'},
],
},
};
void main() {
for (final brightness in Brightness.values) {
for (final highContrast in [false, true]) {
testWidgets(
'report and completion text contrast $brightness highContrast=$highContrast',
(tester) async {
await tester.pumpWidget(
CupertinoApp(
theme: CupertinoThemeData(brightness: brightness),
builder: (context, child) => MediaQuery(
data: MediaQuery.of(context).copyWith(
highContrast: highContrast,
textScaler: const TextScaler.linear(2),
),
child: child!,
),
home: const CupertinoPageScaffold(
child: Column(
children: [
ChatAgentReportCard(row: _report),
ChatSystemNoticeLine(row: _notice),
],
),
),
),
);
await tester.pumpAndSettle();
final context = tester.element(find.byType(ChatAgentReportCard));
final card = CupertinoColors.secondarySystemGroupedBackground
.resolveFrom(context);
final page = CupertinoTheme.of(context).scaffoldBackgroundColor;
final summary = tester.widget<Text>(find.text('Report summary'));
final notice = tester.widget<Text>(
find.text('Background task finished'),
);
expect(
_contrast(summary.style!.color!, card),
greaterThanOrEqualTo(4.5),
);
expect(
_contrast(notice.style!.color!, page),
greaterThanOrEqualTo(4.5),
);
debugPrint(
'contrast $brightness highContrast=$highContrast report=${_contrast(summary.style!.color!, card).toStringAsFixed(2)} notice=${_contrast(notice.style!.color!, page).toStringAsFixed(2)} oldSecondary=${_contrast(CupertinoColors.secondaryLabel.resolveFrom(context), card).toStringAsFixed(2)}',
);
expect(tester.takeException(), isNull);
},
);
}
testWidgets(
'contextual placeholder stays readable on the glass fill $brightness',
(tester) async {
@@ -1,6 +1,5 @@
import 'dart:async';
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';
@@ -71,11 +70,7 @@ Future<void> _pump(WidgetTester tester) async {
await tester.pump();
}
Future<void> _host(
WidgetTester tester,
_Gateway gateway, {
bool cupertino = false,
}) async {
Future<void> _host(WidgetTester tester, _Gateway gateway) async {
var sequence = 0;
final thread = ChatThreadView(
gateway: gateway,
@@ -84,11 +79,7 @@ Future<void> _host(
drafts: MemoryChatDraftStore(),
newOperationId: () => 'op-${++sequence}',
);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: thread))
: MaterialApp(home: Scaffold(body: thread)),
);
await tester.pumpWidget(MaterialApp(home: Scaffold(body: thread)));
await _pump(tester);
}
@@ -154,107 +145,106 @@ void main() {
expect(chatAgentReportSummary('\n- **Done**: all\n'), 'Done: all');
});
for (final cupertino in [false, true]) {
testWidgets('a report is a collapsed card on the agent side, a notice is '
'one line, a prompt stays a bubble ($cupertino)', (tester) async {
tester.view.physicalSize = const Size(1000, 1600);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final gateway = _Gateway()
..messages = [
chatMessage(
'u1',
'user',
parts: [
{'type': 'text', 'text': 'Please delegate this'},
],
),
_reportMessage(),
_noticeMessage(),
];
addTearDown(gateway.close);
await _host(tester, gateway, cupertino: cupertino);
final prompt = find.text('Please delegate this');
expect(prompt, findsOneWidget);
expect(
find.ancestor(of: prompt, matching: find.byType(ChatUserBubble)),
findsOneWidget,
);
final card = find.byType(ChatAgentReportCard);
expect(card, findsOneWidget);
expect(find.text('Agent report · general-purpose'), findsOneWidget);
expect(find.text('Segmented bar report'), findsOneWidget);
// Collapsed: the rest of the report is not laid out yet.
expect(find.textContaining('nested detail'), findsNothing);
expect(
find.ancestor(of: card, matching: find.byType(ChatUserBubble)),
findsNothing,
);
// The card starts on the agent's (leading) side; the prompt ends on
// the operator's (trailing) side.
final width = tester.getSize(find.byType(ChatThreadView)).width;
expect(tester.getTopLeft(card).dx, lessThan(width * 0.2));
expect(
tester.getTopRight(find.byType(ChatUserBubble)).dx,
greaterThan(width * 0.8),
);
final notice = find.text(
'Background task finished: Background command "Build" completed',
);
expect(notice, findsOneWidget);
expect(
find.ancestor(of: notice, matching: find.byType(ChatUserBubble)),
findsNothing,
);
expect(find.bySemanticsLabel('System notice'), findsOneWidget);
await tester.tap(find.text('Agent report · general-purpose'));
await _pump(tester);
expect(find.textContaining('nested detail'), findsOneWidget);
expect(find.textContaining('first finding'), findsOneWidget);
// Markdown is rendered, not shown raw.
expect(find.textContaining('## Segmented'), findsNothing);
expect(find.textContaining('**whole**'), findsNothing);
});
testWidgets('a live report leaves the prompt\'s delivery line alone '
'($cupertino)', (tester) async {
final gateway = _Gateway();
addTearDown(gateway.close);
await _host(tester, gateway, cupertino: cupertino);
await tester.enterText(
find.byKey(const Key('chat-composer-field')),
'Hello',
);
await tester.pump();
await tester.tap(find.byKey(const Key('chat-composer-primary')));
await _pump(tester);
gateway.prompts.single.complete({});
await _pump(tester);
expect(find.byKey(const Key('chat-delivery-sent')), findsOneWidget);
gateway.emitEvent({
'session_id': 's',
'message_id': 'agent-report-1',
'message_kind': 'agent_report',
'kind': 'text',
'part': {'id': 'agent-report-1#text#0', 'name': 'general-purpose'},
'delta': _report,
});
await _pump(tester);
expect(find.byType(ChatAgentReportCard), findsOneWidget);
expect(find.byKey(const Key('chat-delivery-sent')), findsOneWidget);
expect(
find.ancestor(
of: find.text('Hello'),
matching: find.byType(ChatUserBubble),
testWidgets('a report is a collapsed card on the agent side, a notice is '
'one line, a prompt stays a bubble', (tester) async {
tester.view.physicalSize = const Size(1000, 1600);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final gateway = _Gateway()
..messages = [
chatMessage(
'u1',
'user',
parts: [
{'type': 'text', 'text': 'Please delegate this'},
],
),
findsOneWidget,
);
_reportMessage(),
_noticeMessage(),
];
addTearDown(gateway.close);
await _host(tester, gateway);
final prompt = find.text('Please delegate this');
expect(prompt, findsOneWidget);
expect(
find.ancestor(of: prompt, matching: find.byType(ChatUserBubble)),
findsOneWidget,
);
final card = find.byType(ChatAgentReportCard);
expect(card, findsOneWidget);
expect(find.text('Agent report · general-purpose'), findsOneWidget);
expect(find.text('Segmented bar report'), findsOneWidget);
// Collapsed: the rest of the report is not laid out yet.
expect(find.textContaining('nested detail'), findsNothing);
expect(
find.ancestor(of: card, matching: find.byType(ChatUserBubble)),
findsNothing,
);
// The card starts on the agent's (leading) side; the prompt ends on
// the operator's (trailing) side.
final width = tester.getSize(find.byType(ChatThreadView)).width;
expect(tester.getTopLeft(card).dx, lessThan(width * 0.2));
expect(
tester.getTopRight(find.byType(ChatUserBubble)).dx,
greaterThan(width * 0.8),
);
final notice = find.text(
'Background task finished: Background command "Build" completed',
);
expect(notice, findsOneWidget);
expect(
find.ancestor(of: notice, matching: find.byType(ChatUserBubble)),
findsNothing,
);
expect(find.bySemanticsLabel('System notice'), findsOneWidget);
await tester.tap(find.text('Agent report · general-purpose'));
await _pump(tester);
expect(find.textContaining('nested detail'), findsOneWidget);
expect(find.textContaining('first finding'), findsOneWidget);
// Markdown is rendered, not shown raw.
expect(find.textContaining('## Segmented'), findsNothing);
expect(find.textContaining('**whole**'), findsNothing);
});
testWidgets('a live report leaves the prompt\'s delivery line alone ', (
tester,
) async {
final gateway = _Gateway();
addTearDown(gateway.close);
await _host(tester, gateway);
await tester.enterText(
find.byKey(const Key('chat-composer-field')),
'Hello',
);
await tester.pump();
await tester.tap(find.byKey(const Key('chat-composer-primary')));
await _pump(tester);
gateway.prompts.single.complete({});
await _pump(tester);
expect(find.byKey(const Key('chat-delivery-sent')), findsOneWidget);
gateway.emitEvent({
'session_id': 's',
'message_id': 'agent-report-1',
'message_kind': 'agent_report',
'kind': 'text',
'part': {'id': 'agent-report-1#text#0', 'name': 'general-purpose'},
'delta': _report,
});
}
await _pump(tester);
expect(find.byType(ChatAgentReportCard), findsOneWidget);
expect(find.byKey(const Key('chat-delivery-sent')), findsOneWidget);
expect(
find.ancestor(
of: find.text('Hello'),
matching: find.byType(ChatUserBubble),
),
findsOneWidget,
);
});
}
@@ -1,4 +1,3 @@
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';
@@ -17,12 +16,10 @@ JsonMap _delta(String kind, String text) => {
'delta': text,
};
Widget _host(Widget child, bool cupertino) => cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: child))
: MaterialApp(
theme: ThemeData(platform: TargetPlatform.android),
home: Scaffold(body: child),
);
Widget _host(Widget child) => MaterialApp(
theme: ThemeData(platform: TargetPlatform.android),
home: Scaffold(body: child),
);
/// The streaming activity control animates, so pumpAndSettle would never
/// return; this lets its dialog finish its
@@ -45,178 +42,164 @@ Future<void> _dismiss(WidgetTester tester) async {
}
void main() {
for (final cupertino in [false, true]) {
final host = cupertino ? 'Cupertino' : 'Material';
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);
// 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(_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(_activity, findsOneWidget);
expect(tester.takeException(), isNull);
},
);
testWidgets('an open activity dialog follows live deltas, paging and '
'resync ($host)', (tester) async {
testWidgets(
'reasoning arriving after text keeps one streaming activity control',
(tester) async {
final gateway = FakeChatGateway();
addTearDown(gateway.close);
gateway.history = (_) async =>
chatPage(const [], hasMore: true, cursor: 'old');
gateway.history = (_) async => chatPage(const []);
await tester.pumpWidget(
_host(
ChatThreadView(gateway: gateway, sessionId: 's', onBack: () {}),
cupertino,
),
_host(ChatThreadView(gateway: gateway, sessionId: 's', onBack: () {})),
);
await tester.pumpAndSettle();
gateway.emitEvent(_delta('text', 'Answer first'));
await tester.pumpAndSettle();
expect(find.text('Reasoning'), findsNothing);
gateway.emitEvent(_delta('reasoning', 'Provided thought'));
gateway.emitEvent(_delta('reasoning', 'Only supplied reasoning'));
await _settle(tester);
final rowElement = tester.element(find.byType(ChatMessageView));
// 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(_activity);
await _settle(tester);
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(_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(_inDialog('Provided thought continues live'), findsOneWidget);
expect(_inDialog('Only supplied reasoning'), findsOneWidget);
await _dismiss(tester);
// A closed sheet draws nothing; reopening shows the newest text.
gateway.emitEvent(_delta('reasoning', ' while closed'));
gateway.emitEvent(_delta('text', ' continues'));
await tester.pumpAndSettle();
expect(find.textContaining('while closed'), findsNothing);
expect(find.text('Answer continues'), findsOneWidget);
await tester.tap(_activity);
await tester.pumpAndSettle();
expect(find.text('Reasoning 1'), findsOneWidget);
await tester.tap(find.text('Reasoning 1'));
await tester.pumpAndSettle();
expect(
_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 one activity control keeps both steps.
gateway.history = (_) async => chatPage([
chatMessage(
'older',
'assistant',
parts: [
{
'type': 'reasoning',
'id': 'older-r',
'text': 'Older provided thought',
},
],
),
]);
await tester.tap(find.text('Load older'));
// The step ends: the chip settles to its icon.
gateway.emitEvent(chatStepFrame('ended'));
await tester.pumpAndSettle();
expect(_activity, findsOneWidget);
expect(tester.element(find.byType(ChatMessageView)), same(rowElement));
await tester.tap(_activity);
await tester.pumpAndSettle();
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(
_inDialog('Provided thought continues live while closed'),
findsOneWidget,
);
// A resync replaces the stored turn under the open sheet.
gateway.emitEvent(chatStepFrame('ended'));
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(_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));
await _dismiss(tester);
// A fresh history visit draws the chip closed; 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(_activity);
await tester.pumpAndSettle();
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);
});
}
},
);
testWidgets('an open activity dialog follows live deltas, paging and '
'resync', (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: () {})),
);
await tester.pumpAndSettle();
gateway.emitEvent(_delta('reasoning', 'Provided thought'));
await _settle(tester);
final rowElement = tester.element(find.byType(ChatMessageView));
await tester.tap(_activity);
await _settle(tester);
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(_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(_inDialog('Provided thought continues live'), findsOneWidget);
await _dismiss(tester);
// A closed sheet draws nothing; reopening shows the newest text.
gateway.emitEvent(_delta('reasoning', ' while closed'));
gateway.emitEvent(_delta('text', ' continues'));
await tester.pumpAndSettle();
expect(find.textContaining('while closed'), findsNothing);
expect(find.text('Answer continues'), findsOneWidget);
await tester.tap(_activity);
await tester.pumpAndSettle();
expect(find.text('Reasoning 1'), findsOneWidget);
await tester.tap(find.text('Reasoning 1'));
await tester.pumpAndSettle();
expect(
_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 one activity control keeps both steps.
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(_activity, findsOneWidget);
expect(tester.element(find.byType(ChatMessageView)), same(rowElement));
await tester.tap(_activity);
await tester.pumpAndSettle();
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(
_inDialog('Provided thought continues live while closed'),
findsOneWidget,
);
// A resync replaces the stored turn under the open sheet.
gateway.emitEvent(chatStepFrame('ended'));
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(_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));
await _dismiss(tester);
// A fresh history visit draws the chip closed; missing reasoning is
// never fabricated.
await tester.pumpWidget(const SizedBox.shrink());
await tester.pumpWidget(
_host(ChatThreadView(gateway: gateway, sessionId: 's', onBack: () {})),
);
await tester.pumpAndSettle();
expect(find.text('Stored provided thought'), findsNothing);
await tester.tap(_activity);
await tester.pumpAndSettle();
await tester.tap(find.text('Reasoning 1'));
await tester.pumpAndSettle();
expect(_inDialog('Stored provided thought'), findsOneWidget);
expect(tester.takeException(), isNull);
});
}
@@ -1,13 +1,11 @@
import 'dart:async';
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_permission_card.dart';
import 'package:pipelines_app/features/chat/conversation/chat_permission_card_model.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';
@@ -19,16 +17,6 @@ Widget materialHost(Widget child) => MaterialApp(
Widget scrollHost(Widget child) =>
materialHost(SingleChildScrollView(child: child));
Widget cupertinoHost(Widget child) => CupertinoApp(
theme: const CupertinoThemeData(brightness: Brightness.dark),
home: CupertinoPageScaffold(
child: SingleChildScrollView(
padding: const EdgeInsets.all(16),
child: child,
),
),
);
JsonMap permission({
String id = 'req-1',
String action = 'bash',
@@ -212,34 +200,6 @@ void main() {
expect(find.text(card.resources.join('\n')), findsOneWidget);
});
testWidgets('320px at 2x in dark Cupertino keeps the card native and '
'readable', (tester) async {
tester.view.physicalSize = const Size(640, 1400);
tester.view.devicePixelRatio = 2;
tester.platformDispatcher.textScaleFactorTestValue = 2;
tester.platformDispatcher.platformBrightnessTestValue = Brightness.dark;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
addTearDown(tester.platformDispatcher.clearPlatformBrightnessTestValue);
final card = chatPermissionCard(
permission(
action: 'a very long tool name that has to wrap at twice the text size',
resources: const [
'a long resource line that wraps instead of clipping any words at all',
],
),
'',
)!;
await tester.pumpWidget(
cupertinoHost(ChatPermissionCard(card: card, onDecision: (_) async {})),
);
expect(tester.takeException(), isNull);
expect(find.text('Allow once'), findsOneWidget);
expect(find.byType(Material), findsNothing);
});
testWidgets('a pushed chat_permission renders, sends the recorded reply, '
'and a second tap sends once', (tester) async {
final gateway = FakeChatGateway();
@@ -425,61 +385,4 @@ void main() {
);
expect(second.top - first.bottom, greaterThanOrEqualTo(12));
});
testWidgets(
'a Cupertino card lines up with the message bubbles',
(tester) async {
final gateway = FakeChatGateway();
addTearDown(gateway.close);
gateway.history = (_) async => chatPage([
chatMessage(
'u1',
'user',
parts: [
{'type': 'text', 'text': 'Show me the card'},
],
),
]);
await tester.pumpWidget(
CupertinoApp(
home: CupertinoPageScaffold(
child: ChatThreadView(
gateway: gateway,
sessionId: 's',
onBack: () {},
),
),
),
);
await tester.pumpAndSettle();
gateway.emitRaw({
'type': 'chat_permission',
'chat_permission': permission(),
});
await tester.pumpAndSettle();
final bubble = tester.getRect(
find.ancestor(
of: find.text('Show me the card'),
matching: find.byType(ChatMessageView),
),
);
// The card's own box includes the section margin, so measure its body.
final body = tester.getRect(
find
.descendant(
of: find.byType(ChatPermissionCard),
matching: find.byWidgetPredicate(
(widget) =>
widget is Padding &&
widget.padding == const EdgeInsets.all(16),
),
)
.first,
);
expect(body.left, bubble.left);
expect(body.right, bubble.right);
},
variant: TargetPlatformVariant.only(TargetPlatform.iOS),
);
}
@@ -1,6 +1,5 @@
import 'dart:async';
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';
@@ -57,11 +56,7 @@ JsonMap _form({String id = 'form-1'}) => {
const _chip = 'Which database? · Postgres';
/// A chat whose agent turn `a1` is the one the question arrives during.
Future<FakeChatGateway> _open(
WidgetTester tester,
Size size, {
bool cupertino = false,
}) async {
Future<FakeChatGateway> _open(WidgetTester tester, Size size) async {
await tester.binding.setSurfaceSize(size);
addTearDown(() => tester.binding.setSurfaceSize(null));
final gateway = FakeChatGateway()
@@ -83,11 +78,7 @@ Future<FakeChatGateway> _open(
]);
addTearDown(gateway.close);
final view = ChatThreadView(gateway: gateway, sessionId: 's', onBack: () {});
await tester.pumpWidget(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: view))
: MaterialApp(home: Scaffold(body: view)),
);
await tester.pumpWidget(MaterialApp(home: Scaffold(body: view)));
await tester.pumpAndSettle();
gateway.emitEvent({'session_id': 's', 'kind': 'form', 'form': _form()});
await tester.pumpAndSettle();
@@ -267,16 +258,6 @@ void main() {
_expectCollapsed();
});
testWidgets('Cupertino: the answered question collapses to the native chip', (
tester,
) async {
final gateway = await _open(tester, const Size(390, 844), cupertino: true);
gateway.answer = (_) async => const {'type': 'chat_answer'};
await _answerPostgres(tester);
_expectCollapsed();
expect(tester.takeException(), isNull);
});
testWidgets('after a reload the answered question stays gone', (
tester,
) async {
@@ -1,6 +1,5 @@
import 'dart:async';
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';
@@ -27,11 +26,7 @@ Future<void> _pump(WidgetTester tester) async {
await tester.pump();
}
Future<void> _host(
WidgetTester tester,
_Gateway gateway, {
bool cupertino = false,
}) async {
Future<void> _host(WidgetTester tester, _Gateway gateway) async {
gateway.history = (_) async => chatPage([]);
final thread = ChatThreadView(
gateway: gateway,
@@ -45,15 +40,10 @@ Future<void> _host(
child: child!,
);
await tester.pumpWidget(
cupertino
? CupertinoApp(
builder: animations,
home: CupertinoPageScaffold(child: thread),
)
: MaterialApp(
builder: animations,
home: Scaffold(body: thread),
),
MaterialApp(
builder: animations,
home: Scaffold(body: thread),
),
);
await tester.pumpAndSettle();
}
@@ -66,23 +56,32 @@ Future<void> _send(WidgetTester tester) async {
}
void main() {
for (final cupertino in [false, true]) {
testWidgets(
'response bubble exists before frames, through tools, then text '
'($cupertino)',
(tester) async {
final gateway = _Gateway();
addTearDown(gateway.close);
await _host(tester, gateway, cupertino: cupertino);
expect(find.byType(ChatResponsePending), findsNothing);
await _send(tester);
expect(find.byType(ChatResponsePending), findsOneWidget);
expect(
find.bySemanticsLabel(RegExp(r'Thinking.*expand for details')),
findsOneWidget,
);
expect(find.byType(ChatMessageView), findsNWidgets(2));
final opacities = tester
testWidgets(
'response bubble exists before frames, through tools, then text',
(tester) async {
final gateway = _Gateway();
addTearDown(gateway.close);
await _host(tester, gateway);
expect(find.byType(ChatResponsePending), findsNothing);
await _send(tester);
expect(find.byType(ChatResponsePending), findsOneWidget);
expect(
find.bySemanticsLabel(RegExp(r'Thinking.*expand for details')),
findsOneWidget,
);
expect(find.byType(ChatMessageView), findsNWidgets(2));
final opacities = tester
.widgetList<Opacity>(
find.descendant(
of: find.byType(ChatResponsePending),
matching: find.byType(Opacity),
),
)
.map((widget) => widget.opacity)
.toList();
await tester.pump(const Duration(milliseconds: 200));
expect(
tester
.widgetList<Opacity>(
find.descendant(
of: find.byType(ChatResponsePending),
@@ -90,70 +89,58 @@ void main() {
),
)
.map((widget) => widget.opacity)
.toList();
await tester.pump(const Duration(milliseconds: 200));
expect(
tester
.widgetList<Opacity>(
find.descendant(
of: find.byType(ChatResponsePending),
matching: find.byType(Opacity),
),
)
.map((widget) => widget.opacity)
.toList(),
isNot(opacities),
);
gateway.prompt.complete({});
await _pump(tester);
expect(find.byType(ChatResponsePending), findsOneWidget);
.toList(),
isNot(opacities),
);
gateway.prompt.complete({});
await _pump(tester);
expect(find.byType(ChatResponsePending), findsOneWidget);
gateway.emitEvent(chatStepFrame('running'));
gateway.emitEvent({
'session_id': 's',
'kind': 'reasoning',
'message_id': 'a',
'part': {'id': 'reasoning', 'type': 'reasoning'},
'delta': 'Thinking through this.',
});
await _pump(tester);
expect(find.byType(ChatResponsePending), findsOneWidget);
gateway.emitEvent({
'session_id': 's',
'kind': 'tool',
'message_id': 'a',
'part': {
'id': 'tool-1',
'type': 'tool',
'name': 'read',
'state': {'status': 'completed'},
},
});
await _pump(tester);
expect(find.byType(ChatResponsePending), findsOneWidget);
expect(find.textContaining('Thinking'), findsOneWidget);
expect(find.byType(ChatMessageView), findsNWidgets(2));
expect(
find.descendant(
of: find.byKey(const Key('chat-turn-activity')),
matching: find.byType(ChatResponsePending),
),
findsOneWidget,
);
gateway.emitEvent(chatStepFrame('running'));
gateway.emitEvent({
'session_id': 's',
'kind': 'reasoning',
'message_id': 'a',
'part': {'id': 'reasoning', 'type': 'reasoning'},
'delta': 'Thinking through this.',
});
await _pump(tester);
expect(find.byType(ChatResponsePending), findsOneWidget);
gateway.emitEvent({
'session_id': 's',
'kind': 'tool',
'message_id': 'a',
'part': {
'id': 'tool-1',
'type': 'tool',
'name': 'read',
'state': {'status': 'completed'},
},
});
await _pump(tester);
expect(find.byType(ChatResponsePending), findsOneWidget);
expect(find.textContaining('Thinking'), findsOneWidget);
expect(find.byType(ChatMessageView), findsNWidgets(2));
expect(
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), findsOneWidget);
expect(find.text('Here is the answer.'), 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());
},
);
}
gateway.emitEvent(chatTextFrame('Here is the answer.'));
await _pump(tester);
expect(find.byType(ChatResponsePending), findsOneWidget);
expect(find.text('Here is the answer.'), 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());
},
);
for (final result in ['refused', 'queued', 'ended']) {
testWidgets(
@@ -208,28 +195,27 @@ void main() {
expect(tester.binding.hasScheduledFrame, isFalse);
});
for (final cupertino in [false, true]) {
testWidgets('the pending dots sit on the activity text\'s middle '
'($cupertino)', (tester) async {
final gateway = _Gateway();
addTearDown(gateway.close);
await _host(tester, gateway, cupertino: cupertino);
await _send(tester);
testWidgets('the pending dots sit on the activity text\'s middle ', (
tester,
) async {
final gateway = _Gateway();
addTearDown(gateway.close);
await _host(tester, gateway);
await _send(tester);
final dots = tester.getRect(
find.byKey(const Key('chat-response-pending-dots')),
);
final label = tester.getRect(find.textContaining('Thinking'));
expect(dots.center.dy, closeTo(label.center.dy, 1));
expect(dots.height, lessThanOrEqualTo(label.height));
// Round dots, not baseline glyphs.
expect(
find.descendant(
of: find.byType(ChatResponsePending),
matching: find.text('.'),
),
findsNothing,
);
});
}
final dots = tester.getRect(
find.byKey(const Key('chat-response-pending-dots')),
);
final label = tester.getRect(find.textContaining('Thinking'));
expect(dots.center.dy, closeTo(label.center.dy, 1));
expect(dots.height, lessThanOrEqualTo(label.height));
// Round dots, not baseline glyphs.
expect(
find.descendant(
of: find.byType(ChatResponsePending),
matching: find.text('.'),
),
findsNothing,
);
});
}
@@ -1,4 +1,3 @@
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';
@@ -70,9 +69,8 @@ Future<void> _pump(WidgetTester tester) async {
Future<void> _host(
WidgetTester tester,
_Gateway gateway,
MemoryChatDraftStore drafts, {
bool cupertino = false,
}) async {
MemoryChatDraftStore drafts,
) async {
final thread = ChatThreadView(
gateway: gateway,
sessionId: 's',
@@ -80,42 +78,31 @@ Future<void> _host(
drafts: drafts,
newOperationId: () => 'op-new',
);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: thread))
: MaterialApp(home: Scaffold(body: thread)),
);
await tester.pumpWidget(MaterialApp(home: Scaffold(body: thread)));
await _pump(tester);
}
Finder _state(String name) => find.byKey(Key('chat-delivery-$name'));
void main() {
for (final cupertino in [false, true]) {
testWidgets('a reload draws the server-queued prompts as Queued '
'($cupertino)', (tester) async {
final gateway = _Gateway()
..queue = [_prompt('op-1', 'First queued'), _prompt('op-2', 'Second')];
addTearDown(gateway.close);
await _host(
tester,
gateway,
MemoryChatDraftStore(),
cupertino: cupertino,
);
expect(find.text('First queued'), findsOneWidget);
expect(find.text('Second'), findsOneWidget);
expect(_state('queued'), findsNWidgets(2));
expect(find.byKey(const Key('chat-delivery-remove')), findsNWidgets(2));
// They follow the transcript: nothing queued has reached the harness.
expect(
tester.getTopLeft(find.text('First queued')).dy,
greaterThan(tester.getTopLeft(find.text('Working on it')).dy),
);
});
}
testWidgets('a reload draws the server-queued prompts as Queued', (
tester,
) async {
final gateway = _Gateway()
..queue = [_prompt('op-1', 'First queued'), _prompt('op-2', 'Second')];
addTearDown(gateway.close);
await _host(tester, gateway, MemoryChatDraftStore());
expect(find.text('First queued'), findsOneWidget);
expect(find.text('Second'), findsOneWidget);
expect(_state('queued'), findsNWidgets(2));
expect(find.byKey(const Key('chat-delivery-remove')), findsNWidgets(2));
// They follow the transcript: nothing queued has reached the harness.
expect(
tester.getTopLeft(find.text('First queued')).dy,
greaterThan(tester.getTopLeft(find.text('Working on it')).dy),
);
});
testWidgets('a delivered queued prompt enters the transcript as Sent', (
tester,
) async {
@@ -54,9 +54,8 @@ Future<void> _pump(WidgetTester tester) async {
Future<FakeChatGateway> _host(
WidgetTester tester,
List<JsonMap> messages, {
bool cupertino = false,
}) async {
List<JsonMap> messages,
) async {
tester.view.physicalSize = const Size(1000, 1600);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
@@ -75,53 +74,51 @@ Future<FakeChatGateway> _host(
}
void main() {
for (final cupertino in [false, true]) {
testWidgets('consecutive task notices are one chip that opens to each '
'task ($cupertino)', (tester) async {
await _host(tester, _messages, cupertino: cupertino);
testWidgets('consecutive task notices are one chip that opens to each task', (
tester,
) async {
await _host(tester, _messages);
expect(find.byType(ChatTaskNoticesGroup), findsOneWidget);
expect(find.byType(ChatSystemNoticeLine), findsNothing);
final chip = find.byKey(const Key('chat-task-notices-chip'));
expect(chip, findsOneWidget);
expect(find.text('3 background tasks · 1 failed'), findsOneWidget);
expect(
find.ancestor(of: chip, matching: find.byType(ChatUserBubble)),
findsNothing,
);
// Only the operator's prompt is a bubble, on the trailing side; the
// group starts on the agent's side.
expect(find.byType(ChatUserBubble), findsOneWidget);
final width = tester.getSize(find.byType(ChatThreadView)).width;
expect(tester.getTopLeft(chip).dx, lessThan(width * 0.2));
// Collapsed: no summary is laid out yet.
expect(find.textContaining('Build the app'), findsNothing);
expect(find.byType(ChatTaskNoticesGroup), findsOneWidget);
expect(find.byType(ChatSystemNoticeLine), findsNothing);
final chip = find.byKey(const Key('chat-task-notices-chip'));
expect(chip, findsOneWidget);
expect(find.text('3 background tasks · 1 failed'), findsOneWidget);
expect(
find.ancestor(of: chip, matching: find.byType(ChatUserBubble)),
findsNothing,
);
// Only the operator's prompt is a bubble, on the trailing side; the
// group starts on the agent's side.
expect(find.byType(ChatUserBubble), findsOneWidget);
final width = tester.getSize(find.byType(ChatThreadView)).width;
expect(tester.getTopLeft(chip).dx, lessThan(width * 0.2));
// Collapsed: no summary is laid out yet.
expect(find.textContaining('Build the app'), findsNothing);
await tester.tap(chip);
await tester.pumpAndSettle();
final sheet = find.byKey(const Key('chat-task-notices-sheet'));
expect(sheet, findsOneWidget);
for (final summary in [
'Background command "Build the app" completed (exit code 0)',
'Background command "Run the tests" failed (exit code 1)',
'Agent "Review the diff" finished',
]) {
expect(
find.descendant(of: sheet, matching: find.text(summary)),
findsOneWidget,
);
}
await tester.tap(chip);
await tester.pumpAndSettle();
final sheet = find.byKey(const Key('chat-task-notices-sheet'));
expect(sheet, findsOneWidget);
for (final summary in [
'Background command "Build the app" completed (exit code 0)',
'Background command "Run the tests" failed (exit code 1)',
'Agent "Review the diff" finished',
]) {
expect(
find.descendant(of: sheet, matching: find.text('Finished')),
findsNWidgets(2),
);
expect(
find.descendant(of: sheet, matching: find.text('Failed')),
find.descendant(of: sheet, matching: find.text(summary)),
findsOneWidget,
);
});
}
}
expect(
find.descendant(of: sheet, matching: find.text('Finished')),
findsNWidgets(2),
);
expect(
find.descendant(of: sheet, matching: find.text('Failed')),
findsOneWidget,
);
});
testWidgets('a lone notice stays one line and a live second notice joins '
'it into the group', (tester) async {
final gateway = await _host(tester, _messages.take(2).toList());
@@ -1,4 +1,3 @@
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';
@@ -13,11 +12,6 @@ Widget host(Widget child) => MaterialApp(
home: Scaffold(body: child),
);
Widget cupertinoHost(Widget child) => CupertinoApp(
theme: const CupertinoThemeData(brightness: Brightness.dark),
home: CupertinoPageScaffold(child: child),
);
/// A history tall enough that the transcript overflows the test viewport.
JsonMap tallPage() => chatPage([
for (var index = 0; index < 14; index++)
@@ -84,81 +78,70 @@ void main() {
expect(find.byKey(const Key('chat-jump-to-latest')), findsNothing);
});
for (final cupertino in [false, true]) {
testWidgets(
'an upward scroll releases follow and the control counts arrivals '
'(${cupertino ? 'cupertino' : 'material'})',
(tester) async {
final gateway = FakeChatGateway();
addTearDown(gateway.close);
gateway.history = (_) async => tallPage();
testWidgets(
'an upward scroll releases follow and the control counts arrivals',
(tester) async {
final gateway = FakeChatGateway();
addTearDown(gateway.close);
gateway.history = (_) async => tallPage();
await tester.pumpWidget(
(cupertino ? cupertinoHost : host)(
ChatThreadView(gateway: gateway, sessionId: 's', onBack: () {}),
),
);
await tester.pumpAndSettle();
await tester.pumpWidget(
host(ChatThreadView(gateway: gateway, sessionId: 's', onBack: () {})),
);
await tester.pumpAndSettle();
final scroll = transcriptScroll(tester);
await tester.drag(
find.byKey(const Key('chat-thread-s')),
const Offset(0, 360),
);
await tester.pumpAndSettle();
final scroll = transcriptScroll(tester);
await tester.drag(
find.byKey(const Key('chat-thread-s')),
const Offset(0, 360),
);
await tester.pumpAndSettle();
final releasedAt = scroll.position.pixels;
expect(
releasedAt,
lessThan(scroll.position.maxScrollExtent - chatFollowThresholdPx),
);
expect(find.byKey(const Key('chat-jump-to-latest')), findsOneWidget);
expect(find.text('Jump to latest'), findsOneWidget);
final releasedAt = scroll.position.pixels;
expect(
releasedAt,
lessThan(scroll.position.maxScrollExtent - chatFollowThresholdPx),
);
expect(find.byKey(const Key('chat-jump-to-latest')), findsOneWidget);
expect(find.text('Jump to latest'), findsOneWidget);
gateway.emitEvent(chatTextFrame('A new answer. ', messageId: 'live-1'));
await tester.pump();
await tester.pump();
gateway.emitEvent(chatTextFrame('A new answer. ', messageId: 'live-1'));
await tester.pump();
await tester.pump();
// The operator's position is not moved by an arrival; only the
// control's count changes.
expect(scroll.position.pixels, closeTo(releasedAt, 0.5));
expect(find.text('Jump to latest · 1 new message'), findsOneWidget);
// The operator's position is not moved by an arrival; only the
// control's count changes.
expect(scroll.position.pixels, closeTo(releasedAt, 0.5));
expect(find.text('Jump to latest · 1 new message'), findsOneWidget);
gateway.emitEvent(
chatTextFrame('A second answer. ', messageId: 'live-2'),
);
await tester.pump();
await tester.pump();
expect(scroll.position.pixels, closeTo(releasedAt, 0.5));
expect(find.text('Jump to latest · 2 new messages'), findsOneWidget);
gateway.emitEvent(
chatTextFrame('A second answer. ', messageId: 'live-2'),
);
await tester.pump();
await tester.pump();
expect(scroll.position.pixels, closeTo(releasedAt, 0.5));
expect(find.text('Jump to latest · 2 new messages'), findsOneWidget);
if (cupertino) {
// The affordance is a standard Cupertino control; no Material
// ancestor is introduced into the bare Cupertino host.
expect(find.byType(Material), findsNothing);
}
await tester.tap(find.byKey(const Key('chat-jump-to-latest')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-jump-to-latest')));
await tester.pumpAndSettle();
expect(
scroll.position.pixels,
closeTo(scroll.position.maxScrollExtent, 0.5),
);
expect(find.byKey(const Key('chat-jump-to-latest')), findsNothing);
expect(
scroll.position.pixels,
closeTo(scroll.position.maxScrollExtent, 0.5),
);
expect(find.byKey(const Key('chat-jump-to-latest')), findsNothing);
// Returning to the end re-arms following for later frames.
gateway.emitEvent(chatTextFrame('Pinned again. ', messageId: 'live-3'));
await tester.pump();
await tester.pump();
expect(
scroll.position.pixels,
closeTo(scroll.position.maxScrollExtent, 0.5),
);
expect(find.byKey(const Key('chat-jump-to-latest')), findsNothing);
},
);
}
// Returning to the end re-arms following for later frames.
gateway.emitEvent(chatTextFrame('Pinned again. ', messageId: 'live-3'));
await tester.pump();
await tester.pump();
expect(
scroll.position.pixels,
closeTo(scroll.position.maxScrollExtent, 0.5),
);
expect(find.byKey(const Key('chat-jump-to-latest')), findsNothing);
},
);
testWidgets('a reopened conversation restores the position it was left at', (
tester,
@@ -287,46 +270,4 @@ void main() {
expect(scroll.position.maxScrollExtent, 0);
expect(find.byKey(const Key('chat-jump-to-latest')), findsNothing);
});
testWidgets('the control fits a 320px Cupertino viewport at 2x text', (
tester,
) async {
tester.view.physicalSize = const Size(640, 1200);
tester.view.devicePixelRatio = 2;
tester.platformDispatcher.textScaleFactorTestValue = 2;
tester.platformDispatcher.platformBrightnessTestValue = Brightness.dark;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
addTearDown(tester.platformDispatcher.clearPlatformBrightnessTestValue);
final gateway = FakeChatGateway();
addTearDown(gateway.close);
gateway.history = (_) async => tallPage();
await tester.pumpWidget(
cupertinoHost(
ChatThreadView(gateway: gateway, sessionId: 's', onBack: () {}),
),
);
await tester.pumpAndSettle();
await tester.drag(
find.byKey(const Key('chat-thread-s')),
const Offset(0, 360),
);
await tester.pumpAndSettle();
gateway.emitEvent(chatTextFrame('Arrival. ', messageId: 'live'));
await tester.pump();
await tester.pump();
expect(tester.takeException(), isNull);
final control = find.byKey(const Key('chat-jump-to-latest'));
expect(control, findsOneWidget);
expect(find.text('Jump to latest · 1 new message'), findsOneWidget);
final rect = tester.getRect(control);
expect(rect.left, greaterThanOrEqualTo(0));
expect(rect.right, lessThanOrEqualTo(320));
expect(find.byType(Material), findsNothing);
});
}
@@ -1,6 +1,5 @@
import 'dart:async';
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';
@@ -17,11 +16,6 @@ Widget host(Widget child) => MaterialApp(
home: Scaffold(body: child),
);
Widget cupertinoHost(Widget child) => CupertinoApp(
theme: const CupertinoThemeData(brightness: Brightness.dark),
home: CupertinoPageScaffold(child: child),
);
void main() {
for (final reverse in [false, true]) {
testWidgets(
@@ -228,92 +222,85 @@ void main() {
expect(find.text('Load older'), findsNothing);
});
for (final cupertino in [false, true]) {
for (final keepsControl in [true, false]) {
testWidgets(
'a folded assistant turn counts every reasoning step across paging '
'(keeps Load older: $keepsControl, $cupertino)',
(tester) async {
final gateway = FakeChatGateway();
addTearDown(gateway.close);
var reads = 0;
gateway.history = (_) async => ++reads == 1
? assistantFoldPage(
const ['msg_6', 'msg_4'],
const [
'NEWEST folded reasoning body.',
'FOURTH folded reasoning body.',
],
cursor: 'opaque/fold',
hasMore: true,
)
: assistantFoldPage(
const ['msg_2', 'msg_0'],
const [
'SECOND folded reasoning body.',
'OLDEST folded reasoning body.',
],
cursor: keepsControl ? 'opaque/fold-2' : '',
hasMore: keepsControl,
);
for (final keepsControl in [true, false]) {
testWidgets(
'a folded assistant turn counts every reasoning step across paging (keeps Load older: $keepsControl)',
(tester) async {
final gateway = FakeChatGateway();
addTearDown(gateway.close);
var reads = 0;
gateway.history = (_) async => ++reads == 1
? assistantFoldPage(
const ['msg_6', 'msg_4'],
const [
'NEWEST folded reasoning body.',
'FOURTH folded reasoning body.',
],
cursor: 'opaque/fold',
hasMore: true,
)
: assistantFoldPage(
const ['msg_2', 'msg_0'],
const [
'SECOND folded reasoning body.',
'OLDEST folded reasoning body.',
],
cursor: keepsControl ? 'opaque/fold-2' : '',
hasMore: keepsControl,
);
await tester.pumpWidget(
(cupertino ? cupertinoHost : host)(
ChatThreadView(gateway: gateway, sessionId: 's', onBack: () {}),
),
);
await tester.pumpAndSettle();
await tester.pumpWidget(
host(ChatThreadView(gateway: gateway, sessionId: 's', onBack: () {})),
);
await tester.pumpAndSettle();
// 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);
// 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();
await tester.tap(find.text('Load older'));
await tester.pumpAndSettle();
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();
}
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: cupertino
? find.byType(CupertinoAlertDialog)
: find.byType(AlertDialog),
matching: find.text(body),
),
findsOneWidget,
reason: body,
);
}
await tester.tap(find.text('Done'));
await tester.pumpAndSettle();
expect(find.text('OLDEST folded reasoning body.'), findsNothing);
}
for (final body in [
'NEWEST folded reasoning body.',
'OLDEST folded reasoning body.',
]) {
expect(
find.text('Load older'),
keepsControl ? findsOneWidget : findsNothing,
find.descendant(
of: find.byType(AlertDialog),
matching: find.text(body),
),
findsOneWidget,
reason: body,
);
},
);
}
}
await tester.tap(find.text('Done'));
await tester.pumpAndSettle();
expect(find.text('OLDEST folded reasoning body.'), findsNothing);
expect(
find.text('Load older'),
keepsControl ? findsOneWidget : findsNothing,
);
},
);
}
// Assistant prose goes through the landed markdown renderer; the user's
// message keeps the server's characters byte-for-byte.
for (final cupertino in [false, true]) {
testWidgets('assistant history renders markdown while user text stays exact '
'(${cupertino ? 'cupertino' : 'material'})', (tester) async {
testWidgets(
'assistant history renders markdown while user text stays exact',
(tester) async {
final gateway = FakeChatGateway();
addTearDown(gateway.close);
const userText =
@@ -347,9 +334,7 @@ void main() {
]);
await tester.pumpWidget(
(cupertino ? cupertinoHost : host)(
ChatThreadView(gateway: gateway, sessionId: 's', onBack: () {}),
),
host(ChatThreadView(gateway: gateway, sessionId: 's', onBack: () {})),
);
await tester.pumpAndSettle();
@@ -386,13 +371,8 @@ void main() {
find.text('Keep these characters as-is literal.', findRichText: true),
findsNothing,
);
// No Material control is introduced into the Cupertino host.
if (cupertino) {
expect(find.byType(Material), findsNothing);
}
});
}
},
);
testWidgets('a live assistant text frame renders formatted markdown', (
tester,
@@ -425,62 +405,6 @@ void main() {
expect(find.textContaining('`live code`'), findsNothing);
expect(find.byKey(const Key('chat-running')), findsNothing);
});
testWidgets('formatted assistant output fits 320px at 2x in dark Cupertino', (
tester,
) async {
tester.view.physicalSize = const Size(640, 1200);
tester.view.devicePixelRatio = 2;
tester.platformDispatcher.textScaleFactorTestValue = 2;
tester.platformDispatcher.platformBrightnessTestValue = Brightness.dark;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
addTearDown(tester.platformDispatcher.clearPlatformBrightnessTestValue);
final gateway = FakeChatGateway();
addTearDown(gateway.close);
gateway.history = (_) async => chatPage([
chatMessage(
'a1',
'assistant',
parts: [
{
'type': 'text',
'text':
'## A long answer heading that wraps inside a narrow phone\n'
'\n'
'A paragraph long enough to wrap onto several lines without '
'clipping any words at twice the host text size.\n'
'\n'
'| Step | State |\n'
'| --- | --- |\n'
'| build | ok |\n'
'\n'
'```dart\n'
'final value = "a code line that scrolls sideways";\n'
'```',
},
],
),
]);
await tester.pumpWidget(
cupertinoHost(
ChatThreadView(gateway: gateway, sessionId: 's', onBack: () {}),
),
);
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
expect(
find.text('A long answer heading that wraps inside a narrow phone'),
findsOneWidget,
);
expect(find.text('build'), findsOneWidget);
expect(find.text('dart'), findsOneWidget);
expect(find.byType(Material), findsNothing);
});
}
/// The paged-history fixture shape: a page of consecutive assistant messages,