Files
pipelines/app/test/application/open_in_chat_test.dart
T
alan e5403ae257 Open a run or pipeline in a new chat
The run and pipeline More menus offer Open in chat: a new chat in the
run's (or the pipeline's latest run's) workspace opens on the Chat tab
with a draft naming the run or pipeline and how to inspect or change it.
2026-11-13 12:38:27 +00:00

297 lines
9.6 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/application/open_in_chat.dart';
import 'package:pipelines_app/features/chat/chat_runtime.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';
import 'package:pipelines_app/features/pipelines/pipelines_controller.dart';
import 'package:pipelines_app/features/pipelines/widgets/pipeline_archive_action.dart';
import 'package:pipelines_app/features/pipelines/widgets/pipeline_list_panel.dart';
import 'package:pipelines_app/features/runs/ui/run_list_row.dart';
import 'package:pipelines_app/features/runs/ui/run_more_menu.dart';
import '../features/chat/ui/sessions/fake_chat_gateway.dart';
import '../features/pipelines/fixtures.dart';
import '../features/pipelines/test_helpers.dart';
void main() {
test('a run summary names its pipeline in name', () {
final draft = runChatReference({
'id': 7,
'name': 'release',
'title': 'Ship notes',
'version': 3,
'status': 'failed',
});
expect(
draft,
'About Pipelines run #7 "Ship notes" (pipeline "release" v3, '
'status failed). Inspect it with `pipelines inspect 7`.',
);
final untitled = runChatReference({
'id': 8,
'name': 'release',
'version': 3,
'status': 'succeeded',
});
expect(untitled, contains('run #8 "Run 8" (pipeline "release" v3'));
});
test('run references contain the exact inspect command', () {
expect(
runChatReference({
'id': 42,
'title': 'Nightly build',
'pipeline_name': 'Deploy',
'pipeline_version': 3,
'status': 'failed',
}),
'About Pipelines run #42 "Nightly build" (pipeline "Deploy" v3, '
'status failed). Inspect it with `pipelines inspect 42`.',
);
});
test('pipeline references contain show and edit guidance', () {
expect(
pipelineChatReference(7, 'Deploy', 4),
'About pipeline "Deploy" (id 7, version 4). Show it with '
'`pipelines show "Deploy"`; to change it, draft with `pipelines edit` '
'and publish with `pipelines submit`.',
);
});
test('open in chat keeps the more menu available', () {
expect(showRunMoreMenu({'id': 42}, canOpenInChat: true), isTrue);
});
test('pipeline latest run retains its workspace', () {
final run = PipelineRun.fromJson({
'id': 9,
'pipeline_id': 7,
'workspace': '/work/deploy',
});
expect(run.workspace, '/work/deploy');
});
testWidgets(
'open in chat uses the catalog backend, draft, route, and focus',
(tester) async {
final gateway = FakeChatGateway()
..backendsHandler = () async => const {
'chat_backends': ['codex', 'claude'],
};
final runtime = ChatRuntime(gateway: gateway);
String? selected;
await tester.pumpWidget(const MaterialApp(home: Scaffold()));
await openReferenceInChat(
context: tester.element(find.byType(Scaffold)),
runtime: runtime,
selectChat: (id) => selected = id,
directory: '/work/run',
title: 'Run #42: Build',
draft: 'About Pipelines run #42.',
);
final create = gateway.lastFields('chat_create')!['chat_create'] as Map;
expect(create['backend'], 'codex');
expect(create['directory'], '/work/run');
expect(selected, 'created');
expect(runtime.pendingDrafts['created'], 'About Pipelines run #42.');
expect(runtime.composerFocus.take('created'), isTrue);
runtime.dispose();
},
);
testWidgets('open in chat falls back to the default folder', (tester) async {
final gateway = FakeChatGateway();
final runtime = ChatRuntime(gateway: gateway);
await tester.pumpWidget(const MaterialApp(home: Scaffold()));
await openReferenceInChat(
context: tester.element(find.byType(Scaffold)),
runtime: runtime,
selectChat: (_) {},
directory: '',
title: 'Pipeline: Deploy',
draft: 'About pipeline "Deploy".',
);
final create = gateway.lastFields('chat_create')!['chat_create'] as Map;
expect(create['directory'], chatHomeDirectory);
runtime.dispose();
});
testWidgets('create failure leaves navigation and chat state unchanged', (
tester,
) async {
final gateway = FakeChatGateway()..failures['chat_create'] = 'refused';
final runtime = ChatRuntime(gateway: gateway);
String? selected;
await tester.pumpWidget(const MaterialApp(home: Scaffold()));
await openReferenceInChat(
context: tester.element(find.byType(Scaffold)),
runtime: runtime,
selectChat: (id) => selected = id,
directory: '/work/run',
title: 'Run #42: Build',
draft: 'About Pipelines run #42.',
);
await tester.pump();
expect(selected, isNull);
expect(runtime.opened, isEmpty);
expect(find.textContaining('Could not open in chat'), findsOneWidget);
runtime.dispose();
});
testWidgets('run list More selects Open in chat on desktop', (tester) async {
final run = <String, dynamic>{
'id': 42,
'title': 'Build',
'status': 'failed',
'created_at': '2026-10-17T19:00:00',
};
JsonMap? selected;
final gateway = FakeChatGateway();
tester.view.physicalSize = const Size(900, 700);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: RunListRow(
run: run,
now: DateTime(2026, 10, 18),
gateway: gateway,
onRunChanged: (_) {},
onOpenInChat: (context, value) async => selected = value,
),
),
),
);
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(selected, same(run));
});
testWidgets('run detail More selects Open in chat from the phone sheet', (
tester,
) async {
final run = <String, dynamic>{'id': 42, 'title': 'Build'};
JsonMap? selected;
final gateway = FakeChatGateway();
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
appBar: AppBar(
actions: [
RunMoreMenu(
run: run,
gateway: gateway,
onRunChanged: (_) {},
onOpenInChat: (context, value) async => selected = value,
),
],
),
),
),
);
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(selected, same(run));
});
testWidgets('pipeline list row More selects Open in chat with latest run', (
tester,
) async {
final fixture = PipelineFixture();
final gateway = gatewayFor(fixture);
final controller = PipelinesController(PipelinesRepository(gateway));
addTearDown(controller.dispose);
await controller.load();
PipelineSummary? selected;
PipelineRun? selectedRun;
tester.view.physicalSize = const Size(900, 700);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: PipelineListPanel(
controller: controller,
onOpenInChat: (context, pipeline, run) async {
selected = pipeline;
selectedRun = run;
},
),
),
),
);
await tester.pumpAndSettle();
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(selected?.id, 1);
expect(selectedRun?.id, 42);
});
testWidgets(
'pipeline detail actions select Open in chat from phone overflow',
(tester) async {
final fixture = PipelineFixture();
final gateway = gatewayFor(fixture);
final controller = PipelinesController(PipelinesRepository(gateway));
addTearDown(controller.dispose);
final detail = PipelineDetail.fromJson(fixture.details.first);
PipelineDetail? selected;
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Builder(
builder: (context) => pipelineActionsMenu(
context,
controller,
detail,
onOpenInChat: (context, value, run) async => selected = value,
),
),
),
),
);
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(selected?.id, detail.id);
},
);
}