Merge branch 'worktree-agent-aae8756320b8309f6'

# Conflicts:
#	app/lib/features/chat/conversation/chat_thread_view.dart
#	app/tool/perf/perf_fixture.dart
#	internal/protocol/message.go
#	internal/server/chat_hub.go
This commit is contained in:
2026-11-09 16:56:55 +00:00
54 changed files with 4192 additions and 22 deletions
@@ -0,0 +1,215 @@
import 'dart:convert';
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/ui/artifact_fullscreen.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/chat/files/files_urls.dart';
import 'package:pipelines_app/features/chat/files/files_viewer.dart';
import 'package:pipelines_app/features/chat/ui/transcript/shown/chat_shown_card.dart';
import 'package:pipelines_app/features/chat/ui/transcript/shown/chat_shown_html_card.dart';
const _png =
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==';
Widget _stubHtml(BuildContext context, String html) => Container(
key: const Key('stub-html'),
child: Text(
ArtifactFullscreenScope.maybeOf(context) == null
? 'inline $html'
: 'full $html',
),
);
void main() {
late FileUrlResolver original;
final fetched = <Uri>[];
final opened = <Uri>[];
setUp(() {
original = resolveFileUrls;
resolveFileUrls = (endpoint, path) => fileUrls(endpoint, path);
fetched.clear();
opened.clear();
});
tearDown(() => resolveFileUrls = original);
final viewer = FilesViewer(
fetch: (uri) async {
fetched.add(uri);
final path = uri.queryParameters['path'] ?? '';
return ArtifactFetchResult(
status: 200,
bytes: path.endsWith('.png')
? base64Decode(_png)
: utf8.encode('# Release notes\nline two\nline three\n'),
);
},
openExternal: (uri) async {
opened.add(uri);
return true;
},
);
Future<void> pump(WidgetTester tester, JsonMap item) async {
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: SingleChildScrollView(
child: ChatShownCard(
row: {'kind': 'shown', 'item': item},
endpoint: 'ws://peer.example.test/peers/abc/connect',
viewer: viewer,
htmlBuilder: _stubHtml,
),
),
),
),
);
await tester.pumpAndSettle();
}
testWidgets('an image file draws inline and opens the files viewer', (
tester,
) async {
await pump(tester, {
'id': 'i',
'kind': 'file',
'path': '/home/demo/chart.png',
'name': 'chart.png',
'size': 2048,
'title': 'Latency chart',
});
expect(find.text('Latency chart'), findsOneWidget);
expect(find.text('chart.png · Image · 2.0 KiB'), findsOneWidget);
expect(find.bySemanticsLabel('chart.png'), findsOneWidget);
await tester.tap(find.text('Latency chart'));
await tester.pumpAndSettle();
expect(find.byType(ArtifactViewerPage), findsOneWidget);
expect(fetched.last.path, '/peers/abc/files');
expect(fetched.last.queryParameters['path'], '/home/demo/chart.png');
});
testWidgets('a document card shows icon, size and its first lines', (
tester,
) async {
await pump(tester, {
'id': 'd',
'kind': 'file',
'path': '/home/demo/NOTES.md',
'name': 'NOTES.md',
'size': 40,
});
expect(find.text('NOTES.md'), findsOneWidget);
expect(find.byIcon(Icons.description_outlined), findsOneWidget);
expect(find.byKey(const Key('chat-shown-file-lines')), findsOneWidget);
expect(find.textContaining('# Release notes'), findsOneWidget);
expect(fetched.single.queryParameters['path'], '/home/demo/NOTES.md');
await tester.tap(find.text('NOTES.md'));
await tester.pumpAndSettle();
expect(find.byType(ArtifactViewerPage), findsOneWidget);
});
testWidgets('a PDF card opens the host handler', (tester) async {
await pump(tester, {
'id': 'p',
'kind': 'file',
'path': '/home/demo/report.pdf',
'size': 100000,
});
expect(find.byIcon(Icons.picture_as_pdf_outlined), findsOneWidget);
expect(find.byKey(const Key('chat-shown-file-lines')), findsNothing);
await tester.tap(find.text('report.pdf'));
await tester.pumpAndSettle();
expect(opened.single.queryParameters['path'], '/home/demo/report.pdf');
});
testWidgets('a web image shows its address and opens it outside', (
tester,
) async {
await pump(tester, {
'id': 'w',
'kind': 'image',
'url': 'https://example.test/cat.png',
'alt': 'A cat',
});
expect(find.text('https://example.test/cat.png'), findsOneWidget);
await tester.tap(find.text('example.test'));
await tester.pumpAndSettle();
expect(opened.single.toString(), 'https://example.test/cat.png');
});
testWidgets('a non-https image address is never fetched or opened', (
tester,
) async {
await pump(tester, {
'id': 'w',
'kind': 'image',
'url': 'http://example.test/cat.png',
});
expect(find.byType(Image), findsNothing);
expect(find.textContaining('Not an https address'), findsOneWidget);
});
testWidgets('an HTML view renders inline at its hint and opens full screen', (
tester,
) async {
await pump(tester, {
'id': 'h',
'kind': 'html',
'title': 'Pipeline graph',
'html': '<svg></svg>',
'html_bytes': 11,
'height_hint': 2000,
});
expect(find.text('inline <svg></svg>'), findsOneWidget);
final box = tester.getSize(
find
.ancestor(
of: find.byKey(const Key('stub-html')),
matching: find.byType(SizedBox),
)
.first,
);
expect(box.height, 600);
await tester.tap(find.byKey(const Key('chat-shown-html-open')));
await tester.pumpAndSettle();
expect(find.byType(ChatShownHtmlPage), findsOneWidget);
expect(find.text('full <svg></svg>'), findsOneWidget);
});
testWidgets('an expired HTML view says so and offers no Open', (
tester,
) async {
await pump(tester, {'id': 'h', 'kind': 'html', 'expired': true});
expect(find.text('This view is no longer retained'), findsOneWidget);
expect(find.byKey(const Key('chat-shown-html-open')), findsNothing);
expect(find.byKey(const Key('stub-html')), findsNothing);
});
testWidgets('notify rows say whether the phone was notified', (tester) async {
await pump(tester, {
'id': 'n',
'kind': 'notify',
'title': 'Build done',
'message': 'All green',
'delivered': true,
});
expect(find.text('Notified your phone: Build done'), findsOneWidget);
expect(find.text('All green'), findsOneWidget);
await pump(tester, {
'id': 'n2',
'kind': 'notify',
'title': 'Build done',
'delivered': false,
'detail': 'notifications are not set up',
});
expect(
find.text(
'Phone notification not sent: Build done — notifications are not set up',
),
findsOneWidget,
);
});
}