Merge branch 'main' into worktree-agent-a3cb3553b5c91a345

This commit is contained in:
2026-12-03 14:21:22 +00:00
135 changed files with 7973 additions and 443 deletions
@@ -0,0 +1,248 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/core/servers/server_scope.dart';
import 'package:pipelines_app/features/chat/chat_runtime.dart';
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
import 'package:pipelines_app/features/chat/screen.dart';
import 'package:pipelines_app/features/chat/windows/chat_windows.dart';
import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart';
import 'package:pipelines_app/features/chat/workspace/chat_workspace_store.dart';
import 'package:pipelines_app/shell/windows/window_frame.dart';
import 'package:pipelines_app/shell/windows/window_host.dart';
import 'package:pipelines_app/shell/windows/window_kind.dart';
import 'package:pipelines_app/shell/windows/window_manager.dart';
import '../../application/detached/detached_fixtures.dart';
import 'conversation/chat_thread_fixtures.dart';
class _Gateway extends FakeChatGateway {
@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', 'directory': '/home/$id'},
],
});
}
if (type == 'chat_shells') return Future.value({'chat_shells': []});
return super.call(type, fields);
}
}
const _label = 'Open in new window (Alt+Shift+Y)';
Finder _thread(String id) => find.byWidgetPredicate(
(widget) => widget is ChatThreadView && widget.sessionId == id,
skipOffstage: false,
);
List<String> _tiled(WidgetTester tester) => [
for (final pane
in tester
.widget<ChatWorkspace>(
find.byType(ChatWorkspace, skipOffstage: false),
)
.controller
.panes)
pane.sessionId,
];
/// The Chat destination with its floating windows, as the app hosts them,
/// with [opener] as the platform's new windows (none when null).
class _App {
final gateway = _Gateway()..history = (_) async => chatPage([]);
final opener = FakeOpener();
late final ChatRuntime runtime;
late final WindowManager manager;
late final ChatWindows windows;
Future<void> start(WidgetTester tester, {bool detached = true}) async {
tester.view.physicalSize = const Size(1800, 1000);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final layout = ChatWorkspaceController()
..open('a')
..splitActive('b', ChatSplitAxis.horizontal);
SharedPreferences.setMockInitialValues({
scopedServerKey(chatWorkspacePreferenceKey, 'server-a'): layout
.snapshot()!
.encode(),
});
bindServerIdentity(gateway, 'server-a');
runtime = ChatRuntime(gateway: gateway, serverKey: 'server-a');
manager = WindowManager(kinds: WindowKinds(), server: 'server-a');
windows = ChatWindows(
manager: manager,
runtime: runtime,
openInChat: (_) {},
)..start();
if (detached) windows.detached = opener;
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Stack(
fit: StackFit.expand,
children: [
ChatScreen(
gateway: gateway,
persistWorkspace: true,
runtime: runtime,
windows: windows,
),
Positioned.fill(child: WindowHost(manager: manager)),
],
),
),
),
);
await tester.pumpAndSettle();
addTearDown(() async {
await tester.pumpWidget(const SizedBox.shrink());
windows.dispose();
runtime.dispose();
manager.dispose();
gateway.close();
});
}
List<String> get floating => [for (final w in windows.windows) w.contentId];
}
Future<void> _paneMenu(WidgetTester tester, String session) async {
await tester.tap(
find
.descendant(
of: _thread(session),
matching: find.byTooltip('More actions'),
)
.hitTestable(),
);
await tester.pumpAndSettle();
}
Future<void> _rowMenu(WidgetTester tester, String id) async {
await tester.tap(find.byTooltip('Chat actions for Chat $id').first);
await tester.pumpAndSettle();
}
void main() {
testWidgets('the pane menu sends a tiled chat to a new window', (
tester,
) async {
final app = _App();
await app.start(tester);
expect(_tiled(tester), ['a', 'b']);
await _paneMenu(tester, 'b');
expect(find.text('Float (Alt+Y)'), findsOneWidget);
await tester.tap(find.text(_label));
await tester.pumpAndSettle();
expect(app.opener.chats, ['b']);
// It left the tiling, as Float takes it out, and no floating window.
expect(_tiled(tester), ['a']);
expect(app.floating, isEmpty);
});
testWidgets('a chat whose window did not open stays where it was', (
tester,
) async {
final app = _App();
await app.start(tester);
app.opener.opens = false;
await _paneMenu(tester, 'b');
await tester.tap(find.text(_label));
await tester.pumpAndSettle();
expect(app.opener.chats, ['b']);
expect(_tiled(tester), ['a', 'b']);
});
testWidgets('without platform windows the action is not offered', (
tester,
) async {
final app = _App();
await app.start(tester, detached: false);
await _paneMenu(tester, 'b');
expect(find.text('Float (Alt+Y)'), findsOneWidget);
expect(find.textContaining('new window'), findsNothing);
await tester.tapAt(const Offset(5, 995));
await tester.pumpAndSettle();
await _rowMenu(tester, 'c');
expect(find.textContaining('new window'), findsNothing);
});
testWidgets('the row menu offers it after Float, for any chat', (
tester,
) async {
final app = _App();
await app.start(tester);
await _rowMenu(tester, 'c');
final float = tester.getTopLeft(find.text('Float (Alt+Y)').last);
final open = tester.getTopLeft(find.text(_label).last);
expect(open.dy, greaterThan(float.dy));
await tester.tap(find.text(_label).last);
await tester.pumpAndSettle();
expect(app.opener.chats, ['c']);
expect(_tiled(tester), ['a', 'b']);
});
testWidgets('a floating chat goes to a new window from its title bar', (
tester,
) async {
final app = _App();
await app.start(tester);
await _rowMenu(tester, 'c');
await tester.tap(find.text('Float (Alt+Y)').last);
await tester.pumpAndSettle();
expect(app.floating, ['c']);
final window = find.ancestor(
of: find.text('Chat c'),
matching: find.byType(WindowFrame),
);
await tester.tap(
find.descendant(of: window, matching: find.byTooltip(_label)).first,
);
await tester.pumpAndSettle();
expect(app.opener.chats, ['c']);
expect(app.floating, isEmpty);
});
testWidgets('Alt+Shift+Y sends the active pane; Alt+Y still floats', (
tester,
) async {
final app = _App();
await app.start(tester);
// The keyboard is in chat b's composer, the active pane.
await tester.tap(
find
.descendant(
of: find.byKey(const ValueKey('chat-composer-b')),
matching: find.byType(EditableText),
)
.first,
);
await tester.pumpAndSettle();
await tester.sendKeyDownEvent(LogicalKeyboardKey.altLeft);
await tester.sendKeyDownEvent(LogicalKeyboardKey.shiftLeft);
await tester.sendKeyEvent(LogicalKeyboardKey.keyY);
await tester.sendKeyUpEvent(LogicalKeyboardKey.shiftLeft);
await tester.sendKeyUpEvent(LogicalKeyboardKey.altLeft);
await tester.pumpAndSettle();
expect(app.opener.chats, ['b']);
expect(_tiled(tester), ['a']);
expect(app.floating, isEmpty);
});
testWidgets('a chat brought back from its window joins the tiling', (
tester,
) async {
final app = _App();
await app.start(tester);
app.windows.bringBack('c');
await tester.pumpAndSettle();
expect(_tiled(tester), ['a', 'b', 'c']);
});
}
@@ -4,6 +4,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/conversation/chat_composer_bar.dart';
import 'package:pipelines_app/features/chat/conversation/chat_composer_controller.dart';
import 'package:pipelines_app/features/chat/conversation/chat_draft_store.dart';
import 'package:pipelines_app/features/chat/domain/chat_clipboard_paste_native.dart';
import '../../../core/keyboard/browser_keys.dart';
import 'chat_composer_bar_fixtures.dart';
@@ -32,6 +33,12 @@ void main() {
if (call.method == 'Clipboard.hasStrings') return {'value': true};
return null;
});
// The Linux Runner's clipboard reader: no files, so the text is pasted.
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(
chatClipboardFilesChannel,
(call) async => {'files': const [], 'errors': const []},
);
});
tearDown(() {
@@ -39,6 +46,8 @@ void main() {
gateway.close();
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(SystemChannels.platform, null);
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(chatClipboardFilesChannel, null);
});
for (final merged in [false, true]) {
@@ -10,6 +10,7 @@ import 'package:pipelines_app/features/chat/domain/chat_clipboard_paste_native.d
import '../conversation/chat_composer_bar_fixtures.dart';
final _macOS = TargetPlatformVariant.only(TargetPlatform.macOS);
final _linux = TargetPlatformVariant.only(TargetPlatform.linux);
Finder get _field => find.byKey(const Key('chat-composer-field'));
@@ -77,10 +78,10 @@ void main() {
Future<void> done(WidgetTester tester) => tester.pumpWidget(const SizedBox());
test('only the macOS host reads clipboard files natively', () {
test('the macOS and Linux hosts read clipboard files natively', () {
expect(chatHostReadsClipboardFiles(TargetPlatform.macOS), isTrue);
expect(chatHostReadsClipboardFiles(TargetPlatform.linux), isTrue);
for (final platform in [
TargetPlatform.linux,
TargetPlatform.windows,
TargetPlatform.android,
TargetPlatform.iOS,
@@ -228,4 +229,47 @@ void main() {
expect(composer.draft, isEmpty);
await done(tester);
}, variant: _macOS);
testWidgets('Ctrl+V attaches a copied screenshot on Linux', (tester) async {
pasteboard = {
'files': [
{
'name': '',
'mime': 'image/png',
'bytes': Uint8List.fromList([3]),
},
],
'errors': const [],
};
expect(hostChatClipboardPaste.isSupported, isTrue);
await mount(tester);
await tester.showKeyboard(_field);
await tester.pump();
await paste(tester, modifier: LogicalKeyboardKey.controlLeft);
expect(fileReads, 1);
expect(find.text('pasted-1.png'), findsOneWidget);
expect(textReads, 0);
await done(tester);
}, variant: _linux);
testWidgets('Ctrl+V of plain text on Linux pastes it once', (tester) async {
await mount(tester);
await tester.showKeyboard(_field);
await paste(tester, modifier: LogicalKeyboardKey.controlLeft);
expect(fileReads, 1);
expect(composer.draft, 'copied text');
await done(tester);
}, variant: _linux);
testWidgets('the Super key is not the Linux paste shortcut', (tester) async {
await mount(tester);
FocusManager.instance.primaryFocus?.unfocus();
await tester.pump();
await paste(tester);
expect(fileReads, 0);
await done(tester);
}, variant: _linux);
}