Merge branch 'worktree-agent-aae8756320b8309f6'
# Conflicts: # app/lib/features/chat/conversation/chat_thread_view.dart # app/tool/perf/perf_fixture.dart # internal/protocol/message.go # internal/server/chat_hub.go
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_thread_controller.dart';
|
||||
|
||||
import 'chat_thread_fixtures.dart';
|
||||
|
||||
void main() {
|
||||
late FakeChatGateway gateway;
|
||||
late ChatThreadController controller;
|
||||
|
||||
setUp(() {
|
||||
gateway = FakeChatGateway();
|
||||
gateway.history = (_) async => chatPage([]);
|
||||
controller = ChatThreadController(gateway, 's');
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
controller.dispose();
|
||||
gateway.close();
|
||||
});
|
||||
|
||||
test('takes the retained list from the subscribe reply', () async {
|
||||
gateway.subscribe = () async => {
|
||||
'chat_shown': {
|
||||
'session_id': 's',
|
||||
'items': [
|
||||
{'id': 'a', 'kind': 'file', 'created_at': 1, 'path': '/h/a.png'},
|
||||
{'id': 'b', 'kind': 'notify', 'created_at': 2, 'title': 'Done'},
|
||||
],
|
||||
},
|
||||
};
|
||||
await controller.load();
|
||||
expect(controller.shown.map((item) => item['id']), ['a', 'b']);
|
||||
});
|
||||
|
||||
test('a pushed frame adds or replaces one item of this chat only', () async {
|
||||
gateway.subscribe = () async => {
|
||||
'chat_shown': {
|
||||
'session_id': 's',
|
||||
'items': [
|
||||
{'id': 'a', 'kind': 'notify', 'created_at': 1, 'delivered': false},
|
||||
],
|
||||
},
|
||||
};
|
||||
await controller.load();
|
||||
var notified = 0;
|
||||
controller.transcriptChanges.addListener(() => notified++);
|
||||
gateway.emitRaw({
|
||||
'type': 'chat_shown',
|
||||
'chat_shown': {
|
||||
'session_id': 'other',
|
||||
'items': [
|
||||
{'id': 'x', 'kind': 'notify', 'created_at': 3},
|
||||
],
|
||||
},
|
||||
});
|
||||
gateway.emitRaw({
|
||||
'type': 'chat_shown',
|
||||
'chat_shown': {
|
||||
'session_id': 's',
|
||||
'items': [
|
||||
{'id': 'a', 'kind': 'notify', 'created_at': 1, 'delivered': true},
|
||||
{'id': 'c', 'kind': 'html', 'created_at': 4, 'html': '<p>x</p>'},
|
||||
],
|
||||
},
|
||||
});
|
||||
await pumpEventQueue();
|
||||
expect(controller.shown.map((item) => item['id']), ['a', 'c']);
|
||||
expect(controller.shown.first['delivered'], isTrue);
|
||||
expect(notified, 1);
|
||||
});
|
||||
|
||||
test('a resync re-subscribes and adopts the server list', () async {
|
||||
var round = 0;
|
||||
gateway.subscribe = () async => {
|
||||
'chat_shown': {
|
||||
'session_id': 's',
|
||||
'items': [
|
||||
{'id': 'r$round', 'kind': 'notify', 'created_at': 1},
|
||||
],
|
||||
},
|
||||
};
|
||||
gateway.onSubscribe = () => round++;
|
||||
await controller.load();
|
||||
expect(controller.shown.single['id'], 'r1');
|
||||
await controller.resync();
|
||||
expect(controller.shown.single['id'], 'r2');
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user