Merge branch 'worktree-agent-ab99684776b58ed55'
This commit is contained in:
@@ -246,6 +246,34 @@ void main() {
|
||||
expect(reopened.position.pixels, closeTo(saved, 1));
|
||||
});
|
||||
|
||||
testWidgets('a left conversation keeps folding its replies into the cache', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = FakeChatGateway();
|
||||
addTearDown(gateway.close);
|
||||
gateway.history = (_) async => tallPage();
|
||||
final transcripts = ChatTranscriptCache();
|
||||
await tester.pumpWidget(
|
||||
host(
|
||||
ChatThreadView(
|
||||
gateway: gateway,
|
||||
sessionId: 's',
|
||||
transcripts: transcripts,
|
||||
onBack: () {},
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.pumpWidget(host(const SizedBox()));
|
||||
|
||||
// The session stays subscribed, so its reply still arrives.
|
||||
gateway.emitEvent(chatTextFrame('reply while away', messageId: 'late'));
|
||||
await tester.pump();
|
||||
final held = transcripts.read('s')!.messages;
|
||||
expect(held.last['id'], 'late');
|
||||
expect((held.last['parts'] as List).single['text'], 'reply while away');
|
||||
});
|
||||
|
||||
testWidgets('a conversation that fits its viewport offers no control', (
|
||||
tester,
|
||||
) async {
|
||||
|
||||
@@ -79,6 +79,103 @@ void main() {
|
||||
});
|
||||
});
|
||||
|
||||
group('a transcript left while its session stays subscribed', () {
|
||||
late FakeChatGateway gateway;
|
||||
|
||||
setUp(() => gateway = FakeChatGateway());
|
||||
tearDown(() => gateway.close());
|
||||
|
||||
ChatTranscriptSnapshot left() => ChatTranscriptSnapshot(
|
||||
messages: [
|
||||
_text('u1', 'user', 'question'),
|
||||
_text('a1', 'assistant', 'first answer'),
|
||||
],
|
||||
cursor: 'older',
|
||||
hasMore: true,
|
||||
);
|
||||
|
||||
test('folds the replies that arrive in the background', () async {
|
||||
final cache = ChatTranscriptCache();
|
||||
cache.write('s', left(), frames: gateway.frames);
|
||||
cache.write('other', _snapshot(1));
|
||||
|
||||
gateway.emitEvent(chatTextFrame('new ', messageId: 'a2'));
|
||||
gateway.emitEvent(chatTextFrame('reply', messageId: 'a2'));
|
||||
// Another session's frame and a non-event envelope change nothing.
|
||||
gateway.emitEvent(chatTextFrame('elsewhere', session: 'x'));
|
||||
gateway.emitRaw({'type': 'chat_queue', 'chat_queue': {}});
|
||||
await pumpEventQueue();
|
||||
|
||||
final held = cache.read('s')!;
|
||||
expect(_ids(held.messages), ['u1', 'a1', 'a2']);
|
||||
expect((held.messages.last['parts'] as List).single['text'], 'new reply');
|
||||
expect(held.cursor, 'older');
|
||||
expect(held.hasMore, isTrue);
|
||||
expect(cache.messageCount, 4);
|
||||
});
|
||||
|
||||
test('stops following once replaced, removed or cleared', () async {
|
||||
final cache = ChatTranscriptCache();
|
||||
cache.write('s', left(), frames: gateway.frames);
|
||||
cache.write('s', left());
|
||||
gateway.emitEvent(chatTextFrame('ignored', messageId: 'a2'));
|
||||
await pumpEventQueue();
|
||||
expect(_ids(cache.read('s')!.messages), ['u1', 'a1']);
|
||||
|
||||
cache.write('s', left(), frames: gateway.frames);
|
||||
cache.remove('s');
|
||||
cache.write('t', left(), frames: gateway.frames);
|
||||
cache.clear();
|
||||
gateway.emitEvent(chatTextFrame('ignored', messageId: 'a2'));
|
||||
await pumpEventQueue();
|
||||
expect(cache.sessionIds, isEmpty);
|
||||
expect(cache.messageCount, 0);
|
||||
});
|
||||
|
||||
test('a growing transcript keeps the message bound', () async {
|
||||
final cache = ChatTranscriptCache(maxMessages: 4);
|
||||
cache.write('old', _snapshot(2, prefix: 'o'));
|
||||
cache.write('s', left(), frames: gateway.frames);
|
||||
gateway.emitEvent(chatTextFrame('reply', messageId: 'a2'));
|
||||
await pumpEventQueue();
|
||||
expect(cache.sessionIds, ['s']);
|
||||
expect(cache.messageCount, 3);
|
||||
});
|
||||
|
||||
test('a reopened controller shows the background reply before its read '
|
||||
'returns, and the page still replaces it', () async {
|
||||
final cache = ChatTranscriptCache();
|
||||
cache.write('s', left(), frames: gateway.frames);
|
||||
gateway.emitEvent(chatTextFrame('background reply', messageId: 'a2'));
|
||||
await pumpEventQueue();
|
||||
|
||||
final controller = ChatThreadController(
|
||||
gateway,
|
||||
's',
|
||||
cached: cache.read('s'),
|
||||
);
|
||||
addTearDown(controller.dispose);
|
||||
expect(_ids(controller.messages), ['u1', 'a1', 'a2']);
|
||||
|
||||
final load = controller.load();
|
||||
await pumpEventQueue();
|
||||
expect(_ids(controller.messages), ['u1', 'a1', 'a2']);
|
||||
gateway.historyRequests.single.complete(
|
||||
chatPage([
|
||||
_text('u1', 'user', 'question'),
|
||||
_text('a1', 'assistant', 'first answer'),
|
||||
_text('a2', 'assistant', 'recorded reply'),
|
||||
]),
|
||||
);
|
||||
await load;
|
||||
expect(_ids(controller.messages), ['u1', 'a1', 'a2']);
|
||||
expect(
|
||||
(controller.messages.last['parts'] as List).single['text'],
|
||||
'recorded reply',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test('refreshCachedChatHistory lets the page decide and keeps live '
|
||||
'arrivals', () {
|
||||
final held = [
|
||||
|
||||
Reference in New Issue
Block a user