Files
pipelines/app/test/features/chat/conversation/chat_composer_fixtures.dart
T
alan 565cdaaa1b feat(app): add native chat composer draft and send state
Persist the exact per-session draft, send one plain prompt with a stable operation/native identity, restore a refused draft without overwriting newer typing, track the reply's queued flag and stop through chat_interrupt. No UI, transport, server or platform change; the optimistic/rejection callbacks and loadDraft are the thread integration seam.
2026-10-21 21:25:51 +01:00

41 lines
1.4 KiB
Dart

import 'dart:async';
import 'package:pipelines_app/core/api_gateway.dart';
/// A fake gateway for the composer. The test controls each prompt/interrupt
/// reply; unsolicited frames are pushed through [emitEvent].
class FakeComposerGateway implements ApiGateway {
final calls = <({String type, JsonMap fields})>[];
final _frames = StreamController<JsonMap>.broadcast();
Future<JsonMap> Function(String text, String operationId)? prompt;
Future<JsonMap> Function()? interrupt;
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
calls.add((type: type, fields: fields));
switch (type) {
case 'chat_prompt':
final body = fields['chat_prompt'] as JsonMap? ?? const {};
return prompt == null
? <String, dynamic>{}
: prompt!('${body['text'] ?? ''}', '${body['operation_id'] ?? ''}');
case 'chat_interrupt':
return interrupt == null ? <String, dynamic>{} : interrupt!();
}
return <String, dynamic>{};
}
@override
Stream<JsonMap> get frames => _frames.stream;
void emitEvent(JsonMap body) =>
_frames.add({'type': 'chat_event', 'chat_event': body});
List<JsonMap> get promptBodies => calls
.where((call) => call.type == 'chat_prompt')
.map((call) => call.fields['chat_prompt'] as JsonMap)
.toList();
void close() => _frames.close();
}