Files
pipelines/app/test/features/chat/domain/chat_tool_calls_test.dart
T

91 lines
2.2 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/domain/chat_tool_calls.dart';
void main() {
final shell = <String, dynamic>{
'type': 'tool',
'name': 'shell',
'state': {
'status': 'completed',
'input': {'command': 'ls -la\n /srv'},
'content': [
{'type': 'text', 'text': 'a.txt'},
],
},
'time': {'ran': 1000, 'completed': 2200},
};
test('labels and counts follow the web', () {
expect(chatToolLabel(shell), 'shell');
expect(chatToolLabel({'type': 'tool'}), 'tool');
expect(chatToolCallsLabel(1), '1 tool');
expect(chatToolCallsLabel(3), '3 tools');
});
test('the detail is the first command-like input, one line, elided', () {
expect(chatToolDetail(shell), 'ls -la /srv');
final long = {
'type': 'tool',
'state': {
'input': {'description': 'x' * 100},
},
};
expect(chatToolDetail(long)!.length, 72);
expect(chatToolDetail(long), endsWith('…'));
expect(
chatToolDetail({
'type': 'tool',
'state': {'input': '{"par'},
}),
isNull,
);
});
test('duration, running and failure states', () {
expect(chatToolDurationMillis(shell), 1200);
expect(formatChatToolDuration(340), '340ms');
expect(formatChatToolDuration(1200), '1.2s');
expect(formatChatToolDuration(123000), '2m 3s');
expect(chatToolRunning(shell), isFalse);
expect(
chatToolRunning({
'type': 'tool',
'state': {'status': 'running'},
}),
isTrue,
);
expect(
chatToolFailed({
'state': {'status': 'error'},
}),
isTrue,
);
});
test('input is pretty JSON and output is the text content', () {
expect(chatToolInputText(shell), '{\n "command": "ls -la\\n /srv"\n}');
expect(chatToolOutputText(shell), 'a.txt');
expect(
chatToolOutputText({
'state': {'status': 'completed'},
}),
'(no output)',
);
expect(
chatToolOutputText({
'state': {'status': 'running'},
}),
'',
);
expect(
chatToolErrorText({
'state': {
'status': 'error',
'error': {'message': 'denied'},
},
}),
'denied',
);
});
}