Merge branch 'chat/session-row-redesign' into integrate/chat-ntfy-attachments

This commit is contained in:
2026-10-30 21:05:32 +00:00
16 changed files with 519 additions and 555 deletions
@@ -6,7 +6,7 @@ import '../../domain/chat_sessions.dart';
import 'chat_adaptive.dart'; import 'chat_adaptive.dart';
import 'session_row_style.dart'; import 'session_row_style.dart';
enum SessionAction { rename, close, reopen, hide } enum SessionAction { star, rename, close, reopen, hide }
/// The close confirmation's body, matching the web client's explanation. /// The close confirmation's body, matching the web client's explanation.
String closeChatConfirmation(String title) => String closeChatConfirmation(String title) =>
@@ -15,39 +15,6 @@ String closeChatConfirmation(String title) =>
'Nothing is deleted — the chat and its history are kept, ' 'Nothing is deleted — the chat and its history are kept, '
'and you can reopen it from the list.'; 'and you can reopen it from the list.';
class SessionStarButton extends StatelessWidget {
const SessionStarButton({
super.key,
required this.session,
required this.onPressed,
});
final JsonMap session;
final VoidCallback onPressed;
@override
Widget build(BuildContext context) {
final starred = session['starred'] == true;
final label = starred ? 'Unstar chat' : 'Star chat';
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
return Semantics(
label: label,
button: true,
child: CupertinoButton(
padding: EdgeInsets.zero,
onPressed: onPressed,
child: Icon(starred ? CupertinoIcons.star_fill : CupertinoIcons.star),
),
);
}
return IconButton(
tooltip: label,
onPressed: onPressed,
icon: Icon(starred ? Icons.star : Icons.star_border),
);
}
}
class SessionActionsButton extends StatelessWidget { class SessionActionsButton extends StatelessWidget {
const SessionActionsButton({ const SessionActionsButton({
super.key, super.key,
@@ -64,7 +31,9 @@ class SessionActionsButton extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
final label = sessionActionsLabel(session, duplicateTitles); final label = sessionActionsLabel(session, duplicateTitles);
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) { if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
// Its own node, so the row's merged label never swallows the button.
return Semantics( return Semantics(
container: true,
label: label, label: label,
button: true, button: true,
child: CupertinoButton( child: CupertinoButton(
@@ -111,6 +80,10 @@ List<PopupMenuEntry<SessionAction>> _menuItems(JsonMap session) => [
List<({SessionAction action, String label})> _items(JsonMap session) { List<({SessionAction action, String label})> _items(JsonMap session) {
final isClosed = session['closed_at'] != null; final isClosed = session['closed_at'] != null;
return [ return [
(
action: SessionAction.star,
label: session['starred'] == true ? 'Unstar' : 'Star',
),
(action: SessionAction.rename, label: 'Rename…'), (action: SessionAction.rename, label: 'Rename…'),
isClosed isClosed
? (action: SessionAction.reopen, label: 'Reopen') ? (action: SessionAction.reopen, label: 'Reopen')
@@ -7,7 +7,6 @@ import '../../domain/chat_sessions.dart';
import 'chat_adaptive.dart'; import 'chat_adaptive.dart';
import 'chat_sessions_body.dart'; import 'chat_sessions_body.dart';
import 'session_actions.dart'; import 'session_actions.dart';
import 'session_harness_icon.dart';
import 'session_row_content.dart'; import 'session_row_content.dart';
import 'session_row_style.dart'; import 'session_row_style.dart';
@@ -147,67 +146,65 @@ class _CupertinoSessionRow extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final id = '${session['id'] ?? ''}'; final id = '${session['id'] ?? ''}';
// Cupertino's grouped list owns the separators and the native tile metrics; final closed = chatSessionRowStatus(session, unseen: false) == 'Closed';
// the row only decides where the title, its state word and the muted meta // A contact-list row, the same pieces as the Material row. The grouped
// go. Each metadata line keeps the tile's native 12pt style by // list owns the separators and the tile its native text styles; the
// passing colour only, so `Text` merges with `CupertinoListTile`'s own // leading slot is widened to hold the avatar.
// `DefaultTextStyle` instead of overriding it with the title's size. // A narrow pane (a wide window's list beside its detail, or its opening
final theme = CupertinoTheme.of(context); // animation) drops the avatar and tightens the tile's insets, so the
final secondary = CupertinoColors.secondaryLabel.resolveFrom(context); // menu stays reachable and the title keeps some width.
final meta = chatSessionMetaLines(session); return LayoutBuilder(
final recency = relativeChatSessionTime(session['updated_at']); builder: (context, constraints) {
final status = chatSessionRowStatus(session, unseen: unseen); final avatar = constraints.maxWidth >= _avatarMinWidth;
final statusStyle = theme.textTheme.tabLabelTextStyle.copyWith( return Semantics(
color: status == 'Closed' ? secondary : theme.primaryColor, selected: selected,
); child: CupertinoListTile(
return Semantics( key: Key('chat-row-$id'),
selected: selected, backgroundColor: selected
child: CupertinoListTile( ? CupertinoColors.tertiarySystemFill.resolveFrom(context)
key: Key('chat-row-$id'), : null,
backgroundColor: selected padding: avatar
? CupertinoColors.tertiarySystemFill.resolveFrom(context) ? null
: null, : const EdgeInsetsDirectional.only(start: 8, end: 4),
// As on the web: the title with the unread/closed word trailing, then leadingSize: avatar ? 40 : 28,
// the muted `recency · directory · model` line. leading: avatar
title: ChatSessionRowContent( ? ChatSessionAvatar(
leading: SessionHarnessIcon( session: session,
session: session, running: session['running'] == true && !unseen,
color: selected ? theme.primaryColor : null, selected: selected,
), )
actions: [ : null,
SessionStarButton( title: ChatSessionTitleLine(
key: Key('chat-star-$id'), title: chatSessionTitle(session),
session: session, recency: relativeChatSessionTime(session['updated_at']),
onPressed: () => onStar(session), unread: unseen && !closed,
starred: session['starred'] == true,
), ),
SessionActionsButton( subtitle: ChatSessionSubtitleLine(
text: chatSessionSubtitle(session),
unread: unseen && !closed,
closed: closed,
),
trailing: SessionActionsButton(
key: Key('chat-actions-$id'), key: Key('chat-actions-$id'),
session: session, session: session,
duplicateTitles: duplicateTitles, duplicateTitles: duplicateTitles,
onSelected: _select, onSelected: _select,
), ),
], onTap: () => onOpen(session),
title: chatSessionTitle(session),
status: status,
recency: recency.isEmpty ? null : recency,
meta: meta,
titleStyle: theme.textTheme.textStyle.copyWith(
fontWeight: FontWeight.w600,
), ),
metaStyle: theme.textTheme.tabLabelTextStyle.copyWith( );
color: secondary, },
),
statusStyle: statusStyle,
loading: session['running'] == true && !unseen,
),
subtitle: null,
onTap: () => onOpen(session),
),
); );
} }
/// The tile width below which the row is compact: no avatar, tight insets.
static const double _avatarMinWidth = 240;
void _select(SessionAction action) { void _select(SessionAction action) {
switch (action) { switch (action) {
case SessionAction.star:
onStar(session);
case SessionAction.rename: case SessionAction.rename:
onRename(session); onRename(session);
case SessionAction.close: case SessionAction.close:
@@ -7,7 +7,6 @@ import '../../domain/chat_sessions.dart';
import 'chat_adaptive.dart'; import 'chat_adaptive.dart';
import 'chat_sessions_body.dart'; import 'chat_sessions_body.dart';
import 'session_actions.dart'; import 'session_actions.dart';
import 'session_harness_icon.dart';
import 'session_row_content.dart'; import 'session_row_content.dart';
import 'session_row_style.dart'; import 'session_row_style.dart';
@@ -152,63 +151,63 @@ class _MaterialSessionRow extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final id = '${session['id'] ?? ''}'; final id = '${session['id'] ?? ''}';
// The same content as the Cupertino row: title and state, then each
// recorded metadata field on its own muted line.
// `ListTile` does not force one ellipsised line like `CupertinoListTile`,
// so both text widgets state their line limit themselves. The meta line
// passes colour only, so it keeps the tile's native subtitle style.
final theme = Theme.of(context); final theme = Theme.of(context);
final secondary = theme.colorScheme.onSurfaceVariant; final closed = chatSessionRowStatus(session, unseen: false) == 'Closed';
final meta = chatSessionMetaLines(session); // A contact-list row, the same pieces as the Cupertino row: the harness
final recency = relativeChatSessionTime(session['updated_at']); // avatar, the title with its time, one muted line, and the actions menu.
final status = chatSessionRowStatus(session, unseen: unseen); // ListTile asserts when its trailing control leaves the title no width.
final statusStyle = // A narrow pane (a wide window's list beside its detail, or its opening
theme.textTheme.labelSmall?.copyWith( // animation) drops the avatar and tightens the tile's insets, so the
color: status == 'Closed' ? secondary : theme.colorScheme.primary, // menu stays reachable and the title keeps some width.
) ?? return LayoutBuilder(
TextStyle(color: theme.colorScheme.primary); builder: (context, constraints) {
return ListTile( final narrow = constraints.maxWidth < _avatarMinWidth;
key: Key('chat-row-$id'), return ListTile(
selected: selected, key: Key('chat-row-$id'),
selectedTileColor: theme.colorScheme.secondaryContainer, selected: selected,
selectedColor: theme.colorScheme.onSecondaryContainer, selectedTileColor: theme.colorScheme.secondaryContainer,
// As on the web: the title with the unread/closed word trailing, then selectedColor: theme.colorScheme.onSecondaryContainer,
// the muted `recency · directory · model` line. contentPadding: narrow
title: ChatSessionRowContent( ? const EdgeInsetsDirectional.only(start: 8)
leading: SessionHarnessIcon(session: session), : null,
actions: [ horizontalTitleGap: narrow ? 4 : null,
SessionStarButton( leading: narrow
key: Key('chat-star-$id'), ? null
session: session, : ChatSessionAvatar(
onPressed: () => onStar(session), session: session,
running: session['running'] == true && !unseen,
selected: selected,
),
title: ChatSessionTitleLine(
title: chatSessionTitle(session),
recency: relativeChatSessionTime(session['updated_at']),
unread: unseen && !closed,
starred: session['starred'] == true,
), ),
SessionActionsButton( subtitle: ChatSessionSubtitleLine(
text: chatSessionSubtitle(session),
unread: unseen && !closed,
closed: closed,
),
trailing: SessionActionsButton(
key: Key('chat-actions-$id'), key: Key('chat-actions-$id'),
session: session, session: session,
duplicateTitles: duplicateTitles, duplicateTitles: duplicateTitles,
onSelected: _select, onSelected: _select,
), ),
], onTap: () => onOpen(session),
title: chatSessionTitle(session), );
status: status, },
recency: recency.isEmpty ? null : recency,
meta: meta,
titleStyle:
theme.textTheme.titleSmall ??
const TextStyle(fontWeight: FontWeight.w600),
metaStyle:
theme.textTheme.bodySmall?.copyWith(color: secondary) ??
TextStyle(color: secondary),
statusStyle: statusStyle,
loading: session['running'] == true && !unseen,
),
subtitle: null,
onTap: () => onOpen(session),
); );
} }
/// The tile width below which the row is compact: no avatar, tight insets.
static const double _avatarMinWidth = 240;
void _select(SessionAction action) { void _select(SessionAction action) {
switch (action) { switch (action) {
case SessionAction.star:
onStar(session);
case SessionAction.rename: case SessionAction.rename:
onRename(session); onRename(session);
case SessionAction.close: case SessionAction.close:
@@ -1,182 +1,241 @@
import 'dart:math' as math;
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../../core/api_gateway.dart';
import 'chat_adaptive.dart'; import 'chat_adaptive.dart';
import 'session_harness_icon.dart';
/// Hierarchical row copy shared by the Material and Cupertino list variants. /// Row pieces shared by the Material and Cupertino chat lists. Each list puts
/// Metadata stays on the left; recency and native actions share its vertical /// them in its native tile's slots: the avatar leads, the title line and the
/// space on the right instead of adding full-width rows below it. /// subtitle line fill the text column, and the actions menu trails.
class ChatSessionRowContent extends StatelessWidget {
const ChatSessionRowContent({ /// The chat's harness mark in a filled circle, like a contact avatar. A
/// running chat carries a small activity badge on the avatar's corner instead
/// of a line of its own; a selected chat's avatar takes the accent fill.
class ChatSessionAvatar extends StatelessWidget {
const ChatSessionAvatar({
super.key, super.key,
required this.title, required this.session,
required this.status, this.running = false,
required this.recency, this.selected = false,
required this.meta,
required this.titleStyle,
required this.metaStyle,
required this.statusStyle,
this.loading = false,
this.leading,
this.actions = const [],
}); });
final String title; final JsonMap session;
final String? status; final bool running;
final String? recency; final bool selected;
final List<String> meta;
final TextStyle titleStyle;
final TextStyle metaStyle;
final TextStyle statusStyle;
final bool loading;
final Widget? leading;
final List<Widget> actions;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Column( final cupertino =
crossAxisAlignment: CrossAxisAlignment.start, chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
mainAxisSize: MainAxisSize.min, final Color fill;
final Color mark;
if (cupertino) {
final primary = CupertinoTheme.of(context).primaryColor;
fill = selected
? primary.withValues(alpha: 0.2)
: CupertinoColors.systemGrey5.resolveFrom(context);
mark = selected ? primary : CupertinoColors.label.resolveFrom(context);
} else {
final scheme = Theme.of(context).colorScheme;
fill = selected
? scheme.primaryContainer
: scheme.surfaceContainerHighest;
mark = selected ? scheme.onPrimaryContainer : scheme.onSurfaceVariant;
}
final avatar = CircleAvatar(
backgroundColor: fill,
child: SessionHarnessIcon(session: session, color: mark),
);
if (!running) return avatar;
return Stack(
clipBehavior: Clip.none,
children: [ children: [
Row( avatar,
crossAxisAlignment: CrossAxisAlignment.start, PositionedDirectional(
children: [ end: -2,
if (leading != null) ...[leading!, const SizedBox(width: 8)], bottom: -2,
Expanded( child: Semantics(
child: Text( key: const Key('chat-row-working'),
title, label: 'Chat is working',
maxLines: 2, child: _WorkingBadge(cupertino: cupertino),
overflow: TextOverflow.ellipsis, ),
style: titleStyle,
),
),
],
),
LayoutBuilder(
builder: (context, constraints) {
final hasTrailing =
actions.isNotEmpty || (recency?.isNotEmpty ?? false);
final nativeTarget =
chatControlsStyleOf(context) == ChatControlsStyle.cupertino
? kMinInteractiveDimensionCupertino
: kMinInteractiveDimension;
final trailingWidth = math.min(
constraints.maxWidth,
math.max(
nativeTarget,
math.min(
constraints.maxWidth * 0.45,
nativeTarget * math.max(1, actions.length),
),
),
);
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
if (status != null)
_StatusLabel(status: status!, style: statusStyle),
if (status == null && loading)
Semantics(
label: 'Chat is working',
child: const _LoadingStatus(),
),
for (final line in meta)
Text(
line,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: metaStyle,
),
],
),
),
if (hasTrailing)
SizedBox(
width: trailingWidth,
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: [
if (recency?.isNotEmpty ?? false)
Text(
recency!,
maxLines: 2,
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.end,
style: metaStyle,
),
if (actions.isNotEmpty)
Wrap(alignment: WrapAlignment.end, children: actions),
],
),
),
],
);
},
), ),
], ],
); );
} }
} }
class _LoadingStatus extends StatelessWidget { class _WorkingBadge extends StatelessWidget {
const _LoadingStatus(); const _WorkingBadge({required this.cupertino});
final bool cupertino;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) { final background = cupertino
return const Align( ? CupertinoColors.systemBackground.resolveFrom(context)
alignment: AlignmentDirectional.centerStart, : Theme.of(context).colorScheme.surface;
child: CupertinoActivityIndicator(radius: 7), return DecoratedBox(
); decoration: BoxDecoration(color: background, shape: BoxShape.circle),
} child: Padding(
return const Align( padding: const EdgeInsets.all(2),
alignment: AlignmentDirectional.centerStart, child: cupertino
child: SizedBox( ? const CupertinoActivityIndicator(radius: 6)
width: 16, : const SizedBox.square(
height: 16, dimension: 12,
child: CircularProgressIndicator(strokeWidth: 2), child: CircularProgressIndicator(strokeWidth: 2),
),
), ),
); );
} }
} }
class _StatusLabel extends StatelessWidget { /// The title with its recency at the trailing edge. An unread chat's title is
const _StatusLabel({required this.status, required this.style}); /// bold and its time takes the accent, so it stands out at a glance; a starred
/// chat shows a small star after its title.
class ChatSessionTitleLine extends StatelessWidget {
const ChatSessionTitleLine({
super.key,
required this.title,
required this.recency,
this.unread = false,
this.starred = false,
});
final String status; final String title;
final TextStyle style; final String recency;
final bool unread;
final bool starred;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (status != 'New') { final cupertino =
return Text( chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
status, final accent = cupertino
maxLines: 1, ? CupertinoTheme.of(context).primaryColor
style: style.copyWith(fontWeight: FontWeight.w600), : Theme.of(context).colorScheme.primary;
); final secondary = cupertino
} ? CupertinoColors.secondaryLabel.resolveFrom(context)
final color = style.color ?? Theme.of(context).colorScheme.primary; : Theme.of(context).colorScheme.onSurfaceVariant;
return DecoratedBox( final timeStyle =
key: const Key('chat-row-unread'), (cupertino
decoration: ShapeDecoration(color: color, shape: const StadiumBorder()), ? CupertinoTheme.of(context).textTheme.tabLabelTextStyle
child: Padding( : Theme.of(context).textTheme.bodySmall)
padding: const EdgeInsets.symmetric(horizontal: 7, vertical: 1), ?.copyWith(
child: Text( color: unread ? accent : secondary,
status, fontWeight: unread ? FontWeight.w600 : null,
maxLines: 1, );
style: style.copyWith( final star = Icon(
color: Colors.white, cupertino ? CupertinoIcons.star_fill : Icons.star,
fontWeight: FontWeight.w700, key: const Key('chat-row-starred'),
// As tall as the title's text, so it follows text scaling.
size: DefaultTextStyle.of(context).style.fontSize,
color: accent,
semanticLabel: 'Starred',
);
// The star rides in the title's own text, so a narrow row ellipsises
// them together; the time keeps at most about half the line.
return LayoutBuilder(
builder: (context, constraints) => Row(
children: [
Expanded(
child: Text.rich(
TextSpan(
text: title,
children: [
if (starred)
WidgetSpan(
alignment: PlaceholderAlignment.middle,
child: Padding(
padding: const EdgeInsetsDirectional.only(start: 4),
child: star,
),
),
],
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontWeight: unread ? FontWeight.w700 : FontWeight.w500,
),
),
),
if (recency.isNotEmpty)
ConstrainedBox(
constraints: BoxConstraints(maxWidth: constraints.maxWidth / 2),
child: Padding(
padding: const EdgeInsetsDirectional.only(start: 8),
child: Text(
recency,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: timeStyle,
),
),
),
],
),
);
}
}
/// One muted line: `Closed` first when the chat is closed, then the model and
/// folder, with an accent dot at the end while the chat has unread content.
class ChatSessionSubtitleLine extends StatelessWidget {
const ChatSessionSubtitleLine({
super.key,
required this.text,
this.unread = false,
this.closed = false,
});
final String text;
final bool unread;
final bool closed;
@override
Widget build(BuildContext context) {
final cupertino =
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
final accent = cupertino
? CupertinoTheme.of(context).primaryColor
: Theme.of(context).colorScheme.primary;
return Row(
children: [
Expanded(
child: Text.rich(
TextSpan(
children: [
if (closed)
const TextSpan(
text: 'Closed',
style: TextStyle(fontWeight: FontWeight.w600),
),
if (closed && text.isNotEmpty) const TextSpan(text: ' · '),
TextSpan(text: text),
],
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
), ),
), ),
), if (unread)
Padding(
padding: const EdgeInsetsDirectional.only(start: 8),
child: Semantics(
key: const Key('chat-row-unread'),
label: 'New',
child: DecoratedBox(
decoration: BoxDecoration(
color: accent,
shape: BoxShape.circle,
),
child: const SizedBox.square(dimension: 10),
),
),
),
],
); );
} }
} }
@@ -40,27 +40,18 @@ String relativeChatSessionTime(Object? updatedAt, {DateTime? now}) {
return '${then.day} ${_shortMonths[then.month - 1]}'; return '${then.day} ${_shortMonths[then.month - 1]}';
} }
/// Recorded session fields rendered independently beneath the title. /// The row's one muted line: the recorded model and the folder (home as `~`).
List<String> chatSessionMetaLines(JsonMap session) { /// The harness is the row's avatar, so it is not repeated as a word.
final backend = '${session['backend'] ?? ''}'.trim(); String chatSessionSubtitle(JsonMap session) => [
return [ '${session['model'] ?? ''}'.trim(),
backend.isEmpty ? 'opencode' : backend, homeRelativePath('${session['directory'] ?? ''}'.trim()),
'${session['model'] ?? ''}'.trim(), ].where((part) => part.isNotEmpty).join(' · ');
homeRelativePath('${session['directory'] ?? ''}'.trim()),
].where((part) => part.isNotEmpty).toList();
}
final _homePrefix = RegExp(r'^(/Users/[^/]+|/home/[^/]+|/root)(?=/|$)'); final _homePrefix = RegExp(r'^(/Users/[^/]+|/home/[^/]+|/root)(?=/|$)');
/// `/Users/alan/repos/x` (or `/home/alan/...`) as `~/repos/x`. /// `/Users/alan/repos/x` (or `/home/alan/...`) as `~/repos/x`.
String homeRelativePath(String path) => path.replaceFirst(_homePrefix, '~'); String homeRelativePath(String path) => path.replaceFirst(_homePrefix, '~');
/// All secondary row information, each as a distinct line.
List<String> chatSessionRowMetaLines(JsonMap session, {DateTime? now}) => [
relativeChatSessionTime(session['updated_at'], now: now),
...chatSessionMetaLines(session),
].where((part) => part.isNotEmpty).toList();
/// The row's attention/state word: `Closed` takes precedence, otherwise only /// The row's attention/state word: `Closed` takes precedence, otherwise only
/// actually unread content is `New`. Loading activity is rendered separately. /// actually unread content is `New`. Loading activity is rendered separately.
String? chatSessionRowStatus(JsonMap session, {required bool unseen}) { String? chatSessionRowStatus(JsonMap session, {required bool unseen}) {
+20
View File
@@ -0,0 +1,20 @@
# Chat list rows: contact-list layout
Branch `chat/session-row-redesign`.
- Each row uses its native tile's slots: a circular harness avatar
(`ChatSessionAvatar`) leads, the title line carries the time at its trailing
edge, one muted line holds `model · folder`, and the actions menu trails.
- Unread: bold title, accent time and an accent dot (`chat-row-unread`) in
place of the old `New` word. Running: a small activity badge on the avatar
(`chat-row-working`). Closed: `Closed ·` leads the muted line. Starred: a
small star after the title (`chat-row-starred`).
- Star/Unstar moved into the row's actions menu; the separate star button is
gone. The backend name is no longer repeated as text (the avatar shows it).
- A narrow pane (< 240 px tile, e.g. a 640 px window's list beside the detail,
or its opening animation) drops the avatar and tightens the insets so the
menu stays reachable and Material's ListTile never asserts.
- Checks: `flutter test` 1997 passed; `flutter analyze` only the existing
artifacts info. Chrome captures of `tool/chat_sessions_probe_entry.dart`
(Material and Cupertino) show the new rows. `tool/chat_sessions_probe.mjs`
still targets the removed `chat-star-*` button. Not verified on a device.
@@ -207,9 +207,12 @@ void main() {
} }
} }
if (destination == 'Chat') { if (destination == 'Chat') {
final star = find.byKey(const Key('chat-star-b')); // Starring lives in the row's actions menu.
await tester.ensureVisible(star); final menu = find.byKey(const Key('chat-actions-b'));
await tester.tap(star); await tester.ensureVisible(menu);
await tester.tap(menu);
await tester.pumpAndSettle();
await tester.tap(find.text('Star'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect( expect(
gateway gateway
@@ -15,7 +15,10 @@ void main() {
..sessionsReply = {'chat_sessions': sampleSessions()}; ..sessionsReply = {'chat_sessions': sampleSessions()};
await pumpMaterialChat(tester, gateway); await pumpMaterialChat(tester, gateway);
await tester.tap(find.byKey(const Key('chat-star-s2'))); // Starring lives in the row's actions menu.
await tester.tap(find.byKey(const Key('chat-actions-s2')));
await tester.pumpAndSettle();
await tester.tap(find.text('Star'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(gateway.lastFields('chat_star'), { expect(gateway.lastFields('chat_star'), {
'chat_query': {'session_id': 's2', 'starred': true}, 'chat_query': {'session_id': 's2', 'starred': true},
@@ -1,69 +0,0 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/ui/sessions/session_row_content.dart';
import 'package:pipelines_app/features/chat/ui/sessions/session_actions.dart';
void main() {
for (final cupertino in [false, true]) {
for (final width in [120.0, 360.0]) {
testWidgets(
'right-side recency/actions, Cupertino=$cupertino width=$width',
(tester) async {
final star = SessionStarButton(
session: const {'id': 's'},
onPressed: () {},
);
final more = SessionActionsButton(
session: const {'id': 's'},
onSelected: (_) {},
);
final row = Center(
child: SizedBox(
width: width,
child: ChatSessionRowContent(
title: 'Chat title',
status: null,
recency: '5 min ago',
meta: const ['opencode', 'model', '/work'],
titleStyle: const TextStyle(fontSize: 17),
metaStyle: const TextStyle(fontSize: 12),
statusStyle: const TextStyle(fontSize: 12),
actions: [
KeyedSubtree(key: const Key('star'), child: star),
KeyedSubtree(key: const Key('more'), child: more),
],
),
),
);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: row))
: MaterialApp(home: Scaffold(body: row)),
);
await tester.pumpAndSettle();
final backend = tester.getRect(find.text('opencode'));
final time = tester.getRect(find.text('5 min ago'));
final favorite = tester.getRect(find.byKey(const Key('star')));
final menu = tester.getRect(find.byKey(const Key('more')));
expect(time.left, greaterThanOrEqualTo(backend.right));
expect(
time.top,
closeTo(backend.top, 0.1),
reason: 'Timestamp belongs beside metadata, not below it',
);
expect(favorite.left, greaterThanOrEqualTo(backend.right));
expect(menu.left, greaterThanOrEqualTo(backend.right));
if (width == 360) {
expect(
favorite.top,
lessThan(tester.getRect(find.text('/work')).bottom),
);
expect(menu.top, closeTo(favorite.top, 0.1));
}
expect(tester.takeException(), isNull);
},
);
}
}
}
@@ -53,18 +53,18 @@ void main() {
], ],
}; };
await pumpMaterialChat(tester, gateway); await pumpMaterialChat(tester, gateway);
expect(find.text('New'), findsNothing); expect(find.byKey(const Key('chat-row-unread')), findsNothing);
updatedAt = 2000; updatedAt = 2000;
await tester.tap(find.byKey(const Key('chat-refresh'))); await tester.tap(find.byKey(const Key('chat-refresh')));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('New'), findsNothing); expect(find.byKey(const Key('chat-row-unread')), findsNothing);
await tester.tap(find.byKey(const Key('chat-row-s1'))); await tester.tap(find.byKey(const Key('chat-row-s1')));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-refresh'))); await tester.tap(find.byKey(const Key('chat-refresh')));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('New'), findsNothing); expect(find.byKey(const Key('chat-row-unread')), findsNothing);
}); });
testWidgets('a closed row never reports New after newer activity', ( testWidgets('a closed row never reports New after newer activity', (
@@ -85,7 +85,7 @@ void main() {
], ],
}; };
await pumpMaterialChat(tester, gateway); await pumpMaterialChat(tester, gateway);
expect(find.text('New'), findsNothing); expect(find.byKey(const Key('chat-row-unread')), findsNothing);
// Another device moved the chat on and closed it after this device read it. // Another device moved the chat on and closed it after this device read it.
updatedAt = 2000; updatedAt = 2000;
@@ -94,11 +94,11 @@ void main() {
await tester.pumpAndSettle(); await tester.pumpAndSettle();
await expandClosedChats(tester); await expandClosedChats(tester);
expect(find.text('New'), findsNothing); expect(find.byKey(const Key('chat-row-unread')), findsNothing);
expect( expect(
find.descendant( find.descendant(
of: find.byKey(const Key('chat-row-s1')), of: find.byKey(const Key('chat-row-s1')),
matching: find.text('Closed'), matching: find.textContaining(RegExp(r'^Closed( ·|$)')),
), ),
findsOneWidget, findsOneWidget,
); );
@@ -3,6 +3,7 @@ import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart'; import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/chat/ui/sessions/session_list_cupertino.dart'; import 'package:pipelines_app/features/chat/ui/sessions/session_list_cupertino.dart';
import 'package:pipelines_app/features/chat/ui/sessions/session_row_content.dart';
import 'package:pipelines_app/features/chat/ui/sessions/session_row_style.dart'; import 'package:pipelines_app/features/chat/ui/sessions/session_row_style.dart';
/// A grouped Cupertino list, the host the web client runs on macOS/iOS. /// A grouped Cupertino list, the host the web client runs on macOS/iOS.
@@ -32,7 +33,9 @@ Future<void> _pumpRows(
), ),
), ),
); );
await tester.pumpAndSettle(); // A running row's activity badge animates for as long as it runs.
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
} }
void _useNarrowText(WidgetTester tester) { void _useNarrowText(WidgetTester tester) {
@@ -47,7 +50,7 @@ void _useNarrowText(WidgetTester tester) {
/// The resolved style a text is painted with, after merging with the host's /// The resolved style a text is painted with, after merging with the host's
/// own `DefaultTextStyle`. /// own `DefaultTextStyle`.
TextStyle _styleOf(WidgetTester tester, String text) => TextStyle _styleOf(WidgetTester tester, String text) =>
tester.renderObject<RenderParagraph>(find.text(text)).text.style!; tester.renderObject<RenderParagraph>(find.textContaining(text)).text.style!;
void main() { void main() {
test('relative recency uses the web wording and never invents a time', () { test('relative recency uses the web wording and never invents a time', () {
@@ -106,22 +109,21 @@ void main() {
); );
}); });
test('meta and status come only from the row', () { test('the subtitle and status come only from the row', () {
expect(chatSessionMetaLines({'directory': '/work', 'model': 'model-a'}), [
'opencode',
'model-a',
'/work',
]);
expect(chatSessionMetaLines({'directory': '/work'}), ['opencode', '/work']);
expect(chatSessionMetaLines({}), ['opencode']);
// The agent kind is the row's backend; the home folder reads as ~.
expect( expect(
chatSessionMetaLines({ chatSessionSubtitle({'directory': '/work', 'model': 'model-a'}),
'model-a · /work',
);
expect(chatSessionSubtitle({'directory': '/work'}), '/work');
expect(chatSessionSubtitle({}), '');
// The harness is the avatar, not a word; the home folder reads as ~.
expect(
chatSessionSubtitle({
'backend': 'claude', 'backend': 'claude',
'model': 'opus', 'model': 'opus',
'directory': '/Users/alan/repos/pipelines', 'directory': '/Users/alan/repos/pipelines',
}), }),
['claude', 'opus', '~/repos/pipelines'], 'opus · ~/repos/pipelines',
); );
expect(homeRelativePath('/home/dev/x'), '~/x'); expect(homeRelativePath('/home/dev/x'), '~/x');
expect(homeRelativePath('/Users/alan'), '~'); expect(homeRelativePath('/Users/alan'), '~');
@@ -129,7 +131,6 @@ void main() {
expect(chatSessionRowStatus({}, unseen: false), isNull); expect(chatSessionRowStatus({}, unseen: false), isNull);
expect(chatSessionRowStatus({}, unseen: true), 'New'); expect(chatSessionRowStatus({}, unseen: true), 'New');
// Running never hides an unread message; the native spinner is separate.
expect(chatSessionRowStatus({'running': true}, unseen: true), 'New'); expect(chatSessionRowStatus({'running': true}, unseen: true), 'New');
expect(chatSessionRowStatus({'running': true}, unseen: false), isNull); expect(chatSessionRowStatus({'running': true}, unseen: false), isNull);
expect( expect(
@@ -138,24 +139,27 @@ void main() {
); );
}); });
testWidgets('a row reads title, muted meta and trailing recency/unread', ( testWidgets('a row reads avatar, title with time, one muted line and menu', (
tester, tester,
) async { ) async {
final now = DateTime.now(); final now = DateTime.now();
final sessions = <JsonMap>[ final sessions = <JsonMap>[
{ {
'id': 's1', 'id': 's1',
'title': 'Starred chat', 'title': 'Unread chat',
'backend': 'claude',
'directory': '/work', 'directory': '/work',
'model': 'model-a', 'model': 'model-a',
'starred': true,
'updated_at': now 'updated_at': now
.subtract(const Duration(minutes: 5)) .subtract(const Duration(minutes: 5))
.millisecondsSinceEpoch, .millisecondsSinceEpoch,
}, },
{ {
'id': 's2', 'id': 's2',
'title': 'Open chat', 'title': 'Read chat',
'directory': '/work', 'directory': '/work',
'running': true,
'updated_at': now 'updated_at': now
.subtract(const Duration(hours: 2, minutes: 30)) .subtract(const Duration(hours: 2, minutes: 30))
.millisecondsSinceEpoch, .millisecondsSinceEpoch,
@@ -167,41 +171,52 @@ void main() {
isUnseen: (session) => session['id'] == 's1', isUnseen: (session) => session['id'] == 's1',
); );
// As on the web: the unread word trails the title; the muted meta line final title = tester.getRect(find.textContaining('Unread chat'));
// leads with the recency. final time = tester.getRect(find.text('5 min ago'));
expect(find.text('Starred chat'), findsOneWidget); final subtitle = tester.getRect(find.text('model-a · /work'));
expect(find.text('5 min ago'), findsOneWidget); final avatar = tester.getRect(
expect(find.text('model-a'), findsOneWidget); find.descendant(
expect(find.text('New'), findsOneWidget); of: find.byKey(const Key('chat-row-s1')),
expect(find.text('2 hr ago'), findsOneWidget); matching: find.byType(ChatSessionAvatar),
expect(find.text('opencode'), findsNWidgets(2)); ),
expect(find.text('/work'), findsNWidgets(2));
expect(
tester.getCenter(find.text('New')).dy,
greaterThan(tester.getCenter(find.text('Starred chat')).dy),
); );
// Avatar leads, the time trails the title on its line, the muted line
// sits beneath, and the menu trails the whole row.
expect(avatar.right, lessThanOrEqualTo(title.left));
expect(time.left, greaterThan(title.right));
expect(time.center.dy, closeTo(title.center.dy, 2));
expect(subtitle.top, greaterThanOrEqualTo(title.bottom - 1));
expect( expect(
tester.getCenter(find.text('5 min ago')).dx, tester.getRect(find.byKey(const Key('chat-actions-s1'))).left,
greaterThan(tester.getCenter(find.text('Starred chat')).dx), greaterThanOrEqualTo(time.right),
); );
// Metadata and state use native caption roles, not title-sized text. // Unread is bold with an accent time and dot; read rows are not.
final titleStyle = _styleOf(tester, 'Starred chat'); expect(_styleOf(tester, 'Unread chat').fontWeight, FontWeight.w700);
final metaStyle = _styleOf(tester, '5 min ago'); expect(_styleOf(tester, 'Read chat').fontWeight, FontWeight.w500);
expect(metaStyle.fontSize, lessThan(titleStyle.fontSize!)); expect(find.byKey(const Key('chat-row-unread')), findsOneWidget);
expect( final accent = CupertinoTheme.of(
metaStyle.fontSize, tester.element(find.text('5 min ago')),
CupertinoTheme.of( ).primaryColor;
tester.element(find.text('5 min ago')), expect(_styleOf(tester, '5 min ago').color, accent);
).textTheme.tabLabelTextStyle.fontSize, expect(_styleOf(tester, '2 hr ago').color, isNot(accent));
);
expect(_styleOf(tester, 'New').fontSize, metaStyle.fontSize);
// Each session is still its own native tile with its own actions, so the // Starred shows a small star by the title; running a badge on the avatar.
// inset group draws the separator between them. expect(
find.descendant(
of: find.byKey(const Key('chat-row-s1')),
matching: find.byKey(const Key('chat-row-starred')),
),
findsOneWidget,
);
expect(
find.descendant(
of: find.byKey(const Key('chat-row-s2')),
matching: find.byKey(const Key('chat-row-working')),
),
findsOneWidget,
);
expect(find.byType(CupertinoListTile), findsNWidgets(2)); expect(find.byType(CupertinoListTile), findsNWidgets(2));
expect(find.byKey(const Key('chat-star-s1')), findsOneWidget);
expect(find.byKey(const Key('chat-actions-s2')), findsOneWidget);
expect( expect(
tester.getTopLeft(find.byKey(const Key('chat-row-s2'))).dy, tester.getTopLeft(find.byKey(const Key('chat-row-s2'))).dy,
greaterThan( greaterThan(
@@ -210,7 +225,7 @@ void main() {
); );
}); });
testWidgets('at 320px 2x the long title and meta ellipsise, the word does not', ( testWidgets('at 320px 2x the long title and subtitle ellipsise', (
tester, tester,
) async { ) async {
_useNarrowText(tester); _useNarrowText(tester);
@@ -234,43 +249,29 @@ void main() {
], isUnseen: (session) => session['id'] == 's1'); ], isUnseen: (session) => session['id'] == 's1');
expect(tester.takeException(), isNull); expect(tester.takeException(), isNull);
const title = 'A conversation title long enough to need an ellipsis'; final title = tester.renderObject<RenderParagraph>(
const meta = '/a/very/long/directory/that/must/ellipsise'; find.text('A conversation title long enough to need an ellipsis'),
final titleParagraph = tester.renderObject<RenderParagraph>(
find.text(title),
); );
expect(titleParagraph.maxLines, 2); expect(title.maxLines, 1);
expect(titleParagraph.didExceedMaxLines, isTrue); expect(title.didExceedMaxLines, isTrue);
final metaParagraph = tester.renderObject<RenderParagraph>( final subtitle = tester.renderObject<RenderParagraph>(
find.descendant( find.text(
of: find.byKey(const Key('chat-row-s1')), 'provider/an-extremely-long-recorded-model-id · '
matching: find.text(meta), '/a/very/long/directory/that/must/ellipsise',
), ),
); );
expect(metaParagraph.maxLines, 2); expect(subtitle.maxLines, 1);
expect(metaParagraph.didExceedMaxLines, isTrue); expect(subtitle.didExceedMaxLines, isTrue);
// The state word is the row's only unread marker: at the smallest supported // The time and the Closed word stay inside their row.
// surface with 2x text it stays whole (it is scaled down only when even the for (final (row, word) in [('s1', '3 days ago'), ('c1', 'Closed')]) {
// full text column cannot hold it) and inside the tile's trailing edge.
for (final row in ['s1', 'c1']) {
final word = row == 's1' ? 'New' : 'Closed';
final paragraph = tester.renderObject<RenderParagraph>(find.text(word));
expect(paragraph.maxLines, 1);
expect(paragraph.didExceedMaxLines, isFalse, reason: '$word is clipped');
final rect = tester.getRect(find.text(word));
expect(rect.width, greaterThan(0));
expect( expect(
rect.right, tester.getRect(find.textContaining(word)).right,
lessThanOrEqualTo( lessThanOrEqualTo(
tester.getRect(find.byKey(Key('chat-row-$row'))).right, tester.getRect(find.byKey(Key('chat-row-$row'))).right,
), ),
); );
} }
expect(find.byKey(const Key('chat-row-unread')), findsOneWidget);
expect(
tester.getCenter(find.text('New')).dy,
greaterThan(tester.getCenter(find.text(title)).dy),
);
}); });
} }
@@ -3,6 +3,7 @@ import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart'; import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/chat/ui/sessions/session_list_material.dart'; import 'package:pipelines_app/features/chat/ui/sessions/session_list_material.dart';
import 'package:pipelines_app/features/chat/ui/sessions/session_row_content.dart';
import 'expand_closed.dart'; import 'expand_closed.dart';
/// The Android host: a Material grouped list with its native separators. /// The Android host: a Material grouped list with its native separators.
@@ -49,14 +50,14 @@ void _useNarrowText(WidgetTester tester) {
} }
void main() { void main() {
testWidgets('a Material row reads title, muted meta and trailing recency', ( testWidgets('a Material row reads avatar, title with time and muted line', (
tester, tester,
) async { ) async {
final now = DateTime.now(); final now = DateTime.now();
await _pumpRows(tester, [ await _pumpRows(tester, [
{ {
'id': 's1', 'id': 's1',
'title': 'Starred chat', 'title': 'Unread chat',
'directory': '/work', 'directory': '/work',
'model': 'model-a', 'model': 'model-a',
'updated_at': now 'updated_at': now
@@ -65,7 +66,7 @@ void main() {
}, },
{ {
'id': 's2', 'id': 's2',
'title': 'Open chat', 'title': 'Read chat',
'directory': '/work', 'directory': '/work',
'updated_at': now 'updated_at': now
.subtract(const Duration(hours: 2, minutes: 30)) .subtract(const Duration(hours: 2, minutes: 30))
@@ -73,26 +74,38 @@ void main() {
}, },
], isUnseen: (session) => session['id'] == 's1'); ], isUnseen: (session) => session['id'] == 's1');
expect(find.text('Starred chat'), findsOneWidget); final title = tester.getRect(find.text('Unread chat'));
expect(find.text('5 min ago'), findsOneWidget); final time = tester.getRect(find.text('5 min ago'));
expect(find.text('opencode'), findsNWidgets(2)); expect(time.left, greaterThan(title.right));
expect(find.text('model-a'), findsOneWidget); expect(time.center.dy, closeTo(title.center.dy, 2));
expect(find.text('/work'), findsNWidgets(2));
expect(find.text('New'), findsOneWidget);
expect(find.text('2 hr ago'), findsOneWidget);
expect( expect(
tester.getCenter(find.text('New')).dy, tester.getRect(find.text('model-a · /work')).top,
greaterThan(tester.getCenter(find.text('Starred chat')).dy), greaterThanOrEqualTo(title.bottom - 1),
); );
expect(find.text('/work'), findsOneWidget);
expect( expect(
tester.getCenter(find.text('5 min ago')).dx, tester.getRect(find.byType(ChatSessionAvatar).first).right,
greaterThan(tester.getCenter(find.text('Starred chat')).dx), lessThanOrEqualTo(title.left),
); );
// The meta line is the theme's muted colour, not the title colour. // Unread: bold title, accent time and a dot; the read row stays muted.
final meta = tester.widget<Text>(find.text('5 min ago')); final scheme = Theme.of(tester.element(find.text('5 min ago'))).colorScheme;
final context = tester.element(find.text('5 min ago')); expect(
expect(meta.style?.color, Theme.of(context).colorScheme.onSurfaceVariant); tester.widget<Text>(find.text('5 min ago')).style?.color,
scheme.primary,
);
expect(
tester.widget<Text>(find.text('2 hr ago')).style?.color,
scheme.onSurfaceVariant,
);
expect(find.byKey(const Key('chat-row-unread')), findsOneWidget);
expect(
find.descendant(
of: find.byKey(const Key('chat-row-s1')),
matching: find.byKey(const Key('chat-row-unread')),
),
findsOneWidget,
);
// Native Material separators sit between rows, not around the group. // Native Material separators sit between rows, not around the group.
expect(find.byType(Divider), findsOneWidget); expect(find.byType(Divider), findsOneWidget);
@@ -102,7 +115,6 @@ void main() {
tester.getBottomLeft(find.byKey(const Key('chat-row-s1'))).dy, tester.getBottomLeft(find.byKey(const Key('chat-row-s1'))).dy,
), ),
); );
expect(find.byKey(const Key('chat-star-s1')), findsOneWidget);
expect(find.byKey(const Key('chat-actions-s2')), findsOneWidget); expect(find.byKey(const Key('chat-actions-s2')), findsOneWidget);
}); });
@@ -119,18 +131,18 @@ void main() {
], section: 'Closed'); ], section: 'Closed');
await expandClosedChats(tester); await expandClosedChats(tester);
// The section header also says Closed; the row's trailing word is its own. // The section header also says Closed; the row's own line leads with it.
expect( expect(
find.descendant( find.descendant(
of: find.byKey(const Key('chat-row-c1')), of: find.byKey(const Key('chat-row-c1')),
matching: find.text('Closed'), matching: find.text('Closed · /work'),
), ),
findsOneWidget, findsOneWidget,
); );
expect(find.text('New'), findsNothing); expect(find.byKey(const Key('chat-row-unread')), findsNothing);
}); });
testWidgets('at 320px 2x the Material row ellipsises text, not its word', ( testWidgets('at 320px 2x the Material row ellipsises and never overflows', (
tester, tester,
) async { ) async {
_useNarrowText(tester); _useNarrowText(tester);
@@ -141,6 +153,7 @@ void main() {
'title': 'A conversation title long enough to need an ellipsis', 'title': 'A conversation title long enough to need an ellipsis',
'directory': '/a/very/long/directory/that/must/ellipsise', 'directory': '/a/very/long/directory/that/must/ellipsise',
'model': 'provider/an-extremely-long-recorded-model-id', 'model': 'provider/an-extremely-long-recorded-model-id',
'starred': true,
'updated_at': now 'updated_at': now
.subtract(const Duration(days: 3)) .subtract(const Duration(days: 3))
.millisecondsSinceEpoch, .millisecondsSinceEpoch,
@@ -154,50 +167,24 @@ void main() {
], isUnseen: (session) => session['id'] == 's1'); ], isUnseen: (session) => session['id'] == 's1');
expect(tester.takeException(), isNull); expect(tester.takeException(), isNull);
const title = 'A conversation title long enough to need an ellipsis'; final title = tester.renderObject<RenderParagraph>(
const meta = '/a/very/long/directory/that/must/ellipsise'; find.textContaining('A conversation title long enough'),
final titleParagraph = tester.renderObject<RenderParagraph>(
find.text(title),
); );
expect(titleParagraph.maxLines, 2); expect(title.maxLines, 1);
expect(titleParagraph.didExceedMaxLines, isTrue); expect(title.didExceedMaxLines, isTrue);
final metaParagraph = tester.renderObject<RenderParagraph>( final subtitle = tester.renderObject<RenderParagraph>(
find.descendant( find.textContaining('provider/an-extremely-long-recorded-model-id'),
of: find.byKey(const Key('chat-row-s1')),
matching: find.text(meta),
),
); );
expect(metaParagraph.maxLines, 2); expect(subtitle.maxLines, 1);
expect(metaParagraph.didExceedMaxLines, isTrue); expect(subtitle.didExceedMaxLines, isTrue);
for (final (row, word) in [('s1', '3 days ago'), ('c1', 'Closed')]) {
// `New`/`Closed` is the row's only unread marker; it stays whole at the
// smallest supported surface with 2x text.
for (final row in ['s1', 'c1']) {
final word = row == 's1' ? 'New' : 'Closed';
final paragraph = tester.renderObject<RenderParagraph>(find.text(word));
expect(paragraph.maxLines, 1);
expect(paragraph.didExceedMaxLines, isFalse, reason: '$word is clipped');
final rect = tester.getRect(find.text(word));
expect(rect.width, greaterThan(0));
expect( expect(
rect.right, tester.getRect(find.textContaining(word)).right,
lessThanOrEqualTo( lessThanOrEqualTo(
tester.getRect(find.byKey(Key('chat-row-$row'))).right, tester.getRect(find.byKey(Key('chat-row-$row'))).right,
), ),
); );
} }
expect(find.byKey(const Key('chat-row-unread')), findsOneWidget);
// The title/state and every metadata field occupy distinct lines.
expect(
tester
.getCenter(
find.descendant(
of: find.byKey(const Key('chat-row-s1')),
matching: find.text(meta).last,
),
)
.dy,
greaterThan(tester.getCenter(find.text(title)).dy),
);
}); });
} }
@@ -144,7 +144,10 @@ void main() {
}; };
await pumpMaterialChat(tester, gateway); await pumpMaterialChat(tester, gateway);
await tester.tap(find.byKey(const Key('chat-star-s2'))); // Starring lives in the row's actions menu.
await tester.tap(find.byKey(const Key('chat-actions-s2')));
await tester.pumpAndSettle();
await tester.tap(find.text('Star'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(gateway.lastFields('chat_star'), { expect(gateway.lastFields('chat_star'), {
'chat_query': {'session_id': 's2', 'starred': true}, 'chat_query': {'session_id': 's2', 'starred': true},
@@ -152,8 +155,8 @@ void main() {
expect(gateway.count('chat_sessions'), greaterThanOrEqualTo(2)); expect(gateway.count('chat_sessions'), greaterThanOrEqualTo(2));
expect( expect(
find.descendant( find.descendant(
of: find.byKey(const Key('chat-star-s2')), of: find.byKey(const Key('chat-row-s2')),
matching: find.byIcon(Icons.star), matching: find.byKey(const Key('chat-row-starred')),
), ),
findsOneWidget, findsOneWidget,
); );
@@ -6,7 +6,6 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart'; import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/chat/ui/sessions/chat_session_local.dart'; import 'package:pipelines_app/features/chat/ui/sessions/chat_session_local.dart';
import 'package:pipelines_app/features/chat/ui/sessions/chat_sessions_screen.dart'; import 'package:pipelines_app/features/chat/ui/sessions/chat_sessions_screen.dart';
import 'package:pipelines_app/features/chat/ui/sessions/session_row_content.dart';
import 'chat_test_harness.dart'; import 'chat_test_harness.dart';
import 'fake_chat_gateway.dart'; import 'fake_chat_gateway.dart';
@@ -83,16 +82,16 @@ void main() {
) async { ) async {
final fake = gateway(); final fake = gateway();
await _pump(tester, fake); await _pump(tester, fake);
expect(find.text('New'), findsNothing); expect(find.byKey(const Key('chat-row-unread')), findsNothing);
fake.pushed.add(_event('s1')); fake.pushed.add(_event('s1'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('New'), findsOneWidget); expect(find.byKey(const Key('chat-row-unread')), findsOneWidget);
expect(fake.count('chat_sessions'), 1); expect(fake.count('chat_sessions'), 1);
await tester.tap(find.byKey(const Key('chat-row-s1'))); await tester.tap(find.byKey(const Key('chat-row-s1')));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('New'), findsNothing); expect(find.byKey(const Key('chat-row-unread')), findsNothing);
}); });
testWidgets('usage frames and the open chat never raise New', (tester) async { testWidgets('usage frames and the open chat never raise New', (tester) async {
@@ -101,7 +100,7 @@ void main() {
fake.pushed.add(_event('s1')); fake.pushed.add(_event('s1'));
fake.pushed.add(_event('s1', kind: 'usage')); fake.pushed.add(_event('s1', kind: 'usage'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('New'), findsNothing); expect(find.byKey(const Key('chat-row-unread')), findsNothing);
}); });
testWidgets('leaving the conversation lets later activity mark it New', ( testWidgets('leaving the conversation lets later activity mark it New', (
@@ -118,7 +117,7 @@ void main() {
'chat_permission': {'session_id': 's1'}, 'chat_permission': {'session_id': 's1'},
}); });
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('New'), findsOneWidget); expect(find.byKey(const Key('chat-row-unread')), findsOneWidget);
}); });
testWidgets('step and reasoning churn show loading, not New', (tester) async { testWidgets('step and reasoning churn show loading, not New', (tester) async {
@@ -134,19 +133,14 @@ void main() {
}); });
await tester.pump(); await tester.pump();
await tester.pump(); await tester.pump();
expect(find.text('New'), findsNothing); expect(find.byKey(const Key('chat-row-unread')), findsNothing);
expect( expect(find.byKey(const Key('chat-row-working')), findsOneWidget);
tester
.widget<ChatSessionRowContent>(find.byType(ChatSessionRowContent))
.loading,
isTrue,
);
expect(find.byType(CircularProgressIndicator), findsOneWidget); expect(find.byType(CircularProgressIndicator), findsOneWidget);
fake.pushed.add(_event('s1', kind: 'reasoning', delta: 'thinking')); fake.pushed.add(_event('s1', kind: 'reasoning', delta: 'thinking'));
await tester.pump(); await tester.pump();
await tester.pump(); await tester.pump();
expect(find.text('New'), findsNothing); expect(find.byKey(const Key('chat-row-unread')), findsNothing);
expect(fake.count('chat_sessions'), 1); expect(fake.count('chat_sessions'), 1);
fake.pushed.add({ fake.pushed.add({
@@ -160,7 +154,7 @@ void main() {
await tester.pump(); await tester.pump();
await tester.pump(); await tester.pump();
expect(find.byType(CircularProgressIndicator), findsNothing); expect(find.byType(CircularProgressIndicator), findsNothing);
expect(find.text('New'), findsNothing); expect(find.byKey(const Key('chat-row-unread')), findsNothing);
}); });
testWidgets('an unread visible answer remains New while running', ( testWidgets('an unread visible answer remains New while running', (
@@ -178,7 +172,7 @@ void main() {
}); });
fake.pushed.add(_event('s1')); fake.pushed.add(_event('s1'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('New'), findsOneWidget); expect(find.byKey(const Key('chat-row-unread')), findsOneWidget);
expect(find.byType(CircularProgressIndicator), findsNothing); expect(find.byType(CircularProgressIndicator), findsNothing);
}); });
@@ -200,7 +194,7 @@ void main() {
}); });
await tester.pump(); await tester.pump();
await tester.pump(); await tester.pump();
expect(find.text('New'), findsNothing); expect(find.byKey(const Key('chat-row-unread')), findsNothing);
expect(find.byType(CircularProgressIndicator), findsOneWidget); expect(find.byType(CircularProgressIndicator), findsOneWidget);
fake.pushed.add({ fake.pushed.add({
@@ -220,7 +214,7 @@ void main() {
}, },
}); });
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('New'), findsOneWidget); expect(find.byKey(const Key('chat-row-unread')), findsOneWidget);
expect(find.byType(CircularProgressIndicator), findsNothing); expect(find.byType(CircularProgressIndicator), findsNothing);
}); });
@@ -237,13 +231,13 @@ void main() {
}, },
}); });
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('New'), findsNothing); expect(find.byKey(const Key('chat-row-unread')), findsNothing);
fake.pushed.add({ fake.pushed.add({
'type': 'chat_permission', 'type': 'chat_permission',
'chat_permission': {'session_id': 's1', 'request_id': 'p2'}, 'chat_permission': {'session_id': 's1', 'request_id': 'p2'},
}); });
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('New'), findsOneWidget); expect(find.byKey(const Key('chat-row-unread')), findsOneWidget);
}); });
testWidgets('updated_at alone never manufactures unread state', ( testWidgets('updated_at alone never manufactures unread state', (
@@ -261,7 +255,7 @@ void main() {
await tester.pumpAndSettle(); await tester.pumpAndSettle();
fake.pushed.add(_event('unknown')); fake.pushed.add(_event('unknown'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('New'), findsNothing); expect(find.byKey(const Key('chat-row-unread')), findsNothing);
await tester.pumpWidget(const SizedBox.shrink()); await tester.pumpWidget(const SizedBox.shrink());
fake.pushed.add(_event('s1')); fake.pushed.add(_event('s1'));
await tester.pump(); await tester.pump();
@@ -290,7 +284,7 @@ void main() {
delayed.loaded.complete(const ChatSessionLocal()); delayed.loaded.complete(const ChatSessionLocal());
await tester.pump(); await tester.pump();
await tester.pump(); await tester.pump();
expect(find.text('New'), findsNothing); expect(find.byKey(const Key('chat-row-unread')), findsNothing);
expect(delayed.saved?.isUnseen('s1'), isFalse); expect(delayed.saved?.isUnseen('s1'), isFalse);
}); });
@@ -310,14 +304,14 @@ void main() {
await tester.pump(); await tester.pump();
await tester.pump(); await tester.pump();
expect(find.byType(CupertinoActivityIndicator), findsOneWidget); expect(find.byType(CupertinoActivityIndicator), findsOneWidget);
expect(find.text('New'), findsNothing); expect(find.byKey(const Key('chat-row-unread')), findsNothing);
fake.pushed.add(_event('s1')); fake.pushed.add(_event('s1'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('New'), findsOneWidget); expect(find.byKey(const Key('chat-row-unread')), findsOneWidget);
await tester.tap(find.byKey(const Key('chat-row-s1'))); await tester.tap(find.byKey(const Key('chat-row-s1')));
await tester.pump(); await tester.pump();
await tester.pump(); await tester.pump();
expect(find.text('New'), findsNothing); expect(find.byKey(const Key('chat-row-unread')), findsNothing);
}); });
} }
@@ -55,7 +55,7 @@ void main() {
await tester.pumpAndSettle(); await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-refresh'))); await tester.tap(find.byKey(const Key('chat-refresh')));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('New'), findsNothing); expect(find.byKey(const Key('chat-row-unread')), findsNothing);
expect(localStore.state?.watermark('deep-linked'), greaterThan(0)); expect(localStore.state?.watermark('deep-linked'), greaterThan(0));
}); });
@@ -71,19 +71,16 @@ void main() {
expect(find.text('Starred'), findsOneWidget); expect(find.text('Starred'), findsOneWidget);
expect(find.text('Chats'), findsNWidgets(2)); expect(find.text('Chats'), findsNWidgets(2));
// The Closed section header, and each closed row's trailing word. // The Closed section header, and each closed row's trailing word.
expect( expect(find.byKey(const ValueKey('chat-section-Closed')), findsOneWidget);
find.byKey(const ValueKey('chat-section-Closed')),
findsOneWidget,
);
expect( expect(
find.descendant( find.descendant(
of: find.byKey(const Key('chat-row-s4')), of: find.byKey(const Key('chat-row-s4')),
matching: find.text('Closed'), matching: find.textContaining(RegExp(r'^Closed( ·|$)')),
), ),
findsOneWidget, findsOneWidget,
); );
expect(find.text('Starred chat'), findsOneWidget); expect(find.textContaining('Starred chat'), findsOneWidget);
expect(find.text('Starred closed'), findsOneWidget); expect(find.textContaining('Starred closed'), findsOneWidget);
expect(find.text('Open chat'), findsOneWidget); expect(find.text('Open chat'), findsOneWidget);
expect(find.byIcon(Icons.folder_outlined), findsNWidgets(4)); expect(find.byIcon(Icons.folder_outlined), findsNWidgets(4));
expect(find.byType(Scaffold), findsOneWidget); expect(find.byType(Scaffold), findsOneWidget);
@@ -116,7 +113,10 @@ void main() {
expect(find.text('/work'), findsWidgets); expect(find.text('/work'), findsWidgets);
expect(find.text('/else'), findsWidgets); expect(find.text('/else'), findsWidgets);
await tester.tap(find.byKey(const Key('chat-star-s2'))); // Starring lives in the row's actions menu.
await tester.tap(find.byKey(const Key('chat-actions-s2')));
await tester.pumpAndSettle();
await tester.tap(find.text('Star'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(gateway.lastFields('chat_star'), { expect(gateway.lastFields('chat_star'), {
'chat_query': {'session_id': 's2', 'starred': true}, 'chat_query': {'session_id': 's2', 'starred': true},
@@ -9,7 +9,7 @@ void main() {
for (final cupertino in [false, true]) { for (final cupertino in [false, true]) {
for (final backend in ['opencode', 'claude']) { for (final backend in ['opencode', 'claude']) {
testWidgets( testWidgets(
'$backend identity beside title, one actionable star ($cupertino)', '$backend avatar beside title; the menu stars and unstars ($cupertino)',
(tester) async { (tester) async {
var starred = true; var starred = true;
final body = StatefulBuilder( final body = StatefulBuilder(
@@ -72,22 +72,25 @@ void main() {
tester.widget<ImageIcon>(find.byType(ImageIcon)).image, tester.widget<ImageIcon>(find.byType(ImageIcon)).image,
AssetImage('assets/harnesses/$backend.png'), AssetImage('assets/harnesses/$backend.png'),
); );
final title = tester.getRect(find.text('Harness chat')); final title = tester.getRect(find.textContaining('Harness chat'));
final icon = tester.getRect(mark); final icon = tester.getRect(mark);
expect(icon.right, lessThanOrEqualTo(title.left)); expect(icon.right, lessThanOrEqualTo(title.left));
expect(icon.top, lessThan(title.bottom)); expect(icon.top, lessThan(title.bottom));
expect(icon.bottom, greaterThan(title.top)); expect(icon.bottom, greaterThan(title.top));
expect( expect(find.byKey(const Key('chat-row-starred')), findsOneWidget);
find.byIcon(cupertino ? CupertinoIcons.star_fill : Icons.star),
findsOneWidget, // Star and unstar live in the row's menu, not a separate button.
); await tester.tap(find.byKey(const Key('chat-actions-s')));
await tester.tap(find.byKey(const Key('chat-star-s'))); await tester.pumpAndSettle();
await tester.tap(find.text('Unstar'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(starred, isFalse); expect(starred, isFalse);
expect( expect(find.byKey(const Key('chat-row-starred')), findsNothing);
find.byIcon(cupertino ? CupertinoIcons.star : Icons.star_border), await tester.tap(find.byKey(const Key('chat-actions-s')));
findsOneWidget, await tester.pumpAndSettle();
); await tester.tap(find.text('Star'));
await tester.pumpAndSettle();
expect(starred, isTrue);
expect( expect(
find.byType(SessionHarnessIcon), find.byType(SessionHarnessIcon),
findsOneWidget, findsOneWidget,