feat(app): artifact videos play in the viewer, as the web

This commit is contained in:
2026-10-23 14:41:30 +01:00
parent d1555e721f
commit 6fd14e76ca
9 changed files with 345 additions and 17 deletions
@@ -86,7 +86,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('clip.mp4', contentType: 'video/mp4'),
_record('bundle.zip', contentType: 'application/zip'),
]) {
final plan = _plan(record);
@@ -96,4 +95,12 @@ void main() {
expect(plan.resolved, isNotNull);
}
});
test('a same-origin video plays in the viewer without a byte fetch', () {
final plan = _plan(_record('clip.mp4', contentType: 'video/mp4'));
expect(plan.kind, ArtifactPreviewKind.video);
expect(plan.canFetch, isFalse);
expect(plan.message, isEmpty);
expect(plan.resolved, isNotNull);
});
}
@@ -0,0 +1,71 @@
import 'dart:async';
import 'package:flutter/material.dart';
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_url.dart';
import 'package:pipelines_app/features/artifacts/ui/artifact_video_player.dart';
import 'package:pipelines_app/features/artifacts/ui/artifact_viewer_content.dart';
import 'package:video_player/video_player.dart';
/// A controller whose platform work is scripted: [initialize] completes or
/// fails only when the test says so, and nothing reaches a video plugin.
class _ScriptedController extends VideoPlayerController {
_ScriptedController(super.uri) : super.networkUrl();
final ready = Completer<void>();
int plays = 0;
@override
Future<void> initialize() => ready.future;
@override
Future<void> play() async => plays++;
}
Widget _body(ArtifactVideoControllerFactory factory) => MaterialApp(
home: Scaffold(
body: ArtifactPreviewBody(
plan: ArtifactPreviewPlan(
kind: ArtifactPreviewKind.video,
resolved: ResolvedArtifactUrl(
uri: Uri.parse('http://127.0.0.1:8080/artifacts/7/clip.mp4'),
external: false,
),
message: '',
),
loading: false,
markdownBuilder: defaultArtifactMarkdown,
videoControllerFactory: factory,
),
),
);
void main() {
testWidgets('a video preview streams its resolved url and never autoplays', (
tester,
) async {
final opened = <Uri>[];
late _ScriptedController controller;
await tester.pumpWidget(
_body((uri) {
opened.add(uri);
return controller = _ScriptedController(uri);
}),
);
expect(find.byType(ArtifactVideoPlayer), findsOneWidget);
expect(opened.single.path, '/artifacts/7/clip.mp4');
expect(find.byType(CircularProgressIndicator), findsOneWidget);
expect(controller.plays, 0);
});
testWidgets('a video that cannot be opened says so', (tester) async {
late _ScriptedController controller;
await tester.pumpWidget(
_body((uri) => controller = _ScriptedController(uri)),
);
controller.ready.completeError(StateError('unsupported codec'));
await tester.pump();
expect(find.text(artifactVideoError), findsOneWidget);
});
}
@@ -5,6 +5,7 @@ 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/features/artifacts/ui/artifact_video_player.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';
@@ -300,7 +301,7 @@ void main() {
expect(find.byType(Image), findsNothing);
});
testWidgets('an unsupported type is explicit, with Open and Copy link', (
testWidgets('a video plays from its url, with Open and Copy link', (
tester,
) async {
final video = recordedArtifact(
@@ -320,14 +321,12 @@ void main() {
},
);
expect(
find.text('This file type cannot be previewed here.'),
findsOneWidget,
);
// The player streams the url itself; the viewer never fetches its bytes.
expect(find.byType(ArtifactVideoPlayer), findsOneWidget);
expect(find.text('This file type cannot be previewed here.'), findsNothing);
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', (