Fix web transcript cross-message selection

This commit is contained in:
2026-11-05 16:34:58 +00:00
parent 3a9ba55277
commit 9e7140449f
10 changed files with 929 additions and 117 deletions
@@ -5,9 +5,12 @@ 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_thread_view.dart';
import 'package:pipelines_app/features/chat/conversation/chat_transcript_scroll_view.dart';
import 'package:pipelines_app/features/chat/ui/transcript/chat_markdown_view.dart';
import 'package:pipelines_app/features/chat/ui/transcript/chat_transcript_selection.dart';
import 'chat_thread_fixtures.dart';
import '../ui/transcript/chat_transcript_selection_support.dart';
Widget host(Widget child) => MaterialApp(
theme: ThemeData(platform: TargetPlatform.android),
@@ -20,6 +23,99 @@ Widget cupertinoHost(Widget child) => CupertinoApp(
);
void main() {
for (final reverse in [false, true]) {
testWidgets(
'web thread split slivers copy in visual order ${reverse ? 'backward' : 'forward'}',
(tester) async {
ChatTranscriptSelectionArea.debugEnabled = true;
addTearDown(() => ChatTranscriptSelectionArea.debugEnabled = null);
final copied = recordTranscriptClipboard();
final gateway = FakeChatGateway();
addTearDown(gateway.close);
gateway.history = (_) async => chatPage([
chatMessage(
'u1',
'user',
parts: [
{'type': 'text', 'text': 'First question'},
],
),
chatMessage(
'a1',
'assistant',
parts: [
{
'type': 'text',
'text': [
'First answer.',
...List.filled(30, 'Earlier context.'),
].join('\n\n'),
},
],
),
chatMessage(
'u2',
'user',
parts: [
{'type': 'text', 'text': 'Second question'},
],
),
chatMessage(
'a2',
'assistant',
parts: [
{'type': 'text', 'text': 'Last answer.'},
],
),
]);
await tester.pumpWidget(
host(ChatThreadView(gateway: gateway, sessionId: 's', onBack: () {})),
);
await tester.pumpAndSettle();
// The actual thread uses two centre-anchored slivers: the most recent
// user row is before their split and the answer is after it.
final transcript = tester.widget<ChatTranscriptScrollView>(
find.byType(ChatTranscriptScrollView),
);
expect(transcript.splitAfter, isNotNull);
expect(
tester.getTopLeft(find.text('Second question')).dy,
lessThan(tester.getTopLeft(find.text('Last answer.')).dy),
);
final composer = find.descendant(
of: find.byKey(const ValueKey('chat-composer-s')),
matching: find.byType(EditableText),
);
await tester.enterText(composer, 'COMPOSER DRAFT');
await tester.pumpAndSettle();
final start = transcriptBoundary(tester, 'Second question');
final end = transcriptBoundary(tester, 'Last answer.', end: true);
await dragTranscriptSelection(
tester,
reverse ? end : start,
reverse ? start : end,
);
await copyTranscriptSelection(tester);
expect(copied, hasLength(1));
expect(copied.single, contains('Second question'));
expect(copied.single, contains('Last answer.'));
expect(
copied.single.indexOf('Second question'),
lessThan(copied.single.indexOf('Last answer.')),
);
expect(copied.single, isNot(contains('First question')));
expect(copied.single, isNot(contains('COMPOSER DRAFT')));
expect(
tester.widget<EditableText>(composer).controller.text,
'COMPOSER DRAFT',
);
await tester.pumpWidget(const SizedBox.shrink());
await tester.pump();
},
variant: TargetPlatformVariant.only(TargetPlatform.macOS),
);
}
testWidgets('live-subscription refusal is separate from readable history', (
tester,
) async {