Merge branch 'worktree-agent-ad4dacaa0da379451'

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-26 02:44:31 +00:00
36 changed files with 1730 additions and 173 deletions
@@ -0,0 +1,154 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/terminal/terminal_browser_keys.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 '../chat/shell/terminal_view_harness.dart';
import 'terminal_fixtures.dart';
/// A browser's Keyboard Lock, recorded.
class FakeBrowserKeys implements TerminalBrowserKeysBackend {
FakeBrowserKeys({this.supported = true, this.grant = true});
@override
final bool supported;
final bool grant;
int locks = 0;
int unlocks = 0;
void Function()? released;
@override
Future<bool> lock() async {
locks++;
return grant;
}
@override
Future<void> unlock() async => unlocks++;
@override
set onReleased(void Function() callback) => released = callback;
}
void main() {
final original = TerminalBrowserKeys.instance;
tearDown(() => TerminalBrowserKeys.instance = original);
test('capture locks the keys until released by the app or the browser '
'(Esc held)', () async {
final backend = FakeBrowserKeys();
final keys = TerminalBrowserKeys(backend: backend);
expect(keys.supported, isTrue);
expect(await keys.capture(), isTrue);
expect(keys.active, isTrue);
expect(terminalBrowserKeysLabel(keys), 'Release browser keys');
await keys.release();
expect((keys.active, backend.unlocks), (false, 1));
await keys.capture();
backend.released!();
expect(keys.active, isFalse);
expect(terminalBrowserKeysLabel(keys), 'Capture browser keys');
});
test('a refused lock or an unsupported browser leaves it off', () async {
final refused = TerminalBrowserKeys(backend: FakeBrowserKeys(grant: false));
expect(await refused.capture(), isFalse);
expect(refused.active, isFalse);
final none = FakeBrowserKeys(supported: false);
final unsupported = TerminalBrowserKeys(backend: none);
expect(await unsupported.capture(), isFalse);
expect(none.locks, 0);
});
test('native builds (and tests) have nothing to capture', () {
expect(TerminalBrowserKeys().supported, isFalse);
});
Future<void> pumpStrip(WidgetTester tester) async {
final hub = TerminalHub(TestMachines([]));
addTearDown(hub.dispose);
final layout = TerminalLayout(store: MemoryLayoutStore());
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: TerminalTabStrip(hub: hub, layout: layout),
),
),
);
}
const item = ValueKey('terminal-browser-keys');
testWidgets('the terminal menu offers Capture browser keys where the '
'browser can, checked while on', (tester) async {
final backend = FakeBrowserKeys();
TerminalBrowserKeys.instance = TerminalBrowserKeys(backend: backend);
await pumpStrip(tester);
await tester.tap(find.byTooltip('Terminal options'));
await tester.pumpAndSettle();
expect(find.byKey(item), findsOneWidget);
expect(
tester.widget<CheckedPopupMenuItem<Object?>>(find.byKey(item)).checked,
isFalse,
);
await tester.tap(find.byKey(item));
await tester.pumpAndSettle();
expect(backend.locks, 1);
expect(find.textContaining('Hold Esc'), findsOneWidget);
await tester.tap(find.byTooltip('Terminal options'));
await tester.pumpAndSettle();
expect(
tester.widget<CheckedPopupMenuItem<Object?>>(find.byKey(item)).checked,
isTrue,
);
await tester.tap(find.byKey(item));
await tester.pumpAndSettle();
expect(backend.unlocks, 1);
expect(TerminalBrowserKeys.instance.active, isFalse);
});
testWidgets('no such item where the browser cannot capture its keys', (
tester,
) async {
TerminalBrowserKeys.instance = TerminalBrowserKeys(
backend: FakeBrowserKeys(supported: false),
);
await pumpStrip(tester);
await tester.tap(find.byTooltip('Terminal options'));
await tester.pumpAndSettle();
expect(find.byKey(item), findsNothing);
expect(find.byKey(const ValueKey('terminal-hide')), findsOneWidget);
});
testWidgets('a refused capture says so', (tester) async {
TerminalBrowserKeys.instance = TerminalBrowserKeys(
backend: FakeBrowserKeys(grant: false),
);
await pumpStrip(tester);
await tester.tap(find.byTooltip('Terminal options'));
await tester.pumpAndSettle();
await tester.tap(find.byKey(item));
await tester.pumpAndSettle();
expect(find.textContaining('did not let the page'), findsOneWidget);
});
testWidgets("the chat terminal's right-click menu has it too", (
tester,
) async {
final backend = FakeBrowserKeys();
TerminalBrowserKeys.instance = TerminalBrowserKeys(backend: backend);
final harness = TerminalViewHarness();
await harness.pump(tester);
await harness.rightClick(tester, 1, 0);
final menuItem = find.byKey(const ValueKey('terminal-menu-browserKeys'));
expect(menuItem, findsOneWidget);
expect(find.text('Capture browser keys'), findsOneWidget);
await tester.tap(menuItem);
await tester.pumpAndSettle();
expect(backend.locks, 1);
await harness.rightClick(tester, 1, 0);
expect(find.text('Release browser keys'), findsOneWidget);
}, variant: desktops);
}
@@ -10,6 +10,7 @@ import 'package:xterm/xterm.dart';
import 'terminal_app.dart';
import 'terminal_fixtures.dart';
import '../chat/shell/terminal_typing.dart';
void main() {
late TerminalGateway mac;
@@ -160,6 +161,24 @@ void main() {
expect(linuxWeb.summary, contains(linuxWeb.inTerminalNote));
});
test('a browser outside macOS keeps Ctrl+W: the menu says how to send '
'it anyway and what to press instead', () {
const linuxWeb = TerminalShortcutLabels(
web: true,
platform: TargetPlatform.linux,
);
expect(linuxWeb.browserKeysNote, contains('Capture browser keys'));
expect(linuxWeb.browserKeysNote, contains('Alt+Backspace'));
expect(linuxWeb.summary, contains(linuxWeb.browserKeysNote));
for (final labels in const [
TerminalShortcutLabels(web: true, platform: TargetPlatform.macOS),
TerminalShortcutLabels(web: false, platform: TargetPlatform.linux),
]) {
expect(labels.browserKeysNote, isNull);
expect(labels.summary, isNot(contains('Ctrl+W')));
}
});
desktopTestWidgets('holding the chord toggles once and types nothing', (
tester,
) async {
@@ -203,8 +222,7 @@ void main() {
expect(terminalFocused(key('term_a')), isTrue);
expect(appFieldFocused(tester), isFalse);
// Typing goes straight to the shell.
await tester.sendKeyEvent(LogicalKeyboardKey.keyX);
await tester.pump();
await typeKey(tester, LogicalKeyboardKey.keyX);
expect(mac.bodies('terminal_input').last['data'], 'x');
await toggleTerminal(tester);
expect(appFieldFocused(tester), isTrue);
@@ -348,8 +366,7 @@ void main() {
// App-wide shortcuts see a typing surface and leave the key alone.
expect(primaryFocusIsTypingSurface(), isTrue);
expect(primaryFocusTakesTyping(), isTrue);
await tester.sendKeyEvent(LogicalKeyboardKey.slash, character: '/');
await tester.pump();
await typeKey(tester, LogicalKeyboardKey.slash, character: '/');
expect(terminalFocused(key('term_a')), isTrue);
expect(
mac.bodies('terminal_input').map((b) => b['data']).join(),
@@ -13,6 +13,7 @@ import 'package:xterm/xterm.dart';
import 'terminal_app.dart';
import 'terminal_fixtures.dart';
import '../chat/shell/terminal_typing.dart';
void main() {
late TerminalGateway mac;
@@ -73,8 +74,7 @@ void main() {
// The terminal has the keyboard, yet the shortcut still hides it.
await tester.tap(find.byType(TerminalView));
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.keyX);
await tester.pump();
await typeKey(tester, LogicalKeyboardKey.keyX);
expect(mac.bodies('terminal_input').last['data'], 'x');
await ctrlBacktick(tester);
expect(find.byKey(const ValueKey('terminal-panel')), findsNothing);