Merge branch 'main' into worktree-agent-aab11f4f1fe3dff6b

# Conflicts:
#	app/test/features/runs/ui/run_list_row_test.dart
This commit is contained in:
2026-10-31 12:36:49 +00:00
29 changed files with 266 additions and 225 deletions
@@ -152,7 +152,8 @@ String fileChangesSummary(ChangeCapture capture) {
var text = capture.status;
if (capture.files.isNotEmpty) {
if (text.isNotEmpty) text += ' ';
text += '(${capture.files.length} files)';
final count = capture.files.length;
text += '($count ${count == 1 ? 'file' : 'files'})';
}
if (capture.skipped > 0) {
if (text.isNotEmpty) text += ', ';
@@ -45,7 +45,6 @@ class StageCaptureSection extends StatelessWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(stage.stage, style: Theme.of(context).textTheme.titleMedium),
Text(meta, style: Theme.of(context).textTheme.bodySmall),
if (capture != null) ...[
Text(
@@ -1,4 +1,5 @@
import '../../../../core/api_gateway.dart';
import '../../../../ui/text/relative_time.dart';
import '../../domain/chat_sessions.dart';
/// Titles shared by more than one visible session, so row action labels can
@@ -20,24 +21,15 @@ String sessionActionsLabel(JsonMap session, Set<String> duplicateTitles) {
: 'Chat actions for $title';
}
/// The web row's relative recency: `just now`, `N min ago`, `N hr ago`,
/// `N days ago`, then a short date (`22 Oct`). A row without a usable
/// `updated_at` reports nothing rather than inventing a time.
/// The shared list-row recency, or nothing for an unusable `updated_at`.
String relativeChatSessionTime(Object? updatedAt, {DateTime? now}) {
final millis = chatSessionMillis(updatedAt);
if (millis <= 0) return '';
final then = DateTime.fromMillisecondsSinceEpoch(millis);
var elapsed = (now ?? DateTime.now()).difference(then);
if (elapsed.isNegative) elapsed = Duration.zero;
final seconds = elapsed.inSeconds;
if (seconds < 45) return 'just now';
final minutes = seconds ~/ 60 < 1 ? 1 : seconds ~/ 60;
if (minutes < 60) return '$minutes min ago';
final hours = minutes ~/ 60;
if (hours < 24) return '$hours hr ago';
final days = hours ~/ 24;
if (days < 7) return days == 1 ? '1 day ago' : '$days days ago';
return '${then.day} ${_shortMonths[then.month - 1]}';
return formatRelativeTime(
DateTime.fromMillisecondsSinceEpoch(millis),
now: now,
) ??
'';
}
/// The row's one muted line: the recorded model and the folder (home as `~`).
@@ -60,20 +52,3 @@ String? chatSessionRowStatus(JsonMap session, {required bool unseen}) {
}
return unseen ? 'New' : null;
}
const _shortMonths = [
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
// `Intl.DateTimeFormat('en-GB', { month: 'short' })`, which the web row
// uses, abbreviates September as `Sept`, not `Sep`.
'Sept',
'Oct',
'Nov',
'Dec',
];
@@ -38,12 +38,13 @@ String? formatLocalTimestamp(String? text) {
return '${local.day} ${_monthNames[local.month - 1]} $hour:$minute';
}
/// `45s`, `2m 5s`, `1h 2m`. Negative values clamp to `0s`.
/// `45s`, `2m 5s`, `1h 2m`, `9d 16h`. Negative values clamp to `0s`.
String formatDuration(int totalSeconds) {
final seconds = totalSeconds < 0 ? 0 : totalSeconds;
if (seconds < 60) return '${seconds}s';
if (seconds < 3600) return '${seconds ~/ 60}m ${seconds % 60}s';
return '${seconds ~/ 3600}h ${(seconds % 3600) ~/ 60}m';
if (seconds < 86400) return '${seconds ~/ 3600}h ${(seconds % 3600) ~/ 60}m';
return '${seconds ~/ 86400}d ${(seconds % 86400) ~/ 3600}h';
}
/// Whole non-negative seconds between two timestamps, or null when either is
@@ -56,18 +57,6 @@ int? durationSeconds(String? start, String? end) {
return seconds >= 0 ? seconds : null;
}
/// `just now`, `Nm ago`, `Nh ago`, `Nd ago`; a future timestamp reads as
/// `just now`, never a negative age.
String? formatRanAgo(String? createdAt, DateTime now) {
final start = parseInstant(createdAt);
if (start == null) return null;
final seconds = now.difference(start).inSeconds;
if (seconds < 60) return 'just now';
if (seconds < 3600) return '${seconds ~/ 60}m ago';
if (seconds < 86400) return '${seconds ~/ 3600}h ago';
return '${seconds ~/ 86400}d ago';
}
/// `1 stage` / `n stages`.
String stageCountText(int count) => '$count ${count == 1 ? 'stage' : 'stages'}';
@@ -1,4 +1,5 @@
import 'pipeline_format.dart';
import '../../ui/text/relative_time.dart';
import 'pipeline_models.dart';
export 'pipeline_filter.dart';
@@ -27,7 +28,7 @@ class RunBadge {
final String? ranAgo;
final String? duration;
/// `2h ago · 1m 5s · run 42`; missing fragments are omitted.
/// `2h · 1m 5s · run 42`; missing fragments are omitted.
String get metaLine => [
ranAgo,
duration,
@@ -42,7 +43,7 @@ RunBadge runBadge(PipelineRun run, DateTime now) {
return RunBadge(
runId: run.id,
state: runStateOf(run.status),
ranAgo: formatRanAgo(run.createdAt, now),
ranAgo: formatRelativeTimestamp(run.createdAt, now: now),
duration: duration,
);
}
@@ -16,6 +16,7 @@ typedef DetailMetric = ({String label, String value});
typedef DetailVisit = ({
String stage,
int? sequence,
int visit,
String title,
String subtitle,
String status,
@@ -114,22 +115,42 @@ List<DetailMetric> detailUsageMetrics(dynamic raw) {
/// Every recorded visit with its server sequence, in recorded order.
List<DetailVisit> detailTimeline(dynamic steps) {
if (steps is! List) return const [];
final records = steps.whereType<Map>().toList(growable: false);
final ordered = List<int>.generate(records.length, (index) => index)
..sort((a, b) {
final bySequence = (_int(records[a]['sequence']) ?? 0).compareTo(
_int(records[b]['sequence']) ?? 0,
);
return bySequence != 0 ? bySequence : a.compareTo(b);
});
final positions = <String, int>{};
final visits = <int, int>{};
for (final index in ordered) {
final stage = '${records[index]['stage'] ?? ''}'.trim();
final position = (positions[stage] ?? 0) + 1;
positions[stage] = position;
visits[index] = _displayVisit(records[index], position);
}
return [
for (final step in steps.whereType<Map>())
(
stage: '${step['stage'] ?? ''}'.trim(),
sequence: step['sequence'] is num
? (step['sequence'] as num).toInt()
: null,
title:
'${_text(step['stage'], 'Stage unavailable')} · visit '
'${step['sequence'] is num ? (step['sequence'] as num).toInt() : 'unavailable'}',
subtitle: _visitSubtitle(step),
status: '${step['status'] ?? ''}'.trim(),
outcome: '${step['outcome'] ?? ''}'.trim(),
target: '${step['target'] ?? ''}'.trim(),
duration: _visitDuration(step),
),
for (var index = 0; index < records.length; index += 1)
() {
final step = records[index];
final stage = '${step['stage'] ?? ''}'.trim();
final visit = visits[index]!;
return (
stage: stage,
sequence: step['sequence'] is num
? (step['sequence'] as num).toInt()
: null,
visit: visit,
title: '${_text(step['stage'], 'Stage unavailable')} · Visit $visit',
subtitle: _visitSubtitle(step),
status: '${step['status'] ?? ''}'.trim(),
outcome: '${step['outcome'] ?? ''}'.trim(),
target: '${step['target'] ?? ''}'.trim(),
duration: _visitDuration(step),
);
}(),
];
}
@@ -166,6 +187,15 @@ String _visitSubtitle(Map step) {
].join(' · ');
}
/// The stage's own recorded visit number, falling back to its position among
/// visits to that stage rather than the run-wide step sequence.
int _displayVisit(Map step, int position) {
final control = step['control'];
final recorded = control is Map ? control['visit'] : null;
if (recorded is num && recorded > 0) return recorded.toInt();
return position;
}
/// The web's `stepDuration`: finished minus started, when both are recorded.
String? _visitDuration(Map step) {
final started = DateTime.tryParse('${step['started_at'] ?? ''}');
@@ -90,13 +90,13 @@ class _RunVisitPaneState extends State<RunVisitPane> {
}
}
/// The page bar's subtitle for a recorded visit: its sequence, then the run
/// The page bar's subtitle for a recorded visit: its per-stage visit, then the run
/// it belongs to (`Visit 2 · Run 7 · Nightly report`).
String runVisitSubtitle(JsonMap run, DetailVisit visit) {
final runId = '${run['id'] ?? ''}'.trim();
final title = detailTitle(run);
return [
if (visit.sequence != null) 'Visit ${visit.sequence}',
'Visit ${visit.visit}',
if (runId.isNotEmpty) 'Run $runId',
if (title.isNotEmpty && title != 'Run $runId') title,
].join(' · ');
+2 -2
View File
@@ -13,7 +13,7 @@ import '../../attention/notify/notification_controller.dart';
import '../../attention/runtime/attention_controller.dart';
import '../../attention/runtime/attention_store.dart';
import '../../attention/ui/needs_you_runs_heading.dart';
import '../../pipelines/pipeline_format.dart' show formatRanAgo;
import '../../../ui/text/relative_time.dart';
import '../domain/run_models.dart';
import '../../../shell/shell_bar.dart';
import 'run_more_menu.dart';
@@ -354,7 +354,7 @@ class RunListRow extends StatelessWidget {
child: RunStatusIcon(state: state, label: runStatusLabel(run)),
),
title: Text(title),
time: formatRanAgo('${run['created_at'] ?? ''}', now),
time: formatRelativeTimestamp('${run['created_at'] ?? ''}', now: now),
subtitle: Text(subtitle),
compactSubtitle: Text(compactSubtitle),
// A narrow list pane beside the open run leaves the row no room for a
@@ -1,4 +1,5 @@
import '../../domain/saved_schedule.dart';
import '../../../../ui/text/relative_time.dart';
/// User-facing values for one saved schedule row.
///
@@ -91,31 +92,12 @@ String scheduleCountLabel(int visible, int total) {
return total == 1 ? '1 schedule' : '$total schedules';
}
/// A row's short next-run word for its title line: `Paused`, `Not
/// scheduled`, `Next time unavailable`, or the local time as `22 Oct 09:00`.
String scheduleNextDueShort(SavedSchedule schedule) {
/// A row's compact next-run label, using the shared relative-time vocabulary.
String scheduleNextDueShort(SavedSchedule schedule, {DateTime? now}) {
if (!schedule.enabled) return 'Paused';
final value = schedule.nextDue;
if (value.isEmpty) return 'Not scheduled';
final date = DateTime.tryParse(value);
if (date == null) return 'Next time unavailable';
final local = date.toLocal();
String two(int part) => part.toString().padLeft(2, '0');
return '${local.day} ${_shortMonths[local.month - 1]} '
'${two(local.hour)}:${two(local.minute)}';
return formatRelativeTime(date, now: now) ?? 'Next time unavailable';
}
const _shortMonths = [
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec',
];
+8 -14
View File
@@ -1,4 +1,5 @@
import '../../../core/api_gateway.dart';
import '../../../ui/text/relative_time.dart';
import 'search_format.dart';
export 'search_format.dart' show humanBytes, formatSearchTimestamp;
@@ -47,7 +48,7 @@ SearchRowView searchRowView(JsonMap hit, String query) {
final field = _map(hit['field']);
final artifact = _map(hit['artifact']);
final recency = formatSearchTimestamp('${hit['recency'] ?? ''}');
final recency = formatRelativeTimestamp('${hit['recency'] ?? ''}');
final target = _serverTarget(hit);
if (pipeline != null) {
@@ -68,10 +69,7 @@ SearchRowView searchRowView(JsonMap hit, String query) {
title:
'pipeline ${_num(version['pipeline_id'])}'
' · v${_num(version['version'])}',
secondary: _join([
hash == null ? null : 'content $hash',
formatSearchTimestamp('${version['created_at'] ?? ''}'),
]),
secondary: hash == null ? '' : 'content $hash',
kindLabel: 'Pipeline version',
snippetSpans: const [],
recency: recency,
@@ -81,12 +79,8 @@ SearchRowView searchRowView(JsonMap hit, String query) {
if (run != null) {
final name = _nonBlank(run['pipeline_name']);
return SearchRowView(
title: 'run #${_num(run['id'])}${name == null ? '' : ' · $name'}',
secondary: _join([
_nonBlank(run['status']),
_nonBlank(run['workspace']),
formatSearchTimestamp('${run['created_at'] ?? ''}'),
]),
title: 'Run ${_num(run['id'])}${name == null ? '' : ' · $name'}',
secondary: _join([_nonBlank(run['status']), _nonBlank(run['workspace'])]),
kindLabel: 'Run',
snippetSpans: const [],
recency: recency,
@@ -97,7 +91,7 @@ SearchRowView searchRowView(JsonMap hit, String query) {
final stage = _nonBlank(step['stage']) ?? 'step';
return SearchRowView(
title:
'run #${_num(step['run_id'])} · $stage'
'Run ${_num(step['run_id'])} · $stage'
' visit ${_num(step['visit'])}',
secondary: _stepSecondary(step),
kindLabel: 'Step',
@@ -110,7 +104,7 @@ SearchRowView searchRowView(JsonMap hit, String query) {
final snippet = '${field['snippet'] ?? ''}';
return SearchRowView(
title:
'run #${_num(field['run_id'])} · step ${_num(field['sequence'])}'
'Run ${_num(field['run_id'])} · step ${_num(field['sequence'])}'
' · ${_nonBlank(field['field']) ?? 'field'}',
secondary: snippet,
kindLabel: 'Field',
@@ -124,7 +118,7 @@ SearchRowView searchRowView(JsonMap hit, String query) {
return SearchRowView(
title: _nonBlank(artifact['name']) ?? 'artifact',
secondary: _join([
'run #${_num(artifact['run_id'])}',
'Run ${_num(artifact['run_id'])}',
'step ${_num(artifact['sequence'])}',
_nonBlank(artifact['content_type']),
humanBytes(_num(artifact['size_bytes'])),
+40
View File
@@ -0,0 +1,40 @@
const _monthNames = <String>[
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec',
];
/// A compact local recency label for list rows.
///
/// Past instants use `just now`, `Nm`, `Nh`, or `Nd` for their first week,
/// then a short local date. Future instants use the same compact units with an
/// `in` prefix, which keeps scheduled rows truthful.
String? formatRelativeTime(DateTime? instant, {DateTime? now}) {
if (instant == null) return null;
final current = now ?? DateTime.now();
final seconds = instant.difference(current).inSeconds;
final future = seconds > 0;
final age = seconds.abs();
if (age < 60) return 'just now';
final prefix = future ? 'in ' : '';
if (age < 3600) return '$prefix${age ~/ 60}m';
if (age < 86400) return '$prefix${age ~/ 3600}h';
if (age < 7 * 86400) return '$prefix${age ~/ 86400}d';
final local = instant.toLocal();
return '${local.day} ${_monthNames[local.month - 1]}';
}
/// Parses [text] as an RFC3339 timestamp before formatting it for a list row.
String? formatRelativeTimestamp(String? text, {DateTime? now}) {
final value = text?.trim() ?? '';
return formatRelativeTime(DateTime.tryParse(value), now: now);
}
+1 -1
View File
@@ -351,7 +351,7 @@ void main() {
await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
await tester.pump(const Duration(milliseconds: 400));
expectVisitHeading(tester, 'plan', 5);
expectVisitHeading(tester, 'plan', 2);
expect(provider.value.uri.path, '/runs/77/stage/plan');
expect(provider.value.uri.query, 'visit=1');
});
+3 -3
View File
@@ -401,7 +401,7 @@ void main() {
await tester.pump();
await tester.pump();
expect(find.text('run #7 · Preserved run'), findsOneWidget);
expect(find.text('Run 7 · Preserved run'), findsOneWidget);
await tester.tap(find.byKey(const ValueKey('search.result.run:7')));
await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
@@ -497,7 +497,7 @@ void main() {
expect(provider.value.uri.path, '/runs/7');
expect(find.byType(SearchScreen), findsNothing);
expect(find.byKey(const Key('run-visit-pane')), findsOneWidget);
expectVisitHeading(tester, 'build', 2);
expectVisitHeading(tester, 'build', 1);
// Leave the visit page (it covers the shell), then a retired field hit
// opens the plain Summary with no visit.
@@ -608,7 +608,7 @@ void main() {
await tester.pumpAndSettle();
expect(find.byKey(const Key('run-visit-pane')), findsOneWidget);
expectVisitHeading(tester, 'build', 2);
expectVisitHeading(tester, 'build', 1);
await tester.pumpWidget(const SizedBox.shrink());
await tester.pump();
@@ -125,11 +125,11 @@ void main() {
);
// The run-wide aggregate still counts the file this visit recorded.
expect(find.textContaining('1 file changed'), findsOneWidget);
expect(find.text('implementer'), findsOneWidget);
expect(find.text('implementer'), findsNothing);
expect(find.text('Visit 1 · completed'), findsOneWidget);
expect(
find.text(
'partial (1 files), 1 skipped, 2 omitted · Excluded protected files.',
'partial (1 file), 1 skipped, 2 omitted · Excluded protected files.',
),
findsOneWidget,
);
@@ -157,7 +157,7 @@ void main() {
await tester.pump();
expect(find.text('implementer'), findsNothing);
expect(find.text('reviewer'), findsOneWidget);
expect(find.text('reviewer'), findsNothing);
// The reviewer's first visit is Visit 1, not the run-wide step ordinal 2.
expect(find.text('Visit 1 · failed'), findsOneWidget);
expect(find.text('Visit 2 · failed'), findsNothing);
@@ -205,18 +205,18 @@ void main() {
await tester.tap(find.byKey(ChangesVisitPager.nextKey));
await tester.pump();
// The reviewer's first recorded visit is Visit 1 too.
expect(find.text('reviewer'), findsOneWidget);
expect(find.text('reviewer'), findsNothing);
expect(find.text('Visit 1 · completed'), findsOneWidget);
await tester.tap(find.byKey(ChangesVisitPager.nextKey));
await tester.pump();
expect(find.text('implementer'), findsOneWidget);
expect(find.text('implementer'), findsNothing);
expect(find.text('Visit 2 · completed'), findsOneWidget);
await tester.tap(find.byKey(ChangesVisitPager.nextKey));
await tester.pump();
// The resumed reviewer visit records control.visit 6.
expect(find.text('reviewer'), findsOneWidget);
expect(find.text('reviewer'), findsNothing);
expect(find.text('Visit 6 · completed'), findsOneWidget);
expect(find.text('Visit 3 · completed'), findsNothing);
expect(find.text('Visit 4 · completed'), findsNothing);
@@ -411,7 +411,7 @@ void main() {
expect(parsed.files.map((entry) => entry.path), ['x']);
expect(
fileChangesSummary(parsed),
'partial (1 files), 2 skipped, 1 omitted · Excluded protected files.',
'partial (1 file), 2 skipped, 1 omitted · Excluded protected files.',
);
});
@@ -43,7 +43,7 @@ void main() {
// change as the operator pages.
expect(find.text('3 files changed'), findsOneWidget);
expect(find.text('1 of 2'), findsOneWidget);
expect(find.text('implementer'), findsOneWidget);
expect(find.text('implementer'), findsNothing);
expect(find.text('Visit 1 · completed'), findsOneWidget);
expect(find.text('lib/a.dart'), findsOneWidget);
expect(find.text('lib/c.dart'), findsNothing);
@@ -52,7 +52,7 @@ void main() {
await tester.pump();
// The shown page keeps its own visit identity in the heading.
expect(find.text('reviewer'), findsOneWidget);
expect(find.text('reviewer'), findsNothing);
expect(find.text('Visit 1 · completed'), findsOneWidget);
expect(find.text('lib/c.dart'), findsOneWidget);
expect(find.text('lib/a.dart'), findsNothing);
@@ -62,7 +62,7 @@ void main() {
await tester.tap(find.byKey(ChangesVisitPager.previousKey));
await tester.pump();
expect(find.text('implementer'), findsOneWidget);
expect(find.text('implementer'), findsNothing);
expect(find.text('lib/a.dart'), findsOneWidget);
expect(find.text('lib/c.dart'), findsNothing);
expect(find.text('1 of 2'), findsOneWidget);
@@ -104,11 +104,11 @@ void main() {
// The disabled Next is inert; the page stays on the last visit.
await tester.tap(find.byKey(ChangesVisitPager.nextKey));
await tester.pump();
expect(find.text('reviewer'), findsOneWidget);
expect(find.text('reviewer'), findsNothing);
await tester.tap(find.byKey(ChangesVisitPager.previousKey));
await tester.pump();
expect(find.text('implementer'), findsOneWidget);
expect(find.text('implementer'), findsNothing);
expect(previous().onPressed, isNull);
});
@@ -133,7 +133,7 @@ void main() {
findsNothing,
);
// The single visit still keeps its identity heading.
expect(find.text('implementer'), findsOneWidget);
expect(find.text('implementer'), findsNothing);
expect(find.text('Visit 1 · completed'), findsOneWidget);
expect(find.text('lib/only.dart'), findsOneWidget);
});
@@ -154,12 +154,12 @@ void main() {
await tester.pumpWidget(materialHost(ChangesViewer(steps: first)));
await tester.tap(find.byKey(ChangesVisitPager.nextKey));
await tester.pump();
expect(find.text('reviewer'), findsOneWidget);
expect(find.text('reviewer'), findsNothing);
await tester.pumpWidget(materialHost(ChangesViewer(steps: second)));
await tester.pump();
expect(tester.takeException(), isNull);
expect(find.text('implementer'), findsOneWidget);
expect(find.text('implementer'), findsNothing);
expect(find.text('Visit 1 · completed'), findsOneWidget);
expect(find.byKey(ChangesVisitPager.previousKey), findsNothing);
});
@@ -187,7 +187,7 @@ void main() {
await tester.tap(find.byKey(ChangesVisitPager.nextKey));
await tester.pump();
expect(tester.takeException(), isNull);
expect(find.text('reviewer'), findsOneWidget);
expect(find.text('reviewer'), findsNothing);
expect(find.text('Visit 1 · completed'), findsOneWidget);
expect(find.text('lib/c.dart'), findsOneWidget);
});
@@ -210,7 +210,7 @@ void main() {
await tester.tap(find.byKey(ChangesVisitPager.nextKey));
await tester.pump();
expect(find.text('reviewer'), findsOneWidget);
expect(find.text('reviewer'), findsNothing);
expect(
tester
.widget<CupertinoButton>(find.byKey(ChangesVisitPager.nextKey))
@@ -54,61 +54,64 @@ TextStyle _styleOf(WidgetTester tester, String text) =>
tester.renderObject<RenderParagraph>(find.textContaining(text)).text.style!;
void main() {
test('relative recency uses the web wording and never invents a time', () {
final now = DateTime(2026, 10, 22, 12);
final from = now.subtract;
test(
'relative recency uses shared compact wording and never invents a time',
() {
final now = DateTime(2026, 10, 22, 12);
final from = now.subtract;
expect(relativeChatSessionTime(null, now: now), '');
expect(relativeChatSessionTime(0, now: now), '');
expect(
relativeChatSessionTime(now.millisecondsSinceEpoch, now: now),
'just now',
);
expect(
relativeChatSessionTime(
from(const Duration(minutes: 5)).millisecondsSinceEpoch,
now: now,
),
'5 min ago',
);
expect(
relativeChatSessionTime(
from(const Duration(hours: 3)).millisecondsSinceEpoch,
now: now,
),
'3 hr ago',
);
expect(
relativeChatSessionTime(
from(const Duration(hours: 25)).millisecondsSinceEpoch,
now: now,
),
'1 day ago',
);
expect(
relativeChatSessionTime(
from(const Duration(days: 3)).millisecondsSinceEpoch,
now: now,
),
'3 days ago',
);
expect(
relativeChatSessionTime(
DateTime(2026, 10, 1, 9).millisecondsSinceEpoch,
now: now,
),
'1 Oct',
);
// The web formats with `Intl.DateTimeFormat('en-GB', …)`, whose short
// September is `Sept`; its own test asserts `12 Sept`.
expect(
relativeChatSessionTime(
DateTime(2026, 9, 12, 9).millisecondsSinceEpoch,
now: now,
),
'12 Sept',
);
});
expect(relativeChatSessionTime(null, now: now), '');
expect(relativeChatSessionTime(0, now: now), '');
expect(
relativeChatSessionTime(now.millisecondsSinceEpoch, now: now),
'just now',
);
expect(
relativeChatSessionTime(
from(const Duration(minutes: 5)).millisecondsSinceEpoch,
now: now,
),
'5m',
);
expect(
relativeChatSessionTime(
from(const Duration(hours: 3)).millisecondsSinceEpoch,
now: now,
),
'3h',
);
expect(
relativeChatSessionTime(
from(const Duration(hours: 25)).millisecondsSinceEpoch,
now: now,
),
'1d',
);
expect(
relativeChatSessionTime(
from(const Duration(days: 3)).millisecondsSinceEpoch,
now: now,
),
'3d',
);
expect(
relativeChatSessionTime(
DateTime(2026, 10, 1, 9).millisecondsSinceEpoch,
now: now,
),
'1 Oct',
);
// The web formats with `Intl.DateTimeFormat('en-GB', …)`, whose short
// September is `Sept`; its own test asserts `12 Sept`.
expect(
relativeChatSessionTime(
DateTime(2026, 9, 12, 9).millisecondsSinceEpoch,
now: now,
),
'12 Sep',
);
},
);
test('the subtitle and status come only from the row', () {
expect(
@@ -173,7 +176,7 @@ void main() {
);
final title = tester.getRect(find.textContaining('Unread chat'));
final time = tester.getRect(find.text('5 min ago'));
final time = tester.getRect(find.text('5m'));
final subtitle = tester.getRect(find.text('model-a · /work'));
final avatar = tester.getRect(
find.descendant(
@@ -197,10 +200,10 @@ void main() {
expect(_styleOf(tester, 'Read chat').fontWeight, FontWeight.w600);
expect(find.byKey(const Key('chat-row-unread')), findsOneWidget);
final accent = CupertinoTheme.of(
tester.element(find.text('5 min ago')),
tester.element(find.text('5m')),
).primaryColor;
expect(_styleOf(tester, '5 min ago').color, accent);
expect(_styleOf(tester, '2 hr ago').color, isNot(accent));
expect(_styleOf(tester, '5m').color, accent);
expect(_styleOf(tester, '2h').color, isNot(accent));
// Starred shows a small star by the title; running a badge on the avatar.
expect(
@@ -265,7 +268,7 @@ void main() {
expect(subtitle.didExceedMaxLines, isTrue);
// The time and the Closed word stay inside their row.
for (final (row, word) in [('s1', '3 days ago'), ('c1', 'Closed')]) {
for (final (row, word) in [('s1', '3d'), ('c1', 'Closed')]) {
expect(
tester.getRect(find.textContaining(word)).right,
lessThanOrEqualTo(
@@ -76,7 +76,7 @@ void main() {
], isUnseen: (session) => session['id'] == 's1');
final title = tester.getRect(find.text('Unread chat'));
final time = tester.getRect(find.text('5 min ago'));
final time = tester.getRect(find.text('5m'));
expect(time.left, greaterThan(title.right));
expect(time.center.dy, closeTo(title.center.dy, 2));
expect(
@@ -90,13 +90,10 @@ void main() {
);
// Unread: bold title, accent time and a dot; the read row stays muted.
final scheme = Theme.of(tester.element(find.text('5 min ago'))).colorScheme;
final scheme = Theme.of(tester.element(find.text('5m'))).colorScheme;
expect(tester.widget<Text>(find.text('5m')).style?.color, scheme.primary);
expect(
tester.widget<Text>(find.text('5 min ago')).style?.color,
scheme.primary,
);
expect(
tester.widget<Text>(find.text('2 hr ago')).style?.color,
tester.widget<Text>(find.text('2h')).style?.color,
scheme.onSurfaceVariant,
);
expect(find.byKey(const Key('chat-row-unread')), findsOneWidget);
@@ -183,7 +180,7 @@ void main() {
);
expect(subtitle.maxLines, 1);
expect(subtitle.didExceedMaxLines, isTrue);
for (final (row, word) in [('s1', '3 days ago'), ('c1', 'Closed')]) {
for (final (row, word) in [('s1', '3d'), ('c1', 'Closed')]) {
expect(
tester.getRect(find.textContaining(word)).right,
lessThanOrEqualTo(
@@ -7,7 +7,7 @@ import 'fixtures.dart';
void main() {
group('formatting', () {
test('renders local timestamps, durations and ages', () {
test('renders local timestamps and bounded durations', () {
expect(formatLocalTimestamp('2026-10-17T21:26:00'), '17 Oct 21:26');
expect(formatLocalTimestamp(''), isNull);
expect(formatLocalTimestamp('not a time'), isNull);
@@ -15,15 +15,10 @@ void main() {
expect(formatDuration(45), '45s');
expect(formatDuration(125), '2m 5s');
expect(formatDuration(3720), '1h 2m');
expect(formatDuration(840000), '9d 17h');
expect(formatDuration(-4), '0s');
expect(stageCountText(1), '1 stage');
expect(stageCountText(2), '2 stages');
final now = DateTime(2026, 10, 17, 21, 30);
expect(formatRanAgo('2026-10-17T21:29:40', now), 'just now');
expect(formatRanAgo('2026-10-17T21:25:00', now), '5m ago');
expect(formatRanAgo('2026-10-17T19:30:00', now), '2h ago');
expect(formatRanAgo('2026-10-14T21:30:00', now), '3d ago');
expect(formatRanAgo('2026-10-17T22:00:00', now), 'just now');
});
test('maps the server status vocabulary and unknown values', () {
@@ -181,7 +181,7 @@ void main() {
await pumpDeepLink(tester, RunDetailTestPlatform.material, stage: 'plan');
expect(find.byKey(const Key('run-visit-pane')), findsOneWidget);
expectVisitHeading(tester, 'plan', 5);
expectVisitHeading(tester, 'plan', 2);
});
testWidgets('a Graph click opens the same latest visit as the stage route', (
@@ -195,7 +195,7 @@ void main() {
// The web client's graph click takes the last visit in sequence order, not
// the last row in reply order, so both entry points agree.
expect(find.byKey(const Key('run-visit-pane')), findsOneWidget);
expectVisitHeading(tester, 'plan', 5);
expectVisitHeading(tester, 'plan', 2);
});
testWidgets('an out-of-range visit is clamped to the stage last visit', (
@@ -209,7 +209,7 @@ void main() {
);
expect(find.byKey(const Key('run-visit-pane')), findsOneWidget);
expectVisitHeading(tester, 'plan', 5);
expectVisitHeading(tester, 'plan', 2);
});
testWidgets('a declared but unvisited stage selects its graph node', (
@@ -259,7 +259,7 @@ void main() {
await tester.pumpAndSettle();
expect(find.byKey(const Key('run-visit-pane')), findsOneWidget);
expectVisitHeading(tester, 'plan', 5);
expectVisitHeading(tester, 'plan', 2);
});
testWidgets('a route change applies its visit and a plain route closes it', (
@@ -301,7 +301,7 @@ void main() {
rebuild(() => visit = 1);
await tester.pumpAndSettle();
expectVisitHeading(tester, 'plan', 5);
expectVisitHeading(tester, 'plan', 2);
rebuild(() => stage = null);
await tester.pumpAndSettle();
@@ -14,8 +14,8 @@ Finder runDetailText(String text) => find.descendant(
);
/// The stage page's bar names the stage over its visit (and run): the title
/// is keyed `run-visit-title` and the subtitle starts `Visit <sequence>`.
void expectVisitHeading(WidgetTester tester, String stage, num sequence) {
/// is keyed `run-visit-title` and the subtitle starts `Visit <stage visit>`.
void expectVisitHeading(WidgetTester tester, String stage, num visit) {
expect(find.byKey(const Key('run-visit-pane')), findsOneWidget);
final heading = find.byKey(const Key('run-visit-title'));
expect(
@@ -25,7 +25,7 @@ void expectVisitHeading(WidgetTester tester, String stage, num sequence) {
expect(
find.descendant(
of: heading,
matching: find.textContaining(RegExp('^Visit $sequence( ·|\$)')),
matching: find.textContaining(RegExp('^Visit $visit( ·|\$)')),
),
findsOneWidget,
);
@@ -100,7 +100,7 @@ void main() {
expect(find.byKey(const Key('run-visit-pane')), findsNothing);
expect(find.byType(RunTimelineList), findsOneWidget);
expect(find.text('plan · visit 1'), findsOneWidget);
expect(find.text('plan · Visit 1'), findsOneWidget);
});
testWidgets('${platform.name} visit pane at 320 with 2x dark text', (
@@ -201,17 +201,17 @@ void main() {
matching: find.byType(Scrollable),
);
await tester.scrollUntilVisible(
find.textContaining('build · visit 3'),
find.textContaining('build · Visit 1').last,
200,
scrollable: timelineScroll,
);
expect(find.textContaining('build · visit 3'), findsOneWidget);
expect(find.textContaining('build · Visit 1').last, findsOneWidget);
await tester.scrollUntilVisible(
find.textContaining('test · visit 4'),
find.textContaining('test · Visit 1').last,
200,
scrollable: timelineScroll,
);
expect(find.textContaining('test · visit 4'), findsOneWidget);
expect(find.textContaining('test · Visit 1').last, findsOneWidget);
final before = tester
.state<ScrollableState>(timelineScroll)
@@ -58,7 +58,7 @@ void main() {
);
Rect at(String text) => tester.getRect(find.text(text));
final title = at('Ship the release notes');
final age = at('12h ago');
final age = at('12h');
final subtitle = at('release · 2m 5s · 3 steps');
expect(age.center.dy, moreOrLessEquals(title.center.dy));
@@ -113,7 +113,7 @@ void main() {
);
expect(find.byKey(const Key('run-visit-pane')), findsOneWidget);
expectVisitHeading(tester, 'build', 2);
expectVisitHeading(tester, 'build', 1);
});
}
@@ -65,13 +65,13 @@ void main() {
await _openVisitChanges(tester);
expect(find.byKey(const Key('run-visit-pane')), findsOneWidget);
// The body keeps the landed viewer's own identity for that visit.
// The stage is already named in the page bar, so Changes does not repeat it.
expect(
find.descendant(
of: find.byType(ChangesViewer),
matching: find.text('plan'),
),
findsOneWidget,
findsNothing,
);
expect(find.text('Visit 1 · completed'), findsOneWidget);
expect(find.text('lib/plan.dart'), findsOneWidget);
@@ -33,7 +33,7 @@ void main() {
// Two lines per row: the name with its next run, then the timer
// and pinned pipeline version. The editor holds the rest.
expect(find.text('Research batteries'), findsOneWidget);
expect(find.text('22 Oct 09:00'), findsOneWidget);
expect(find.text('22 Oct'), findsOneWidget);
expect(
find.text('Every 24h · mon, wed · Pipeline 4 · v2'),
findsOneWidget,
@@ -90,24 +90,23 @@ void main() {
final version = searchRowView(versionHit(), 'release');
expect(version.title, 'pipeline 9 · v2');
expect(version.secondary, startsWith('content abc · '));
expect(version.secondary, 'content abc');
expect(version.recency, isNotNull);
final run = searchRowView(runHit(), 'release');
expect(run.title, 'run #11 · release');
expect(run.secondary, startsWith('succeeded · '));
expect(run.secondary.split(' · '), hasLength(2));
expect(run.title, 'Run 11 · release');
expect(run.secondary, 'succeeded');
final unnamed = searchRowView(runHit({'pipeline_name': ''}), '');
expect(unnamed.title, 'run #11');
expect(unnamed.title, 'Run 11');
final step = searchRowView(stepHit({'target': '#success'}), '');
expect(step.title, 'run #11 · builder visit 2');
expect(step.title, 'Run 11 · builder visit 2');
expect(step.secondary, 'success · → #success');
final artifact = searchRowView(artifactHit(), 'notes');
expect(artifact.title, 'notes.md');
expect(artifact.secondary, 'run #11 · step 4 · text/markdown · 2.0 KiB');
expect(artifact.secondary, 'Run 11 · step 4 · text/markdown · 2.0 KiB');
});
test('a field snippet marks the first case-insensitive query occurrence', () {
+36
View File
@@ -0,0 +1,36 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/ui/text/relative_time.dart';
void main() {
final now = DateTime(2026, 10, 22, 12);
test('formats compact past and future list-row times', () {
expect(formatRelativeTime(now, now: now), 'just now');
expect(
formatRelativeTime(now.subtract(const Duration(minutes: 5)), now: now),
'5m',
);
expect(
formatRelativeTime(now.subtract(const Duration(hours: 3)), now: now),
'3h',
);
expect(
formatRelativeTime(now.subtract(const Duration(days: 3)), now: now),
'3d',
);
expect(
formatRelativeTime(now.subtract(const Duration(days: 8)), now: now),
'14 Oct',
);
expect(
formatRelativeTime(now.add(const Duration(hours: 2)), now: now),
'in 2h',
);
});
test('parses timestamps and omits unusable values', () {
expect(formatRelativeTimestamp('2026-10-22T11:55:00', now: now), '5m');
expect(formatRelativeTimestamp('', now: now), isNull);
expect(formatRelativeTimestamp('not a time', now: now), isNull);
});
}