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
@@ -198,12 +198,12 @@ bool isMarkdownArtifact(String contentType, String name) {
/// How the viewer presents an artifact in-app, or [none] when it only offers
/// Open/Download.
enum ArtifactPreviewFormat { image, video, markdown, text, none }
enum ArtifactPreviewFormat { image, video, markdown, text, table, none }
/// The one rule for in-app previews, shared by the gallery's paging and the
/// viewer's fetch plan. Images and videos come from the content type; markdown
/// from `text/markdown` or an md/markdown name; plain text, logs, JSON and
/// source/config files are shown as selectable monospace text.
/// from `text/markdown` or an md/markdown name; CSV/TSV as a table; plain
/// text, logs, JSON and source/config files as selectable monospace text.
ArtifactPreviewFormat artifactPreviewFormat(String contentType, String name) {
if (isImageContentType(contentType)) return ArtifactPreviewFormat.image;
if (isVideoContentType(contentType)) return ArtifactPreviewFormat.video;
@@ -212,6 +212,12 @@ ArtifactPreviewFormat artifactPreviewFormat(String contentType, String name) {
if (mime == 'text/markdown' || ext == 'md' || ext == 'markdown') {
return ArtifactPreviewFormat.markdown;
}
if (mime == 'text/csv' ||
mime == 'text/tab-separated-values' ||
ext == 'csv' ||
ext == 'tsv') {
return ArtifactPreviewFormat.table;
}
final kind = artifactKind(contentType, name);
if (kind == ArtifactKind.json ||
kind == ArtifactKind.log ||
@@ -224,6 +230,12 @@ ArtifactPreviewFormat artifactPreviewFormat(String contentType, String name) {
return ArtifactPreviewFormat.none;
}
/// Whether a delimited artifact is tab-separated rather than comma-separated.
bool isTabSeparatedArtifact(String contentType, String name) =>
contentType.split(';').first.trim().toLowerCase() ==
'text/tab-separated-values' ||
_extensionOf(name) == 'tsv';
/// Whether an artifact opens inside the viewer (see [artifactPreviewFormat]).
bool isViewerArtifact(String contentType, String name) =>
artifactPreviewFormat(contentType, name) != ArtifactPreviewFormat.none;
@@ -12,7 +12,10 @@ enum ArtifactPreviewKind {
/// fetched as bytes, never autoplayed), as the web viewer does.
video,
/// A recorded file the viewer cannot draw (CSV, archives, ...).
/// A CSV/TSV drawn as a table from its fetched text.
table,
/// A recorded file the viewer cannot draw (archives, PDFs, ...).
unsupported,
/// No safe same-origin url to fetch: absent, unsafe or another origin.
@@ -31,6 +34,7 @@ class ArtifactPreviewPlan {
required this.kind,
required this.resolved,
required this.message,
this.delimiter = ',',
});
final ArtifactPreviewKind kind;
@@ -40,12 +44,16 @@ class ArtifactPreviewPlan {
/// image, text or markdown document that may be fetched.
final String message;
/// The field separator of a [ArtifactPreviewKind.table] preview.
final String delimiter;
bool get canFetch =>
resolved != null &&
resolved!.external == false &&
(kind == ArtifactPreviewKind.image ||
kind == ArtifactPreviewKind.text ||
kind == ArtifactPreviewKind.markdown);
kind == ArtifactPreviewKind.markdown ||
kind == ArtifactPreviewKind.table);
}
const String artifactPreviewNoUrl = 'No artifact URL recorded.';
@@ -94,10 +102,18 @@ ArtifactPreviewPlan planArtifactPreview({
ArtifactPreviewFormat.video => ArtifactPreviewKind.video,
ArtifactPreviewFormat.markdown => ArtifactPreviewKind.markdown,
ArtifactPreviewFormat.text => ArtifactPreviewKind.text,
ArtifactPreviewFormat.table => ArtifactPreviewKind.table,
ArtifactPreviewFormat.none => null,
};
if (kind != null) {
return ArtifactPreviewPlan(kind: kind, resolved: resolved, message: '');
return ArtifactPreviewPlan(
kind: kind,
resolved: resolved,
message: '',
delimiter: isTabSeparatedArtifact(artifact.contentType, artifact.name)
? '\t'
: ',',
);
}
return ArtifactPreviewPlan(
kind: ArtifactPreviewKind.unsupported,
@@ -0,0 +1,87 @@
/// A delimited text artifact (CSV/TSV) parsed for the viewer's table preview.
///
/// RFC 4180 quoting: a field in double quotes may contain the delimiter, line
/// breaks and doubled quotes (`""` is one quote). Rows may be ragged; the table
/// pads short rows when drawn rather than inventing values here.
class ArtifactTable {
const ArtifactTable({required this.rows, required this.totalRows});
/// At most [artifactTableRowLimit] parsed rows, the first being the header.
final List<List<String>> rows;
/// Every record in the file, so a capped preview can say what it omits.
final int totalRows;
bool get truncated => totalRows > rows.length;
int get columnCount =>
rows.fold(0, (widest, row) => row.length > widest ? row.length : widest);
}
/// Rows drawn in the viewer; larger files say how many were omitted.
const int artifactTableRowLimit = 500;
/// Parses [text] separated by [delimiter] (`,` for CSV, a tab for TSV).
ArtifactTable parseArtifactTable(
String text, {
String delimiter = ',',
int limit = artifactTableRowLimit,
}) {
final rows = <List<String>>[];
var total = 0;
var row = <String>[];
final field = StringBuffer();
var quoted = false;
var fieldStarted = false;
void endField() {
row.add(field.toString());
field.clear();
fieldStarted = false;
}
void endRow() {
endField();
// A trailing line break does not start an empty record.
if (row.length == 1 && row.first.isEmpty) {
row = <String>[];
return;
}
total++;
if (rows.length < limit) rows.add(row);
row = <String>[];
}
for (var i = 0; i < text.length; i++) {
final char = text[i];
if (quoted) {
if (char == '"') {
if (i + 1 < text.length && text[i + 1] == '"') {
field.write('"');
i++;
} else {
quoted = false;
}
} else {
field.write(char);
}
continue;
}
if (char == '"' && !fieldStarted) {
quoted = true;
fieldStarted = true;
} else if (char == delimiter) {
endField();
} else if (char == '\n') {
endRow();
} else if (char == '\r') {
if (i + 1 < text.length && text[i + 1] == '\n') i++;
endRow();
} else {
field.write(char);
fieldStarted = true;
}
}
if (fieldStarted || field.isNotEmpty || row.isNotEmpty) endRow();
return ArtifactTable(rows: rows, totalRows: total);
}
@@ -0,0 +1,84 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../ui/adaptive/host.dart';
import '../domain/artifact_table.dart';
/// The truncation note for a capped table preview.
String artifactTableNote(ArtifactTable table) =>
'Showing ${table.rows.length} of ${table.totalRows} rows. Open the file '
'for the rest.';
/// A CSV/TSV preview: the first row as the header, every cell selectable, and
/// the whole grid scrolling horizontally inside the viewer's own vertical
/// scroll. Short rows are padded with empty cells; nothing is invented.
class ArtifactTableView extends StatelessWidget {
const ArtifactTableView({
super.key,
required this.text,
required this.delimiter,
});
final String text;
final String delimiter;
@override
Widget build(BuildContext context) {
final table = parseArtifactTable(text, delimiter: delimiter);
if (table.rows.isEmpty) {
return const Padding(
padding: EdgeInsets.all(16),
child: Text('The table is empty.'),
);
}
final cupertino = usesCupertinoHost(context);
final border = cupertino
? CupertinoColors.separator.resolveFrom(context)
: Theme.of(context).dividerColor;
final header = cupertino
? CupertinoColors.secondarySystemFill.resolveFrom(context)
: Theme.of(context).colorScheme.surfaceContainerHighest;
final columns = table.columnCount;
Widget cell(String value, {bool head = false}) => Padding(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
child: SelectableText(
value,
style: head ? const TextStyle(fontWeight: FontWeight.w600) : null,
),
);
return Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (table.truncated)
Padding(
padding: const EdgeInsets.only(bottom: 8),
child: Text(artifactTableNote(table)),
),
SingleChildScrollView(
key: const Key('artifact-table'),
scrollDirection: Axis.horizontal,
child: Table(
defaultColumnWidth: const IntrinsicColumnWidth(),
border: TableBorder.all(color: border),
children: [
for (var r = 0; r < table.rows.length; r++)
TableRow(
decoration: r == 0 ? BoxDecoration(color: header) : null,
children: [
for (var c = 0; c < columns; c++)
cell(
c < table.rows[r].length ? table.rows[r][c] : '',
head: r == 0,
),
],
),
],
),
),
],
),
);
}
}
@@ -3,6 +3,7 @@ import 'dart:typed_data';
import 'package:flutter/material.dart';
import '../domain/artifact_preview.dart';
import 'artifact_table_view.dart';
import 'artifact_video_player.dart';
import '../../../ui/text/monospace.dart';
@@ -79,6 +80,8 @@ class ArtifactPreviewBody extends StatelessWidget {
);
case ArtifactPreviewKind.markdown:
return _PreviewPadding(child: markdownBuilder(context, text ?? ''));
case ArtifactPreviewKind.table:
return ArtifactTableView(text: text ?? '', delimiter: plan.delimiter);
case ArtifactPreviewKind.video:
return ArtifactVideoPlayer(
uri: plan.resolved!.uri,
@@ -23,9 +23,9 @@ const _endpoint = 'ws://127.0.0.1:8081/connect';
final Uint8List _bytes = Uint8List.fromList(<int>[7, 8, 9]);
final ArtifactRecord _record = ArtifactRecord.fromJson(<String, dynamic>{
'name': 'report.csv',
'url': '/artifacts/1/1/report.csv',
'content_type': 'text/csv',
'name': 'report.zip',
'url': '/artifacts/1/1/report.zip',
'content_type': 'application/zip',
'size_bytes': 3,
});
@@ -115,10 +115,10 @@ void main() {
await tester.pumpAndSettle();
expect(saved, hasLength(1));
expect(saved.single.name, 'report.csv');
expect(saved.single.mimeType, 'text/csv');
expect(saved.single.name, 'report.zip');
expect(saved.single.mimeType, 'application/zip');
expect(saved.single.bytes, _bytes);
expect(find.text('Downloaded report.csv.'), findsOneWidget);
expect(find.text('Downloaded report.zip.'), findsOneWidget);
});
testWidgets('Share starts one file transfer, not a link', (tester) async {
@@ -130,7 +130,7 @@ void main() {
await tester.tap(find.text('Share'));
await tester.pumpAndSettle();
expect(shared.single.name, 'report.csv');
expect(shared.single.name, 'report.zip');
expect(shared.single.byteLength, 3);
expect(find.text('File shared.'), findsOneWidget);
});
@@ -223,7 +223,7 @@ void main() {
stage: 'review',
visit: 1,
artifacts: <JsonMap>[
artifact('report.csv', contentType: 'text/csv', sizeBytes: 3),
artifact('report.zip', contentType: 'application/zip', sizeBytes: 3),
],
),
],
@@ -235,7 +235,7 @@ void main() {
);
await tester.pumpAndSettle();
await tester.tap(find.text('report.csv'));
await tester.tap(find.text('report.zip'));
await tester.pumpAndSettle();
expect(find.byType(AlertDialog), findsOneWidget);
expect(find.text('Download'), findsOneWidget);
@@ -246,7 +246,7 @@ void main() {
await tester.tap(find.text('Download'));
await tester.pumpAndSettle();
expect(saved.single.bytes, _bytes);
expect(find.text('Downloaded report.csv.'), findsOneWidget);
expect(find.text('Downloaded report.zip.'), findsOneWidget);
expect(find.byType(AlertDialog), findsOneWidget);
});
@@ -299,7 +299,7 @@ void main() {
stage: 'review',
visit: 1,
artifacts: <JsonMap>[
artifact('report.csv', contentType: 'text/csv', sizeBytes: 3),
artifact('report.zip', contentType: 'application/zip', sizeBytes: 3),
],
),
];
@@ -326,7 +326,7 @@ void main() {
),
);
await tester.pumpAndSettle();
await tester.tap(find.text('report.csv'));
await tester.tap(find.text('report.zip'));
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
@@ -111,7 +111,6 @@ void main() {
);
for (final (contentType, name) in <(String, String)>[
('text/html', 'session.html'),
('text/csv', 'rows.csv'),
('application/zip', 'bundle.zip'),
('application/octet-stream', 'blob.bin'),
('', ''),
@@ -85,7 +85,6 @@ void main() {
test('unsupported types are explicit instead of a fake preview', () {
for (final record in <ArtifactRecord>[
_record('result.csv', contentType: 'text/csv'),
_record('bundle.zip', contentType: 'application/zip'),
]) {
final plan = _plan(record);
@@ -103,4 +102,14 @@ void main() {
expect(plan.message, isEmpty);
expect(plan.resolved, isNotNull);
});
test('CSV and TSV are tables, with their own delimiter', () {
final csv = _plan(_record('result.csv', contentType: 'text/csv'));
expect(csv.kind, ArtifactPreviewKind.table);
expect(csv.canFetch, isTrue);
expect(csv.delimiter, ',');
final tsv = _plan(_record('rows.tsv', contentType: 'text/plain'));
expect(tsv.kind, ArtifactPreviewKind.table);
expect(tsv.delimiter, '\t');
});
}
@@ -0,0 +1,58 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/artifacts/domain/artifact_table.dart';
void main() {
test('plain rows split on the delimiter', () {
final table = parseArtifactTable('id,name\n1,alpha\n2,beta\n');
expect(table.rows, [
['id', 'name'],
['1', 'alpha'],
['2', 'beta'],
]);
expect(table.totalRows, 3);
expect(table.truncated, isFalse);
expect(table.columnCount, 2);
});
test('quoted fields keep delimiters, line breaks and doubled quotes', () {
final table = parseArtifactTable(
'k,v\r\n"a,b","line1\nline2"\r\n"say ""hi""",\r\n',
);
expect(table.rows, [
['k', 'v'],
['a,b', 'line1\nline2'],
['say "hi"', ''],
]);
});
test('ragged rows are kept as recorded', () {
final table = parseArtifactTable('a,b,c\n1\n1,2,3,4');
expect(table.rows, [
['a', 'b', 'c'],
['1'],
['1', '2', '3', '4'],
]);
expect(table.columnCount, 4);
});
test('tab-separated values use the tab delimiter', () {
final table = parseArtifactTable('a\tb\n1\t2', delimiter: '\t');
expect(table.rows, [
['a', 'b'],
['1', '2'],
]);
});
test('a large file is capped and says how many rows it has', () {
final text = List.generate(10, (i) => 'r$i').join('\n');
final table = parseArtifactTable(text, limit: 4);
expect(table.rows, hasLength(4));
expect(table.totalRows, 10);
expect(table.truncated, isTrue);
});
test('an empty file has no rows', () {
expect(parseArtifactTable('').rows, isEmpty);
expect(parseArtifactTable('\n').totalRows, 0);
});
}
@@ -42,6 +42,7 @@ void main() {
'main.py',
'clip.mp4',
'memory.txt',
'rows.csv',
'output.md',
]);
expect(pagedArtifacts(const []), isEmpty);
@@ -163,7 +164,7 @@ void main() {
artifacts: <Map<String, dynamic>>[
artifact('session.html', contentType: 'text/html'),
artifact('bundle.zip', contentType: 'application/zip'),
artifact('result.csv', contentType: 'text/csv'),
artifact('report.pdf', contentType: 'application/pdf'),
],
),
]);
@@ -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);
});
}
+16 -16
View File
@@ -44,7 +44,7 @@ JsonMap _file(
};
/// The recorded steps for one probe state. `default` carries two visits that
/// both record `result.csv` plus a partial capture on the second visit.
/// both record `result.zip` plus a partial capture on the second visit.
List<JsonMap> _steps(String origin, String state) {
if (state == 'unavailable') {
return <JsonMap>[
@@ -76,9 +76,9 @@ List<JsonMap> _steps(String origin, String state) {
'control': <String, dynamic>{'visit': 1},
'artifacts': [
_file(
'result.csv',
url: state == 'unsafe' ? '//evil.test/result.csv' : '',
contentType: 'text/csv',
'result.zip',
url: state == 'unsafe' ? '//evil.test/result.zip' : '',
contentType: 'application/zip',
sizeBytes: 2048,
),
],
@@ -130,9 +130,9 @@ List<JsonMap> _steps(String origin, String state) {
'control': <String, dynamic>{'visit': 1},
'artifacts': [
_file(
'report.csv',
url: '$origin/fixture/report.csv',
contentType: 'text/csv',
'report.zip',
url: '$origin/fixture/report.zip',
contentType: 'application/zip',
sizeBytes: 23,
),
_file(
@@ -188,9 +188,9 @@ List<JsonMap> _steps(String origin, String state) {
'control': <String, dynamic>{'visit': 1},
'artifacts': [
_file(
'report.csv',
url: '$origin/fixture/report.csv',
contentType: 'text/csv',
'report.zip',
url: '$origin/fixture/report.zip',
contentType: 'application/zip',
sizeBytes: 23,
),
],
@@ -225,9 +225,9 @@ List<JsonMap> _steps(String origin, String state) {
'control': <String, dynamic>{'visit': 1},
'artifacts': [
_file(
'result.csv',
url: '$origin/fixture/result.csv',
contentType: 'text/csv',
'result.zip',
url: '$origin/fixture/result.zip',
contentType: 'application/zip',
sizeBytes: 2048,
),
_file(
@@ -251,9 +251,9 @@ List<JsonMap> _steps(String origin, String state) {
'control': <String, dynamic>{'visit': 2},
'artifacts': [
_file(
'result.csv',
url: '$origin/fixture/result-2.csv',
contentType: 'text/csv',
'result.zip',
url: '$origin/fixture/result-2.zip',
contentType: 'application/zip',
sizeBytes: 4096,
),
],
+22 -22
View File
@@ -118,9 +118,9 @@ const server = createServer(async (req, res) => {
res.end('missing artifact\n');
return;
}
if (pathname.endsWith('/report.csv')) {
if (pathname.endsWith('/report.zip')) {
res.writeHead(200, {
'content-type': 'text/csv',
'content-type': 'application/zip',
'content-length': probeCsv.length,
});
res.end(probeCsv);
@@ -460,7 +460,7 @@ try {
await clickExact('Artifacts');
const galleryBody = await bodyText();
for (const recorded of ['build.log', 'shot.png', 'text/csv', 'implementer · visit 1', 'reviewer · visit 2']) {
for (const recorded of ['build.log', 'shot.png', 'application/zip', 'implementer · visit 1', 'reviewer · visit 2']) {
if (!galleryBody.includes(recorded)) {
throw new Error(`Gallery is missing recorded row ${recorded}: ${JSON.stringify(galleryBody)}`);
}
@@ -468,16 +468,16 @@ try {
if (!galleryBody.includes('Artifacts · 6 recorded')) {
throw new Error(`Gallery summary missing: ${JSON.stringify(galleryBody)}`);
}
const resultRows = (await labels()).filter((label) => label.startsWith('result.csv')).length;
const resultRows = (await labels()).filter((label) => label.startsWith('result.zip')).length;
if (resultRows < 2) {
throw new Error(`Duplicate result.csv rows missing: ${JSON.stringify(await labels())}`);
throw new Error(`Duplicate result.zip rows missing: ${JSON.stringify(await labels())}`);
}
evidence.checks.push({ check: 'the gallery lists the actual recorded rows, not nav labels', value: true });
await capture('a1w-material-gallery');
await clickLowestPrefix('result.csv');
await clickLowestPrefix('result.zip');
const selectedBody = await bodyText();
for (const fact of ['reviewer · visit 2', 'text/csv · 4.0\u00a0KiB', 'Artifacts · 1 recorded · partial capture', '2 files excluded from artifact capture.']) {
for (const fact of ['reviewer · visit 2', 'application/zip · 4.0\u00a0KiB', 'Artifacts · 1 recorded · partial capture', '2 files excluded from artifact capture.']) {
if (!selectedBody.includes(fact)) {
throw new Error(`Selected visit-2 facts missing ${fact}: ${JSON.stringify(selectedBody)}`);
}
@@ -504,7 +504,7 @@ try {
await navigate(`${origin}/?origin=${encodeURIComponent(origin)}&state=unsafe`);
await clickExact('Artifacts');
await clickLowestPrefix('result.csv');
await clickLowestPrefix('result.zip');
const unsafeBody = await bodyText();
if (!unsafeBody.includes('The recorded artifact URL cannot be opened safely.')) {
throw new Error(`Unsafe url wording missing: ${JSON.stringify(unsafeBody)}`);
@@ -517,7 +517,7 @@ try {
await navigate(`${origin}/?origin=${encodeURIComponent(origin)}&state=nourl`);
await clickExact('Artifacts');
await clickLowestPrefix('result.csv');
await clickLowestPrefix('result.zip');
const nourlBody = await bodyText();
if (!nourlBody.includes('No artifact URL recorded.')) {
throw new Error(`No-url wording missing: ${JSON.stringify(nourlBody)}`);
@@ -678,7 +678,7 @@ try {
}
evidence.checks.push({ check: 'Cupertino lists the same recorded rows', value: true });
await capture('a1w-cupertino-gallery');
await clickLowestPrefix('result.csv');
await clickLowestPrefix('result.zip');
if (!(await hasLabel('Open')) || !(await hasLabel('Copy link'))) {
throw new Error(`Cupertino selection offers no actions: ${JSON.stringify(await labels())}`);
}
@@ -692,10 +692,10 @@ try {
// Cupertino dark: the gallery and its dialog on the dark host.
await openGallery(`platform=cupertino&theme=dark&origin=${encodeURIComponent(origin)}`);
await capture('a1w-cupertino-dark-gallery');
await clickLowestPrefix('result.csv');
await clickLowestPrefix('result.zip');
const darkLabels = await labels();
const darkTitle = darkLabels.find((label) => label.startsWith('result.csv'));
const titleRect = await rectOfPrefix('result.csv');
const darkTitle = darkLabels.find((label) => label.startsWith('result.zip'));
const titleRect = await rectOfPrefix('result.zip');
const darkText = [await bodyText(), ...darkLabels].join('\n');
if (!darkText.includes('Artifacts · 1 recorded · partial capture')) {
throw new Error(`Dark Cupertino dialog did not render: ${JSON.stringify(darkText)}`);
@@ -723,7 +723,7 @@ try {
}
}
await capture(`${prefix}-gallery`, 320, 720, 1);
await clickLowestPrefix('result.csv');
await clickLowestPrefix('result.zip');
const facts = await bodyText();
if (!facts.includes('Artifacts · 3 recorded') &&
!facts.includes('Artifacts · 1 recorded · partial capture')) {
@@ -863,7 +863,7 @@ try {
}, session);
const before = await targetCount();
await navigate(galleryView(`&state=files${extra}`, platform), 'Artifacts');
await clickExact('report.csv');
await clickExact('report.zip');
await delay(500);
if (!(await hasLabel('Download')) || !(await hasLabel('Share'))) {
throw new Error(`${platform} selection lost its file actions: ${JSON.stringify(await labels())}`);
@@ -887,23 +887,23 @@ try {
if (downloaded.downloads.length !== 1) {
throw new Error(`${platform} did not request exactly one download: ${JSON.stringify(downloaded)}`);
}
if (download.name !== 'report.csv') {
if (download.name !== 'report.zip') {
throw new Error(`${platform} download name was ${JSON.stringify(download.name)}`);
}
if (!download.href.startsWith('blob:')) {
throw new Error(`${platform} download used a non-blob href: ${JSON.stringify(download.href)}`);
}
if (object.type !== 'text/csv' || object.size !== probeCsv.length) {
throw new Error(`${platform} blob was ${object.type}/${object.size}, expected text/csv/${probeCsv.length}`);
if (object.type !== 'application/zip' || object.size !== probeCsv.length) {
throw new Error(`${platform} blob was ${object.type}/${object.size}, expected application/zip/${probeCsv.length}`);
}
if (!sameBytes(object.bytes, Array.from(probeCsv))) {
throw new Error(`${platform} download bytes differed from the served artifact`);
}
if (!(await bodyText()).includes('Downloaded report.csv.')) {
if (!(await bodyText()).includes('Downloaded report.zip.')) {
throw new Error(`${platform} download did not report its file: ${JSON.stringify(await bodyText())}`);
}
evidence.checks.push({
check: `${platform} Download hands the host report.csv, text/csv, ${probeCsv.length} exact bytes`,
check: `${platform} Download hands the host report.zip, application/zip, ${probeCsv.length} exact bytes`,
value: true,
name: download.name,
mime: object.type,
@@ -928,7 +928,7 @@ try {
if (shared.shares.length !== 1 || shared.shares[0].length !== 1) {
throw new Error(`${platform} share received ${JSON.stringify(shared.shares)}`);
}
if (file.name !== 'report.csv' || file.type !== 'text/csv' || file.size !== probeCsv.length) {
if (file.name !== 'report.zip' || file.type !== 'application/zip' || file.size !== probeCsv.length) {
throw new Error(`${platform} shared file was ${JSON.stringify(file)}`);
}
if (!sameBytes(file.bytes, Array.from(probeCsv))) {
@@ -941,7 +941,7 @@ try {
throw new Error(`${platform} file actions opened a browser tab`);
}
evidence.checks.push({
check: `${platform} Share hands the host a report.csv, text/csv, ${probeCsv.length} byte file`,
check: `${platform} Share hands the host a report.zip, application/zip, ${probeCsv.length} byte file`,
value: true,
name: file.name,
mime: file.type,