feat(app): add in-app artifact preview with paging and honest limits
This commit is contained in:
@@ -91,6 +91,7 @@ void main() {
|
||||
('video/mp4', 'clip.mp4'),
|
||||
('text/markdown', 'input.md'),
|
||||
('text/plain', 'memory.txt'),
|
||||
('text/plain', 'run.log'),
|
||||
('', 'output.md'),
|
||||
]) {
|
||||
expect(isViewerArtifact(contentType, name), isTrue, reason: name);
|
||||
@@ -100,7 +101,6 @@ void main() {
|
||||
('text/csv', 'rows.csv'),
|
||||
('application/json', 'payload.json'),
|
||||
('text/x-python', 'main.py'),
|
||||
('text/plain', 'run.log'),
|
||||
('application/octet-stream', 'blob.bin'),
|
||||
('', ''),
|
||||
]) {
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/artifact_preview.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/artifact_record.dart';
|
||||
|
||||
import 'artifact_fixtures.dart';
|
||||
|
||||
const _endpoint = 'ws://127.0.0.1:8081/connect';
|
||||
|
||||
ArtifactRecord _record(String name, {String? url, String contentType = ''}) =>
|
||||
ArtifactRecord.fromJson(artifact(name, url: url, contentType: contentType));
|
||||
|
||||
ArtifactPreviewPlan _plan(
|
||||
ArtifactRecord artifact, {
|
||||
String endpoint = _endpoint,
|
||||
}) => planArtifactPreview(artifact: artifact, configuredEndpoint: endpoint);
|
||||
|
||||
void main() {
|
||||
test('an image on the configured origin is fetched locally', () {
|
||||
final plan = _plan(_record('shot.png', contentType: 'image/png'));
|
||||
expect(plan.kind, ArtifactPreviewKind.image);
|
||||
expect(plan.canFetch, isTrue);
|
||||
expect(plan.resolved?.url, 'http://127.0.0.1:8081/artifacts/1/1/shot.png');
|
||||
expect(plan.message, isEmpty);
|
||||
});
|
||||
|
||||
test('text/plain and markdown are selectable text plans', () {
|
||||
expect(
|
||||
_plan(_record('build.log', contentType: 'text/plain')).kind,
|
||||
ArtifactPreviewKind.text,
|
||||
);
|
||||
expect(
|
||||
_plan(_record('notes.txt', contentType: 'text/plain')).kind,
|
||||
ArtifactPreviewKind.text,
|
||||
);
|
||||
expect(
|
||||
_plan(_record('notes.md', contentType: 'text/markdown')).kind,
|
||||
ArtifactPreviewKind.markdown,
|
||||
);
|
||||
expect(
|
||||
_plan(
|
||||
_record('notes.markdown', contentType: 'application/octet-stream'),
|
||||
).kind,
|
||||
ArtifactPreviewKind.markdown,
|
||||
);
|
||||
});
|
||||
|
||||
test('an external origin is marked and never fetchable', () {
|
||||
final plan = _plan(
|
||||
_record(
|
||||
'shot.png',
|
||||
url: 'https://elsewhere.test/shot.png',
|
||||
contentType: 'image/png',
|
||||
),
|
||||
);
|
||||
expect(plan.kind, ArtifactPreviewKind.unavailable);
|
||||
expect(plan.canFetch, isFalse);
|
||||
expect(plan.message, artifactPreviewExternalUrl);
|
||||
expect(plan.resolved?.url, 'https://elsewhere.test/shot.png');
|
||||
});
|
||||
|
||||
test('unsafe and absent urls are explicit and never fetchable', () {
|
||||
final unsafe = _plan(
|
||||
_record(
|
||||
'shot.png',
|
||||
url: '//evil.test/shot.png',
|
||||
contentType: 'image/png',
|
||||
),
|
||||
);
|
||||
expect(unsafe.kind, ArtifactPreviewKind.unavailable);
|
||||
expect(unsafe.canFetch, isFalse);
|
||||
expect(unsafe.message, artifactPreviewUnsafeUrl);
|
||||
|
||||
final absent = _plan(
|
||||
ArtifactRecord.fromJson(<String, dynamic>{
|
||||
'name': 'shot.png',
|
||||
'url': '',
|
||||
'content_type': 'image/png',
|
||||
'size_bytes': 1,
|
||||
}),
|
||||
);
|
||||
expect(absent.kind, ArtifactPreviewKind.unavailable);
|
||||
expect(absent.canFetch, isFalse);
|
||||
expect(absent.message, artifactPreviewNoUrl);
|
||||
});
|
||||
|
||||
test('unsupported types are explicit instead of a fake preview', () {
|
||||
for (final record in <ArtifactRecord>[
|
||||
_record('result.csv', contentType: 'text/csv'),
|
||||
_record('clip.mp4', contentType: 'video/mp4'),
|
||||
_record('bundle.zip', contentType: 'application/zip'),
|
||||
]) {
|
||||
final plan = _plan(record);
|
||||
expect(plan.kind, ArtifactPreviewKind.unsupported);
|
||||
expect(plan.canFetch, isFalse);
|
||||
expect(plan.message, 'This file type cannot be previewed here.');
|
||||
expect(plan.resolved, isNotNull);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -37,6 +37,7 @@ void main() {
|
||||
|
||||
expect(pagedArtifacts(groups).map((page) => page.artifact.name), <String>[
|
||||
'input.md',
|
||||
'run.log',
|
||||
'shot.png',
|
||||
'clip.mp4',
|
||||
'memory.txt',
|
||||
@@ -161,7 +162,7 @@ void main() {
|
||||
artifacts: <Map<String, dynamic>>[
|
||||
artifact('session.html', contentType: 'text/html'),
|
||||
artifact('main.py', contentType: 'text/x-python'),
|
||||
artifact('run.log', contentType: 'text/plain'),
|
||||
artifact('result.csv', contentType: 'text/csv'),
|
||||
],
|
||||
),
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user