Chat: draw agent follow-ups and automatic continues apart from the operator

The server now names a user turn's origin (followup, auto_continue,
auto_switch, scheduled) on chat messages, user frames and queued prompts,
from the prompt's operation id while it holds the prompt and from its own
text prefixes in history read later. Origin is a new field, so older
clients keep treating these as ordinary user turns.

The app draws an agent follow-up, auto-continue and account-switch prompt
as a quiet outlined card on the agent's side with an icon, label and the
schedule facts from the preamble; the operator's own scheduled message
keeps its bubble with a small Scheduled mark. Find searches the drawn text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 15:40:34 +00:00
parent 608b6b8edb
commit 9a6363b80e
22 changed files with 946 additions and 26 deletions
@@ -0,0 +1,183 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/chat/ui/transcript/chat_message_bubble.dart';
import 'package:pipelines_app/features/chat/ui/transcript/chat_message_view.dart';
JsonMap _row(Map<String, dynamic> message) => {
'kind': 'user',
'key': message['id'],
'message': message,
};
JsonMap _message(String text, [Map<String, dynamic> extra = const {}]) => {
'id': 'u1',
'role': 'user',
'created_at': DateTime.utc(2026, 12, 3, 11).millisecondsSinceEpoch,
'client': 'Agent follow-up',
'parts': [
{'type': 'text', 'text': text},
],
...extra,
};
const _followup =
'[Follow-up you scheduled at 2026-12-03T10:00:00Z with schedule_followup] '
'Check the deploy finished.';
Widget _host(
JsonMap row, {
Brightness brightness = Brightness.light,
bool scheduleShown = false,
}) => MaterialApp(
theme: ThemeData(brightness: brightness),
home: Scaffold(
body: ListView(
children: [ChatMessageView(row: row, scheduleShown: scheduleShown)],
),
),
);
void _wide(WidgetTester tester) {
tester.view.physicalSize = const Size(1000, 800);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
}
void main() {
for (final brightness in Brightness.values) {
testWidgets('an agent follow-up is a quiet card on the agent side '
'(${brightness.name})', (tester) async {
_wide(tester);
await tester.pumpWidget(
_host(
_row(_message(_followup, {'origin': 'followup'})),
brightness: brightness,
),
);
expect(find.byType(ChatUserBubble), findsNothing);
final card = find.byKey(const Key('chat-automated-prompt'));
expect(card, findsOneWidget);
expect(find.text('Follow-up from agent'), findsOneWidget);
expect(find.textContaining('· scheduled '), findsOneWidget);
expect(find.byIcon(Icons.update), findsOneWidget);
// The preamble is header facts, not body text; the sender label is not
// repeated inside the card.
expect(find.text('Check the deploy finished.'), findsOneWidget);
expect(find.textContaining('[Follow-up'), findsNothing);
expect(find.text('Agent follow-up'), findsNothing);
// Start-aligned, not on the operator's trailing side.
expect(tester.getTopLeft(card).dx, lessThan(40));
final material = tester.widget<Material>(card);
final scheme = Theme.of(tester.element(card)).colorScheme;
expect(material.color, scheme.surfaceContainerLow);
expect(
(material.shape! as RoundedRectangleBorder).side.color,
scheme.outlineVariant,
);
expect(
find.bySemanticsLabel('Follow-up from agent message'),
findsOneWidget,
);
});
}
testWidgets('the follow-up body stays selectable and copies without the '
'preamble', (tester) async {
_wide(tester);
String? copied;
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
SystemChannels.platform,
(call) async {
if (call.method == 'Clipboard.setData') {
copied = (call.arguments as Map)['text'] as String?;
}
return null;
},
);
addTearDown(
() => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
SystemChannels.platform,
null,
),
);
await tester.pumpWidget(
_host(_row(_message(_followup, {'operation_id': 'followup-ab'}))),
);
expect(
find.widgetWithText(SelectableText, 'Check the deploy finished.'),
findsOneWidget,
);
await tester.tap(find.byKey(const Key('chat-message-copy')));
await tester.pump();
expect(copied, 'Check the deploy finished.');
await tester.pump(const Duration(seconds: 3));
});
testWidgets('auto-continue and auto-switch name the server', (tester) async {
_wide(tester);
await tester.pumpWidget(
_host(_row(_message('continue', {'origin': 'auto_continue'}))),
);
expect(find.text('Auto-continue after limit reset'), findsOneWidget);
expect(find.text('continue'), findsOneWidget);
await tester.pumpWidget(
_host(
_row(
_message('[Sent automatically by Pipelines] Usage ran out on a.', {
'operation_id': 'auto-switch-m1',
}),
),
),
);
expect(find.text('Continued on another account'), findsOneWidget);
expect(find.text('Usage ran out on a.'), findsOneWidget);
});
testWidgets('a run follow-up says what it waited for', (tester) async {
_wide(tester);
await tester.pumpWidget(
_host(
_row(
_message(
'[Follow-up you scheduled at 2026-12-03T10:00:00Z with '
'schedule_followup, for when run 42 finishes; delivered at '
'2026-12-04T10:00:00Z at the latest] Review it.',
),
),
),
);
expect(find.text('· when run 42 finishes'), findsOneWidget);
expect(find.text('Review it.'), findsOneWidget);
});
testWidgets("the operator's scheduled message keeps its bubble with a mark", (
tester,
) async {
_wide(tester);
final row = _row(
_message('send this later', {'origin': 'scheduled', 'client': 'Laptop'}),
);
await tester.pumpWidget(_host(row));
expect(find.byType(ChatUserBubble), findsOneWidget);
expect(find.byKey(const Key('chat-automated-prompt')), findsNothing);
expect(find.byKey(const Key('chat-scheduled-mark')), findsOneWidget);
expect(find.text('Laptop'), findsOneWidget);
// While the delivery line already reads "Scheduled · sends at", no mark.
await tester.pumpWidget(_host(row, scheduleShown: true));
expect(find.byKey(const Key('chat-scheduled-mark')), findsNothing);
});
testWidgets('an ordinary message is unchanged', (tester) async {
_wide(tester);
await tester.pumpWidget(
_host(_row(_message('hello', {'client': 'Phone'}))),
);
expect(find.byType(ChatUserBubble), findsOneWidget);
expect(find.byKey(const Key('chat-scheduled-mark')), findsNothing);
expect(find.byKey(const Key('chat-automated-prompt')), findsNothing);
expect(find.bySemanticsLabel('User message'), findsOneWidget);
});
}