App: open a chat, the terminal or a diff in a new window

"Open in new window" sits beside Float: the chat pane and chat list row
menus, a floating chat window's title bar, the terminal options menu and
the diff bar, plus Alt+Shift+Y for the chat with the keyboard (listed in
the shortcut help). Once the window opens the item leaves the main window
as Float takes a pane out of the tiling.

The window is its own app instance at /window/chat/<id>,
/window/terminal?tab=<key> or /window/diff/<token>: only that item, named
after it, with "Bring back to main window". It has its own connection and
writes no shared layout (no open-chat workspace, window store or terminal
layout) and posts no notifications, so they stay the main window's.

Web opens a popup window (a blocked popup offers a tab); Linux and macOS
start a second process with --detached (Flutter's multi-window API is still
experimental); Android and iOS hide the action. The capture kit gains a
follow step for windows a page opens.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 12:47:42 +00:00
parent c4de1de27b
commit 61c7eee2b0
46 changed files with 3223 additions and 72 deletions
@@ -0,0 +1,142 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/application/detached/detached_diff.dart';
import 'package:pipelines_app/application/detached/detached_route.dart';
import 'package:pipelines_app/application/detached/detached_window_body.dart';
import 'package:pipelines_app/features/changes/changes.dart';
import 'package:pipelines_app/shell/detached/detached_window_scope.dart';
import '../../application/detached/detached_fixtures.dart';
FileChange _file(String path) => FileChange(
path: path,
kind: ChangeKind.modified,
patch: '--- a/$path\n+++ b/$path\n@@ -0,0 +1,1 @@\n+line of $path\n',
beforeMode: '100644',
afterMode: '100755',
).withSteps(const ['build']);
void main() {
setUp(() => diffShowsAllFiles.value = false);
test('a file change survives the hand-over to another window', () {
final file = _file('lib/a.dart');
final back = FileChange.fromHandover(
jsonDecode(jsonEncode(file.toJson())),
)!;
expect(back.path, file.path);
expect(back.kind, file.kind);
expect(back.patch, file.patch);
expect(back.beforeMode, '100644');
expect(back.afterMode, '100755');
expect(back.steps, ['build']);
expect(back.added, 1);
});
testWidgets('a diff page offers Open in new window and closes once open', (
tester,
) async {
tester.view.physicalSize = const Size(1000, 700);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final opener = FakeOpener();
final files = [_file('lib/a.dart'), _file('lib/b.dart')];
await tester.pumpWidget(
DetachedWindowScope(
opener: opener,
child: MaterialApp(
home: Builder(
builder: (context) => Scaffold(
body: TextButton(
onPressed: () =>
showFileDiffViewer(context, files[1], files: files),
child: const Text('open'),
),
),
),
),
),
);
await tester.tap(find.text('open'));
await tester.pumpAndSettle();
expect(find.byType(FileDiffPage), findsOneWidget);
await tester.tap(find.byTooltip('Open in new window'));
await tester.pumpAndSettle();
expect(opener.diffs.single.map((f) => f['path']), [
'lib/a.dart',
'lib/b.dart',
]);
expect(find.byType(FileDiffPage), findsNothing);
});
testWidgets('without platform windows the diff page has no such button', (
tester,
) async {
await tester.pumpWidget(
MaterialApp(home: FileDiffPage(files: [_file('a')])),
);
expect(find.byTooltip('Open in new window'), findsNothing);
});
testWidgets('a detached diff shows the handed files and gives them back', (
tester,
) async {
tester.view.physicalSize = const Size(1000, 820);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final platform = FakeDetachedPlatform();
platform.stored['tok'] = jsonEncode({
'files': [_file('lib/a.dart').toJson(), _file('lib/b.dart').toJson()],
'index': 1,
});
final titles = <String>[];
final back = <(DetachedKind, String, int, int)>[];
await tester.pumpWidget(
MaterialApp(
home: DetachedDiff(
token: 'tok',
platform: platform,
window: DetachedWindowControls(
ready: ValueNotifier(true),
sync: ValueNotifier(0),
setTitle: titles.add,
close: () {},
bringBackItem: (kind, id, files, index) =>
back.add((kind, id, files.length, index)),
),
),
),
);
await tester.pumpAndSettle();
expect(find.byType(FileDiffPage), findsOneWidget);
expect(titles.last, '2 files changed');
expect(find.text('b.dart'), findsWidgets);
// No Back in a window of its own, and no window to open from it.
expect(find.byType(BackButton), findsNothing);
expect(find.byTooltip('Open in new window'), findsNothing);
await tester.tap(find.byTooltip('Bring back to main window'));
expect(back, [(DetachedKind.diff, 'tok', 2, 1)]);
});
testWidgets('a diff handed over to nobody says it is gone', (tester) async {
await tester.pumpWidget(
MaterialApp(
home: DetachedDiff(
token: 'missing',
platform: FakeDetachedPlatform(),
window: DetachedWindowControls(
ready: ValueNotifier(true),
sync: ValueNotifier(0),
setTitle: (_) {},
close: () {},
bringBackItem: (_, _, _, _) {},
),
),
),
);
await tester.pumpAndSettle();
expect(find.text('This diff is no longer available.'), findsOneWidget);
});
}
@@ -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']);
});
}
@@ -0,0 +1,120 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/application/app_terminals.dart';
import 'package:pipelines_app/application/detached/detached_route.dart';
import 'package:pipelines_app/application/detached/detached_terminal.dart';
import 'package:pipelines_app/application/detached/detached_window_body.dart';
import 'package:pipelines_app/features/terminal/terminal_hub.dart';
import 'package:pipelines_app/features/terminal/terminal_layout.dart';
import 'package:pipelines_app/features/terminal/terminal_tab_strip.dart';
import 'package:pipelines_app/shell/detached/detached_window_scope.dart';
import '../../application/detached/detached_fixtures.dart';
import 'terminal_fixtures.dart';
void main() {
testWidgets('the options menu sends the terminal to a new window', (
tester,
) async {
final mac = TerminalGateway()..add('t1', text: 'hello\r\n');
addTearDown(mac.close);
final hub = TerminalHub(TestMachines([machine('mac', mac)]))..activate();
addTearDown(hub.dispose);
await tester.runAsync(hub.listed);
final layout = TerminalLayout(store: MemoryLayoutStore())..show();
final opener = FakeOpener();
await tester.pumpWidget(
DetachedWindowScope(
opener: opener,
child: MaterialApp(
home: Scaffold(
body: TerminalTabStrip(hub: hub, layout: layout),
),
),
),
);
await tester.tap(find.byTooltip('Terminal options'));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const ValueKey('terminal-new-window')));
await tester.pumpAndSettle();
expect(opener.terminals, ['mac/t1']);
expect(layout.visible, isFalse, reason: 'it leaves the main window');
});
testWidgets('without platform windows the menu has no such choice', (
tester,
) async {
final hub = TerminalHub(TestMachines([]));
addTearDown(hub.dispose);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: TerminalTabStrip(
hub: hub,
layout: TerminalLayout(store: MemoryLayoutStore()),
),
),
),
);
await tester.tap(find.byTooltip('Terminal options'));
await tester.pumpAndSettle();
expect(find.byKey(const ValueKey('terminal-new-window')), findsNothing);
expect(find.text('Floating window'), findsOneWidget);
});
test('a layout that does not persist never saves', () async {
final store = MemoryLayoutStore();
final layout = TerminalLayout(store: store)..persist = false;
layout
..setFontSize(18)
..show();
await layout.save();
expect(store.saves, 0);
expect(layout.fontSize, 18, reason: 'the window still follows it');
});
testWidgets('a detached terminal opens on its tab, without modes, and '
'gives it back', (tester) async {
final mac = TerminalGateway()
..add('t1', text: 'one\r\n')
..add('t2', text: 'two\r\n');
addTearDown(mac.close);
final connection = ValueNotifier(0);
final terminals = AppTerminals(
pool: null,
connection: connection,
connected: () => true,
gateway: mac,
machineId: 'mac',
machineName: () => 'Mac',
layout: TerminalLayout(store: MemoryLayoutStore()),
);
addTearDown(terminals.dispose);
final back = <(DetachedKind, String)>[];
final titles = <String>[];
await tester.pumpWidget(
MaterialApp(
home: DetachedTerminal(
terminals: terminals,
tabKey: 'mac/t2',
window: DetachedWindowControls(
ready: ValueNotifier(true),
sync: ValueNotifier(0),
setTitle: titles.add,
close: () {},
bringBackItem: (kind, id, _, _) => back.add((kind, id)),
),
),
),
);
await tester.runAsync(terminals.hub.listed);
await tester.pump();
expect(terminals.hub.selected?.key, 'mac/t2');
expect(titles.last, startsWith('Terminal'));
// There is no panel or floating mode to choose in a window of its own.
expect(find.byTooltip('Terminal options'), findsNothing);
await tester.tap(find.byTooltip('Bring back to main window'));
expect(back, [(DetachedKind.terminal, 'mac/t2')]);
await tester.pumpWidget(const SizedBox());
});
}