diff --git a/app/lib/features/changes/domain/change_wording.dart b/app/lib/features/changes/domain/change_wording.dart index 5d614070..cf81814d 100644 --- a/app/lib/features/changes/domain/change_wording.dart +++ b/app/lib/features/changes/domain/change_wording.dart @@ -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 += ', '; diff --git a/app/lib/features/changes/widgets/capture_section.dart b/app/lib/features/changes/widgets/capture_section.dart index 7f6e3eb2..2c570b17 100644 --- a/app/lib/features/changes/widgets/capture_section.dart +++ b/app/lib/features/changes/widgets/capture_section.dart @@ -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( diff --git a/app/lib/features/chat/ui/sessions/session_row_style.dart b/app/lib/features/chat/ui/sessions/session_row_style.dart index 2d0a1eca..86f5c989 100644 --- a/app/lib/features/chat/ui/sessions/session_row_style.dart +++ b/app/lib/features/chat/ui/sessions/session_row_style.dart @@ -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 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', -]; diff --git a/app/lib/features/pipelines/pipeline_format.dart b/app/lib/features/pipelines/pipeline_format.dart index f70fe675..ea1a1721 100644 --- a/app/lib/features/pipelines/pipeline_format.dart +++ b/app/lib/features/pipelines/pipeline_format.dart @@ -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'}'; diff --git a/app/lib/features/pipelines/pipeline_query.dart b/app/lib/features/pipelines/pipeline_query.dart index eeb5701d..56c0b1ee 100644 --- a/app/lib/features/pipelines/pipeline_query.dart +++ b/app/lib/features/pipelines/pipeline_query.dart @@ -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, ); } diff --git a/app/lib/features/runs/ui/run_detail_content.dart b/app/lib/features/runs/ui/run_detail_content.dart index 4f7eef7f..1412fc13 100644 --- a/app/lib/features/runs/ui/run_detail_content.dart +++ b/app/lib/features/runs/ui/run_detail_content.dart @@ -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 detailUsageMetrics(dynamic raw) { /// Every recorded visit with its server sequence, in recorded order. List detailTimeline(dynamic steps) { if (steps is! List) return const []; + final records = steps.whereType().toList(growable: false); + final ordered = List.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 = {}; + final visits = {}; + 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()) - ( - 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'] ?? ''}'); diff --git a/app/lib/features/runs/ui/run_detail_visit.dart b/app/lib/features/runs/ui/run_detail_visit.dart index 49446124..b51bc533 100644 --- a/app/lib/features/runs/ui/run_detail_visit.dart +++ b/app/lib/features/runs/ui/run_detail_visit.dart @@ -90,13 +90,13 @@ class _RunVisitPaneState extends State { } } -/// 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(' · '); diff --git a/app/lib/features/runs/ui/runs_list.dart b/app/lib/features/runs/ui/runs_list.dart index b6c38534..d73d5789 100644 --- a/app/lib/features/runs/ui/runs_list.dart +++ b/app/lib/features/runs/ui/runs_list.dart @@ -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 diff --git a/app/lib/features/schedules/ui/list/schedule_list_format.dart b/app/lib/features/schedules/ui/list/schedule_list_format.dart index e1a6d1d8..efa10212 100644 --- a/app/lib/features/schedules/ui/list/schedule_list_format.dart +++ b/app/lib/features/schedules/ui/list/schedule_list_format.dart @@ -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', -]; diff --git a/app/lib/features/search/domain/search_row.dart b/app/lib/features/search/domain/search_row.dart index 283feca7..a6d2ffc9 100644 --- a/app/lib/features/search/domain/search_row.dart +++ b/app/lib/features/search/domain/search_row.dart @@ -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'])), diff --git a/app/lib/ui/text/relative_time.dart b/app/lib/ui/text/relative_time.dart new file mode 100644 index 00000000..5f396620 --- /dev/null +++ b/app/lib/ui/text/relative_time.dart @@ -0,0 +1,40 @@ +const _monthNames = [ + '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); +} diff --git a/app/test/application/pipelines_app_test.dart b/app/test/application/pipelines_app_test.dart index c1818907..0defd93a 100644 --- a/app/test/application/pipelines_app_test.dart +++ b/app/test/application/pipelines_app_test.dart @@ -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'); }); diff --git a/app/test/application/search_wiring_test.dart b/app/test/application/search_wiring_test.dart index cc9b13a9..b4ca51df 100644 --- a/app/test/application/search_wiring_test.dart +++ b/app/test/application/search_wiring_test.dart @@ -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(); diff --git a/app/test/features/changes/changes_viewer_test.dart b/app/test/features/changes/changes_viewer_test.dart index 387164cd..5158469a 100644 --- a/app/test/features/changes/changes_viewer_test.dart +++ b/app/test/features/changes/changes_viewer_test.dart @@ -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); diff --git a/app/test/features/changes/run_changes_test.dart b/app/test/features/changes/run_changes_test.dart index 60353033..0b196d3f 100644 --- a/app/test/features/changes/run_changes_test.dart +++ b/app/test/features/changes/run_changes_test.dart @@ -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.', ); }); diff --git a/app/test/features/changes/visit_paging_test.dart b/app/test/features/changes/visit_paging_test.dart index c8b99427..bc0ae765 100644 --- a/app/test/features/changes/visit_paging_test.dart +++ b/app/test/features/changes/visit_paging_test.dart @@ -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(find.byKey(ChangesVisitPager.nextKey)) diff --git a/app/test/features/chat/ui/sessions/chat_session_row_layout_test.dart b/app/test/features/chat/ui/sessions/chat_session_row_layout_test.dart index 483ab04c..1b9eec76 100644 --- a/app/test/features/chat/ui/sessions/chat_session_row_layout_test.dart +++ b/app/test/features/chat/ui/sessions/chat_session_row_layout_test.dart @@ -54,61 +54,64 @@ TextStyle _styleOf(WidgetTester tester, String text) => tester.renderObject(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( diff --git a/app/test/features/chat/ui/sessions/chat_session_row_material_test.dart b/app/test/features/chat/ui/sessions/chat_session_row_material_test.dart index 03f05607..f2746b8c 100644 --- a/app/test/features/chat/ui/sessions/chat_session_row_material_test.dart +++ b/app/test/features/chat/ui/sessions/chat_session_row_material_test.dart @@ -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(find.text('5m')).style?.color, scheme.primary); expect( - tester.widget(find.text('5 min ago')).style?.color, - scheme.primary, - ); - expect( - tester.widget(find.text('2 hr ago')).style?.color, + tester.widget(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( diff --git a/app/test/features/pipelines/pipeline_format_test.dart b/app/test/features/pipelines/pipeline_format_test.dart index 189b9af8..ad55f787 100644 --- a/app/test/features/pipelines/pipeline_format_test.dart +++ b/app/test/features/pipelines/pipeline_format_test.dart @@ -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', () { diff --git a/app/test/features/runs/ui/run_detail_deep_link_test.dart b/app/test/features/runs/ui/run_detail_deep_link_test.dart index 711639b2..6c07e320 100644 --- a/app/test/features/runs/ui/run_detail_deep_link_test.dart +++ b/app/test/features/runs/ui/run_detail_deep_link_test.dart @@ -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(); diff --git a/app/test/features/runs/ui/run_detail_finders.dart b/app/test/features/runs/ui/run_detail_finders.dart index a41a6066..c2294aaa 100644 --- a/app/test/features/runs/ui/run_detail_finders.dart +++ b/app/test/features/runs/ui/run_detail_finders.dart @@ -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 `. -void expectVisitHeading(WidgetTester tester, String stage, num sequence) { +/// is keyed `run-visit-title` and the subtitle starts `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, ); diff --git a/app/test/features/runs/ui/run_detail_visit_test.dart b/app/test/features/runs/ui/run_detail_visit_test.dart index 5ba115e6..872ea86c 100644 --- a/app/test/features/runs/ui/run_detail_visit_test.dart +++ b/app/test/features/runs/ui/run_detail_visit_test.dart @@ -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', ( diff --git a/app/test/features/runs/ui/run_detail_widget_test.dart b/app/test/features/runs/ui/run_detail_widget_test.dart index 993f44b8..8adfd687 100644 --- a/app/test/features/runs/ui/run_detail_widget_test.dart +++ b/app/test/features/runs/ui/run_detail_widget_test.dart @@ -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(timelineScroll) diff --git a/app/test/features/runs/ui/run_list_row_test.dart b/app/test/features/runs/ui/run_list_row_test.dart index c11c260d..47037374 100644 --- a/app/test/features/runs/ui/run_list_row_test.dart +++ b/app/test/features/runs/ui/run_list_row_test.dart @@ -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)); diff --git a/app/test/features/runs/ui/run_search_selection_test.dart b/app/test/features/runs/ui/run_search_selection_test.dart index 71940085..5fd77fc7 100644 --- a/app/test/features/runs/ui/run_search_selection_test.dart +++ b/app/test/features/runs/ui/run_search_selection_test.dart @@ -113,7 +113,7 @@ void main() { ); expect(find.byKey(const Key('run-visit-pane')), findsOneWidget); - expectVisitHeading(tester, 'build', 2); + expectVisitHeading(tester, 'build', 1); }); } diff --git a/app/test/features/runs/ui/run_visit_changes_action_test.dart b/app/test/features/runs/ui/run_visit_changes_action_test.dart index e4a96c72..f841ff21 100644 --- a/app/test/features/runs/ui/run_visit_changes_action_test.dart +++ b/app/test/features/runs/ui/run_visit_changes_action_test.dart @@ -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); diff --git a/app/test/features/schedules/ui/list/schedules_layout_test.dart b/app/test/features/schedules/ui/list/schedules_layout_test.dart index ad53a690..7ad2a8b9 100644 --- a/app/test/features/schedules/ui/list/schedules_layout_test.dart +++ b/app/test/features/schedules/ui/list/schedules_layout_test.dart @@ -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, diff --git a/app/test/features/search/search_row_test.dart b/app/test/features/search/search_row_test.dart index 086f2246..588f5637 100644 --- a/app/test/features/search/search_row_test.dart +++ b/app/test/features/search/search_row_test.dart @@ -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', () { diff --git a/app/test/ui/text/relative_time_test.dart b/app/test/ui/text/relative_time_test.dart new file mode 100644 index 00000000..0e3cd2e6 --- /dev/null +++ b/app/test/ui/text/relative_time_test.dart @@ -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); + }); +}