Present background tasks as adaptive status cards

This commit is contained in:
2026-11-06 23:58:05 +00:00
parent d739166cf9
commit cd175e099b
11 changed files with 945 additions and 392 deletions
@@ -65,13 +65,14 @@ void main() {
),
);
await tester.pumpAndSettle();
expect(find.text('Running · 2m 0s'), findsOneWidget);
expect(find.text('18 tool calls · 12450 tokens'), findsOneWidget);
expect(find.textContaining('Started 6 November 2026'), findsOneWidget);
expect(find.text('2m 0s'), findsOneWidget);
expect(find.text('18'), findsOneWidget);
expect(find.text('12,450'), findsOneWidget);
expect(find.textContaining('6 November 2026'), findsOneWidget);
final requests = gateway.calls.length;
now = now.add(const Duration(seconds: 11));
await tester.pump(const Duration(seconds: 11));
expect(find.text('Running · 2m 11s'), findsOneWidget);
expect(find.text('2m 11s'), findsOneWidget);
expect(gateway.calls.length, requests);
expect(
gateway.calls.where((call) => call.type == 'chat_shell_output'),
@@ -127,19 +128,16 @@ void main() {
);
await tester.pumpAndSettle();
expect(find.text('Review integration'), findsOneWidget);
expect(find.text('Last tool: Read'), findsNothing);
expect(find.text('Read'), findsNothing);
expect(
gateway.calls.where((call) => call.type == 'chat_shell_output'),
isEmpty,
);
await tester.tap(find.byKey(const ValueKey('chat-bg-task-a')));
await tester.pumpAndSettle();
expect(find.text('Agent: Review integration'), findsOneWidget);
expect(find.text('Last tool: Read'), findsOneWidget);
expect(
find.textContaining('Last update 6 November 2026'),
findsOneWidget,
);
expect(find.text('Review integration'), findsOneWidget);
expect(find.text('Read'), findsOneWidget);
expect(find.textContaining('09:20'), findsOneWidget);
expect(
gateway.calls.where((call) => call.type == 'chat_shell_output'),
hasLength(1),
@@ -162,9 +160,11 @@ void main() {
),
);
expect(find.text('Start time unavailable'), findsOneWidget);
expect(find.text('Reported runtime: 1m 14s'), findsOneWidget);
expect(find.text('Running'), findsOneWidget);
expect(find.text('0 tool calls'), findsOneWidget);
expect(find.text('Reported runtime'), findsOneWidget);
expect(find.text('1m 14s'), findsOneWidget);
expect(find.text('Running'), findsNothing);
expect(find.text('Tool calls'), findsOneWidget);
expect(find.text('0'), findsOneWidget);
expect(find.textContaining('tokens'), findsNothing);
});
}
@@ -0,0 +1,109 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/conversation/chat_background_task_card.dart';
import 'package:pipelines_app/features/chat/conversation/chat_background_tasks_controller.dart';
import 'package:pipelines_app/features/chat/conversation/chat_background_tasks_panel.dart';
import 'package:pipelines_app/features/chat/conversation/chat_task_presentation.dart';
import 'chat_background_tasks_fixtures.dart';
const example = 'Reading screenshots/intake-ui-review-r2/23-more-menu.png';
void main() {
test(
'progress comparison suppresses exact, prefixed and whitespace duplicates',
() {
for (final command in [
example,
'Agent: $example',
'Agent: Reading\n screenshots/intake-ui-review-r2/23-more-menu.png',
]) {
expect(
distinctTaskProgress({'command': command, 'progress': example}),
isNull,
);
}
expect(
distinctTaskProgress({
'description': example,
'progress': 'Checking test results',
}),
'Checking test results',
);
expect(formatTaskCount(120905), '120,905');
expect(formatTaskCount(0), '0');
},
);
for (final cupertino in [false, true]) {
testWidgets(
'one task has GUI hierarchy, no duplicate path, explicit lazy details ($cupertino)',
(tester) async {
tester.view.physicalSize = const Size(560, 1000);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final now = DateTime.utc(2026, 11, 6, 23, 44, 40);
final gateway = TasksGateway()
..shells = (_) async => {
'chat_shells': [
{
'id': 'example',
'status': 'running',
'task_type': 'local_agent',
'command': example,
'description': example,
'progress': example,
'started_at': now
.subtract(const Duration(minutes: 4, seconds: 40))
.millisecondsSinceEpoch,
'tool_count': 37,
'token_count': 120905,
},
],
};
final controller = ChatBackgroundTasksController(gateway, 's');
addTearDown(controller.dispose);
addTearDown(gateway.close);
final panel = SingleChildScrollView(
child: ChatBackgroundTasksPanel(
controller: controller,
clock: () => now,
),
);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: panel))
: MaterialApp(home: Scaffold(body: panel)),
);
await tester.pumpAndSettle();
expect(find.byType(ChatBackgroundTaskCard), findsOneWidget);
expect(find.byType(ChatTaskSurface), findsOneWidget);
expect(find.text(example), findsOneWidget);
expect(find.text('4m 40s'), findsOneWidget);
expect(find.text('Running'), findsOneWidget);
expect(find.text('120,905'), findsOneWidget);
expect(find.text('Tokens'), findsOneWidget);
expect(find.text('37'), findsOneWidget);
expect(find.text('Tool calls'), findsOneWidget);
expect(find.text('Details'), findsOneWidget);
expect(
gateway.calls.where((call) => call.type == 'chat_shell_output'),
isEmpty,
);
await tester.tap(find.byKey(const ValueKey('chat-bg-task-example')));
await tester.pumpAndSettle();
expect(find.text(example), findsOneWidget);
expect(find.text('Hide details'), findsOneWidget);
expect(find.text('Output'), findsOneWidget);
expect(
gateway.calls.where((call) => call.type == 'chat_shell_output'),
hasLength(1),
);
expect(tester.takeException(), isNull);
await tester.pumpWidget(const SizedBox.shrink());
},
);
}
}
@@ -212,7 +212,7 @@ void main() {
await _openTasks(tester);
expect(find.text('4 running'), findsOneWidget);
expect(find.byType(AlertDialog), findsOneWidget);
expect(find.byType(Dialog), findsOneWidget);
expect(find.byType(SingleChildScrollView), findsWidgets);
for (var index = 0; index < 4; index++) {
expect(
@@ -253,10 +253,10 @@ void main() {
},
]);
expect(find.byKey(const Key('chat-bg-task-detail')), findsOneWidget);
expect(find.text('Command'), findsOneWidget);
expect(find.text('Command'), findsNothing);
expect(find.text('Task identity'), findsOneWidget);
expect(find.text('sh1'), findsOneWidget);
expect(find.text('Status: running'), findsOneWidget);
expect(find.text('Running'), findsOneWidget);
expect(find.text('Output'), findsOneWidget);
expect(
tester
@@ -417,8 +417,8 @@ void main() {
expect(find.text('1 running'), findsOneWidget);
await _tapTask(tester, 'sh1');
expect(find.text('Command'), findsOneWidget);
expect(find.text('Status: running'), findsOneWidget);
expect(find.text('Command'), findsNothing);
expect(find.text('Running'), findsOneWidget);
expect(
tester
.widget<SelectableText>(find.byKey(const Key('chat-bg-task-output')))
@@ -468,6 +468,8 @@ void main() {
tester.widget<SelectableText>(outputFinder).data,
contains('line 199'),
);
await tester.ensureVisible(outputFinder);
await tester.pumpAndSettle();
final scrollable = tester.state<ScrollableState>(
find.descendant(of: outputFinder, matching: find.byType(Scrollable)),
);