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.broadcast(); Future Function(String text, String operationId)? prompt; Future Function()? interrupt; @override Future 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 ? {} : prompt!('${body['text'] ?? ''}', '${body['operation_id'] ?? ''}'); case 'chat_interrupt': return interrupt == null ? {} : interrupt!(); } return {}; } @override Stream get frames => _frames.stream; void emitEvent(JsonMap body) => _frames.add({'type': 'chat_event', 'chat_event': body}); List get promptBodies => calls .where((call) => call.type == 'chat_prompt') .map((call) => call.fields['chat_prompt'] as JsonMap) .toList(); void close() => _frames.close(); }