Show recorded timing and progress in background task lists

This commit is contained in:
2026-11-06 15:08:11 +00:00
parent c9a4cd0bf6
commit 6dfb5d7a4b
9 changed files with 513 additions and 9 deletions
@@ -0,0 +1,170 @@
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_tasks_controller.dart';
import 'package:pipelines_app/features/chat/conversation/chat_background_tasks_panel.dart';
import 'package:pipelines_app/features/chat/conversation/chat_task_metadata_view.dart';
import 'chat_background_tasks_fixtures.dart';
void main() {
for (final cupertino in [false, true]) {
testWidgets(
'recorded facts wrap at 2x, tick without requests, dispose clock ($cupertino)',
(tester) async {
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
var now = DateTime.utc(2026, 11, 6, 10);
var clockReads = 0;
final gateway = TasksGateway()
..shells = (_) async => {
'chat_shells': [
{
'id': 'a',
'status': 'running',
'command': 'Review integration changes',
'started_at': now
.subtract(const Duration(minutes: 2))
.millisecondsSinceEpoch,
'progress':
'Checking the targeted tests and reviewing the remaining findings',
'tool_count': 18,
'token_count': 12450,
},
],
};
final controller = ChatBackgroundTasksController(gateway, 's');
addTearDown(controller.dispose);
addTearDown(gateway.close);
final panel = ChatBackgroundTasksPanel(
controller: controller,
clock: () {
clockReads++;
return now;
},
);
Widget builder(BuildContext context, Widget? child) => MediaQuery(
data: MediaQuery.of(
context,
).copyWith(textScaler: const TextScaler.linear(2)),
child: child!,
);
await tester.pumpWidget(
cupertino
? CupertinoApp(
builder: builder,
home: CupertinoPageScaffold(
child: SingleChildScrollView(child: panel),
),
)
: MaterialApp(
builder: builder,
home: Scaffold(body: SingleChildScrollView(child: panel)),
),
);
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);
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(gateway.calls.length, requests);
expect(
gateway.calls.where((call) => call.type == 'chat_shell_output'),
isEmpty,
);
expect(tester.takeException(), isNull);
await tester.pumpWidget(const SizedBox.shrink());
final stoppedAt = clockReads;
await tester.pump(const Duration(seconds: 11));
expect(clockReads, stoppedAt);
expect(tester.takeException(), isNull);
},
);
}
testWidgets(
'selected detail keeps full metadata and requests only its output',
(tester) async {
final gateway = TasksGateway()
..shells = (_) async => {
'chat_shells': [
{
'id': 'a',
'status': 'running',
'command': 'Agent: Review integration',
'description': 'Review integration',
'last_tool': 'Read',
'started_at': DateTime.utc(2026, 11, 6, 9).millisecondsSinceEpoch,
'updated_at': DateTime.utc(
2026,
11,
6,
9,
20,
).millisecondsSinceEpoch,
},
],
};
final controller = ChatBackgroundTasksController(gateway, 's');
addTearDown(controller.dispose);
addTearDown(gateway.close);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: SingleChildScrollView(
child: ChatBackgroundTasksPanel(
controller: controller,
clock: () => DateTime.utc(2026, 11, 6, 10),
),
),
),
),
);
await tester.pumpAndSettle();
expect(find.text('Review integration'), findsOneWidget);
expect(find.text('Last tool: 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(
gateway.calls.where((call) => call.type == 'chat_shell_output'),
hasLength(1),
);
await tester.pumpWidget(const SizedBox.shrink());
},
);
testWidgets('unknown start and reported runtime stay distinct from elapsed', (
tester,
) async {
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: ChatTaskMetadataView(
shell: const {'duration_ms': 74000, 'tool_count': 0},
now: DateTime.utc(2026, 11, 6),
),
),
),
);
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.textContaining('tokens'), findsNothing);
});
}