Show a chat turn's changed files as a chip that opens its diff
The answer footer shows '3 files changed +9 -2'; tapping opens the turn's files in the sheet (wide) or a full-screen page (narrow), and a file opens the run Changes diff viewer. Patches load through the chat's own gateway.
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
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_thread_view.dart';
|
||||
|
||||
import 'chat_thread_fixtures.dart';
|
||||
|
||||
/// Answers chat_turn_diff with one recorded file for the asked turn.
|
||||
class _DiffGateway extends FakeChatGateway {
|
||||
final asked = <JsonMap>[];
|
||||
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
|
||||
if (type != 'chat_turn_diff') return super.call(type, fields);
|
||||
final body = Map<String, dynamic>.from(fields['chat_turn_diff'] as Map);
|
||||
asked.add(body);
|
||||
return {
|
||||
'type': 'chat_turn_diff',
|
||||
'chat_turn_diff': {
|
||||
...body,
|
||||
'changes': {
|
||||
'status': 'complete',
|
||||
'files': [
|
||||
{
|
||||
'path': 'lib/${body['turn_id']}.dart',
|
||||
'kind': 'added',
|
||||
'patch': '@@ -0,0 +1 @@\n+x\n',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
JsonMap _summary(String turn, String message) => {
|
||||
'turn_id': turn,
|
||||
'message_ids': [message],
|
||||
'files': 1,
|
||||
'additions': 1,
|
||||
'deletions': 0,
|
||||
'status': 'complete',
|
||||
};
|
||||
|
||||
void main() {
|
||||
testWidgets('history and live summaries draw a change chip per turn; the '
|
||||
'chip fetches that turn through the chat gateway', (tester) async {
|
||||
final gateway = _DiffGateway();
|
||||
addTearDown(gateway.close);
|
||||
gateway.history = (_) async => {
|
||||
...chatPage([
|
||||
chatMessage(
|
||||
'u1',
|
||||
'user',
|
||||
parts: [
|
||||
{'type': 'text', 'text': 'Edit it'},
|
||||
],
|
||||
),
|
||||
chatMessage(
|
||||
'a1',
|
||||
'assistant',
|
||||
parts: [
|
||||
{'type': 'text', 'text': 'Edited.'},
|
||||
],
|
||||
),
|
||||
chatMessage(
|
||||
'u2',
|
||||
'user',
|
||||
parts: [
|
||||
{'type': 'text', 'text': 'Again'},
|
||||
],
|
||||
),
|
||||
chatMessage(
|
||||
'a2',
|
||||
'assistant',
|
||||
parts: [
|
||||
{'type': 'text', 'text': 'Edited again.'},
|
||||
],
|
||||
),
|
||||
]),
|
||||
'chat_turn_diffs': {
|
||||
'session_id': 's',
|
||||
'turn_diffs': [_summary('turn_a', 'a1')],
|
||||
},
|
||||
};
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeData(platform: TargetPlatform.android),
|
||||
home: Scaffold(
|
||||
body: ChatThreadView(gateway: gateway, sessionId: 's', onBack: () {}),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final chips = find.byKey(const Key('chat-turn-diff-chip'));
|
||||
expect(chips, findsOneWidget);
|
||||
expect(find.text('1 file changed +1 −0'), findsOneWidget);
|
||||
|
||||
// Another session's push is ignored; this session's push adds a chip.
|
||||
gateway.emitRaw({
|
||||
'type': 'chat_turn_diffs',
|
||||
'chat_turn_diffs': {
|
||||
'session_id': 'other',
|
||||
'turn_diffs': [_summary('turn_x', 'a2')],
|
||||
},
|
||||
});
|
||||
await tester.pumpAndSettle();
|
||||
expect(chips, findsOneWidget);
|
||||
gateway.emitRaw({
|
||||
'type': 'chat_turn_diffs',
|
||||
'chat_turn_diffs': {
|
||||
'session_id': 's',
|
||||
'turn_diffs': [_summary('turn_b', 'a2')],
|
||||
},
|
||||
});
|
||||
await tester.pumpAndSettle();
|
||||
expect(chips, findsNWidgets(2));
|
||||
|
||||
await tester.tap(chips.last);
|
||||
await tester.pumpAndSettle();
|
||||
expect(gateway.asked, [
|
||||
{'session_id': 's', 'turn_id': 'turn_b'},
|
||||
]);
|
||||
expect(find.text('lib/turn_b.dart'), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user