Show a reopened chat's last transcript while it refreshes
ChatScreen keeps a bounded in-memory cache of recently left transcripts (16 chats / 4000 messages, LRU). A reopened chat is seeded from it with no loading state, still re-subscribes and re-reads, and the newest page replaces the cached copy while live frames received during the read are kept. /close removes the entry; only transcripts backed by a successful read on the current connection are written. Adds tool/chat_reopen_probe.mjs and an optional history delay in the loopback fixture. Measurement shows a second cost the cache does not remove: opening at the end of the top-anchored transcript lays out every row (notes).
This commit is contained in:
@@ -4,6 +4,7 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_scroll.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_transcript_cache.dart';
|
||||
|
||||
import 'chat_thread_fixtures.dart';
|
||||
|
||||
@@ -211,6 +212,51 @@ void main() {
|
||||
expect(find.byKey(const Key('chat-jump-to-latest')), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('a cached reopen restores the position before the read replies', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = FakeChatGateway();
|
||||
addTearDown(gateway.close);
|
||||
gateway.history = (_) async => tallPage();
|
||||
final positions = MemoryChatScrollStore();
|
||||
final transcripts = ChatTranscriptCache();
|
||||
Widget thread() => host(
|
||||
ChatThreadView(
|
||||
gateway: gateway,
|
||||
sessionId: 's',
|
||||
scrollPositions: positions,
|
||||
transcripts: transcripts,
|
||||
onBack: () {},
|
||||
),
|
||||
);
|
||||
|
||||
await tester.pumpWidget(thread());
|
||||
await tester.pumpAndSettle();
|
||||
await tester.drag(
|
||||
find.byKey(const Key('chat-thread-s')),
|
||||
const Offset(0, 360),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final saved = transcriptScroll(tester).position.pixels;
|
||||
await tester.pumpWidget(host(const SizedBox()));
|
||||
expect(transcripts.sessionIds, ['s']);
|
||||
|
||||
// The reopened read stays pending: the position is restored on the
|
||||
// cached transcript alone.
|
||||
gateway.history = null;
|
||||
await tester.pumpWidget(thread());
|
||||
await tester.pumpAndSettle();
|
||||
final reopened = transcriptScroll(tester);
|
||||
expect(find.byKey(const Key('chat-thread-loading')), findsNothing);
|
||||
expect(reopened.position.pixels, closeTo(saved, 1));
|
||||
expect(find.byKey(const Key('chat-jump-to-latest')), findsOneWidget);
|
||||
|
||||
// The same transcript from the server keeps the operator's position.
|
||||
gateway.historyRequests.last.complete(tallPage());
|
||||
await tester.pumpAndSettle();
|
||||
expect(reopened.position.pixels, closeTo(saved, 1));
|
||||
});
|
||||
|
||||
testWidgets('a conversation that fits its viewport offers no control', (
|
||||
tester,
|
||||
) async {
|
||||
|
||||
Reference in New Issue
Block a user