App: open a chat with one round trip
The thread controller asks chat_subscribe to carry the newest history page (history: true, limit 200) and applies it from the reply; a server that leaves the page out is asked with chat_messages as before. Deltas arriving before the reply are recorded from the start of the subscribe, and settle against the page's live_seq exactly as for a separate read. Also documents the subscribe history field and benchmarks the indexed page at limits 20 and 100. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -303,9 +303,9 @@ void main() {
|
||||
|
||||
final channel = FakeChannel()..readyCompleter.complete();
|
||||
final client = PipelinesClient(
|
||||
replaceSilentSocket: false,
|
||||
channelFactory: (_) => channel,
|
||||
);
|
||||
replaceSilentSocket: false,
|
||||
channelFactory: (_) => channel,
|
||||
);
|
||||
final provider = PlatformRouteInformationProvider(
|
||||
initialRouteInformation: RouteInformation(uri: Uri.parse('/chat/s1')),
|
||||
);
|
||||
@@ -331,6 +331,8 @@ void main() {
|
||||
// The exact route names the session; the request carries the same id.
|
||||
expect(requestOf(channel, 'chat_subscribe')!['chat_subscribe'], {
|
||||
'session_id': 's1',
|
||||
'history': true,
|
||||
'limit': 200,
|
||||
});
|
||||
expect(requestOf(channel, 'chat_messages')!['chat_query'], {
|
||||
'session_id': 's1',
|
||||
@@ -461,6 +463,8 @@ void main() {
|
||||
|
||||
expect(requestOf(channel, 'chat_subscribe', index: 1)!['chat_subscribe'], {
|
||||
'session_id': 'target',
|
||||
'history': true,
|
||||
'limit': 200,
|
||||
});
|
||||
expect(requestOf(channel, 'chat_messages', index: 1)!['chat_query'], {
|
||||
'session_id': 'target',
|
||||
@@ -499,9 +503,9 @@ void main() {
|
||||
|
||||
final channel = FakeChannel()..readyCompleter.complete();
|
||||
final client = PipelinesClient(
|
||||
replaceSilentSocket: false,
|
||||
channelFactory: (_) => channel,
|
||||
);
|
||||
replaceSilentSocket: false,
|
||||
channelFactory: (_) => channel,
|
||||
);
|
||||
final provider = PlatformRouteInformationProvider(
|
||||
initialRouteInformation: RouteInformation(uri: Uri.parse('/chat')),
|
||||
);
|
||||
@@ -712,9 +716,9 @@ void main() {
|
||||
addTearDown(tester.view.reset);
|
||||
final channel = FakeChannel()..readyCompleter.complete();
|
||||
final client = PipelinesClient(
|
||||
replaceSilentSocket: false,
|
||||
channelFactory: (_) => channel,
|
||||
);
|
||||
replaceSilentSocket: false,
|
||||
channelFactory: (_) => channel,
|
||||
);
|
||||
final provider = PlatformRouteInformationProvider(
|
||||
initialRouteInformation: RouteInformation(uri: Uri.parse('/chat')),
|
||||
);
|
||||
@@ -797,9 +801,9 @@ void main() {
|
||||
addTearDown(tester.view.reset);
|
||||
final channel = FakeChannel()..readyCompleter.complete();
|
||||
final client = PipelinesClient(
|
||||
replaceSilentSocket: false,
|
||||
channelFactory: (_) => channel,
|
||||
);
|
||||
replaceSilentSocket: false,
|
||||
channelFactory: (_) => channel,
|
||||
);
|
||||
final provider = PlatformRouteInformationProvider(
|
||||
initialRouteInformation: RouteInformation(uri: Uri.parse('/chat')),
|
||||
);
|
||||
@@ -855,9 +859,9 @@ void main() {
|
||||
addTearDown(tester.view.reset);
|
||||
final channel = FakeChannel()..readyCompleter.complete();
|
||||
final client = PipelinesClient(
|
||||
replaceSilentSocket: false,
|
||||
channelFactory: (_) => channel,
|
||||
);
|
||||
replaceSilentSocket: false,
|
||||
channelFactory: (_) => channel,
|
||||
);
|
||||
final provider = PlatformRouteInformationProvider(
|
||||
initialRouteInformation: RouteInformation(uri: Uri.parse('/chat')),
|
||||
);
|
||||
|
||||
@@ -45,7 +45,7 @@ void main() {
|
||||
'chat_messages',
|
||||
]);
|
||||
expect(gateway.calls.first.fields, {
|
||||
'chat_subscribe': {'session_id': 's'},
|
||||
'chat_subscribe': {'session_id': 's', 'history': true, 'limit': 200},
|
||||
});
|
||||
expect(gateway.calls.last.fields['chat_query'], {
|
||||
'session_id': 's',
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_thread_controller.dart';
|
||||
|
||||
import 'chat_thread_fixtures.dart';
|
||||
|
||||
// Opening a chat used to take two round trips: chat_subscribe, then
|
||||
// chat_messages. The subscribe now asks for the newest page in its reply; a
|
||||
// server that leaves it out is asked with chat_messages as before.
|
||||
|
||||
void main() {
|
||||
late FakeChatGateway gateway;
|
||||
late ChatThreadController controller;
|
||||
|
||||
setUp(() {
|
||||
gateway = FakeChatGateway();
|
||||
controller = ChatThreadController(gateway, 's');
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
controller.dispose();
|
||||
gateway.close();
|
||||
});
|
||||
|
||||
List<String> types() => [for (final call in gateway.calls) call.type];
|
||||
|
||||
test('the subscribe reply carries the newest page', () async {
|
||||
gateway.subscribe = () async => {
|
||||
...chatPage([chatMessage('u', 'user'), chatMessage('a', 'assistant')]),
|
||||
'chat_queue': {'session_id': 's', 'prompts': []},
|
||||
};
|
||||
await controller.load();
|
||||
expect(gateway.calls.single.fields, {
|
||||
'chat_subscribe': {'session_id': 's', 'history': true, 'limit': 200},
|
||||
});
|
||||
expect(types(), ['chat_subscribe']);
|
||||
expect([for (final m in controller.messages) m['id']], ['u', 'a']);
|
||||
expect(controller.loading, isFalse);
|
||||
});
|
||||
|
||||
test(
|
||||
'a subscribe reply without a page falls back to chat_messages',
|
||||
() async {
|
||||
gateway.history = (_) async => chatPage([chatMessage('u', 'user')]);
|
||||
await controller.load();
|
||||
expect(types(), ['chat_subscribe', 'chat_messages']);
|
||||
expect([for (final m in controller.messages) m['id']], ['u']);
|
||||
},
|
||||
);
|
||||
|
||||
test('deltas before the reply settle against the page it carries', () async {
|
||||
final reply = Completer<JsonMap>();
|
||||
gateway.subscribe = () => reply.future;
|
||||
final loading = controller.load();
|
||||
await pumpEventQueue();
|
||||
JsonMap delta(String text, int seq) => {
|
||||
...chatTextFrame(text, messageId: 'a'),
|
||||
'seq': seq,
|
||||
};
|
||||
gateway.emitEvent(delta('part. ', 11));
|
||||
gateway.emitEvent(delta('And more.', 12));
|
||||
await pumpEventQueue();
|
||||
final page = chatPage([
|
||||
chatMessage('u', 'user'),
|
||||
chatMessage(
|
||||
'a',
|
||||
'assistant',
|
||||
parts: [
|
||||
{'type': 'text', 'id': 'p', 'text': 'The first part. '},
|
||||
],
|
||||
),
|
||||
]);
|
||||
(page['chat_history'] as JsonMap)
|
||||
..['live_seq'] = 11
|
||||
..['live_parts'] = ['p'];
|
||||
reply.complete(page);
|
||||
await loading;
|
||||
expect(types(), ['chat_subscribe']);
|
||||
final parts = controller.messages.last['parts'] as List;
|
||||
expect(
|
||||
[for (final part in parts) (part as Map)['text']],
|
||||
['The first part. And more.'],
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user