Files
pipelines/app/test/features/chat/conversation/chat_composer_bar_fixtures.dart
T
alan d1390994cc Chat: offer the session's Claude Code skills and slash commands in the palette
The server reads the commands Claude Code's initialize response lists (bundled,
user, project, plugin and claude.ai-synced skills plus CLI commands, with
descriptions and argument hints), drops terminal-only ones, and serves them per
chat over a new chat_commands request without waiting for a CLI start. The
composer palette lists them after the recorded commands; choosing one inserts
"/<name> " and sending passes it to the harness as an ordinary prompt.
Codex, OpenCode and Pi chats reply with an empty list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 20:53:57 +00:00

129 lines
3.7 KiB
Dart

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/chat/conversation/chat_draft_store.dart';
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
import 'chat_thread_fixtures.dart';
/// A gateway for one open fixture conversation with a composer. History pages
/// are tests' own; prompt/interrupt replies are controlled per test.
class ComposerBarGateway implements ApiGateway {
final calls = <({String type, JsonMap fields})>[];
final _frames = StreamController<JsonMap>.broadcast();
JsonMap page = chatPage(const []);
Future<JsonMap> Function(String text, String operationId)? prompt;
Future<JsonMap> Function()? interrupt;
Future<JsonMap> Function()? stopTasks;
/// The `chat_commands` reply list: the session's harness commands.
List<JsonMap> commands = const [];
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
calls.add((type: type, fields: fields));
switch (type) {
case 'chat_commands':
return <String, dynamic>{'chat_commands': commands};
case 'chat_subscribe':
return <String, dynamic>{};
case 'chat_messages':
return page;
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!();
case 'chat_stop_tasks':
return stopTasks == null ? <String, dynamic>{} : stopTasks!();
}
return <String, dynamic>{};
}
@override
Stream<JsonMap> get frames => _frames.stream;
List<JsonMap> get promptBodies => calls
.where((call) => call.type == 'chat_prompt')
.map((call) => call.fields['chat_prompt'] as JsonMap)
.toList();
List<JsonMap> get interruptBodies => calls
.where((call) => call.type == 'chat_interrupt')
.map((call) => call.fields['chat_query'] as JsonMap)
.toList();
List<JsonMap> get stopTasksBodies => calls
.where((call) => call.type == 'chat_stop_tasks')
.map((call) => call.fields['chat_query'] as JsonMap)
.toList();
void emitEvent(JsonMap body) =>
_frames.add({'type': 'chat_event', 'chat_event': body});
void close() => _frames.close();
}
Widget materialHost(Widget child) => MaterialApp(
theme: ThemeData(
platform: TargetPlatform.android,
brightness: Brightness.light,
),
home: Scaffold(body: child),
);
Widget composerThread(
ComposerBarGateway gateway, {
int syncToken = 0,
ChatDraftStore? drafts,
String Function()? newOperationId,
VoidCallback? onBack,
JsonMap? session,
}) {
final thread = ChatThreadView(
gateway: gateway,
sessionId: 's',
session: session,
syncToken: syncToken,
onBack: onBack ?? () {},
drafts: drafts ?? MemoryChatDraftStore(),
newOperationId: newOperationId,
);
return materialHost(thread);
}
/// The common fixture turn, so a rebuild has real transcript content to move.
JsonMap fixtureTurn({
String user = 'Stored question',
String answer = 'Stored answer',
}) => chatPage([
chatMessage(
'u1',
'user',
parts: [
{'type': 'text', 'text': user},
],
),
chatMessage(
'a1',
'assistant',
parts: [
{'type': 'text', 'text': answer},
],
),
]);
String fieldText(WidgetTester tester) => tester
.widget<EditableText>(
find.descendant(
of: find.byKey(const Key('chat-composer-field')),
matching: find.byType(EditableText),
),
)
.controller
.text;