Merge main into chat drag

This commit is contained in:
2026-11-13 12:46:09 +00:00
35 changed files with 902 additions and 95 deletions
+302
View File
@@ -0,0 +1,302 @@
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'));
final unversioned = runChatReference({
'id': 9,
'name': 'release',
'status': 'running',
});
expect(unversioned, contains('(pipeline "release", status running)'));
});
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);
},
);
}
@@ -12,12 +12,17 @@ import 'package:pipelines_app/shell/destination.dart';
import 'conversation/chat_thread_fixtures.dart';
class _Gateway extends FakeChatGateway {
_Gateway({this.rows = const ['a', 'b', 'c']});
final List<String> rows;
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
if (type == 'chat_sessions') {
return Future.value({
'chat_sessions': [
for (final id in ['a', 'b', 'c']) {'id': id, 'title': 'Chat $id'},
for (final id in rows)
{'id': id, 'title': 'Chat $id', if (id == 'closed') 'closed_at': 1},
],
});
}
@@ -57,12 +62,16 @@ Future<void> _chord(
await tester.pumpAndSettle();
}
Future<void> _setup(WidgetTester tester, {bool open = true}) async {
Future<void> _setup(
WidgetTester tester, {
bool open = true,
List<String> rows = const ['a', 'b', 'c'],
}) async {
SharedPreferences.setMockInitialValues({});
tester.view.physicalSize = const Size(1800, 1000);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final gateway = _Gateway()..history = (_) async => chatPage([]);
final gateway = _Gateway(rows: rows)..history = (_) async => chatPage([]);
addTearDown(gateway.close);
await tester.pumpWidget(
MaterialApp(
@@ -133,20 +142,44 @@ void main() {
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('single pane with no shown window does nothing; empty workspace '
'does not consume', (tester) async {
await _setup(tester, open: false);
await _chord(tester);
expect(find.byType(ChatWorkspace), findsNothing);
testWidgets(
'single pane cycles list chats; empty workspace does not consume',
(tester) async {
await _setup(tester, open: false);
await _chord(tester);
expect(find.byType(ChatWorkspace), findsNothing);
await tester.tap(find.byKey(const Key('chat-row-a')));
await tester.pumpAndSettle();
_focusSidebar(tester);
await tester.pumpAndSettle();
await _chord(tester);
expect(find.byType(ChatWorkspace), findsOneWidget);
expect(_workspace(tester).paneCount, 1);
expect(_workspace(tester).activePane?.sessionId, 'b');
expect(_editable(tester, 'b').focusNode.hasPrimaryFocus, isTrue);
await tester.pumpWidget(const SizedBox.shrink());
},
);
testWidgets('single pane skips closed and hidden-on-this-device chats', (
tester,
) async {
await _setup(tester, open: false, rows: ['a', 'hidden', 'c', 'closed']);
await tester.tap(_actions('hidden'));
await tester.pumpAndSettle();
await tester.tap(find.text('Hide on this device'));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-row-a')));
await tester.pumpAndSettle();
_focusSidebar(tester);
await tester.pumpAndSettle();
await _chord(tester);
expect(find.byType(ChatWorkspace), findsOneWidget);
expect(_workspace(tester).paneCount, 1);
expect(_editable(tester, 'a').focusNode.hasPrimaryFocus, isFalse);
expect(_editable(tester, 'a').controller.text, isEmpty);
expect(_workspace(tester).activePane?.sessionId, 'c');
await _chord(tester);
expect(_workspace(tester).activePane?.sessionId, 'a');
await _chord(tester, reverse: true);
expect(_workspace(tester).activePane?.sessionId, 'c');
await tester.pumpWidget(const SizedBox.shrink());
});
@@ -592,10 +592,8 @@ void main() {
await app.stop(tester);
});
testWidgets('with the tiling focused Ctrl+Tab goes to the top-most shown '
'window, and cycles the panes only when no window is shown', (
tester,
) async {
testWidgets('with the tiling focused Ctrl+Tab cycles the single pane chat '
'list and cycles panes when there are multiple panes', (tester) async {
await _saved('a', 'b', 'c');
final app = _App(_Store());
await app.start(tester);
@@ -603,20 +601,20 @@ void main() {
expect(app.floating, ['c']);
final controller = _workspace(tester);
// A window is shown: from the tiling, Ctrl+Tab takes the keyboard to it
// and the panes stay where they are.
// A shown floating chat is skipped while the single tiled pane cycles the
// remaining open chats.
await tester.tapAt(tester.getCenter(_input('a')));
await tester.pump();
expect(controller.activePane?.sessionId, 'a');
await _tab(tester);
expect(controller.activePane?.sessionId, 'a');
expect(_composerFocused(tester, 'c'), isTrue);
expect(controller.activePane?.sessionId, 'b');
expect(_composerFocused(tester, 'b'), isTrue);
expect(app.floating, ['c']);
// A single shown window has nothing to cycle to.
// It wraps back to the other non-floating chat.
await _tab(tester);
expect(controller.activePane?.sessionId, 'a');
expect(_composerFocused(tester, 'c'), isTrue);
expect(_composerFocused(tester, 'a'), isTrue);
expect(app.floating, ['c']);
// No window shown: the panes cycle and the hidden window stays hidden.
@@ -150,28 +150,25 @@ void main() {
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('Control Tab over one pane does nothing: it never brings up '
'another chat', (tester) async {
testWidgets('Control Tab over one pane cycles the sidebar chats in both '
'directions', (tester) async {
await _setup(tester);
await _openRow(tester, 'a');
final workspace = _workspace(tester);
await _controlTab(tester);
expect(workspace.activePane?.sessionId, 'a');
expect(_editable(tester, 'a').focusNode.hasPrimaryFocus, isFalse);
// Opening b replaces the lone pane; a is no longer shown anywhere.
await _openRow(tester, 'b');
await tester.enterText(_input('b'), 'Draft B');
await _focusSidebar(tester);
for (final shift in [false, true]) {
await _controlTab(tester, shift: shift);
expect(workspace.paneCount, 1);
expect(workspace.activePane?.sessionId, 'b');
expect(_editable(tester, 'b').focusNode.hasPrimaryFocus, isFalse);
expect(_editable(tester, 'b').controller.text, 'Draft B');
for (final id in ['b', 'c', 'a']) {
await _controlTab(tester);
expect(workspace.activePane?.sessionId, id);
expect(_editable(tester, id).focusNode.hasPrimaryFocus, isTrue);
}
await _focusSidebar(tester);
for (final id in ['c', 'b', 'a']) {
await _controlTab(tester, shift: true);
expect(workspace.activePane?.sessionId, id);
expect(_editable(tester, id).focusNode.hasPrimaryFocus, isTrue);
}
// Two panes cycle the panes, not the history.
// Two panes still cycle panes, not the chat list.
await _openRow(tester, 'c');
await tester.tap(_actions('a'));
await tester.pumpAndSettle();
@@ -85,6 +85,7 @@ void main() {
activeSessionId: null,
visibleSessionIds: const {'a'},
onOpen: (_) {},
onNewChat: () {},
onExpand: () {},
navigation: const Text('Destinations'),
),
@@ -139,6 +140,7 @@ void main() {
activeSessionId: 'a',
visibleSessionIds: const {'a', 'b'},
onOpen: (_) {},
onNewChat: () {},
onExpand: () {},
),
),
@@ -107,6 +107,7 @@ void main() {
await controller.refresh();
final folds = ChatSectionFolds();
addTearDown(folds.dispose);
var newChatPressed = false;
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
@@ -116,12 +117,16 @@ void main() {
activeSessionId: 'a',
visibleSessionIds: const {'a', 'b'},
onOpen: (_) {},
onNewChat: () => newChatPressed = true,
onExpand: () {},
),
),
),
);
await tester.pumpAndSettle();
expect(find.byTooltip('New chat'), findsOneWidget);
await tester.tap(find.byTooltip('New chat'));
expect(newChatPressed, isTrue);
expect(find.byTooltip('Expand chat list'), findsOneWidget);
expect(edge(tester, 'a').width, 10);
expect(edge(tester, 'b').width, 3);
@@ -18,7 +18,7 @@ const _implemented = [
'Stop a running chat',
'Focus the neighbouring chat pane',
'Move the active chat pane',
'Cycle chat panes and floating chats',
'Cycle chats and floating chat panes',
'Resize panes with a focused divider',
'Scroll a wide transcript block',
'Show or hide floating chats',