Files
pipelines/app/test/features/chat/domain/chat_turn_diffs_test.dart
T
alan 3374bea2ef 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.
2026-11-09 16:08:35 +00:00

92 lines
2.3 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/domain/chat_turn_diffs.dart';
void main() {
test('summaries apply only for their session and attach by message id', () {
final diffs = ChatTurnDiffs();
expect(
diffs.apply({
'session_id': 'other',
'turn_diffs': [
{'turn_id': 't0', 'files': 1},
],
}, 'ses_1'),
isFalse,
);
expect(
diffs.apply({
'session_id': 'ses_1',
'turn_diffs': [
{
'turn_id': 't1',
'message_ids': ['m2'],
'files': 1,
'additions': 3,
'deletions': 1,
},
{'turn_id': 'empty', 'files': 0},
],
}, 'ses_1'),
isTrue,
);
final rows = [
{
'kind': 'assistant',
'messageIds': ['m1'],
},
{'kind': 'user'},
{
'kind': 'assistant',
'messageIds': ['m2', 'm3'],
},
];
final attached = attachChatTurnDiffs(rows, diffs);
expect(attached[0].containsKey('turnDiff'), isFalse);
expect((attached[2]['turnDiff'] as Map)['turn_id'], 't1');
expect(diffs.summaries, hasLength(1));
expect(chatTurnDiffLabel(diffs.summaries.single), '1 file changed +3 −1');
});
test('a summary without a held message id falls back to its time span', () {
final diffs = ChatTurnDiffs()
..apply({
'session_id': 's',
'turn_diffs': [
{
'turn_id': 't',
'message_ids': ['gone'],
'started_at': 1000,
'ended_at': 2000,
'files': 2,
},
],
}, 's');
final rows = [
{
'kind': 'assistant',
'messageIds': ['a'],
'created_at': 500,
},
{
'kind': 'assistant',
'messageIds': ['b'],
'created_at': 1500,
},
];
final attached = attachChatTurnDiffs(rows, diffs);
expect(attached[0].containsKey('turnDiff'), isFalse);
expect(attached[1].containsKey('turnDiff'), isTrue);
// A summary for a turn not held at all draws nothing.
expect(
attachChatTurnDiffs([
{
'kind': 'assistant',
'messageIds': ['x'],
'created_at': 9000,
},
], diffs).single.containsKey('turnDiff'),
isFalse,
);
});
}