feat(app): artifact viewer shows CSV and TSV files as tables

This commit is contained in:
2026-10-23 15:02:17 +01:00
parent 89675dcfa8
commit 5ac8fcc6ef
14 changed files with 411 additions and 91 deletions
@@ -14,7 +14,7 @@ enum _Platform { material, cupertino }
JsonMap _recorded(
String name, {
String url = '',
String contentType = 'text/csv',
String contentType = 'application/zip',
int sizeBytes = 2048,
}) => artifact(
name,
@@ -37,7 +37,7 @@ List<JsonMap> _steps() => <JsonMap>[
sequence: 2,
visit: 1,
artifacts: [
_recorded('result.csv'),
_recorded('result.zip'),
_recorded('notes.md', contentType: 'text/markdown'),
],
),
@@ -45,7 +45,7 @@ List<JsonMap> _steps() => <JsonMap>[
stage: 'review',
sequence: 3,
visit: 2,
artifacts: [_recorded('result.csv', url: '/artifacts/1/2/result.csv')],
artifacts: [_recorded('result.zip', url: '/artifacts/1/2/result.zip')],
),
];
@@ -101,7 +101,7 @@ void main() {
expect(find.text('build · visit 1'), findsOneWidget);
expect(find.text('review · visit 1'), findsOneWidget);
expect(find.text('review · visit 2'), findsOneWidget);
expect(find.text('result.csv'), findsNWidgets(2));
expect(find.text('result.zip'), findsNWidgets(2));
expect(find.text('notes.md'), findsOneWidget);
expect(find.text('text/markdown · 2.0\u00a0KiB'), findsOneWidget);
});
@@ -111,7 +111,7 @@ void main() {
) async {
final steps = _steps();
await _pumpGallery(tester, platform, steps);
await tester.tap(find.text('result.csv').at(1));
await tester.tap(find.text('result.zip').at(1));
await tester.pumpAndSettle();
final groups = artifactGroups(steps);
@@ -138,7 +138,7 @@ void main() {
step(
stage: 'review',
visit: 1,
artifacts: [_recorded('result.csv'), _recorded('notes.md')],
artifacts: [_recorded('result.zip'), _recorded('notes.md')],
skipped: 2,
truncated: 3,
),
@@ -147,7 +147,7 @@ void main() {
find.text('Artifacts · 2 recorded · partial capture'),
findsOneWidget,
);
await tester.tap(find.text('result.csv'));
await tester.tap(find.text('result.zip'));
await tester.pumpAndSettle();
expect(
_inDialog(_Platform.material, 'Artifacts · 2 recorded · partial capture'),
@@ -201,7 +201,7 @@ void main() {
stage: 'review',
visit: 1,
artifacts: [
_recorded('result.csv', url: '/artifacts/1/1/result.csv'),
_recorded('result.zip', url: '/artifacts/1/1/result.zip'),
],
),
],
@@ -211,13 +211,13 @@ void main() {
return true;
},
);
await tester.tap(find.text('result.csv'));
await tester.tap(find.text('result.zip'));
await tester.pumpAndSettle();
await tester.tap(_inDialog(_Platform.material, 'Open'));
await tester.pumpAndSettle();
expect(opened, [
Uri.parse('http://127.0.0.1:8081/artifacts/1/1/result.csv'),
Uri.parse('http://127.0.0.1:8081/artifacts/1/1/result.zip'),
]);
expect(find.text('Link opened externally.'), findsOneWidget);
expect(find.byType(AlertDialog), findsNothing);
@@ -230,10 +230,10 @@ void main() {
step(
stage: 'review',
visit: 1,
artifacts: [_recorded('result.csv', url: '//evil.test/result.csv')],
artifacts: [_recorded('result.zip', url: '//evil.test/result.zip')],
),
], configuredEndpoint: 'ws://127.0.0.1:8081/connect');
await tester.tap(find.text('result.csv'));
await tester.tap(find.text('result.zip'));
await tester.pumpAndSettle();
expect(
_inDialog(
@@ -255,15 +255,15 @@ void main() {
visit: 1,
artifacts: [
<String, dynamic>{
'name': 'result.csv',
'name': 'result.zip',
'url': '',
'content_type': 'text/csv',
'content_type': 'application/zip',
'size_bytes': 10,
},
],
),
]);
await tester.tap(find.text('result.csv'));
await tester.tap(find.text('result.zip'));
await tester.pumpAndSettle();
expect(
_inDialog(_Platform.material, 'No artifact URL recorded.'),
@@ -300,7 +300,7 @@ void main() {
stage: 'review',
visit: 1,
artifacts: [
_recorded('result.csv', url: '/artifacts/1/1/result.csv'),
_recorded('result.zip', url: '/artifacts/1/1/result.zip'),
],
),
],
@@ -310,12 +310,12 @@ void main() {
return true;
},
);
await tester.tap(find.text('result.csv'));
await tester.tap(find.text('result.zip'));
await tester.pumpAndSettle();
await tester.tap(_inDialog(_Platform.material, 'Copy link'));
await tester.pumpAndSettle();
expect(copied, ['http://127.0.0.1:8081/artifacts/1/1/result.csv']);
expect(copied, ['http://127.0.0.1:8081/artifacts/1/1/result.zip']);
expect(opened, isEmpty);
expect(find.text('Link copied.'), findsOneWidget);
});
@@ -339,14 +339,14 @@ void main() {
step(
stage: 'review',
visit: 1,
artifacts: [_recorded('first.csv')],
artifacts: [_recorded('first.zip')],
skipped: 2,
),
step(
stage: 'review',
sequence: 2,
visit: 2,
artifacts: [_recorded('second.csv')],
artifacts: [_recorded('second.zip')],
truncated: 3,
),
]);
@@ -371,7 +371,7 @@ void main() {
step(
stage: 'review',
visit: 1,
artifacts: [_recorded('result.csv')],
artifacts: [_recorded('result.zip')],
skipped: 2,
truncated: 3,
),
@@ -379,7 +379,7 @@ void main() {
stage: 'review',
sequence: 2,
visit: 2,
artifacts: [_recorded('later.csv')],
artifacts: [_recorded('later.zip')],
),
], focusIndex: 0);
@@ -395,12 +395,12 @@ void main() {
find.text('3 files omitted by artifact capture limits.'),
findsOneWidget,
);
expect(find.text('later.csv'), findsNothing);
expect(find.text('later.zip'), findsNothing);
});
testWidgets('a complete capture adds no header notes', (tester) async {
await _pumpGallery(tester, _Platform.material, [
step(stage: 'review', visit: 1, artifacts: [_recorded('result.csv')]),
step(stage: 'review', visit: 1, artifacts: [_recorded('result.zip')]),
]);
expect(find.text('Artifact · 1 recorded'), findsOneWidget);
@@ -420,7 +420,7 @@ void main() {
stage: 'review',
sequence: visit,
visit: visit,
artifacts: [_recorded('file$visit.csv')],
artifacts: [_recorded('file$visit.zip')],
skipped: 1,
),
], surface: const Size(360, 640));
@@ -437,8 +437,8 @@ void main() {
),
findsOneWidget,
);
await tester.scrollUntilVisible(find.text('file10.csv'), 200);
expect(find.text('file10.csv'), findsOneWidget);
await tester.scrollUntilVisible(find.text('file10.zip'), 200);
expect(find.text('file10.zip'), findsOneWidget);
},
);
@@ -453,7 +453,7 @@ void main() {
stage: 'review',
visit: 1,
artifacts: [
_recorded('result.csv', url: '/artifacts/1/1/result.csv'),
_recorded('result.zip', url: '/artifacts/1/1/result.zip'),
],
skipped: 12,
truncated: 34,
@@ -474,8 +474,8 @@ void main() {
find.text('34 files omitted by artifact capture limits.'),
findsOneWidget,
);
await tester.scrollUntilVisible(find.text('result.csv'), 200);
expect(find.text('result.csv'), findsOneWidget);
await tester.scrollUntilVisible(find.text('result.zip'), 200);
expect(find.text('result.zip'), findsOneWidget);
},
);
@@ -487,11 +487,11 @@ void main() {
stage: 'review',
visit: 1,
artifacts: [
_recorded('result.csv', url: '/artifacts/1/1/result.csv'),
_recorded('result.zip', url: '/artifacts/1/1/result.zip'),
],
),
], configuredEndpoint: 'ws://127.0.0.1:8081/connect');
await tester.tap(find.text('result.csv'));
await tester.tap(find.text('result.zip'));
await tester.pumpAndSettle();
double orderOf(String label) {
@@ -0,0 +1,51 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/artifacts/domain/artifact_table.dart';
import 'package:pipelines_app/features/artifacts/ui/artifact_table_view.dart';
Widget _host(String text, {String delimiter = ','}) => MaterialApp(
home: Scaffold(
body: SingleChildScrollView(
child: ArtifactTableView(text: text, delimiter: delimiter),
),
),
);
void main() {
testWidgets('a CSV draws its header and cells, padding short rows', (
tester,
) async {
await tester.pumpWidget(_host('id,name,score\n1,alpha,9\n2,"beta, b"\n'));
final table = tester.widget<Table>(find.byType(Table));
expect(table.children, hasLength(3));
expect(table.children.every((row) => row.children.length == 3), isTrue);
for (final text in ['id', 'name', 'score', 'alpha', 'beta, b']) {
expect(find.text(text), findsOneWidget, reason: text);
}
expect(
(table.children.first.decoration as BoxDecoration?)?.color,
isNotNull,
);
expect(find.textContaining('Showing'), findsNothing);
});
testWidgets('a capped table says how many rows it omits', (tester) async {
final text = List.generate(
artifactTableRowLimit + 20,
(i) => 'r$i,v$i',
).join('\n');
await tester.pumpWidget(_host(text));
expect(
find.text(
'Showing $artifactTableRowLimit of ${artifactTableRowLimit + 20} '
'rows. Open the file for the rest.',
),
findsOneWidget,
);
});
testWidgets('an empty table says so', (tester) async {
await tester.pumpWidget(_host(''));
expect(find.text('The table is empty.'), findsOneWidget);
});
}