Chat: fold activity-only rows between messages into one summary line

Tool-only turns, thinking-only turns and background-task notices that sit
between two content rows become one collapsible activity_group row, e.g.
"Ran 7 commands · used 9 tools · 8 background tasks finished · 1 failed",
the failure count in the error colour and never ellipsized. Expanding it
shows the folded rows as they render on their own. A run's task notices
fold into one chip at the newest notice; a notice whose id recurs later is
counted only at its latest position.

Grouping is a pure domain step (groupChatActivity) applied last in the
thread view's row pipeline; group rows list every member id so ChatRowKeys
keeps their identity, unchanged runs return the identical group object, and
the transcript anchor accepts a group's agent-turn ids. The scroll fixture
gains ?bgwork=1 for the shape.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 10:58:25 +00:00
parent 33874005c4
commit 22866ec0ce
10 changed files with 963 additions and 13 deletions
@@ -0,0 +1,140 @@
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_draft_store.dart';
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
import 'package:pipelines_app/features/chat/ui/transcript/chat_activity_group_view.dart';
import 'package:pipelines_app/features/chat/ui/transcript/chat_task_notices_group.dart';
import 'package:pipelines_app/features/chat/ui/transcript/chat_turn_activity_view.dart';
import 'chat_thread_fixtures.dart';
/// Tool-only turns and background-task notices between two answers are one
/// summary line that opens to the rows as they render on their own.
JsonMap _notice(String id) => {
'id': id,
'role': 'assistant',
'kind': 'notice',
'parts': [
{'type': 'text', 'text': 'Background task finished: task $id'},
],
};
JsonMap _tool(String id, {bool failed = false}) => {
'type': 'tool',
'id': id,
'name': 'bash',
'state': {'status': failed ? 'error' : 'completed'},
};
JsonMap _text(String text) => {'type': 'text', 'text': text};
final _messages = [
chatMessage('u1', 'user', parts: [_text('Run the checks')]),
chatMessage('a1', 'assistant', parts: [_text('Starting them now.')]),
_notice('n1'),
chatMessage('w1', 'assistant', parts: [_tool('t1')]),
_notice('n2'),
_notice('n3'),
chatMessage(
'w2',
'assistant',
parts: [_tool('t2'), _tool('t3', failed: true)],
),
_notice('n4'),
chatMessage('a2', 'assistant', parts: [_text('All done.')]),
];
Future<void> _host(WidgetTester tester) async {
tester.view.physicalSize = const Size(1000, 1600);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final gateway = FakeChatGateway()..history = (_) async => chatPage(_messages);
addTearDown(gateway.close);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: ChatThreadView(
gateway: gateway,
sessionId: 's',
onBack: () {},
drafts: MemoryChatDraftStore(),
newOperationId: () => 'op',
),
),
),
);
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
await tester.pump();
}
void main() {
testWidgets('the activity summary expands to its rows and collapses again', (
tester,
) async {
final semantics = tester.ensureSemantics();
await _host(tester);
const label = 'Ran 3 commands · 4 background tasks finished · 1 failed';
final summary = find.byKey(const Key('chat-activity-group'));
expect(find.byType(ChatActivityGroupView), findsOneWidget);
expect(summary, findsOneWidget);
expect(
find.text('Ran 3 commands · 4 background tasks finished'),
findsOneWidget,
);
// The failure is drawn whole, in the error colour.
final failed = tester.widget<Text>(
find.byKey(const Key('chat-activity-group-failed')),
);
expect(failed.data, ' · 1 failed');
final context = tester.element(summary);
expect(failed.style?.color, Theme.of(context).colorScheme.error);
expect(
tester.getSemantics(summary),
matchesSemantics(
label: '$label, show all 3 activity rows',
isButton: true,
hasTapAction: true,
hasExpandedState: true,
isExpanded: false,
),
);
// Collapsed: neither the turns' own lines nor the notices are built; the
// answers on both sides still are.
expect(find.byType(ChatTurnActivityView), findsNothing);
expect(find.byType(ChatTaskNoticesGroup), findsNothing);
expect(find.text('Starting them now.'), findsOneWidget);
expect(find.text('All done.'), findsOneWidget);
await tester.tap(summary);
await tester.pumpAndSettle();
expect(find.text('Ran 1 command'), findsOneWidget);
expect(find.text('Ran 2 commands · 1 failed'), findsOneWidget);
// Every notice of the run is one chip, shown once at the newest notice.
expect(find.byType(ChatTaskNoticesGroup), findsOneWidget);
expect(find.text('4 background tasks'), findsOneWidget);
expect(
tester.getTopLeft(find.byType(ChatTaskNoticesGroup)).dy,
greaterThan(tester.getTopLeft(find.text('Ran 2 commands · 1 failed')).dy),
);
expect(
tester.getSemantics(summary),
matchesSemantics(
label: '$label, hide all 3 activity rows',
isButton: true,
hasTapAction: true,
hasExpandedState: true,
isExpanded: true,
),
);
await tester.tap(summary);
await tester.pumpAndSettle();
expect(find.byType(ChatTurnActivityView), findsNothing);
expect(find.byType(ChatTaskNoticesGroup), findsNothing);
semantics.dispose();
});
}
@@ -191,6 +191,12 @@ void main() {
greaterThan(width * 0.8),
);
// A task notice folds into the activity summary on the agent's side and
// shows as its own line once that is opened.
final summary = find.text('1 background task finished');
expect(summary, findsOneWidget);
await tester.tap(summary);
await _pump(tester);
final notice = find.text(
'Background task finished: Background command "Build" completed',
);
@@ -10,8 +10,8 @@ import 'package:pipelines_app/features/chat/ui/transcript/chat_task_notices_grou
import 'chat_thread_fixtures.dart';
/// Consecutive background-task notices are one collapsed chip on the agent's
/// side; it opens a sheet with one compact row per task. None of them is ever
/// the operator's bubble.
/// side, inside the activity summary they fold into; the chip opens a sheet
/// with one compact row per task. None of them is ever the operator's bubble.
JsonMap _notice(String id, String text) => {
'id': id,
@@ -73,11 +73,18 @@ Future<FakeChatGateway> _host(
return gateway;
}
/// Opens the activity summary the notices fold into.
Future<void> _expand(WidgetTester tester, String label) async {
await tester.tap(find.text(label));
await _pump(tester);
}
void main() {
testWidgets('consecutive task notices are one chip that opens to each task', (
tester,
) async {
await _host(tester, _messages);
await _expand(tester, '3 background tasks ended');
expect(find.byType(ChatTaskNoticesGroup), findsOneWidget);
expect(find.byType(ChatSystemNoticeLine), findsNothing);
@@ -122,6 +129,7 @@ void main() {
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());
await _expand(tester, '1 background task finished');
expect(find.byType(ChatSystemNoticeLine), findsOneWidget);
expect(find.byType(ChatTaskNoticesGroup), findsNothing);
@@ -136,6 +144,8 @@ void main() {
'failed (exit code 1)',
});
await _pump(tester);
// The summary keeps its place and open state as the notice joins it.
expect(find.text('2 background tasks ended'), findsOneWidget);
expect(find.byType(ChatSystemNoticeLine), findsNothing);
expect(find.text('2 background tasks · 1 failed'), findsOneWidget);
expect(find.byType(ChatUserBubble), findsOneWidget);