Send artifacts, runs and pipelines to a new or existing chat
One picker offers a new chat (the saved Open in chat harness and model) or any open chat. An existing chat gets the reference appended to its draft and focused, never sent. Artifacts gain the action in their viewer and gallery; the run and pipeline item becomes Send to chat.
This commit is contained in:
@@ -4,8 +4,13 @@ import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/application/open_in_chat.dart';
|
||||
import 'package:pipelines_app/application/send_to_chat.dart';
|
||||
import 'package:pipelines_app/application/open_in_chat_preferences.dart';
|
||||
import 'package:pipelines_app/features/chat/chat_runtime.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_composer_controller.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/artifact_chat_context.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/chat/ui/sessions/chat_create_fields.dart';
|
||||
import 'package:pipelines_app/features/pipelines/pipeline_models.dart';
|
||||
import 'package:pipelines_app/features/pipelines/pipeline_repository.dart';
|
||||
@@ -58,6 +63,96 @@ void main() {
|
||||
runtime.dispose();
|
||||
});
|
||||
|
||||
testWidgets('Send to chat lists and searches existing chats', (tester) async {
|
||||
final gateway = FakeChatGateway()
|
||||
..sessionsReply = {
|
||||
'chat_sessions': [
|
||||
{
|
||||
'id': 'older',
|
||||
'title': 'Old notes',
|
||||
'directory': '/archive',
|
||||
'backend': 'codex',
|
||||
'updated_at': '2026-10-01T00:00:00Z',
|
||||
},
|
||||
{
|
||||
'id': 'release',
|
||||
'title': 'Release review',
|
||||
'directory': '/work',
|
||||
'backend': 'claude',
|
||||
'updated_at': '2026-10-20T00:00:00Z',
|
||||
},
|
||||
],
|
||||
};
|
||||
final runtime = ChatRuntime(gateway: gateway);
|
||||
await tester.pumpWidget(const MaterialApp(home: Scaffold()));
|
||||
final picker = showSendToChatPicker(
|
||||
context: tester.element(find.byType(Scaffold)),
|
||||
runtime: runtime,
|
||||
selectChat: (_) {},
|
||||
directory: '/work',
|
||||
title: 'Artifact',
|
||||
draft: 'artifact',
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('New chat'), findsOneWidget);
|
||||
expect(find.text('Release review'), findsOneWidget);
|
||||
expect(find.text('Old notes'), findsOneWidget);
|
||||
// A short list is only as tall as its rows, with no empty space below.
|
||||
final rows = tester
|
||||
.widgetList<ListTile>(find.byType(ListTile))
|
||||
.map((tile) => tester.getSize(find.byWidget(tile)).height)
|
||||
.fold<double>(0, (sum, height) => sum + height);
|
||||
expect(tester.getSize(find.byType(ListView)).height, closeTo(rows, 1));
|
||||
await tester.enterText(find.byType(TextField), 'release');
|
||||
await tester.pump();
|
||||
expect(find.text('Release review'), findsOneWidget);
|
||||
expect(find.text('Old notes'), findsNothing);
|
||||
await tester.tap(find.text('New chat'));
|
||||
await picker;
|
||||
runtime.dispose();
|
||||
});
|
||||
|
||||
testWidgets('Send to chat appends an existing draft and focuses it', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = FakeChatGateway()
|
||||
..sessionsReply = {
|
||||
'chat_sessions': [
|
||||
{
|
||||
'id': 'existing',
|
||||
'title': 'Existing chat',
|
||||
'directory': '/work',
|
||||
'backend': 'opencode',
|
||||
'updated_at': '2026-10-20T00:00:00Z',
|
||||
},
|
||||
],
|
||||
};
|
||||
final runtime = ChatRuntime(gateway: gateway);
|
||||
final composer = ChatComposerController(gateway, 'existing');
|
||||
await composer.setDraft('Before');
|
||||
runtime.registerComposer('existing', composer);
|
||||
var selected = '';
|
||||
await tester.pumpWidget(const MaterialApp(home: Scaffold()));
|
||||
final picker = showSendToChatPicker(
|
||||
context: tester.element(find.byType(Scaffold)),
|
||||
runtime: runtime,
|
||||
selectChat: (id) => selected = id,
|
||||
directory: '/work',
|
||||
title: 'Artifact',
|
||||
draft: 'Artifact details',
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Existing chat'));
|
||||
await picker;
|
||||
await tester.pump();
|
||||
expect(selected, 'existing');
|
||||
expect(composer.draft, 'Before\nArtifact details');
|
||||
expect(runtime.composerFocus.take('existing'), isTrue);
|
||||
expect(gateway.calls.where((call) => call.type == 'chat_send'), isEmpty);
|
||||
composer.dispose();
|
||||
runtime.dispose();
|
||||
});
|
||||
|
||||
testWidgets('a harness the server no longer offers falls back to the '
|
||||
'default, without the saved model', (tester) async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
@@ -140,6 +235,45 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
test('artifact references identify provenance and inspection', () {
|
||||
final reference = artifactChatReference(
|
||||
const ArtifactChatContext(
|
||||
runId: '42',
|
||||
runTitle: 'Build',
|
||||
pipelineName: 'Release',
|
||||
stageKey: 'test',
|
||||
visit: 2,
|
||||
configuredEndpoint: 'ws://server.example/connect',
|
||||
),
|
||||
const ArtifactGroup(
|
||||
stageKey: 'test',
|
||||
visit: 2,
|
||||
artifacts: [
|
||||
ArtifactRecord(
|
||||
name: 'report.txt',
|
||||
contentType: 'text/plain',
|
||||
sizeBytes: 12,
|
||||
url: '/artifacts/42/2/report.txt',
|
||||
raw: {},
|
||||
),
|
||||
],
|
||||
),
|
||||
const ArtifactRecord(
|
||||
name: 'report.txt',
|
||||
contentType: 'text/plain',
|
||||
sizeBytes: 12,
|
||||
url: '/artifacts/42/2/report.txt',
|
||||
raw: {},
|
||||
),
|
||||
);
|
||||
expect(reference, contains('report.txt'));
|
||||
expect(reference, contains('pipelines inspect 42'));
|
||||
expect(
|
||||
reference,
|
||||
contains('http://server.example/artifacts/42/2/report.txt'),
|
||||
);
|
||||
});
|
||||
|
||||
test('open in chat keeps the more menu available', () {
|
||||
expect(showRunMoreMenu({'id': 42}, canOpenInChat: true), isTrue);
|
||||
});
|
||||
@@ -226,7 +360,7 @@ void main() {
|
||||
runtime.dispose();
|
||||
});
|
||||
|
||||
testWidgets('run list More selects Open in chat on desktop', (tester) async {
|
||||
testWidgets('run list More selects Send to chat on desktop', (tester) async {
|
||||
final run = <String, dynamic>{
|
||||
'id': 42,
|
||||
'title': 'Build',
|
||||
@@ -256,12 +390,12 @@ void main() {
|
||||
|
||||
await tester.tap(find.byKey(const Key('run-list-more-menu-42')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Open in chat'), findsOneWidget);
|
||||
await tester.tap(find.text('Open in chat'));
|
||||
expect(find.text('Send to chat…'), findsOneWidget);
|
||||
await tester.tap(find.text('Send to chat…'));
|
||||
expect(selected, same(run));
|
||||
});
|
||||
|
||||
testWidgets('run detail More selects Open in chat from the phone sheet', (
|
||||
testWidgets('run detail More selects Send to chat from the phone sheet', (
|
||||
tester,
|
||||
) async {
|
||||
final run = <String, dynamic>{'id': 42, 'title': 'Build'};
|
||||
@@ -291,12 +425,12 @@ void main() {
|
||||
|
||||
await tester.tap(find.byTooltip('More actions'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Open in chat'), findsOneWidget);
|
||||
await tester.tap(find.text('Open in chat'));
|
||||
expect(find.text('Send to chat…'), findsOneWidget);
|
||||
await tester.tap(find.text('Send to chat…'));
|
||||
expect(selected, same(run));
|
||||
});
|
||||
|
||||
testWidgets('pipeline list row More selects Open in chat with latest run', (
|
||||
testWidgets('pipeline list row More selects Send to chat with latest run', (
|
||||
tester,
|
||||
) async {
|
||||
final fixture = PipelineFixture();
|
||||
@@ -328,14 +462,14 @@ void main() {
|
||||
|
||||
await tester.tap(find.byKey(const Key('pipeline-row-more-menu-1')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Open in chat'), findsOneWidget);
|
||||
await tester.tap(find.text('Open in chat'));
|
||||
expect(find.text('Send to chat…'), findsOneWidget);
|
||||
await tester.tap(find.text('Send to chat…'));
|
||||
expect(selected?.id, 1);
|
||||
expect(selectedRun?.id, 42);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'pipeline detail actions select Open in chat from phone overflow',
|
||||
'pipeline detail actions select Send to chat from phone overflow',
|
||||
(tester) async {
|
||||
final fixture = PipelineFixture();
|
||||
final gateway = gatewayFor(fixture);
|
||||
@@ -365,8 +499,8 @@ void main() {
|
||||
|
||||
await tester.tap(find.byTooltip('Pipeline actions'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Open in chat'), findsOneWidget);
|
||||
await tester.tap(find.text('Open in chat'));
|
||||
expect(find.text('Send to chat…'), findsOneWidget);
|
||||
await tester.tap(find.text('Send to chat…'));
|
||||
expect(selected?.id, detail.id);
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user