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:
@@ -0,0 +1,88 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_thread_controller.dart';
|
||||
|
||||
import 'chat_thread_fixtures.dart';
|
||||
|
||||
void main() {
|
||||
late FakeChatGateway gateway;
|
||||
late ChatThreadController controller;
|
||||
|
||||
setUp(() {
|
||||
gateway = FakeChatGateway();
|
||||
gateway.history = (_) async => chatPage([]);
|
||||
controller = ChatThreadController(gateway, 's');
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
controller.dispose();
|
||||
gateway.close();
|
||||
});
|
||||
|
||||
test('takes the retained list from the subscribe reply', () async {
|
||||
gateway.subscribe = () async => {
|
||||
'chat_shown': {
|
||||
'session_id': 's',
|
||||
'items': [
|
||||
{'id': 'a', 'kind': 'file', 'created_at': 1, 'path': '/h/a.png'},
|
||||
{'id': 'b', 'kind': 'notify', 'created_at': 2, 'title': 'Done'},
|
||||
],
|
||||
},
|
||||
};
|
||||
await controller.load();
|
||||
expect(controller.shown.map((item) => item['id']), ['a', 'b']);
|
||||
});
|
||||
|
||||
test('a pushed frame adds or replaces one item of this chat only', () async {
|
||||
gateway.subscribe = () async => {
|
||||
'chat_shown': {
|
||||
'session_id': 's',
|
||||
'items': [
|
||||
{'id': 'a', 'kind': 'notify', 'created_at': 1, 'delivered': false},
|
||||
],
|
||||
},
|
||||
};
|
||||
await controller.load();
|
||||
var notified = 0;
|
||||
controller.transcriptChanges.addListener(() => notified++);
|
||||
gateway.emitRaw({
|
||||
'type': 'chat_shown',
|
||||
'chat_shown': {
|
||||
'session_id': 'other',
|
||||
'items': [
|
||||
{'id': 'x', 'kind': 'notify', 'created_at': 3},
|
||||
],
|
||||
},
|
||||
});
|
||||
gateway.emitRaw({
|
||||
'type': 'chat_shown',
|
||||
'chat_shown': {
|
||||
'session_id': 's',
|
||||
'items': [
|
||||
{'id': 'a', 'kind': 'notify', 'created_at': 1, 'delivered': true},
|
||||
{'id': 'c', 'kind': 'html', 'created_at': 4, 'html': '<p>x</p>'},
|
||||
],
|
||||
},
|
||||
});
|
||||
await pumpEventQueue();
|
||||
expect(controller.shown.map((item) => item['id']), ['a', 'c']);
|
||||
expect(controller.shown.first['delivered'], isTrue);
|
||||
expect(notified, 1);
|
||||
});
|
||||
|
||||
test('a resync re-subscribes and adopts the server list', () async {
|
||||
var round = 0;
|
||||
gateway.subscribe = () async => {
|
||||
'chat_shown': {
|
||||
'session_id': 's',
|
||||
'items': [
|
||||
{'id': 'r$round', 'kind': 'notify', 'created_at': 1},
|
||||
],
|
||||
},
|
||||
};
|
||||
gateway.onSubscribe = () => round++;
|
||||
await controller.load();
|
||||
expect(controller.shown.single['id'], 'r1');
|
||||
await controller.resync();
|
||||
expect(controller.shown.single['id'], 'r2');
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/chat/domain/chat_shown_items.dart';
|
||||
import 'package:pipelines_app/features/chat/domain/chat_transcript.dart';
|
||||
|
||||
JsonMap _item(String id, int at, {String kind = 'notify'}) => {
|
||||
'id': id,
|
||||
'kind': kind,
|
||||
'created_at': at,
|
||||
'title': id,
|
||||
};
|
||||
|
||||
JsonMap _message(String id, String role, int at, {List<JsonMap>? parts}) => {
|
||||
'id': id,
|
||||
'role': role,
|
||||
'created_at': at,
|
||||
'parts':
|
||||
parts ??
|
||||
[
|
||||
{'type': 'text', 'text': id},
|
||||
],
|
||||
};
|
||||
|
||||
List<String> _shape(List<JsonMap> rows) => [
|
||||
for (final row in rows)
|
||||
row['kind'] == 'shown'
|
||||
? 'shown:${(row['item'] as Map)['id']}'
|
||||
: '${row['kind']}:${row['key']}',
|
||||
];
|
||||
|
||||
void main() {
|
||||
group('chatShownItemsOf', () {
|
||||
test('reads only this session and known kinds with ids', () {
|
||||
final body = {
|
||||
'session_id': 's',
|
||||
'items': [
|
||||
_item('a', 1),
|
||||
{'id': '', 'kind': 'file'},
|
||||
{'id': 'x', 'kind': 'future'},
|
||||
'junk',
|
||||
],
|
||||
};
|
||||
expect(chatShownItemsOf(body, 's')!.map((i) => i['id']), ['a']);
|
||||
expect(chatShownItemsOf(body, 'other'), isNull);
|
||||
expect(chatShownItemsOf(null, 's'), isNull);
|
||||
});
|
||||
});
|
||||
|
||||
test('merge replaces by id in place and appends new items', () {
|
||||
final held = [_item('a', 1), _item('b', 2)];
|
||||
final updated = {..._item('a', 1), 'title': 'A2'};
|
||||
final merged = mergeChatShownItems(held, [updated, _item('c', 3)]);
|
||||
expect(merged.map((i) => i['id']), ['a', 'b', 'c']);
|
||||
expect(merged.first['title'], 'A2');
|
||||
expect(
|
||||
mergeChatShownItems(held, [_item('z', 9)], replace: true).single['id'],
|
||||
'z',
|
||||
);
|
||||
});
|
||||
|
||||
group('withChatShownItems', () {
|
||||
final messages = [
|
||||
_message('u1', 'user', 100),
|
||||
_message('a1', 'assistant', 110),
|
||||
_message('u2', 'user', 200),
|
||||
_message('a2', 'assistant', 210),
|
||||
];
|
||||
|
||||
test('interleaves items by time before trailing cards', () {
|
||||
final rows = transcriptRows(
|
||||
messages,
|
||||
trailing: [
|
||||
{'kind': 'permission', 'key': 'p'},
|
||||
],
|
||||
);
|
||||
final out = withChatShownItems(rows, [
|
||||
_item('late', 500),
|
||||
_item('mid', 150),
|
||||
], hasMore: false);
|
||||
expect(_shape(out), [
|
||||
'user:u1',
|
||||
'assistant:a1',
|
||||
'shown:mid',
|
||||
'user:u2',
|
||||
'assistant:a2',
|
||||
'shown:late',
|
||||
'permission:p',
|
||||
]);
|
||||
final shown = out.firstWhere((row) => row['kind'] == 'shown');
|
||||
expect(shown['messageIds'], ['shown:mid']);
|
||||
});
|
||||
|
||||
test('older items wait for their history page while more remains', () {
|
||||
final rows = transcriptRows(messages);
|
||||
final early = [_item('early', 50), _item('mid', 150)];
|
||||
expect(
|
||||
_shape(withChatShownItems(rows, early, hasMore: true)),
|
||||
isNot(contains('shown:early')),
|
||||
);
|
||||
expect(
|
||||
_shape(withChatShownItems(rows, early, hasMore: false)).first,
|
||||
'shown:early',
|
||||
);
|
||||
});
|
||||
|
||||
test('items lead an empty transcript only when no history remains', () {
|
||||
expect(_shape(withChatShownItems([], [_item('a', 1)], hasMore: false)), [
|
||||
'shown:a',
|
||||
]);
|
||||
expect(withChatShownItems([], [_item('a', 1)], hasMore: true), isEmpty);
|
||||
});
|
||||
|
||||
test('hides represented Pipelines tool calls, keeps others and errors', () {
|
||||
JsonMap tool(String name, {String status = 'completed'}) => {
|
||||
'type': 'tool',
|
||||
'id': name,
|
||||
'name': name,
|
||||
'state': {'status': status},
|
||||
};
|
||||
final turn = _message(
|
||||
'a',
|
||||
'assistant',
|
||||
10,
|
||||
parts: [
|
||||
{'type': 'text', 'text': 'Here it is'},
|
||||
tool('mcp__pipelines__show_file'),
|
||||
tool('pipelines_show_html'),
|
||||
tool('pipelines/notify'),
|
||||
tool('pipelines_show_image', status: 'error'),
|
||||
tool('bash'),
|
||||
tool('pipelines_other'),
|
||||
],
|
||||
);
|
||||
final out = withChatShownItems(
|
||||
transcriptRows([turn]),
|
||||
[],
|
||||
hasMore: false,
|
||||
);
|
||||
final names = [
|
||||
for (final part in out.single['parts'] as List)
|
||||
if (part['type'] == 'tool') part['name'],
|
||||
];
|
||||
expect(names, ['pipelines_show_image', 'bash', 'pipelines_other']);
|
||||
});
|
||||
|
||||
test('a turn holding only a represented call is not drawn', () {
|
||||
final turn = _message(
|
||||
'a',
|
||||
'assistant',
|
||||
10,
|
||||
parts: [
|
||||
{
|
||||
'type': 'tool',
|
||||
'name': 'pipelines_notify',
|
||||
'state': {'status': 'completed'},
|
||||
},
|
||||
],
|
||||
);
|
||||
final out = withChatShownItems(transcriptRows([turn]), [
|
||||
_item('n', 20),
|
||||
], hasMore: false);
|
||||
expect(_shape(out), ['shown:n']);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -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,
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user