558eedb410
Phase 2.1 of docs/plans/floating-windows.md. The session list controller, opened rows, accepted models, transcript positions and caches, composer focus requests and list folds move from ChatScreen's state to ChatRuntime. ChatScreen builds its own unless one is passed; behaviour is unchanged.
86 lines
2.8 KiB
Dart
86 lines
2.8 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/core/api_gateway.dart';
|
|
import 'package:pipelines_app/features/chat/chat_runtime.dart';
|
|
import 'package:pipelines_app/features/chat/conversation/chat_models.dart';
|
|
|
|
class _Gateway implements ApiGateway {
|
|
@override
|
|
Stream<JsonMap> get frames => const Stream.empty();
|
|
@override
|
|
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async => {};
|
|
}
|
|
|
|
void main() {
|
|
late ChatRuntime runtime;
|
|
late int notified;
|
|
setUp(() {
|
|
runtime = ChatRuntime(gateway: _Gateway());
|
|
notified = 0;
|
|
runtime.addListener(() => notified++);
|
|
});
|
|
tearDown(() => runtime.dispose());
|
|
|
|
test('adopts listed rows for opened, selected and retained chats only', () {
|
|
runtime.opened['a'] = {'id': 'a', 'title': 'Old', 'running': true};
|
|
runtime.adoptRows(
|
|
[
|
|
{'id': 'a', 'title': 'New', 'running': false},
|
|
{'id': 'b', 'title': 'B'},
|
|
{'id': 'c', 'title': 'C'},
|
|
{'id': 'd', 'title': 'D'},
|
|
],
|
|
selected: 'b',
|
|
retained: {'c'},
|
|
);
|
|
// The conversation keeps its own running flag.
|
|
expect(runtime.opened['a'], {'id': 'a', 'title': 'New', 'running': true});
|
|
expect(runtime.opened.keys, ['a', 'b', 'c']);
|
|
expect(notified, 1);
|
|
// A chat that is only listed still resolves its row.
|
|
expect(runtime.rowFor('d')?['title'], 'D');
|
|
expect(runtime.titleFor('zz'), 'zz');
|
|
});
|
|
|
|
test('an unchanged listing never reverts an accepted mode', () {
|
|
final rows = [
|
|
{'id': 'a', 'mode': 'ask'},
|
|
];
|
|
runtime.adoptRows(rows, selected: 'a', retained: const {});
|
|
expect(runtime.modeChanged('a', 'auto', 'Auto'), isTrue);
|
|
runtime.adoptRows(rows, selected: 'a', retained: const {});
|
|
expect(runtime.opened['a']?['mode'], 'auto');
|
|
expect(notified, 2);
|
|
expect(runtime.modeChanged('missing', 'auto', 'Auto'), isFalse);
|
|
});
|
|
|
|
test('an accepted model wins over the row and follows /new', () {
|
|
runtime.opened['a'] = {'id': 'a', 'model': 'old'};
|
|
runtime.modelChanged('a', (
|
|
provider: 'p',
|
|
model: 'new',
|
|
selection: 'p/new',
|
|
));
|
|
expect(runtime.rowFor('a')?['model'], 'new');
|
|
runtime.movedToSession('a', {'id': 'b', 'running': true}, 'Started');
|
|
expect(runtime.rowFor('b'), {
|
|
'id': 'b',
|
|
'model': 'new',
|
|
'model_provider': 'p',
|
|
'model_selection': 'p/new',
|
|
});
|
|
expect(runtime.startNotice, (id: 'b', notice: 'Started'));
|
|
});
|
|
|
|
test('rename updates the opened row; a new gateway drops transcripts', () {
|
|
runtime.opened['a'] = {'id': 'a', 'title': 'Old'};
|
|
runtime.renamed('a', 'New');
|
|
expect(runtime.titleFor('a'), 'New');
|
|
expect(notified, 1);
|
|
final other = _Gateway();
|
|
runtime.gateway = other;
|
|
expect(runtime.gateway, same(other));
|
|
expect(runtime.gatewayFor('a'), same(other));
|
|
expect(runtime.serverIdFor('a'), '');
|
|
});
|
|
}
|