Files
pipelines/app/test/features/chat/ui/sessions/fake_chat_gateway.dart
T
alan 41d30a4280 feat(app): split chat sessions into native Material and Cupertino views
Split the 406-line chat session browser into a controller, body, shared
adaptive primitives and separate standard Material and Cupertino lists and
dialogs. Preserve the existing server directory/backend catalogs,
instructions field, closed/starred grouping, directory headings and
empty/no-match states.

- keep refresh generations so stale replies are discarded
- open a created chat immediately and refresh the list in the background
- disable rename Save while the trimmed name is blank
- label row actions per session, with the id on duplicate titles
- wrap Cupertino empty/no-match/error messages instead of clipping, and
  give them a Cupertino text style under a bare MaterialApp
- allow the Material rename helper to wrap at large text scales
- cover both native branches, lifecycle ordering, create/rename/close/star
  and the Cupertino theme path with widget tests
2026-10-21 17:42:39 +01:00

57 lines
1.7 KiB
Dart

import 'dart:async';
import 'dart:collection';
import 'package:pipelines_app/core/api_gateway.dart';
/// Scripted gateway for session-browser widget tests.
class FakeChatGateway implements ApiGateway {
final calls = <({String type, JsonMap fields})>[];
final pendingSessions = Queue<Completer<JsonMap>>();
JsonMap sessionsReply = const {'chat_sessions': []};
Future<JsonMap> Function()? sessionsHandler;
JsonMap createReply = const {
'chat_session': {'id': 'created', 'title': 'New chat'},
};
Future<JsonMap> Function()? directoriesHandler;
Future<JsonMap> Function()? backendsHandler;
@override
Stream<JsonMap> get frames => const Stream.empty();
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
calls.add((type: type, fields: fields));
switch (type) {
case 'chat_sessions':
if (pendingSessions.isNotEmpty) {
return pendingSessions.removeFirst().future;
}
if (sessionsHandler != null) return sessionsHandler!();
return Future.value(sessionsReply);
case 'chat_directories':
return directoriesHandler?.call() ??
Future.value(const {
'chat_directories': ['/work', '/archive'],
});
case 'chat_backends':
return backendsHandler?.call() ??
Future.value(const {
'chat_backends': ['opencode', 'codex'],
});
case 'chat_create':
return Future.value(createReply);
default:
return Future.value(const {});
}
}
int count(String type) => calls.where((call) => call.type == type).length;
JsonMap? lastFields(String type) {
for (final call in calls.reversed) {
if (call.type == type) return call.fields;
}
return null;
}
}