Files
pipelines/app/test/features/chat/conversation/chat_question_group_test.dart
T
alan a3a59adb30 Quieter transcript metadata: day dividers, time-only rows, muted meta rows
- Date once per calendar day: a muted centred divider above each day's
  first timed row (chatDayDividers); rows show only their time ("10:16"),
  with the full date and time kept in the tooltip and semantics. The user's
  time shares the delivery line; a harness notice's time trails its line.
- Activity line and turn chips are secondary: bodyMedium, regular weight,
  onSurfaceVariant (error colour kept for failures), a small chevron_right
  that turns down while its details are open (replaces expand_less).
- Copy / Read aloud: 18 px muted icons; on pointer devices shown only while
  the reply is hovered or an action is focused (also without the gutter);
  touch keeps them visible with a full tap target. The time leads the
  footer so hidden actions leave no gap.
- Settled questions: the question on one line, the operator's answer in
  full on its own line beneath it.
- Meta rows (activity, chips, notices, compaction line) start at the reply
  text's leading edge; turn chips sit in their own column under the answer.
- Scroll fixture: ?timestamps=1 spreads messages over two days.

Row keys are unchanged; the divider joins a row without replacing it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 11:10:51 +00:00

299 lines
9.4 KiB
Dart

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/chat/conversation/chat_question_card_model.dart';
import 'package:pipelines_app/features/chat/conversation/chat_question_group.dart';
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
import 'chat_thread_fixtures.dart';
JsonMap _turn(String id) => {
'kind': 'assistant',
'key': id,
'messageIds': [id],
'parts': const [],
};
JsonMap _card(
String id, {
String? raisedIn,
bool resolved = false,
bool cancelled = false,
String? error,
}) => {
'kind': 'question',
'key': 'chat-question-$id',
'form': {
'id': id,
'resolved': resolved,
'cancelled': cancelled,
chatQuestionRaisedIn: ?raisedIn,
},
'error': error,
};
JsonMap _form({String id = 'form-1'}) => {
'id': id,
'session_id': 's',
'kind': 'question',
'title': 'Database',
'fields': [
{
'key': 'q0',
'title': 'Which database?',
'type': 'string',
'required': true,
'options': [
{'value': 'pg', 'label': 'Postgres'},
{'value': 'lite', 'label': 'SQLite'},
],
},
],
};
const _chip = 'Which database? · Postgres';
/// One line of the settled question's chip: the question, or the recorded
/// outcome on its own line beneath it.
Finder _settledLine(String text) => find.descendant(
of: find.byKey(const ValueKey('chat-question-chip-form-1')),
matching: find.text(text),
);
/// A chat whose agent turn `a1` is the one the question arrives during.
Future<FakeChatGateway> _open(WidgetTester tester, Size size) async {
await tester.binding.setSurfaceSize(size);
addTearDown(() => tester.binding.setSurfaceSize(null));
final gateway = FakeChatGateway()
..history = (_) async => chatPage([
chatMessage(
'u1',
'user',
parts: [
{'type': 'text', 'text': 'Ship the release.'},
],
),
chatMessage(
'a1',
'assistant',
parts: [
{'type': 'text', 'text': 'Which database first?'},
],
),
]);
addTearDown(gateway.close);
final view = ChatThreadView(gateway: gateway, sessionId: 's', onBack: () {});
await tester.pumpWidget(MaterialApp(home: Scaffold(body: view)));
await tester.pumpAndSettle();
gateway.emitEvent({'session_id': 's', 'kind': 'form', 'form': _form()});
await tester.pumpAndSettle();
expect(find.text(chatQuestionWaiting), findsOneWidget);
return gateway;
}
Future<void> _answerPostgres(WidgetTester tester) async {
await tester.tap(find.text('Postgres'));
await tester.pump();
await tester.tap(find.text(chatQuestionSubmit));
await tester.pumpAndSettle();
}
void _expectCollapsed() {
expect(find.text(chatQuestionWaiting), findsNothing);
expect(find.text(chatQuestionSubmit), findsNothing);
expect(find.text(chatQuestionAnswered), findsNothing);
expect(_settledLine('Which database?'), findsOneWidget);
expect(_settledLine('Postgres'), findsOneWidget);
// The chip sits among its turn's chips, under the turn that asked.
expect(
find.descendant(
of: find.byKey(const Key('chat-turn-chips')),
matching: find.byKey(const ValueKey('chat-question-chip-form-1')),
),
findsOneWidget,
);
}
void main() {
test('settled questions join the turn they were raised during', () {
final rows = groupSettledQuestions([
_turn('m1'),
_turn('m2'),
_card('a', raisedIn: 'm1', resolved: true),
_card('b', raisedIn: 'm2', cancelled: true),
]);
expect(rows.map((r) => r['kind']), ['assistant', 'assistant']);
expect(chatRowQuestions(rows[0]).map((f) => f['id']), ['a']);
expect(chatRowQuestions(rows[1]).map((f) => f['id']), ['b']);
});
test('questions naming no turn share one row; open ones stay cards', () {
final rows = groupSettledQuestions([
_turn('m1'),
_card('loose-1', resolved: true),
_card('pending', raisedIn: 'm1'),
_card('refused', raisedIn: 'm1', error: 'no longer awaiting'),
_card('loose-2', raisedIn: 'paged-out', resolved: true),
]);
expect(rows.map((r) => r['kind']), [
'assistant',
'questions',
'question',
'question',
]);
expect(rows[0].containsKey('questions'), isFalse);
expect(chatRowQuestions(rows[1]).map((f) => f['id']), [
'loose-1',
'loose-2',
]);
});
test('the summary names the question and its outcome', () {
final form = _form();
expect(
chatQuestionSummary({
...form,
'resolved': true,
'answers': {'q0': 'pg'},
}),
_chip,
);
expect(
chatQuestionSummary({
...form,
'resolved': true,
'answers': {'q0': 'pg', 'extra': 'x'},
}),
'$_chip · +1 more',
);
expect(
chatQuestionSummary({...form, 'cancelled': true}),
'Which database? · Expired',
);
expect(
chatQuestionSummary({...form, 'resolved': true}),
'Which database? · Closed',
);
});
for (final (name, size) in [
('narrow', const Size(390, 844)),
('wide', const Size(1280, 900)),
]) {
testWidgets('$name: an acknowledged answer collapses into its turn at once '
'(Claude Code: the ack is the only signal)', (tester) async {
final gateway = await _open(tester, size);
final held = Completer<JsonMap>();
gateway.answer = (_) => held.future;
await tester.tap(find.text('Postgres'));
await tester.pump();
await tester.tap(find.text(chatQuestionSubmit));
await tester.pump();
// Still the card while the reply is in flight.
expect(find.text(chatQuestionWaiting), findsOneWidget);
held.complete(const {'type': 'chat_answer'});
await tester.pumpAndSettle();
_expectCollapsed();
// A late replay of the pending frame cannot reopen it.
gateway.emitEvent({'session_id': 's', 'kind': 'form', 'form': _form()});
await tester.pumpAndSettle();
_expectCollapsed();
await tester.tap(find.byKey(const ValueKey('chat-question-chip-form-1')));
await tester.pumpAndSettle();
final sheet = find.byKey(const Key('chat-question-sheet'));
expect(sheet, findsOneWidget);
Finder inSheet(String text) =>
find.descendant(of: sheet, matching: find.text(text));
expect(inSheet('Which database?'), findsOneWidget);
expect(inSheet('Postgres'), findsOneWidget);
expect(inSheet(chatQuestionAnswered), findsOneWidget);
expect(tester.takeException(), isNull);
});
testWidgets('$name: a refused answer keeps the full card with the reason', (
tester,
) async {
final gateway = await _open(tester, size);
gateway.answer = (_) async =>
throw StateError('the question is no longer awaiting an answer');
await _answerPostgres(tester);
expect(find.textContaining('no longer awaiting'), findsOneWidget);
expect(find.text(chatQuestionWaiting), findsOneWidget);
expect(find.text(chatQuestionSubmit), findsOneWidget);
expect(
find.byKey(const ValueKey('chat-question-chip-form-1')),
findsNothing,
);
});
}
testWidgets('OpenCode/Codex: the server resolution collapses a question '
'answered elsewhere', (tester) async {
final gateway = await _open(tester, const Size(390, 844));
gateway.emitEvent({
'session_id': 's',
'kind': 'form',
'form': {'id': 'form-1', 'session_id': 's', 'resolved': true},
});
await tester.pumpAndSettle();
expect(find.text(chatQuestionWaiting), findsNothing);
expect(_settledLine('Which database?'), findsOneWidget);
expect(_settledLine('Closed'), findsOneWidget);
});
testWidgets('a cancelled question collapses as expired', (tester) async {
final gateway = await _open(tester, const Size(390, 844));
gateway.emitEvent({
'session_id': 's',
'kind': 'form',
'form': {'id': 'form-1', 'session_id': 's', 'cancelled': true},
});
await tester.pumpAndSettle();
expect(find.text(chatQuestionWaiting), findsNothing);
expect(_settledLine('Which database?'), findsOneWidget);
expect(_settledLine('Expired'), findsOneWidget);
});
testWidgets('OpenCode: ack then form.replied leaves one collapsed row', (
tester,
) async {
final gateway = await _open(tester, const Size(390, 844));
gateway.answer = (_) async {
gateway.emitEvent({
'session_id': 's',
'kind': 'form',
'form': {'id': 'form-1', 'session_id': 's', 'resolved': true},
});
return const {'type': 'chat_answer'};
};
await _answerPostgres(tester);
_expectCollapsed();
});
testWidgets('after a reload the answered question stays gone', (
tester,
) async {
final gateway = await _open(tester, const Size(390, 844));
gateway.answer = (_) async => const {'type': 'chat_answer'};
await _answerPostgres(tester);
_expectCollapsed();
// A fresh view over the same server: the subscribe replays only pending
// forms, and this one is no longer pending.
await tester.pumpWidget(const SizedBox());
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: ChatThreadView(gateway: gateway, sessionId: 's', onBack: () {}),
),
),
);
await tester.pumpAndSettle();
expect(find.text('Which database first?'), findsOneWidget);
expect(find.text(chatQuestionWaiting), findsNothing);
});
}