merge(app): land in-app artifact preview after retained-deadline recovery
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'),
|
||||
],
|
||||
),
|
||||
]);
|
||||
|
||||
@@ -0,0 +1,406 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/artifact_groups.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/artifact_record.dart';
|
||||
import 'package:pipelines_app/features/artifacts/ui/artifact_external_open.dart';
|
||||
import 'package:pipelines_app/features/artifacts/ui/artifact_gallery_page.dart';
|
||||
import 'package:pipelines_app/features/artifacts/ui/artifact_viewer_fetch.dart';
|
||||
import 'package:pipelines_app/features/artifacts/ui/artifact_viewer_page.dart';
|
||||
import 'package:pipelines_app/features/artifacts/ui/artifact_visit_list.dart';
|
||||
|
||||
import '../domain/artifact_fixtures.dart';
|
||||
import 'artifact_visit_list_fixture.dart';
|
||||
|
||||
const _endpoint = 'ws://127.0.0.1:8081/connect';
|
||||
|
||||
/// A real 1x1 PNG so the image preview decodes instead of only holding bytes.
|
||||
final Uint8List _png = base64Decode(
|
||||
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAE'
|
||||
'hQGAhKmMIQAAAABJRU5ErkJggg==',
|
||||
);
|
||||
|
||||
ArtifactGroup _group(
|
||||
List<ArtifactRecord> artifacts, {
|
||||
String stageKey = 'review',
|
||||
int visit = 1,
|
||||
}) => visitGroup(stageKey: stageKey, visit: visit, artifacts: artifacts);
|
||||
|
||||
Future<void> _pumpViewer(
|
||||
WidgetTester tester, {
|
||||
required List<ArtifactGroup> groups,
|
||||
required String selected,
|
||||
bool cupertino = false,
|
||||
ArtifactFetch? fetch,
|
||||
Widget Function(String)? markdownBuilder,
|
||||
ArtifactExternalOpen? openExternal,
|
||||
}) async {
|
||||
final page = ArtifactViewerPage(
|
||||
groups: groups,
|
||||
selectedIdentity: selected,
|
||||
configuredEndpoint: _endpoint,
|
||||
fetch: fetch ?? (_) async => ArtifactFetchResult(status: 200, bytes: _png),
|
||||
markdownBuilder: markdownBuilder ?? (value) => SelectableText(value),
|
||||
openExternal: openExternal ?? (_) async => true,
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? CupertinoApp(home: page)
|
||||
: MaterialApp(home: Scaffold(body: page)),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
TextButton _textButton(WidgetTester tester, String label) {
|
||||
return tester.widget<TextButton>(
|
||||
find
|
||||
.ancestor(of: find.text(label), matching: find.byType(TextButton))
|
||||
.first,
|
||||
);
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('an image is previewed in-app without opening a tab', (
|
||||
tester,
|
||||
) async {
|
||||
final fetched = <Uri>[];
|
||||
final opened = <Uri>[];
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: ArtifactGalleryPage(
|
||||
steps: <JsonMap>[
|
||||
step(
|
||||
stage: 'review',
|
||||
visit: 1,
|
||||
artifacts: [
|
||||
artifact(
|
||||
'shot.png',
|
||||
url: '/artifacts/1/1/shot.png',
|
||||
contentType: 'image/png',
|
||||
sizeBytes: 1024,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
configuredEndpoint: _endpoint,
|
||||
fetch: (uri) async {
|
||||
fetched.add(uri);
|
||||
return ArtifactFetchResult(status: 200, bytes: _png);
|
||||
},
|
||||
openExternal: (uri) async {
|
||||
opened.add(uri);
|
||||
return true;
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('shot.png'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(ArtifactViewerPage), findsOneWidget);
|
||||
expect(fetched, [
|
||||
Uri.parse('http://127.0.0.1:8081/artifacts/1/1/shot.png'),
|
||||
]);
|
||||
expect(find.byType(Image), findsOneWidget);
|
||||
expect(find.text('1 of 1 · image/png'), findsOneWidget);
|
||||
expect(find.text('image/png · 1.0\u00a0KiB'), findsOneWidget);
|
||||
expect(opened, isEmpty);
|
||||
expect(find.byType(AlertDialog), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('text/plain is fetched and shown as selectable text', (
|
||||
tester,
|
||||
) async {
|
||||
final text = recordedArtifact(
|
||||
'build.log',
|
||||
url: '/artifacts/1/1/build.log',
|
||||
contentType: 'text/plain; charset=utf-8',
|
||||
);
|
||||
await _pumpViewer(
|
||||
tester,
|
||||
groups: [
|
||||
_group([text]),
|
||||
],
|
||||
selected: artifactVisitIdentity(_group([text]), text),
|
||||
fetch: (_) async =>
|
||||
ArtifactFetchResult(status: 200, bytes: utf8.encode('build ok\n')),
|
||||
);
|
||||
|
||||
expect(find.byType(SelectableText), findsOneWidget);
|
||||
expect(find.text('build ok\n'), findsOneWidget);
|
||||
expect(find.text('text/plain · 0\u00a0B'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('markdown uses the injected builder and defaults to text', (
|
||||
tester,
|
||||
) async {
|
||||
final markdown = recordedArtifact(
|
||||
'notes.md',
|
||||
url: '/artifacts/1/1/notes.md',
|
||||
contentType: 'text/markdown',
|
||||
);
|
||||
final group = _group([markdown]);
|
||||
final identity = artifactVisitIdentity(group, markdown);
|
||||
await _pumpViewer(
|
||||
tester,
|
||||
groups: [group],
|
||||
selected: identity,
|
||||
fetch: (_) async =>
|
||||
ArtifactFetchResult(status: 200, bytes: utf8.encode('# Title')),
|
||||
markdownBuilder: (value) => Text('MARKDOWN $value'),
|
||||
);
|
||||
expect(find.text('MARKDOWN # Title'), findsOneWidget);
|
||||
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
await _pumpViewer(
|
||||
tester,
|
||||
groups: [group],
|
||||
selected: identity,
|
||||
fetch: (_) async =>
|
||||
ArtifactFetchResult(status: 200, bytes: utf8.encode('# Raw title')),
|
||||
);
|
||||
expect(find.byType(SelectableText), findsOneWidget);
|
||||
expect(find.text('# Raw title'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('an external origin is marked and never fetched', (tester) async {
|
||||
final fetched = <Uri>[];
|
||||
final opened = <Uri>[];
|
||||
final image = recordedArtifact(
|
||||
'shot.png',
|
||||
url: 'https://elsewhere.test/shot.png',
|
||||
contentType: 'image/png',
|
||||
);
|
||||
final group = _group([image]);
|
||||
await _pumpViewer(
|
||||
tester,
|
||||
groups: [group],
|
||||
selected: artifactVisitIdentity(group, image),
|
||||
fetch: (uri) async {
|
||||
fetched.add(uri);
|
||||
return ArtifactFetchResult(status: 200, bytes: _png);
|
||||
},
|
||||
openExternal: (uri) async {
|
||||
opened.add(uri);
|
||||
return true;
|
||||
},
|
||||
);
|
||||
|
||||
expect(
|
||||
find.text(
|
||||
'This artifact is hosted on another origin and is not previewed here.',
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(fetched, isEmpty);
|
||||
expect(find.byType(Image), findsNothing);
|
||||
await tester.tap(find.text('Open'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(opened, [Uri.parse('https://elsewhere.test/shot.png')]);
|
||||
});
|
||||
|
||||
testWidgets('the gallery marks an external viewer artifact without fetching', (
|
||||
tester,
|
||||
) async {
|
||||
final fetched = <Uri>[];
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: ArtifactGalleryPage(
|
||||
steps: <JsonMap>[
|
||||
step(
|
||||
stage: 'review',
|
||||
visit: 1,
|
||||
artifacts: [
|
||||
artifact(
|
||||
'shot.png',
|
||||
url: 'https://elsewhere.test/shot.png',
|
||||
contentType: 'image/png',
|
||||
sizeBytes: 10,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
configuredEndpoint: _endpoint,
|
||||
fetch: (uri) async {
|
||||
fetched.add(uri);
|
||||
return ArtifactFetchResult(status: 200, bytes: _png);
|
||||
},
|
||||
openExternal: (_) async => true,
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('shot.png'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(ArtifactViewerPage), findsOneWidget);
|
||||
expect(
|
||||
find.text(
|
||||
'This artifact is hosted on another origin and is not previewed here.',
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(fetched, isEmpty);
|
||||
expect(find.byType(Image), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('an unsupported type is explicit, with Open and Copy link', (
|
||||
tester,
|
||||
) async {
|
||||
final video = recordedArtifact(
|
||||
'clip.mp4',
|
||||
url: '/artifacts/1/1/clip.mp4',
|
||||
contentType: 'video/mp4',
|
||||
);
|
||||
final group = _group([video]);
|
||||
var fetches = 0;
|
||||
await _pumpViewer(
|
||||
tester,
|
||||
groups: [group],
|
||||
selected: artifactVisitIdentity(group, video),
|
||||
fetch: (_) async {
|
||||
fetches += 1;
|
||||
return ArtifactFetchResult(status: 200, bytes: _png);
|
||||
},
|
||||
);
|
||||
|
||||
expect(
|
||||
find.text('This file type cannot be previewed here.'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text('Open'), findsOneWidget);
|
||||
expect(find.text('Copy link'), findsOneWidget);
|
||||
expect(fetches, 0);
|
||||
expect(find.byType(Image), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('paging clamps at both ends and keeps the visit facts', (
|
||||
tester,
|
||||
) async {
|
||||
final first = recordedArtifact(
|
||||
'a.png',
|
||||
url: '/artifacts/1/1/a.png',
|
||||
contentType: 'image/png',
|
||||
);
|
||||
final second = recordedArtifact(
|
||||
'b.png',
|
||||
url: '/artifacts/1/2/b.png',
|
||||
contentType: 'image/png',
|
||||
);
|
||||
final third = recordedArtifact(
|
||||
'c.png',
|
||||
url: '/artifacts/1/3/c.png',
|
||||
contentType: 'image/png',
|
||||
);
|
||||
final groups = [
|
||||
_group([first], visit: 1),
|
||||
_group([second], visit: 2),
|
||||
_group([third], visit: 3),
|
||||
];
|
||||
await _pumpViewer(
|
||||
tester,
|
||||
groups: groups,
|
||||
selected: artifactVisitIdentity(groups[0], first),
|
||||
);
|
||||
|
||||
expect(find.text('1 of 3 · image/png'), findsOneWidget);
|
||||
expect(_textButton(tester, 'Previous artifact').onPressed, isNull);
|
||||
expect(_textButton(tester, 'Next artifact').onPressed, isNotNull);
|
||||
|
||||
await tester.tap(find.text('Next artifact'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('2 of 3 · image/png'), findsOneWidget);
|
||||
expect(find.text('review · visit 2'), findsOneWidget);
|
||||
expect(_textButton(tester, 'Previous artifact').onPressed, isNotNull);
|
||||
|
||||
await tester.tap(find.text('Next artifact'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('3 of 3 · image/png'), findsOneWidget);
|
||||
expect(_textButton(tester, 'Next artifact').onPressed, isNull);
|
||||
await tester.tap(find.text('Next artifact'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('3 of 3 · image/png'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('Previous artifact'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('2 of 3 · image/png'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('loading and HTTP failure are honest', (tester) async {
|
||||
final text = recordedArtifact(
|
||||
'notes.txt',
|
||||
url: '/artifacts/1/1/notes.txt',
|
||||
contentType: 'text/plain',
|
||||
);
|
||||
final group = _group([text]);
|
||||
final pending = Completer<ArtifactFetchResult>();
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: ArtifactViewerPage(
|
||||
groups: [group],
|
||||
selectedIdentity: artifactVisitIdentity(group, text),
|
||||
configuredEndpoint: _endpoint,
|
||||
fetch: (_) => pending.future,
|
||||
openExternal: (_) async => true,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(find.text('Loading preview…'), findsOneWidget);
|
||||
|
||||
pending.complete(ArtifactFetchResult(status: 404, bytes: Uint8List(0)));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('The server answered 404.'), findsOneWidget);
|
||||
expect(find.byType(SelectableText), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('a network failure is reported instead of an empty preview', (
|
||||
tester,
|
||||
) async {
|
||||
final text = recordedArtifact(
|
||||
'notes.txt',
|
||||
url: '/artifacts/1/1/notes.txt',
|
||||
contentType: 'text/plain',
|
||||
);
|
||||
final group = _group([text]);
|
||||
await _pumpViewer(
|
||||
tester,
|
||||
groups: [group],
|
||||
selected: artifactVisitIdentity(group, text),
|
||||
fetch: (_) async => throw const ArtifactFetchException('network down'),
|
||||
);
|
||||
expect(find.textContaining('Could not load preview'), findsOneWidget);
|
||||
expect(find.textContaining('network down'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('Cupertino draws the same text preview and controls', (
|
||||
tester,
|
||||
) async {
|
||||
final text = recordedArtifact(
|
||||
'notes.txt',
|
||||
url: '/artifacts/1/1/notes.txt',
|
||||
contentType: 'text/plain',
|
||||
);
|
||||
final group = _group([text]);
|
||||
await _pumpViewer(
|
||||
tester,
|
||||
cupertino: true,
|
||||
groups: [group],
|
||||
selected: artifactVisitIdentity(group, text),
|
||||
fetch: (_) async => ArtifactFetchResult(
|
||||
status: 200,
|
||||
bytes: utf8.encode('cupertino text'),
|
||||
),
|
||||
);
|
||||
expect(find.text('cupertino text'), findsOneWidget);
|
||||
expect(find.byType(CupertinoButton), findsWidgets);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user