Merge main

This commit is contained in:
2026-11-10 22:42:42 +00:00
17 changed files with 535 additions and 598 deletions
+83 -13
View File
@@ -6,6 +6,11 @@ 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_surface.dart';
import 'package:pipelines_app/features/terminal/terminal_toggle_button.dart';
import 'package:pipelines_app/features/terminal/terminal_window.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_layer.dart';
import 'package:pipelines_app/shell/windows/window_manager.dart';
const appField = Key('app-field');
@@ -27,23 +32,78 @@ Future<void> pumpTerminalApp(
data: MediaQuery.of(context).copyWith(disableAnimations: reduceMotion),
child: child!,
),
home: TerminalSurface(
hub: hub,
layout: layout,
cupertino: false,
child: Scaffold(
appBar: AppBar(
title: const Text('App'),
actions: [TerminalToggleButton(layout: layout, cupertino: false)],
),
body: const TextField(key: appField),
),
),
home: TerminalTestApp(hub: hub, layout: layout),
),
);
await tester.pump();
}
/// The terminal surface around an app with a text field, with the app's
/// window system as the real app wires it: the terminal's floating mode is a
/// window in the host above the surface's stage.
class TerminalTestApp extends StatefulWidget {
const TerminalTestApp({
super.key,
required this.hub,
required this.layout,
this.shortcutHere = true,
});
final TerminalHub hub;
final TerminalLayout layout;
final bool shortcutHere;
@override
State<TerminalTestApp> createState() => TerminalTestAppState();
}
class TerminalTestAppState extends State<TerminalTestApp> {
final WindowManager manager = WindowManager(kinds: WindowKinds());
late final TerminalWindows floating = TerminalWindows(
manager: manager,
hub: widget.hub,
layout: widget.layout,
);
@override
void initState() {
super.initState();
floating
..start()
..ready();
}
@override
void dispose() {
floating.dispose();
manager.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) => TerminalSurface(
hub: widget.hub,
layout: widget.layout,
cupertino: false,
shortcutHere: widget.shortcutHere,
floating: floating,
windows: WindowHost(manager: manager),
child: Scaffold(
appBar: AppBar(
title: const Text('App'),
actions: [
TerminalToggleButton(layout: widget.layout, cupertino: false),
],
),
body: const TextField(key: appField),
),
);
}
/// The test app's window manager.
WindowManager terminalWindowManager(WidgetTester tester) =>
tester.state<TerminalTestAppState>(find.byType(TerminalTestApp)).manager;
/// Presses [key] with [modifiers] held, then lets the motion finish unless
/// [settle] is false.
Future<void> chord(
@@ -102,4 +162,14 @@ bool appFieldFocused(WidgetTester tester) => tester
.hasFocus;
final Finder panelFinder = find.byKey(const ValueKey('terminal-panel'));
final Finder floatFinder = find.byKey(const ValueKey('terminal-float'));
/// The terminal's floating window, shown or hiding.
final Finder floatLayer = find.byWidgetPredicate(
(w) => w is WindowLayer && w.entry.kind == terminalWindowKind,
skipOffstage: false,
);
/// The terminal's floating window while it is shown.
final Finder floatFinder = find.byWidgetPredicate(
(w) => w is WindowLayer && w.entry.kind == terminalWindowKind && w.visible,
);
@@ -34,7 +34,13 @@ void main() {
.opacity
.value;
ScaleTransition floatScale(WidgetTester tester) => tester.widget(
find.descendant(of: floatFinder, matching: find.byType(ScaleTransition)),
find
.descendant(
of: floatLayer,
matching: find.byType(ScaleTransition, skipOffstage: false),
skipOffstage: false,
)
.first,
);
testWidgets('the panel slides up from the bottom edge as the app above '
@@ -72,17 +78,19 @@ void main() {
layout.setMode(TerminalMode.float);
await pumpTerminalApp(tester, hub: hub, layout: layout);
await altT(tester, settle: false);
// The window is built, then its motion starts.
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
final scale = floatScale(tester).scale.value;
expect(scale, inExclusiveRange(0.92, 1));
expect(floatScale(tester).alignment, Alignment.center);
// The app underneath never moves for a window.
expect(appBottom(tester), 800);
await tester.pumpAndSettle();
expect(floatScale(tester).scale.value, 1);
await altT(tester, settle: false);
await tester.pump(const Duration(milliseconds: 100));
expect(floatFinder, findsOneWidget);
// Hiding: no longer shown, still painted while it shrinks away.
expect(floatFinder, findsNothing);
expect(floatScale(tester).scale.value, inExclusiveRange(0.92, 1));
await tester.pumpAndSettle();
expect(floatFinder, findsNothing);
@@ -5,13 +5,12 @@ import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/shell/chat_shell_terminal_keys.dart';
import 'package:pipelines_app/features/settings/settings_terminal_section.dart';
import 'package:pipelines_app/features/terminal/terminal_float.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_surface.dart';
import 'package:pipelines_app/features/terminal/terminal_toggle_button.dart';
import 'package:xterm/xterm.dart';
import 'terminal_app.dart';
import 'terminal_fixtures.dart';
void main() {
@@ -43,19 +42,7 @@ void main() {
addTearDown(tester.view.reset);
await tester.pumpWidget(
MaterialApp(
home: TerminalSurface(
hub: hub,
layout: layout,
cupertino: false,
shortcutHere: onChat,
child: Scaffold(
appBar: AppBar(
title: const Text('App'),
actions: [TerminalToggleButton(layout: layout, cupertino: false)],
),
body: const TextField(key: Key('app-field')),
),
),
home: TerminalTestApp(hub: hub, layout: layout, shortcutHere: onChat),
),
);
await tester.pump();
@@ -133,47 +120,85 @@ void main() {
);
desktopTestWidgets(
'the floating window moves, resizes, minimises and maximises',
'the floating terminal is a window: it moves, resizes, maximises, and '
'Minimise and Close hide the terminal',
(tester) async {
layout
..setMode(TerminalMode.float)
..show();
await pumpApp(tester);
await tester.pump();
final window = find.byKey(const ValueKey('terminal-float'));
expect(window, findsOneWidget);
final start = layout.floatRect;
await tester.pumpAndSettle();
expect(floatFinder, findsOneWidget);
final manager = terminalWindowManager(tester);
Rect frame() => manager.windows.single.frame;
expect(frame(), terminalFloatDefaultRect);
final start = frame();
await tester.drag(
find.byKey(const ValueKey('terminal-float-title')),
find.byKey(const ValueKey('window-title')),
const Offset(60, 40),
);
await tester.pumpAndSettle();
expect(layout.floatRect.topLeft, start.topLeft + const Offset(60, 40));
expect(frame().topLeft, start.topLeft + const Offset(60, 40));
await tester.drag(
find.byKey(const ValueKey('terminal-float-resize')),
find.byKey(const ValueKey('window-resize')),
const Offset(80, 50),
);
await tester.pumpAndSettle();
expect(layout.floatRect.size, start.size + const Offset(80, 50));
expect(saved()['float'][2], closeTo(start.width + 80, 1));
await tester.tap(find.byTooltip('Minimise'));
await tester.pumpAndSettle();
expect(find.byType(TerminalView), findsNothing);
expect(hub.tabs, hasLength(2));
await tester.tap(find.byTooltip('Restore'));
await tester.pumpAndSettle();
expect(frame().size, start.size + const Offset(80, 50));
// The window shows the terminal's tabs and the selected terminal.
expect(find.text('src'), findsWidgets);
expect(find.byType(TerminalView), findsOneWidget);
await tester.tap(find.byTooltip('Maximise'));
await tester.pumpAndSettle();
expect(
tester.getRect(
find.descendant(of: window, matching: find.byType(Material)).first,
),
const Rect.fromLTWH(0, 0, 1200, 800).deflate(terminalFloatMargin),
);
expect(manager.windows.single.maximized, isTrue);
await tester.tap(find.byTooltip('Restore size'));
await tester.pumpAndSettle();
expect(layout.maximized, isFalse);
// Minimise hides the terminal; the toggle brings the window back
// where it was, with its shells.
await tester.tap(find.byTooltip('Minimise'));
await tester.pumpAndSettle();
expect(layout.visible, isFalse);
expect(floatFinder, findsNothing);
expect(hub.tabs, hasLength(2));
await ctrlBacktick(tester);
expect(layout.visible, isTrue);
expect(floatFinder, findsOneWidget);
expect(frame().size, start.size + const Offset(80, 50));
await tester.tap(find.byTooltip('Close'));
await tester.pumpAndSettle();
expect(layout.visible, isFalse);
expect(manager.windows, isEmpty);
expect(hub.tabs, hasLength(2));
await ctrlBacktick(tester);
expect(floatFinder, findsOneWidget);
expect(frame().size, start.size + const Offset(80, 50));
},
);
desktopTestWidgets(
'the first window takes the frame the terminal saved before windows',
(tester) async {
store.saved = jsonEncode({
'mode': 'float',
'visible': true,
'panel_height': 300,
'float': [200, 150, 640, 360],
'minimized': false,
'maximized': true,
});
await layout.restore();
await pumpApp(tester);
await tester.pumpAndSettle();
final entry = terminalWindowManager(tester).windows.single;
expect(entry.frame, const Rect.fromLTWH(200, 150, 640, 360));
expect(entry.maximized, isTrue);
// The old record is still written, unchanged, for an older build.
layout.hide();
await tester.pumpAndSettle();
expect(saved()['float'], [200, 150, 640, 360]);
},
);
@@ -209,14 +234,14 @@ void main() {
await tester.tap(find.byKey(const ValueKey('terminal-mode-float')));
await tester.pumpAndSettle();
expect(layout.mode, TerminalMode.float);
expect(find.byKey(const ValueKey('terminal-float')), findsOneWidget);
expect(floatFinder, findsOneWidget);
expect(find.byKey(const ValueKey('terminal-panel')), findsNothing);
expect(saved()['mode'], 'float');
await tester.tap(find.byTooltip('Terminal options'));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const ValueKey('terminal-hide')));
await tester.pumpAndSettle();
expect(find.byKey(const ValueKey('terminal-float')), findsNothing);
expect(floatFinder, findsNothing);
});
desktopTestWidgets('Settings chooses the mode', (tester) async {