Show recorded timing and progress in background task lists
This commit is contained in:
@@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
|
|||||||
|
|
||||||
import '../../../core/api_gateway.dart';
|
import '../../../core/api_gateway.dart';
|
||||||
import '../domain/chat_shells.dart';
|
import '../domain/chat_shells.dart';
|
||||||
|
import 'chat_task_metadata_view.dart';
|
||||||
import '../ui/sessions/chat_adaptive.dart';
|
import '../ui/sessions/chat_adaptive.dart';
|
||||||
import '../../../ui/text/monospace.dart';
|
import '../../../ui/text/monospace.dart';
|
||||||
|
|
||||||
@@ -30,12 +31,14 @@ class ChatBackgroundTaskDetail extends StatelessWidget {
|
|||||||
const ChatBackgroundTaskDetail({
|
const ChatBackgroundTaskDetail({
|
||||||
super.key,
|
super.key,
|
||||||
required this.shell,
|
required this.shell,
|
||||||
|
required this.now,
|
||||||
required this.output,
|
required this.output,
|
||||||
required this.heightBudget,
|
required this.heightBudget,
|
||||||
required this.onRefresh,
|
required this.onRefresh,
|
||||||
});
|
});
|
||||||
|
|
||||||
final JsonMap shell;
|
final JsonMap shell;
|
||||||
|
final DateTime now;
|
||||||
final ChatShellOutputSnapshot? output;
|
final ChatShellOutputSnapshot? output;
|
||||||
|
|
||||||
/// The modal viewport's height budget, used to bound its selectable output.
|
/// The modal viewport's height budget, used to bound its selectable output.
|
||||||
@@ -67,6 +70,7 @@ class ChatBackgroundTaskDetail extends StatelessWidget {
|
|||||||
style: const TextStyle(fontFamily: appMonospaceFamily),
|
style: const TextStyle(fontFamily: appMonospaceFamily),
|
||||||
),
|
),
|
||||||
Text(shellStatusRunningLabel),
|
Text(shellStatusRunningLabel),
|
||||||
|
ChatTaskMetadataView(shell: shell, now: now, detail: true),
|
||||||
_outputArea(context, cupertino),
|
_outputArea(context, cupertino),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,21 +1,54 @@
|
|||||||
|
import 'dart:async';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import '../domain/chat_shells.dart';
|
import '../domain/chat_shells.dart';
|
||||||
|
import '../domain/chat_task_metadata.dart';
|
||||||
import '../ui/sessions/chat_adaptive.dart';
|
import '../ui/sessions/chat_adaptive.dart';
|
||||||
import 'chat_background_task_detail.dart';
|
import 'chat_background_task_detail.dart';
|
||||||
import 'chat_background_tasks_controller.dart';
|
import 'chat_background_tasks_controller.dart';
|
||||||
|
import 'chat_task_metadata_view.dart';
|
||||||
|
|
||||||
/// Scrollable modal content, backed by the same live controller as its badge.
|
/// Scrollable modal content, backed by the same live controller as its badge.
|
||||||
class ChatBackgroundTasksPanel extends StatelessWidget {
|
class ChatBackgroundTasksPanel extends StatefulWidget {
|
||||||
const ChatBackgroundTasksPanel({super.key, required this.controller});
|
const ChatBackgroundTasksPanel({
|
||||||
|
super.key,
|
||||||
|
required this.controller,
|
||||||
|
this.clock,
|
||||||
|
});
|
||||||
|
|
||||||
final ChatBackgroundTasksController controller;
|
final ChatBackgroundTasksController controller;
|
||||||
|
final DateTime Function()? clock;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<ChatBackgroundTasksPanel> createState() =>
|
||||||
|
_ChatBackgroundTasksPanelState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ChatBackgroundTasksPanelState extends State<ChatBackgroundTasksPanel> {
|
||||||
|
late final Timer _ticker;
|
||||||
|
ChatBackgroundTasksController get controller => widget.controller;
|
||||||
|
DateTime get now => (widget.clock ?? DateTime.now)();
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_ticker = Timer.periodic(const Duration(seconds: 1), (_) {
|
||||||
|
if (mounted && widget.controller.running.isNotEmpty) setState(() {});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_ticker.cancel();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) => ListenableBuilder(
|
Widget build(BuildContext context) => ListenableBuilder(
|
||||||
listenable: controller,
|
listenable: controller,
|
||||||
builder: (context, _) {
|
builder: (context, _) {
|
||||||
|
final at = now;
|
||||||
final cupertino =
|
final cupertino =
|
||||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||||
final running = controller.running;
|
final running = controller.running;
|
||||||
@@ -44,11 +77,12 @@ class ChatBackgroundTasksPanel extends StatelessWidget {
|
|||||||
if (running.isNotEmpty)
|
if (running.isNotEmpty)
|
||||||
Text(backgroundTasksRunningLabel(running.length)),
|
Text(backgroundTasksRunningLabel(running.length)),
|
||||||
for (final task in running) ...[
|
for (final task in running) ...[
|
||||||
_taskRow(context, task, cupertino),
|
_taskRow(context, task, cupertino, at),
|
||||||
if (shell != null && shellIdOf(task) == controller.selectedId)
|
if (shell != null && shellIdOf(task) == controller.selectedId)
|
||||||
ChatBackgroundTaskDetail(
|
ChatBackgroundTaskDetail(
|
||||||
key: const Key('chat-bg-task-detail'),
|
key: const Key('chat-bg-task-detail'),
|
||||||
shell: shell,
|
shell: shell,
|
||||||
|
now: at,
|
||||||
output: controller.output,
|
output: controller.output,
|
||||||
heightBudget: MediaQuery.sizeOf(context).height,
|
heightBudget: MediaQuery.sizeOf(context).height,
|
||||||
onRefresh: controller.readOutput,
|
onRefresh: controller.readOutput,
|
||||||
@@ -63,11 +97,12 @@ class ChatBackgroundTasksPanel extends StatelessWidget {
|
|||||||
BuildContext context,
|
BuildContext context,
|
||||||
Map<String, dynamic> shell,
|
Map<String, dynamic> shell,
|
||||||
bool cupertino,
|
bool cupertino,
|
||||||
|
DateTime at,
|
||||||
) {
|
) {
|
||||||
final id = shellIdOf(shell);
|
final id = shellIdOf(shell);
|
||||||
final selected = controller.selectedId == id;
|
final selected = controller.selectedId == id;
|
||||||
final title = Text(
|
final title = Text(
|
||||||
shellCommandSummary(shell['command']),
|
shellCommandSummary(taskText(shell, 'description') ?? shell['command']),
|
||||||
maxLines: 2,
|
maxLines: 2,
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
);
|
);
|
||||||
@@ -77,7 +112,7 @@ class ChatBackgroundTasksPanel extends StatelessWidget {
|
|||||||
child: CupertinoListTile(
|
child: CupertinoListTile(
|
||||||
key: ValueKey('chat-bg-task-$id'),
|
key: ValueKey('chat-bg-task-$id'),
|
||||||
title: title,
|
title: title,
|
||||||
subtitle: const Text(shellRowLabel),
|
subtitle: ChatTaskMetadataView(shell: shell, now: at),
|
||||||
backgroundColor: selected
|
backgroundColor: selected
|
||||||
? CupertinoColors.tertiarySystemFill.resolveFrom(context)
|
? CupertinoColors.tertiarySystemFill.resolveFrom(context)
|
||||||
: null,
|
: null,
|
||||||
@@ -88,7 +123,7 @@ class ChatBackgroundTasksPanel extends StatelessWidget {
|
|||||||
return ListTile(
|
return ListTile(
|
||||||
key: ValueKey('chat-bg-task-$id'),
|
key: ValueKey('chat-bg-task-$id'),
|
||||||
title: title,
|
title: title,
|
||||||
subtitle: const Text(shellRowLabel),
|
subtitle: ChatTaskMetadataView(shell: shell, now: at),
|
||||||
selected: selected,
|
selected: selected,
|
||||||
onTap: () => controller.select(id),
|
onTap: () => controller.select(id),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,96 @@
|
|||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import '../../../core/api_gateway.dart';
|
||||||
|
import '../domain/chat_task_metadata.dart';
|
||||||
|
|
||||||
|
/// Recorded task facts in the row, with unabridged progress in selected detail.
|
||||||
|
class ChatTaskMetadataView extends StatelessWidget {
|
||||||
|
const ChatTaskMetadataView({
|
||||||
|
super.key,
|
||||||
|
required this.shell,
|
||||||
|
required this.now,
|
||||||
|
this.detail = false,
|
||||||
|
});
|
||||||
|
|
||||||
|
final JsonMap shell;
|
||||||
|
final DateTime now;
|
||||||
|
final bool detail;
|
||||||
|
|
||||||
|
String _date(BuildContext context, DateTime time) {
|
||||||
|
final material = Localizations.of<MaterialLocalizations>(
|
||||||
|
context,
|
||||||
|
MaterialLocalizations,
|
||||||
|
);
|
||||||
|
final date = material != null
|
||||||
|
? '${time.day} ${material.formatMonthYear(time)}'
|
||||||
|
: '${time.day} ${CupertinoLocalizations.of(context).datePickerMonth(time.month)} ${time.year}';
|
||||||
|
return '$date · ${time.hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')}';
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final start = taskInstant(shell, 'started_at');
|
||||||
|
final elapsed = taskElapsed(shell, now);
|
||||||
|
final duration = taskNumber(shell, 'duration_ms');
|
||||||
|
final updated = taskInstant(shell, 'updated_at');
|
||||||
|
final description = taskText(shell, 'description');
|
||||||
|
final progress = taskText(shell, 'progress');
|
||||||
|
final kind = taskText(shell, 'task_type');
|
||||||
|
final lastTool = taskText(shell, 'last_tool');
|
||||||
|
final tools = taskNumber(shell, 'tool_count');
|
||||||
|
final tokens = taskNumber(shell, 'token_count');
|
||||||
|
final counters = [
|
||||||
|
if (tools != null) '$tools tool calls',
|
||||||
|
if (tokens != null) '$tokens tokens',
|
||||||
|
];
|
||||||
|
final state = elapsed == null
|
||||||
|
? 'Running'
|
||||||
|
: 'Running · ${taskDuration(elapsed)}';
|
||||||
|
final kindLabel = kind == null
|
||||||
|
? null
|
||||||
|
: '${kind[0].toUpperCase()}${kind.substring(1).replaceAll('_', ' ')}';
|
||||||
|
final summary =
|
||||||
|
progress ??
|
||||||
|
(description != null &&
|
||||||
|
!'${shell['command'] ?? ''}'.endsWith(description)
|
||||||
|
? description
|
||||||
|
: null);
|
||||||
|
final facts = <String>[
|
||||||
|
if (!detail) kindLabel == null ? state : '$kindLabel · $state',
|
||||||
|
if (detail && elapsed != null) 'Elapsed: ${taskDuration(elapsed)}',
|
||||||
|
start == null
|
||||||
|
? 'Start time unavailable'
|
||||||
|
: 'Started ${_date(context, start)}',
|
||||||
|
if (start != null && elapsed == null)
|
||||||
|
'Start time is ahead of this device’s clock',
|
||||||
|
if (elapsed == null && duration != null)
|
||||||
|
'Reported runtime: ${taskDuration(Duration(milliseconds: duration))}',
|
||||||
|
if (detail) ...[?kindLabel, ?description, ?progress] else ...[?summary],
|
||||||
|
if (counters.isNotEmpty) counters.join(' · '),
|
||||||
|
if (detail && lastTool != null) 'Last tool: $lastTool',
|
||||||
|
if (detail && updated != null) 'Last update ${_date(context, updated)}',
|
||||||
|
];
|
||||||
|
// CupertinoListTile supplies a one-line default; explicitly allow metadata
|
||||||
|
// to wrap and grow with the available width and system text scaling.
|
||||||
|
return DefaultTextStyle(
|
||||||
|
style: DefaultTextStyle.of(context).style,
|
||||||
|
softWrap: true,
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
for (final fact in facts)
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 2),
|
||||||
|
child: Text(
|
||||||
|
fact,
|
||||||
|
maxLines: detail ? null : 2,
|
||||||
|
overflow: detail ? TextOverflow.clip : TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -71,7 +71,11 @@ List<JsonMap> mergeShellFrame(List<JsonMap> shells, JsonMap? shell) {
|
|||||||
final index = next.indexWhere((candidate) => shellIdOf(candidate) == id);
|
final index = next.indexWhere((candidate) => shellIdOf(candidate) == id);
|
||||||
final prior = index >= 0 ? next[index] : null;
|
final prior = index >= 0 ? next[index] : null;
|
||||||
final merged = <String, dynamic>{
|
final merged = <String, dynamic>{
|
||||||
...shell,
|
...?prior,
|
||||||
|
for (final entry in shell.entries)
|
||||||
|
if (entry.value != null &&
|
||||||
|
!(entry.value is String && (entry.value as String).trim().isEmpty))
|
||||||
|
entry.key: entry.value,
|
||||||
'id': id,
|
'id': id,
|
||||||
'command': blankShellValue(shell['command'])
|
'command': blankShellValue(shell['command'])
|
||||||
? (prior?['command'] ?? '')
|
? (prior?['command'] ?? '')
|
||||||
@@ -100,7 +104,13 @@ List<JsonMap> shellsLoaded(List<JsonMap> shells, List<JsonMap> running) {
|
|||||||
}
|
}
|
||||||
for (final shell in running) {
|
for (final shell in running) {
|
||||||
if (blankShellValue(shell['id'])) continue;
|
if (blankShellValue(shell['id'])) continue;
|
||||||
byId[shellIdOf(shell)] = shell;
|
final prior = shells
|
||||||
|
.where((entry) => shellIdOf(entry) == shellIdOf(shell))
|
||||||
|
.firstOrNull;
|
||||||
|
byId[shellIdOf(shell)] = mergeShellFrame(
|
||||||
|
prior == null ? const [] : [prior],
|
||||||
|
shell,
|
||||||
|
).single;
|
||||||
}
|
}
|
||||||
final values = byId.values.toList();
|
final values = byId.values.toList();
|
||||||
return values.length <= observedShellLimit
|
return values.length <= observedShellLimit
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
import '../../../core/api_gateway.dart';
|
||||||
|
|
||||||
|
/// Optional numeric facts are present only when finite, integral and nonnegative.
|
||||||
|
int? taskNumber(JsonMap shell, String field) {
|
||||||
|
final value = shell[field];
|
||||||
|
if (value is! num ||
|
||||||
|
!value.isFinite ||
|
||||||
|
value < 0 ||
|
||||||
|
value > 8640000000000000 ||
|
||||||
|
value != value.roundToDouble()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return value.toInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
DateTime? taskInstant(JsonMap shell, String field) {
|
||||||
|
final millis = taskNumber(shell, field);
|
||||||
|
return millis == null || millis == 0
|
||||||
|
? null
|
||||||
|
: DateTime.fromMillisecondsSinceEpoch(millis, isUtc: true).toLocal();
|
||||||
|
}
|
||||||
|
|
||||||
|
String? taskText(JsonMap shell, String field) {
|
||||||
|
final value = shell[field];
|
||||||
|
return value is String && value.trim().isNotEmpty ? value.trim() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A clock ahead of this device is not a negative runtime.
|
||||||
|
Duration? taskElapsed(JsonMap shell, DateTime now) {
|
||||||
|
final start = taskInstant(shell, 'started_at');
|
||||||
|
if (start == null || start.isAfter(now)) return null;
|
||||||
|
return now.difference(start);
|
||||||
|
}
|
||||||
|
|
||||||
|
String taskDuration(Duration elapsed) {
|
||||||
|
if (elapsed.inDays > 0) return '${elapsed.inDays}d ${elapsed.inHours % 24}h';
|
||||||
|
if (elapsed.inHours > 0) {
|
||||||
|
return '${elapsed.inHours}h ${elapsed.inMinutes % 60}m';
|
||||||
|
}
|
||||||
|
if (elapsed.inMinutes > 0) {
|
||||||
|
return '${elapsed.inMinutes}m ${elapsed.inSeconds % 60}s';
|
||||||
|
}
|
||||||
|
return '${elapsed.inSeconds}s';
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
# Rich background task list
|
||||||
|
|
||||||
|
Task rows now use the recorded description as their title (retaining the full command in selected detail). Native Material and Cupertino rows show task type/status and elapsed runtime, a day-first written local start date with 24-hour time, one bounded progress/description preview, and available tool/token counts. Selecting a task exposes the full command and identity, full progress/description, last tool, last update, counters and the existing lazy bounded output page.
|
||||||
|
|
||||||
|
Only recorded `started_at` drives elapsed time. Missing or invalid starts say “Start time unavailable”; an upstream `duration_ms` is labelled “Reported runtime” and never presented as a clock-derived uptime. Future starts report clock skew instead of a negative runtime. Zero counters remain distinguishable from absent counters.
|
||||||
|
|
||||||
|
One timer belongs to the mounted modal panel and captures one clock value per rebuild for all rows/detail. Closing/disposal cancels it. Ticks neither poll the server nor load output. Streaming partial frames and snapshots preserve metadata already learned without retaining tasks the current server snapshot no longer lists.
|
||||||
|
|
||||||
|
Focused watchdog checks: 36 existing shell/domain/background-controller/modal tests passed (peak 1296 MB, 12s); 6 new metadata/clock/layout/selection tests passed (peak 794 MB, 4s). Tests cover both native hosts at 390px and 2x text, duration/clock-skew/malformed values, partial metadata, no new requests on timer ticks, timer disposal, and lazy output only when selected. Bounded analysis was clean before the final opt-in fixture polish; final analysis and integration results follow below.
|
||||||
|
|
||||||
|
Rendered evidence uses the real full-app scratch fixture with opt-in `chats=1&tasks=rich`. Inspected wide Material light list/detail at `/private/tmp/background-task-ui-wide-final/01-list.png` and `02-detail.png`, narrow Material dark list/detail at `/private/tmp/background-task-ui-narrow-final/01-list.png` and `02-detail.png`, and Cupertino light list at `/private/tmp/background-task-ui-cupertino-final/01-list.png`. The native dialogs scroll selected detail and keep output bounded. Capture-owned servers and browsers exited normally. No production chats, devices or services were modified. Metadata availability depends on the backend update and provider support; the frontend never invents missing facts.
|
||||||
|
|
||||||
|
Final integration: `tool/memwatch/full.sh 'test/features/chat/conversation test/features/chat/domain --no-pub'` passed all 522 tests (peak 1966 MB, 44s), log `/tmp/memwatch/out.YASMW0`. Final bounded analysis of every changed Dart path is clean. Fresh fixture web build (including Wasm dry run) passed. Screenshot list/detail interactions succeeded and all five final PNGs were inspected. No physical-device or Safari acceptance is claimed.
|
||||||
@@ -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);
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:pipelines_app/features/chat/domain/chat_shells.dart';
|
||||||
|
import 'package:pipelines_app/features/chat/domain/chat_task_metadata.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
test('missing, malformed and future start never invent an elapsed time', () {
|
||||||
|
final now = DateTime.utc(2026, 11, 6, 10);
|
||||||
|
for (final value in [
|
||||||
|
null,
|
||||||
|
0,
|
||||||
|
-1,
|
||||||
|
'2026-11-06',
|
||||||
|
double.nan,
|
||||||
|
double.infinity,
|
||||||
|
8640000000000001,
|
||||||
|
]) {
|
||||||
|
expect(taskElapsed({'started_at': value}, now), isNull);
|
||||||
|
}
|
||||||
|
expect(
|
||||||
|
taskElapsed({
|
||||||
|
'started_at': now
|
||||||
|
.add(const Duration(minutes: 1))
|
||||||
|
.millisecondsSinceEpoch,
|
||||||
|
}, now),
|
||||||
|
isNull,
|
||||||
|
);
|
||||||
|
expect(taskElapsed({'duration_ms': 120000}, now), isNull);
|
||||||
|
expect(taskDuration(const Duration(days: 2, hours: 4)), '2d 4h');
|
||||||
|
expect(taskDuration(const Duration(hours: 2, minutes: 14)), '2h 14m');
|
||||||
|
expect(taskDuration(const Duration(seconds: 74)), '1m 14s');
|
||||||
|
expect(taskNumber({'tool_count': 0}, 'tool_count'), 0);
|
||||||
|
expect(taskNumber({'tool_count': 1.5}, 'tool_count'), isNull);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('partial stream frames and snapshots retain known task facts', () {
|
||||||
|
final initial = <String, dynamic>{
|
||||||
|
'id': 'a',
|
||||||
|
'status': 'running',
|
||||||
|
'command': 'check',
|
||||||
|
'started_at': 123000,
|
||||||
|
'updated_at': 124000,
|
||||||
|
'description': 'Verify changes',
|
||||||
|
'progress': 'Checking',
|
||||||
|
'task_type': 'agent',
|
||||||
|
'tool_count': 2,
|
||||||
|
'token_count': 50,
|
||||||
|
};
|
||||||
|
final progress = mergeShellFrame(
|
||||||
|
[initial],
|
||||||
|
{
|
||||||
|
'id': 'a',
|
||||||
|
'status': 'running',
|
||||||
|
'progress': 'Reviewing',
|
||||||
|
'tool_count': 0,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
final loaded = shellsLoaded(progress, [
|
||||||
|
{'id': 'a', 'status': 'running', 'command': ''},
|
||||||
|
]).single;
|
||||||
|
expect(loaded['started_at'], 123000);
|
||||||
|
expect(loaded['description'], 'Verify changes');
|
||||||
|
expect(loaded['progress'], 'Reviewing');
|
||||||
|
expect(loaded['tool_count'], 0);
|
||||||
|
expect(loaded['token_count'], 50);
|
||||||
|
expect(loaded['command'], 'check');
|
||||||
|
final exited = mergeShellFrame(
|
||||||
|
[loaded],
|
||||||
|
{'id': 'a', 'status': 'exited'},
|
||||||
|
).single;
|
||||||
|
expect(exited['started_at'], 123000);
|
||||||
|
expect(exited['status'], 'exited');
|
||||||
|
expect(runningShells([exited]), isEmpty);
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -256,7 +256,33 @@ JsonMap? perfChatReply(JsonMap request) {
|
|||||||
// watch the sent message itself.
|
// watch the sent message itself.
|
||||||
return {'id': id, 'type': 'chat_prompt', 'chat_queued': false};
|
return {'id': id, 'type': 'chat_prompt', 'chat_queued': false};
|
||||||
case 'chat_shells':
|
case 'chat_shells':
|
||||||
return {'id': id, 'type': 'chat_shells', 'chat_shells': const []};
|
return {
|
||||||
|
'id': id,
|
||||||
|
'type': 'chat_shells',
|
||||||
|
'chat_shells': _params['tasks'] == 'rich'
|
||||||
|
? backgroundTaskFixture()
|
||||||
|
: const [],
|
||||||
|
};
|
||||||
|
case 'chat_shell_output':
|
||||||
|
final outputQuery = request['chat_shell_output_query'];
|
||||||
|
final outputId = outputQuery is Map ? outputQuery['shell_id'] : null;
|
||||||
|
final selectedTask = _params['tasks'] == 'rich'
|
||||||
|
? backgroundTaskFixture()
|
||||||
|
.where((task) => task['id'] == outputId)
|
||||||
|
.firstOrNull
|
||||||
|
: null;
|
||||||
|
return {
|
||||||
|
'id': id,
|
||||||
|
'type': 'chat_shell_output',
|
||||||
|
'chat_shell_output': selectedTask == null
|
||||||
|
? {'unavailable': true}
|
||||||
|
: {
|
||||||
|
'shell': selectedTask,
|
||||||
|
'output':
|
||||||
|
'Checking the integration changes…\nTargeted checks passed.\nReviewing remaining findings.',
|
||||||
|
'cursor': 0,
|
||||||
|
},
|
||||||
|
};
|
||||||
case 'chat_messages':
|
case 'chat_messages':
|
||||||
final query = request['chat_query'];
|
final query = request['chat_query'];
|
||||||
final session = query is Map ? '${query['session_id'] ?? ''}' : '';
|
final session = query is Map ? '${query['session_id'] ?? ''}' : '';
|
||||||
@@ -321,3 +347,35 @@ List<JsonMap> perfChatRows() => [for (var i = 0; i < _chats; i++) _chatRow(i)];
|
|||||||
/// The text of message `perf-m<m>` in the bench's short transcript, newest
|
/// The text of message `perf-m<m>` in the bench's short transcript, newest
|
||||||
/// last (20 messages).
|
/// last (20 messages).
|
||||||
String perfChatMessageText(int m) => m.isEven ? 'Question $m' : _answer(m);
|
String perfChatMessageText(int m) => m.isEven ? 'Question $m' : _answer(m);
|
||||||
|
|
||||||
|
/// Opt-in recorded task facts for background-list captures; never contacts a backend.
|
||||||
|
List<JsonMap> backgroundTaskFixture() => [
|
||||||
|
{
|
||||||
|
'id': 'task-review',
|
||||||
|
'status': 'running',
|
||||||
|
'command': 'Agent: Review the integration changes',
|
||||||
|
'task_type': 'agent',
|
||||||
|
'description': 'Review the integration changes',
|
||||||
|
'started_at': DateTime.utc(2026, 11, 6, 9, 5).millisecondsSinceEpoch,
|
||||||
|
'updated_at': DateTime.utc(2026, 11, 6, 9, 24).millisecondsSinceEpoch,
|
||||||
|
'progress': 'Checking tests and reviewing the remaining findings',
|
||||||
|
'last_tool': 'Read',
|
||||||
|
'tool_count': 18,
|
||||||
|
'token_count': 12450,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'id': 'task-checks',
|
||||||
|
'status': 'running',
|
||||||
|
'command': 'flutter analyze && integration checks',
|
||||||
|
'task_type': 'shell',
|
||||||
|
'started_at': DateTime.utc(2026, 11, 6, 9, 18).millisecondsSinceEpoch,
|
||||||
|
'progress': 'Analyzing application sources',
|
||||||
|
'tool_count': 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'id': 'task-legacy',
|
||||||
|
'status': 'running',
|
||||||
|
'command': 'Wait for upstream release',
|
||||||
|
'duration_ms': 74000,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user