129 lines
3.8 KiB
Dart
129 lines
3.8 KiB
Dart
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_permission_card_model.dart';
|
|
import 'package:pipelines_app/features/chat/conversation/chat_permission_group.dart';
|
|
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
|
|
|
|
import 'chat_thread_fixtures.dart';
|
|
|
|
JsonMap _turn(String id, {List<String> tools = const []}) => {
|
|
'kind': 'assistant',
|
|
'key': id,
|
|
'messageIds': [id],
|
|
'parts': [
|
|
for (final tool in tools) {'type': 'tool', 'id': tool, 'name': 'Bash'},
|
|
],
|
|
};
|
|
|
|
JsonMap _card(
|
|
String id, {
|
|
Map<String, String>? source,
|
|
String answer = '',
|
|
bool resolved = false,
|
|
String? error,
|
|
}) => {
|
|
'kind': 'permission',
|
|
'key': 'chat-permission-$id',
|
|
'frame': {
|
|
'request_id': id,
|
|
'action': 'Bash',
|
|
'source': ?source,
|
|
'resolved': resolved,
|
|
if (resolved) 'decision': 'reject',
|
|
},
|
|
'answer': answer,
|
|
'error': error,
|
|
};
|
|
|
|
List<String> _ids(Object? permissions) => [
|
|
for (final p in permissions as List<ChatPermissionCardData>) p.requestId,
|
|
];
|
|
|
|
void main() {
|
|
test('answered requests join the turn that raised them', () {
|
|
final rows = groupSettledPermissions([
|
|
_turn('m1', tools: ['call-1']),
|
|
_turn('m2'),
|
|
_card('claude', source: {'type': 'tool', 'id': 'call-1'}, answer: 'once'),
|
|
_card('opencode', source: {'message_id': 'm2'}, resolved: true),
|
|
]);
|
|
expect(rows.map((r) => r['kind']), ['assistant', 'assistant']);
|
|
expect(_ids(rows[0]['permissions']), ['claude']);
|
|
expect(_ids(rows[1]['permissions']), ['opencode']);
|
|
});
|
|
|
|
test('requests naming no turn share one row; open ones stay cards', () {
|
|
final rows = groupSettledPermissions([
|
|
_turn('m1'),
|
|
_card('codex-1', answer: 'once'),
|
|
_card('pending'),
|
|
_card('refused', answer: 'reject', error: 'request expired'),
|
|
_card('codex-2', resolved: true),
|
|
]);
|
|
expect(rows.map((r) => r['kind']), [
|
|
'assistant',
|
|
'permissions',
|
|
'permission',
|
|
'permission',
|
|
]);
|
|
expect(rows[0].containsKey('permissions'), isFalse);
|
|
expect(_ids(rows[1]['permissions']), ['codex-1', 'codex-2']);
|
|
expect(rows[2]['key'], 'chat-permission-pending');
|
|
expect(rows[3]['key'], 'chat-permission-refused');
|
|
});
|
|
|
|
testWidgets('a turn shows its answered permissions beside its tools', (
|
|
tester,
|
|
) async {
|
|
final gateway = FakeChatGateway()
|
|
..history = (_) async => chatPage([
|
|
chatMessage(
|
|
'm1',
|
|
'assistant',
|
|
parts: [
|
|
{'type': 'text', 'text': 'Done.'},
|
|
{
|
|
'type': 'tool',
|
|
'id': 'call-1',
|
|
'name': 'Bash',
|
|
'state': {'status': 'completed'},
|
|
},
|
|
],
|
|
),
|
|
]);
|
|
addTearDown(gateway.close);
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Scaffold(
|
|
body: ChatThreadView(gateway: gateway, sessionId: 's', onBack: () {}),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
gateway.emitRaw({
|
|
'type': 'chat_permission',
|
|
'chat_permission': {
|
|
'session_id': 's',
|
|
'request_id': 'req-1',
|
|
'action': 'Bash',
|
|
'resources': ['rm -rf build'],
|
|
'source': {'type': 'tool', 'id': 'call-1'},
|
|
'resolved': true,
|
|
'decision': 'reject',
|
|
},
|
|
});
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.text('Ran 1 command'), findsOneWidget);
|
|
expect(find.text('1 permission'), findsOneWidget);
|
|
expect(find.text('Rejected'), findsNothing);
|
|
|
|
await tester.tap(find.byKey(const Key('chat-permission-chip')));
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.text('Bash · Rejected'));
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('rm -rf build'), findsOneWidget);
|
|
});
|
|
}
|