feat(app): render markdown in chat messages and artifact previews

This commit is contained in:
2026-10-22 00:26:36 +01:00
parent 0e323dde10
commit dc6b963170
8 changed files with 926 additions and 12 deletions
@@ -13,6 +13,7 @@ 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 'package:pipelines_app/features/chat/ui/transcript/chat_markdown_view.dart';
import '../domain/artifact_fixtures.dart';
import 'artifact_visit_list_fixture.dart';
@@ -37,7 +38,7 @@ Future<void> _pumpViewer(
required String selected,
bool cupertino = false,
ArtifactFetch? fetch,
Widget Function(String)? markdownBuilder,
Widget Function(BuildContext, String)? markdownBuilder,
ArtifactExternalOpen? openExternal,
}) async {
final page = ArtifactViewerPage(
@@ -45,7 +46,8 @@ Future<void> _pumpViewer(
selectedIdentity: selected,
configuredEndpoint: _endpoint,
fetch: fetch ?? (_) async => ArtifactFetchResult(status: 200, bytes: _png),
markdownBuilder: markdownBuilder ?? (value) => SelectableText(value),
markdownBuilder:
markdownBuilder ?? (context, value) => SelectableText(value),
openExternal: openExternal ?? (_) async => true,
);
await tester.pumpWidget(
@@ -64,6 +66,54 @@ TextButton _textButton(WidgetTester tester, String label) {
);
}
const String _markdownBody =
'# Report\n'
'\n'
'A paragraph with **bold** and `code`.\n'
'\n'
'| Step | State |\n'
'| --- | --- |\n'
'| build | ok |\n'
'\n'
'```dart\n'
'final n = 1;\n'
'```';
/// Opens the gallery's markdown row so the default builder composes the real
/// viewer exactly as the run detail does.
Future<void> _openMarkdownFromGallery(
WidgetTester tester, {
required bool cupertino,
String name = 'notes.md',
String contentType = 'text/markdown',
}) async {
final page = ArtifactGalleryPage(
steps: <JsonMap>[
step(
stage: 'review',
visit: 1,
artifacts: [
artifact(
name,
url: '/artifacts/1/1/$name',
contentType: contentType,
sizeBytes: 4096,
),
],
),
],
configuredEndpoint: _endpoint,
fetch: (_) async =>
ArtifactFetchResult(status: 200, bytes: utf8.encode(_markdownBody)),
);
await tester.pumpWidget(
cupertino ? CupertinoApp(home: page) : MaterialApp(home: page),
);
await tester.pumpAndSettle();
await tester.tap(find.text(name));
await tester.pumpAndSettle();
}
void main() {
testWidgets('an image is previewed in-app without opening a tab', (
tester,
@@ -153,7 +203,7 @@ void main() {
selected: identity,
fetch: (_) async =>
ArtifactFetchResult(status: 200, bytes: utf8.encode('# Title')),
markdownBuilder: (value) => Text('MARKDOWN $value'),
markdownBuilder: (context, value) => Text('MARKDOWN $value'),
);
expect(find.text('MARKDOWN # Title'), findsOneWidget);
@@ -403,4 +453,66 @@ void main() {
expect(find.text('cupertino text'), findsOneWidget);
expect(find.byType(CupertinoButton), findsWidgets);
});
testWidgets('the gallery previews markdown through the chat renderer', (
tester,
) async {
await _openMarkdownFromGallery(tester, cupertino: false);
expect(find.byType(ArtifactViewerPage), findsOneWidget);
expect(find.byType(ChatMarkdownView), findsOneWidget);
// The subset renders as native blocks, not raw markers.
expect(find.text('Report'), findsOneWidget);
expect(find.text('build'), findsOneWidget);
expect(find.text('ok'), findsOneWidget);
expect(find.text('dart'), findsOneWidget);
expect(find.text('final n = 1;'), findsOneWidget);
expect(find.text('# Report'), findsNothing);
expect(find.text('A paragraph with bold and code.'), findsOneWidget);
// The recorded facts stay visible above the preview.
expect(find.text('1 of 1 · text/markdown'), findsOneWidget);
expect(find.text('text/markdown · 4.0\u00a0KiB'), findsOneWidget);
expect(find.text('review · visit 1'), findsOneWidget);
});
testWidgets('a .markdown name previews without a recorded MIME', (
tester,
) async {
await _openMarkdownFromGallery(
tester,
cupertino: false,
name: 'notes.markdown',
contentType: '',
);
expect(find.byType(ArtifactViewerPage), findsOneWidget);
expect(find.byType(ChatMarkdownView), findsOneWidget);
expect(find.text('Report'), findsOneWidget);
expect(find.text('dart'), findsOneWidget);
expect(find.text('1 of 1 · artifact'), findsOneWidget);
expect(find.text('type not recorded · 4.0\u00a0KiB'), findsOneWidget);
});
testWidgets('Cupertino markdown preview is native at 320px and 2x text', (
tester,
) async {
tester.view.physicalSize = const Size(640, 1200);
tester.view.devicePixelRatio = 2;
tester.platformDispatcher.textScaleFactorTestValue = 2;
tester.platformDispatcher.platformBrightnessTestValue = Brightness.dark;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
addTearDown(tester.platformDispatcher.clearPlatformBrightnessTestValue);
await _openMarkdownFromGallery(tester, cupertino: true);
expect(tester.takeException(), isNull);
expect(find.byType(ChatMarkdownView), findsOneWidget);
expect(find.text('Report'), findsOneWidget);
expect(find.text('dart'), findsOneWidget);
expect(find.text('1 of 1 · text/markdown'), findsOneWidget);
// The viewer and its markdown add no Material control to a Cupertino host.
expect(find.byType(Material), findsNothing);
});
}