75 lines
2.3 KiB
Dart
75 lines
2.3 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/features/chat/domain/chat_shells.dart';
|
|
import 'package:pipelines_app/features/chat/domain/chat_task_metadata.dart';
|
|
|
|
void main() {
|
|
test('missing, malformed and future start never invent an elapsed time', () {
|
|
final now = DateTime.utc(2026, 11, 6, 10);
|
|
for (final value in [
|
|
null,
|
|
0,
|
|
-1,
|
|
'2026-11-06',
|
|
double.nan,
|
|
double.infinity,
|
|
8640000000000001,
|
|
]) {
|
|
expect(taskElapsed({'started_at': value}, now), isNull);
|
|
}
|
|
expect(
|
|
taskElapsed({
|
|
'started_at': now
|
|
.add(const Duration(minutes: 1))
|
|
.millisecondsSinceEpoch,
|
|
}, now),
|
|
isNull,
|
|
);
|
|
expect(taskElapsed({'duration_ms': 120000}, now), isNull);
|
|
expect(taskDuration(const Duration(days: 2, hours: 4)), '2d 4h');
|
|
expect(taskDuration(const Duration(hours: 2, minutes: 14)), '2h 14m');
|
|
expect(taskDuration(const Duration(seconds: 74)), '1m 14s');
|
|
expect(taskNumber({'tool_count': 0}, 'tool_count'), 0);
|
|
expect(taskNumber({'tool_count': 1.5}, 'tool_count'), isNull);
|
|
});
|
|
|
|
test('partial stream frames and snapshots retain known task facts', () {
|
|
final initial = <String, dynamic>{
|
|
'id': 'a',
|
|
'status': 'running',
|
|
'command': 'check',
|
|
'started_at': 123000,
|
|
'updated_at': 124000,
|
|
'description': 'Verify changes',
|
|
'progress': 'Checking',
|
|
'task_type': 'agent',
|
|
'tool_count': 2,
|
|
'token_count': 50,
|
|
};
|
|
final progress = mergeShellFrame(
|
|
[initial],
|
|
{
|
|
'id': 'a',
|
|
'status': 'running',
|
|
'progress': 'Reviewing',
|
|
'tool_count': 0,
|
|
},
|
|
);
|
|
final loaded = shellsLoaded(progress, [
|
|
{'id': 'a', 'status': 'running', 'command': ''},
|
|
]).single;
|
|
expect(loaded['started_at'], 123000);
|
|
expect(loaded['description'], 'Verify changes');
|
|
expect(loaded['progress'], 'Reviewing');
|
|
expect(loaded['tool_count'], 0);
|
|
expect(loaded['token_count'], 50);
|
|
expect(loaded['command'], 'check');
|
|
final exited = mergeShellFrame(
|
|
[loaded],
|
|
{'id': 'a', 'status': 'exited'},
|
|
).single;
|
|
expect(exited['started_at'], 123000);
|
|
expect(exited['status'], 'exited');
|
|
expect(runningShells([exited]), isEmpty);
|
|
});
|
|
}
|