Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

Desktop: five small follow-ups from today's reviews (Dee) (#2455)

0xken15ec1b2cd5d066
diff --git a/desktop/lib/app_shell.dart b/desktop/lib/app_shell.dart
index 0647ff951..271d2aab2 100644
--- a/desktop/lib/app_shell.dart
+++ b/desktop/lib/app_shell.dart
@@ -22,6 +22,7 @@ import 'core/windows_status_tray.dart';
import 'settings/settings_screen.dart';
import 'settings/settings_section.dart';
import 'screens/login_screen.dart';
+import 'screens/swarm_menu_bus.dart';
import 'state/app_state.dart';
import 'stats/stats_lifecycle.dart';
import 'viewer/viewer_services.dart';
@@ -42,6 +43,7 @@ import 'core/startup.dart';
import 'logging/app_log.dart';
import 'logging/install.dart';
import 'shortcuts/app_keymap.dart';
+import 'shortcuts/keymap_native.dart';
import 'shortcuts/keyboard_practice.dart';
import 'widgets/shortcuts_sheet.dart';
import 'widgets/new_device_notice.dart';
@@ -236,6 +238,30 @@ class RootShell extends ConsumerStatefulWidget {
class _RootShellState extends ConsumerState<RootShell>
with WidgetsBindingObserver {
bool _menuDialogOpen = false;
+
+ /// Whether the workspace is the window's screen: it then owns what AppKit
+ /// hands to Flutter ([_handSignedOutKeymap] otherwise).
+ bool _home = false;
+
+ /// Before a workspace (signed out), AppKit's File menu keeps ⌘W for Close
+ /// Tab, which is off there, so Settings over the sign-in page never hears
+ /// it. Hand AppKit the keymap with Close Tab's keys alone going to Flutter:
+ /// ⌘, ⌘H and ⌘M stay with the menu. Also on leaving the workspace, whose
+ /// keymap handed Flutter every key.
+ void _handSignedOutKeymap() {
+ if (!mounted) return;
+ final keymap = KeymapTheme.of(context, listen: false);
+ if (keymap == null) return;
+ unawaited(
+ swarmMenuBus
+ .send(
+ 'keymapState',
+ nativeKeymapSnapshot(keymap, inputOnly: const {'swarm.close'}),
+ )
+ .catchError((Object _) {}),
+ );
+ }
+
SharedAgentLocation? _sharedLocation;
@override
@@ -295,6 +321,7 @@ class _RootShellState extends ConsumerState<RootShell>
switch (action) {
case 'settings':
final app = ref.read(appStateProvider);
+ if (!_home) _handSignedOutKeymap();
await _menuDialog(
() => showSettingsScreen(
context,
@@ -422,6 +449,12 @@ class _RootShellState extends ConsumerState<RootShell>
// of inside each of them.
final home =
app.status == AppStatus.authenticated && !touring && !signInStep;
+ if (_home && !home) {
+ WidgetsBinding.instance.addPostFrameCallback(
+ (_) => _handSignedOutKeymap(),
+ );
+ }
+ _home = home;
final framed = home ? screen : FullWindowScreen(child: screen);
// The band takes a row of its own rather than floating over one. As an
// overlay it landed on the rail's head — covering the wordmark and the
diff --git a/desktop/lib/screens/swarm_menu_bus.dart b/desktop/lib/screens/swarm_menu_bus.dart
index aec654d23..abca1c21a 100644
--- a/desktop/lib/screens/swarm_menu_bus.dart
+++ b/desktop/lib/screens/swarm_menu_bus.dart
@@ -118,6 +118,10 @@ class SwarmMenuState extends ChangeNotifier {
/// (HarnessKeymap.applyMenuKeys), so a rebinding shows up in both.
Map<String, String> hints = const {};
+ /// The only keys AppKit hands to Flutter, when the keymap names them
+ /// (`input`, before a workspace: Close Tab's); null is every binding's.
+ Set<String>? input;
+
void apply(String method, Map<Object?, Object?> args) {
switch (method) {
case 'update':
@@ -149,6 +153,10 @@ class SwarmMenuState extends ChangeNotifier {
};
case 'keymapState':
hints = _parseHints(args['contexts']);
+ input = switch (args['input']) {
+ final List keys => {...keys.whereType<String>()},
+ _ => null,
+ };
default:
return;
}
diff --git a/desktop/lib/settings/settings_compact.dart b/desktop/lib/settings/settings_compact.dart
index 79aaf6454..08a0acf7e 100644
--- a/desktop/lib/settings/settings_compact.dart
+++ b/desktop/lib/settings/settings_compact.dart
@@ -122,7 +122,8 @@ class SettingsCompactScreen extends StatelessWidget {
onPopInvokedWithResult: (didPop, _) {
if (!didPop) onBack();
},
- child: Focus(
+ // A scope, as in [SettingsScreen]: the keys still reach it after a click.
+ child: FocusScope(
onKeyEvent: onKeyEvent,
child: Scaffold(
backgroundColor: grid.AppPalette.windowBg,
diff --git a/desktop/lib/settings/settings_screen.dart b/desktop/lib/settings/settings_screen.dart
index f060db341..22d97dd1b 100644
--- a/desktop/lib/settings/settings_screen.dart
+++ b/desktop/lib/settings/settings_screen.dart
@@ -3,6 +3,10 @@ import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:flutter/services.dart';
import '../shared/theme/app_theme.dart' as grid;
+import '../shortcuts/app_keymap.dart';
+import '../shortcuts/keymap.dart';
+import '../shortcuts/keymap_commands.dart';
+import '../shortcuts/keymap_keyboard.dart';
import '../state/app_state.dart';
import '../widgets/harness_customize_pane.dart';
import 'experimental_features.dart';
@@ -154,14 +158,13 @@ class _SettingsScreenState extends State<SettingsScreen> {
bool get _compact => MediaQuery.sizeOf(context).width < widget.compactBelow;
+ /// Escape, or Close Tab's key (⌘W unless the person moved it), leaves
+ /// Settings as Back to app does. Signed out there is no workspace under it
+ /// to hear ⌘W, so Settings hears it itself (Scholes's end-to-end test).
KeyEventResult _key(FocusNode node, KeyEvent event) {
if (event is! KeyDownEvent ||
- event.logicalKey != LogicalKeyboardKey.escape ||
- HardwareKeyboard.instance.isControlPressed ||
- HardwareKeyboard.instance.isAltPressed ||
- HardwareKeyboard.instance.isMetaPressed ||
- HardwareKeyboard.instance.isShiftPressed ||
- ModalRoute.of(context)?.isCurrent == false) {
+ ModalRoute.of(context)?.isCurrent == false ||
+ !(_isEscape(event) || _isCloseTab(event))) {
return KeyEventResult.ignored;
}
final editing = FocusManager.instance.primaryFocus?.context
@@ -178,6 +181,30 @@ class _SettingsScreenState extends State<SettingsScreen> {
return KeyEventResult.handled;
}
+ bool _isEscape(KeyEvent event) {
+ final keys = HardwareKeyboard.instance;
+ return event.logicalKey == LogicalKeyboardKey.escape &&
+ !keys.isControlPressed &&
+ !keys.isAltPressed &&
+ !keys.isMetaPressed &&
+ !keys.isShiftPressed;
+ }
+
+ bool _isCloseTab(KeyEvent event) {
+ final stroke = keyStrokeForEvent(event);
+ if (stroke == null) return false;
+ final keymap =
+ KeymapTheme.of(context, listen: false)?.current ?? harnessDefaultKeymap;
+ return keymap
+ .bindingsFor(KeymapContext.workspace)
+ .any(
+ (binding) =>
+ binding.command == 'swarm.close' &&
+ binding.keys.length == 1 &&
+ binding.keys.single == stroke,
+ );
+ }
+
/// Move to another pane, from the settings rail.
void _show(SettingsSection target) {
if (target == SettingsSection.customize) {
@@ -209,7 +236,10 @@ class _SettingsScreenState extends State<SettingsScreen> {
body: body,
);
}
- return Focus(
+ // A scope, not a plain Focus: a click that takes the keyboard off a field
+ // leaves it here, where Escape and ⌘W are still heard, rather than on the
+ // route above this page.
+ return FocusScope(
onKeyEvent: _key,
child: Scaffold(
backgroundColor: grid.AppPalette.windowBg,
diff --git a/desktop/lib/shortcuts/keymap_native.dart b/desktop/lib/shortcuts/keymap_native.dart
index 8a25024cc..42e150e20 100644
--- a/desktop/lib/shortcuts/keymap_native.dart
+++ b/desktop/lib/shortcuts/keymap_native.dart
@@ -4,8 +4,25 @@ import 'keymap_commands.dart';
/// Resolved bindings cross to AppKit only when configuration changes. Native
/// input never reads the file or waits for a Dart reply to decide ownership.
-Map<String, Object> nativeKeymapSnapshot(AppKeymap keymap) => {
+///
+/// AppKit hands Flutter every binding's first key, unless [inputOnly] names
+/// the commands whose keys alone it hands over (`input`): before a workspace,
+/// only Close Tab's, for Settings. The menu rows still take their keys from
+/// every binding.
+Map<String, Object> nativeKeymapSnapshot(
+ AppKeymap keymap, {
+ Set<String>? inputOnly,
+}) => {
'version': 1,
+ if (inputOnly != null)
+ 'input': {
+ for (final context in KeymapContext.values)
+ for (final binding in keymap.current.bindingsFor(context))
+ if (!binding.outsideTerminal &&
+ binding.keys.length == 1 &&
+ inputOnly.contains(binding.command))
+ binding.keys.single.toString(),
+ }.toList(),
'contexts': {
for (final context in KeymapContext.values)
context.name: [
diff --git a/desktop/lib/super_tabs/attention.dart b/desktop/lib/super_tabs/attention.dart
index ba0e1604a..b79a88a6d 100644
--- a/desktop/lib/super_tabs/attention.dart
+++ b/desktop/lib/super_tabs/attention.dart
@@ -170,7 +170,8 @@ class SuperTabAttention extends ChangeNotifier {
static const _unknown = 1 << 52;
/// The Threads row's number: tags of the reader inside threads they have
- /// not read past, in chats this Swarm still lists for them.
+ /// not read past, in chats this Swarm still lists for them. A muted chat's
+ /// threads never count, as its main stream does not ([mentionsIn]).
int get threadMentions {
final snapshot = controller.snapshot;
if (controller.accessRevoked || snapshot == null) return 0;
@@ -180,6 +181,7 @@ class SuperTabAttention extends ChangeNotifier {
(m) =>
m.threadId != null &&
chats.contains(m.conversationId) &&
+ controller.notifyOf(m.conversationId) != SuperTabNotify.muted &&
(m.messageSequence ?? _unknown) >
controller.threadReadMark(m.threadId!),
)
diff --git a/desktop/lib/super_tabs/workspace.dart b/desktop/lib/super_tabs/workspace.dart
index 50f5dca2c..1576ae84b 100644
--- a/desktop/lib/super_tabs/workspace.dart
+++ b/desktop/lib/super_tabs/workspace.dart
@@ -187,8 +187,9 @@ class _SuperTabWorkspaceState extends State<SuperTabWorkspace> {
if (!shown) {
if (!current()) return;
// One of the person's own panes leaves this view only: its tab
- // keeps it, and it is no closed harness.
- if (_isPersonsOwn(pane, swarmId)) {
+ // keeps it, or its tab's close already put it in recently closed.
+ if (_isPersonsOwn(pane, swarmId) || _shownFromTab[pane] == true) {
+ _shownFromTab[pane] = null;
await app.releaseSuperTabView(swarmId, pane.id);
} else {
await app.closePane(pane.id, swarmId: swarmId);
@@ -216,6 +217,7 @@ class _SuperTabWorkspaceState extends State<SuperTabWorkspace> {
if (!current()) return;
// The very pane its tab shows, as it is there: same session, same
// input and composer. No Swarm terminal sharing is asked for.
+ _shownFromTab[pane] = true;
await app.assignAgentToPane(
null,
pane.machineId,
@@ -257,6 +259,12 @@ class _SuperTabWorkspaceState extends State<SuperTabWorkspace> {
});
}
+ /// The person's own panes this view showed from their tabs. One of them
+ /// stays theirs after its tab closes: that close already went into recently
+ /// closed, so the view lets the pane go without a second entry. Weak, so a
+ /// pane gone everywhere is forgotten with it.
+ static final _shownFromTab = Expando<bool>('shownFromTab');
+
/// Whether [pane] in Swarm tab [swarmId] is one of the person's own panes,
/// held by one of their other tabs too.
bool _isPersonsOwn(TerminalPane pane, String swarmId) => app.swarms.any(
diff --git a/desktop/lib/widgets/sign_in_step.dart b/desktop/lib/widgets/sign_in_step.dart
index 7d7f2675d..bbdc3fc8b 100644
--- a/desktop/lib/widgets/sign_in_step.dart
+++ b/desktop/lib/widgets/sign_in_step.dart
@@ -46,22 +46,44 @@ const signInStepBenefits = [
/// The bottom bar's line while nothing is under way: which computer this is,
/// and whether Harness is already set up on it (Scholes's end-to-end test of
/// 1.3.44, finding 5: every relaunch showed a bare page that knew nothing of
-/// the computer). [mac] words it "This Mac", else "This computer".
+/// the computer). [mac] words it "This Mac", else "This computer". The name
+/// is always in brackets, "This Mac (Studio)", on a first run as after setup.
String signInStepReadyLine({
String? computerName,
bool setUp = false,
bool mac = true,
+}) {
+ final (:lead, :name, :rest) = signInStepReadyParts(
+ computerName: computerName,
+ setUp: setUp,
+ mac: mac,
+ );
+ return '$lead${name ?? ''}$rest';
+}
+
+/// The ready line in three parts: a long [name] is what the bar cuts, never
+/// the rest of the sentence ("Sign in to continue." above all).
+typedef SignInReadyLine = ({String lead, String? name, String rest});
+
+/// [signInStepReadyLine] in its [SignInReadyLine] parts.
+SignInReadyLine signInStepReadyParts({
+ String? computerName,
+ bool setUp = false,
+ bool mac = true,
}) {
final here = mac ? 'This Mac' : 'This computer';
final name = computerName?.trim();
+ final tail = setUp
+ ? ' is set up. Sign in to continue.'
+ : '. Sign in to continue.';
if (name == null || name.isEmpty) {
- return setUp
- ? '$here is set up. Sign in to continue.'
- : 'Sign in to continue.';
+ return (
+ lead: setUp ? '$here$tail' : 'Sign in to continue.',
+ name: null,
+ rest: '',
+ );
}
- return setUp
- ? '$here ($name) is set up. Sign in to continue.'
- : '$here: $name. Sign in to continue.';
+ return (lead: '$here (', name: name, rest: ')$tail');
}
/// The page itself, apart from the app: what it says and its three controls.
@@ -80,7 +102,7 @@ class SignInStep extends StatelessWidget {
this.signOutError,
this.onRetrySignOut,
this.recovery,
- this.readyLine = 'Sign in to continue.',
+ this.readyLine = (lead: 'Sign in to continue.', name: null, rest: ''),
});
/// Continue with Google, Continue with Apple, or — with no provider — Email,
@@ -113,8 +135,8 @@ class SignInStep extends StatelessWidget {
final Widget? recovery;
/// The bottom bar's line while nothing is under way
- /// ([signInStepReadyLine]).
- final String readyLine;
+ /// ([signInStepReadyParts]).
+ final SignInReadyLine readyLine;
@override
Widget build(BuildContext context) {
@@ -132,13 +154,16 @@ class SignInStep extends StatelessWidget {
Expanded(child: _stage(context, gutter)),
_ReadyBar(
gutter: gutter,
- line: signingOut
+ line: switch (signingOut
? 'Signing out…'
: finishing
? 'Signing in…'
: sessionExpired
? 'Your session ended. Sign in again to continue.'
- : readyLine,
+ : null) {
+ final busy? => (lead: busy, name: null, rest: ''),
+ null => readyLine,
+ },
),
],
);
@@ -396,7 +421,7 @@ class _ReadyBar extends StatelessWidget {
const _ReadyBar({required this.gutter, required this.line});
final double gutter;
- final String line;
+ final SignInReadyLine line;
@override
Widget build(BuildContext context) => Container(
@@ -425,15 +450,10 @@ class _ReadyBar extends StatelessWidget {
const SizedBox(width: 8),
Flexible(
child: Semantics(
+ key: const Key('sign-in-step-ready-line'),
liveRegion: true,
- child: Text(
- line,
- key: const Key('sign-in-step-ready-line'),
- overflow: TextOverflow.ellipsis,
- style: grid.AppType.label(
- color: grid.AppPalette.textPrimary,
- ),
- ),
+ label: '${line.lead}${line.name ?? ''}${line.rest}',
+ child: ExcludeSemantics(child: _parts(context)),
),
),
],
@@ -447,6 +467,46 @@ class _ReadyBar extends StatelessWidget {
],
),
);
+
+ /// The line as it reads, with only the computer's name giving way to a
+ /// narrow window: "This Mac (Studio-with-a-very-lo…) is set up. Sign in to
+ /// continue." Narrower than the sentence around a name cut to "…", the
+ /// line is one text cut at its end, as it always was: never an overflow.
+ Widget _parts(BuildContext context) {
+ final style = grid.AppType.label(color: grid.AppPalette.textPrimary);
+ Text part(String text, String key) => Text(
+ text,
+ key: Key('sign-in-step-ready-$key'),
+ maxLines: 1,
+ softWrap: false,
+ overflow: TextOverflow.ellipsis,
+ style: style,
+ );
+ final name = line.name;
+ if (name == null) {
+ return part('${line.lead}${line.rest}', 'text');
+ }
+ return LayoutBuilder(
+ builder: (context, constraints) {
+ final around = TextPainter(
+ text: TextSpan(text: '${line.lead}…${line.rest}', style: style),
+ textDirection: Directionality.of(context),
+ textScaler: MediaQuery.textScalerOf(context),
+ maxLines: 1,
+ )..layout();
+ final fits = around.width <= constraints.maxWidth;
+ around.dispose();
+ if (!fits) return part('${line.lead}$name${line.rest}', 'text');
+ return Row(
+ children: [
+ part(line.lead, 'lead'),
+ Flexible(child: part(name, 'name')),
+ part(line.rest, 'rest'),
+ ],
+ );
+ },
+ );
+ }
}
/// The sign-in step bound to the app: shown by RootShell between setup and the
@@ -567,7 +627,7 @@ class _SignInStepScreenState extends State<SignInStepScreen> {
finishing: app.signingIn && !app.canCancelLogin,
error: app.loginBrowserError ?? _error,
sessionExpired: app.sessionExpired,
- readyLine: signInStepReadyLine(
+ readyLine: signInStepReadyParts(
computerName: app.thisComputerName,
setUp: app.harnessSetUpBefore,
mac: RuntimePlatform.isMacOS,
diff --git a/desktop/macos/Runner/HarnessKeymap.swift b/desktop/macos/Runner/HarnessKeymap.swift
index 9d0483e74..5539eb837 100644
--- a/desktop/macos/Runner/HarnessKeymap.swift
+++ b/desktop/macos/Runner/HarnessKeymap.swift
@@ -129,6 +129,11 @@ final class HarnessNativeKeymap {
static let contexts: Set<String> = ["workspace", "terminal", "picker", "project", "swarmChat"]
private var roots: [String: HarnessKeyNode] = [:]
private(set) var bindings: [String: [HarnessNativeBinding]] = [:]
+ /// The only first strokes handed to Flutter, when Dart names them: before a
+ /// workspace (signed out) just Close Tab's, so Settings hears ⌘W while ⌘,
+ /// ⌘H and ⌘M keep their menu rows. Nil hands over every binding's first
+ /// stroke, as the workspace wants.
+ private(set) var inputStrokes: Set<HarnessKeyStroke>?
init?(_ payload: [String: Any]) {
guard payload["version"] as? Int == 1,
@@ -160,6 +165,12 @@ final class HarnessNativeKeymap {
roots[context] = root
bindings[context] = parsed
}
+ if let raw = payload["input"] {
+ guard let keys = raw as? [String], keys.count <= 16 else { return nil }
+ let strokes = keys.compactMap(HarnessKeyStroke.init)
+ guard strokes.count == keys.count else { return nil }
+ inputStrokes = Set(strokes)
+ }
}
func match(_ keys: [HarnessKeyStroke], context: String) -> (binding: HarnessNativeBinding?, prefix: Bool) {
@@ -231,7 +242,8 @@ final class HarnessKeymapMenu: NSMenu {
func update(_ map: HarnessNativeKeymap, window: NSWindow) {
keymap = map
ownerWindow = window
- inputStrokes = Set(map.bindings.values.flatMap { $0.compactMap { $0.keys.first } })
+ inputStrokes = map.inputStrokes
+ ?? Set(map.bindings.values.flatMap { $0.compactMap { $0.keys.first } })
}
func defersToInput(_ event: NSEvent) -> Bool {
diff --git a/desktop/test/keymap_native_test.dart b/desktop/test/keymap_native_test.dart
index a8244b601..db3c8f508 100644
--- a/desktop/test/keymap_native_test.dart
+++ b/desktop/test/keymap_native_test.dart
@@ -144,4 +144,19 @@ void main() {
}
},
);
+
+ test('a snapshot that names its input hands AppKit those keys alone, and '
+ 'keeps every binding for the menu rows', () {
+ addTearDown(() => debugDefaultTargetPlatformOverride = null);
+ debugDefaultTargetPlatformOverride = TargetPlatform.macOS;
+ final map = MemoryKeymap();
+ final whole = nativeKeymapSnapshot(map);
+ expect(whole, isNot(contains('input')));
+ final signedOut = nativeKeymapSnapshot(
+ map,
+ inputOnly: const {'swarm.close'},
+ );
+ expect(signedOut['input'], ['cmd+w']);
+ expect(signedOut['contexts'], whole['contexts']);
+ });
}
diff --git a/desktop/test/settings_close_keys_test.dart b/desktop/test/settings_close_keys_test.dart
new file mode 100644
index 000000000..46b8a5906
--- /dev/null
+++ b/desktop/test/settings_close_keys_test.dart
@@ -0,0 +1,206 @@
+/// Signed out, Settings is the page over the sign-in page, and ⌘W and Escape
+/// close it as Back to app does (Scholes's end-to-end test: there was no
+/// workspace under it to hear ⌘W, so it stayed open).
+library;
+
+import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
+import 'package:flutter_riverpod/flutter_riverpod.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness/app_shell.dart';
+import 'package:harness/auth/auth_session.dart';
+import 'package:harness/core/config.dart';
+import 'package:harness/measurement/product_measurement.dart';
+import 'package:harness/screens/login_screen.dart';
+import 'package:harness/screens/swarm_menu_bus.dart';
+import 'package:harness/settings/settings_screen.dart';
+import 'package:harness/shortcuts/app_keymap.dart';
+import 'package:harness/state/app_state.dart';
+import 'package:package_info_plus/package_info_plus.dart';
+
+import 'support/memory_key_value_store.dart';
+
+Future<AppNotifier> _signedOut(WidgetTester tester, {AppKeymap? keymap}) async {
+ tester.view.devicePixelRatio = 1;
+ tester.view.physicalSize = const Size(1100, 760);
+ addTearDown(tester.view.reset);
+ final usage = ProductMeasurement(
+ surface: 'desktop',
+ automatic: false,
+ setupStorage: MemoryKeyValueStore(),
+ sendSetup: (_) async => {'accepted': true},
+ );
+ await usage.setupChoiceReady;
+ final app =
+ AppNotifier(
+ config: AppConfig.dev,
+ authSession: AuthSession(storage: MemoryKeyValueStore()),
+ productMeasurement: usage,
+ )
+ ..signedIn = false
+ ..status = AppStatus.unauthenticated;
+ addTearDown(app.dispose);
+ await tester.pumpWidget(
+ ProviderScope(
+ overrides: [appStateProvider.overrideWithValue(app)],
+ child: HarnessApp(
+ keymap: keymap,
+ authenticatedScreen: (_) => const SizedBox.shrink(),
+ ),
+ ),
+ );
+ await tester.pump(const Duration(milliseconds: 400));
+ expect(find.byType(LoginScreen), findsOneWidget);
+ return app;
+}
+
+/// Settings from the app menu, as macOS's pre-workspace Settings item sends.
+Future<void> _openSettings(WidgetTester tester) async {
+ tester.binding.defaultBinaryMessenger.handlePlatformMessage(
+ 'harness/app_menu',
+ const StandardMethodCodec().encodeMethodCall(const MethodCall('settings')),
+ (_) {},
+ );
+ await tester.pumpAndSettle();
+ expect(find.byType(SettingsScreen), findsOneWidget);
+}
+
+Future<void> _press(
+ WidgetTester tester,
+ LogicalKeyboardKey key, {
+ bool meta = false,
+}) async {
+ if (meta) await tester.sendKeyDownEvent(LogicalKeyboardKey.metaLeft);
+ await tester.sendKeyEvent(key);
+ if (meta) await tester.sendKeyUpEvent(LogicalKeyboardKey.metaLeft);
+ await tester.pumpAndSettle();
+}
+
+void main() {
+ PackageInfo.setMockInitialValues(
+ appName: 'Harness',
+ packageName: 'ai.autonomous.harness',
+ version: '1.2.80',
+ buildNumber: '80',
+ buildSignature: '',
+ );
+
+ testWidgets('signed out, ⌘W closes Settings and the sign-in page is back', (
+ tester,
+ ) async {
+ await _signedOut(tester);
+ await _openSettings(tester);
+ await _press(tester, LogicalKeyboardKey.keyW, meta: true);
+ expect(find.byType(SettingsScreen), findsNothing);
+ expect(find.byType(LoginScreen), findsOneWidget);
+
+ // Again after a click in Settings moved the keyboard off its search.
+ await _openSettings(tester);
+ await tester.tap(find.byKey(const ValueKey('product-usage-sharing')));
+ await tester.pumpAndSettle();
+ await _press(tester, LogicalKeyboardKey.keyW, meta: true);
+ expect(find.byType(SettingsScreen), findsNothing);
+ expect(find.byType(LoginScreen), findsOneWidget);
+ expect(tester.takeException(), isNull);
+ await tester.pumpWidget(const SizedBox.shrink());
+ }, variant: TargetPlatformVariant.only(TargetPlatform.macOS));
+
+ testWidgets(
+ 'signed out, Escape closes Settings and the sign-in page is back',
+ (tester) async {
+ await _signedOut(tester);
+ await _openSettings(tester);
+ await _press(tester, LogicalKeyboardKey.escape);
+ expect(find.byType(SettingsScreen), findsNothing);
+ expect(find.byType(LoginScreen), findsOneWidget);
+
+ // Again after a click in Settings moved the keyboard off its search.
+ await _openSettings(tester);
+ await tester.tap(find.byKey(const ValueKey('product-usage-sharing')));
+ await tester.pumpAndSettle();
+ await _press(tester, LogicalKeyboardKey.escape);
+ expect(find.byType(SettingsScreen), findsNothing);
+ expect(find.byType(LoginScreen), findsOneWidget);
+ expect(tester.takeException(), isNull);
+ await tester.pumpWidget(const SizedBox.shrink());
+ },
+ variant: TargetPlatformVariant.only(TargetPlatform.macOS),
+ );
+
+ testWidgets(
+ 'typing w, or another ⌘ key, in Settings\' search keeps Settings open',
+ (tester) async {
+ await _signedOut(tester);
+ await _openSettings(tester);
+ await _press(tester, LogicalKeyboardKey.keyW);
+ await _press(tester, LogicalKeyboardKey.keyE, meta: true);
+ expect(find.byType(SettingsScreen), findsOneWidget);
+ expect(tester.takeException(), isNull);
+ await tester.pumpWidget(const SizedBox.shrink());
+ },
+ variant: TargetPlatformVariant.only(TargetPlatform.macOS),
+ );
+
+ testWidgets(
+ 'signed out, Settings hands AppKit only Close Tab\'s key; the menu rows '
+ 'keep theirs',
+ (tester) async {
+ // Before a workspace nothing else sends the keymap, and AppKit's Close
+ // Tab, off while signed out, would take ⌘W first. Only ⌘W goes to
+ // Flutter: ⌘, ⌘H and ⌘M stay with the menu (review of #2455).
+ _resetBus();
+ final keymap = AppKeymap();
+ addTearDown(keymap.dispose);
+ await _signedOut(tester, keymap: keymap);
+ expect(swarmMenuBus.state.input, isNull);
+ expect(swarmMenuBus.state.hints, isEmpty);
+ await _openSettings(tester);
+ expect(swarmMenuBus.state.input, {'cmd+w'});
+ // Every menu row still gets its key from the whole keymap.
+ expect(swarmMenuBus.state.hints['settings'], '⌘,');
+ expect(swarmMenuBus.state.hints['machineList'], '⌘M');
+ await _press(tester, LogicalKeyboardKey.keyW, meta: true);
+ expect(find.byType(SettingsScreen), findsNothing);
+ expect(find.byType(LoginScreen), findsOneWidget);
+ await tester.pumpWidget(const SizedBox.shrink());
+ },
+ variant: TargetPlatformVariant.only(TargetPlatform.macOS),
+ );
+
+ testWidgets(
+ 'leaving the workspace (sign-out) takes back every key but Close Tab\'s',
+ (tester) async {
+ _resetBus();
+ final keymap = AppKeymap();
+ addTearDown(keymap.dispose);
+ final app = await _signedOut(tester, keymap: keymap);
+ app
+ ..signedIn = true
+ ..status = AppStatus.authenticated;
+ app.notifyListeners();
+ await tester.pumpAndSettle();
+ expect(find.byType(LoginScreen), findsNothing);
+ // The workspace's own keymap hands Flutter every key.
+ swarmMenuBus.state.input = null;
+
+ app
+ ..signedIn = false
+ ..status = AppStatus.unauthenticated;
+ app.notifyListeners();
+ await tester.pumpAndSettle();
+ expect(find.byType(LoginScreen), findsOneWidget);
+ expect(swarmMenuBus.state.input, {'cmd+w'});
+ expect(swarmMenuBus.state.hints['settings'], '⌘,');
+ await tester.pumpWidget(const SizedBox.shrink());
+ },
+ variant: TargetPlatformVariant.only(TargetPlatform.macOS),
+ );
+}
+
+void _resetBus() {
+ void reset() => swarmMenuBus.state
+ ..hints = const {}
+ ..input = null;
+ reset();
+ addTearDown(reset);
+}
diff --git a/desktop/test/sign_in_step_machine_line_test.dart b/desktop/test/sign_in_step_machine_line_test.dart
index 5dd46d9fe..b5ebdf878 100644
--- a/desktop/test/sign_in_step_machine_line_test.dart
+++ b/desktop/test/sign_in_step_machine_line_test.dart
@@ -25,7 +25,17 @@ import 'support/capture.dart';
final _line = find.byKey(const Key('sign-in-step-ready-line'));
final _boundary = GlobalKey();
-String _lineText(WidgetTester tester) => tester.widget<Text>(_line).data!;
+String _lineText(WidgetTester tester) =>
+ tester.widget<Semantics>(_line).properties.label!;
+
+/// What the bar draws of its line, part by part: each part's text, and
+/// whether it was cut short.
+List<({String text, bool cut})> _drawn(WidgetTester tester) => [
+ for (final paragraph in tester.renderObjectList<RenderParagraph>(
+ find.descendant(of: _line, matching: find.byType(RichText)),
+ ))
+ (text: paragraph.text.toPlainText(), cut: paragraph.didExceedMaxLines),
+];
Machine _machine(String id, String? name) => Machine(
machineId: id,
@@ -55,8 +65,9 @@ void _otherMachine(AppNotifier app, String name) {
Future<void> _mountPage(
WidgetTester tester, {
- required String readyLine,
+ required SignInReadyLine readyLine,
Brightness brightness = Brightness.dark,
+ double width = 1280,
bool finishing = false,
bool sessionExpired = false,
bool signingOut = false,
@@ -65,7 +76,7 @@ Future<void> _mountPage(
grid.AppTheme.brightness.value = brightness;
addTearDown(() => grid.AppTheme.brightness.value = previous);
tester.view.devicePixelRatio = 1;
- tester.view.physicalSize = const Size(1280, 800);
+ tester.view.physicalSize = Size(width, 800);
addTearDown(tester.view.reset);
await tester.pumpWidget(
MaterialApp(
@@ -113,10 +124,10 @@ void main() {
);
});
- test('a first run: its name', () {
+ test('a first run: its name, in the same form as after setup', () {
expect(
signInStepReadyLine(computerName: 'Studio'),
- 'This Mac: Studio. Sign in to continue.',
+ 'This Mac (Studio). Sign in to continue.',
);
});
@@ -136,21 +147,92 @@ void main() {
);
expect(
signInStepReadyLine(computerName: 'box', mac: false),
- 'This computer: box. Sign in to continue.',
+ 'This computer (box). Sign in to continue.',
);
});
});
group('the page', () {
testWidgets('shows the line in its bottom bar', (tester) async {
- const line = 'This Mac (Studio) is set up. Sign in to continue.';
- await _mountPage(tester, readyLine: line);
- expect(_lineText(tester), line);
+ await _mountPage(
+ tester,
+ readyLine: signInStepReadyParts(computerName: 'Studio', setUp: true),
+ );
+ expect(
+ _lineText(tester),
+ 'This Mac (Studio) is set up. Sign in to continue.',
+ );
expect(tester.takeException(), isNull);
});
+ for (final setUp in [true, false]) {
+ testWidgets('a very long name is cut, never "Sign in to continue." '
+ '(${setUp ? 'set up' : 'first run'})', (tester) async {
+ final name = 'Studio-${'very-long-computer-name-' * 20}end';
+ await _mountPage(
+ tester,
+ width: 900,
+ readyLine: signInStepReadyParts(computerName: name, setUp: setUp),
+ );
+ expect(tester.takeException(), isNull);
+ // Read aloud whole.
+ expect(
+ _lineText(tester),
+ signInStepReadyLine(computerName: name, setUp: setUp),
+ );
+ // Drawn with the name cut and the sentence whole, inside the bar.
+ final drawn = _drawn(tester);
+ final whole = [
+ for (final part in drawn)
+ if (!part.cut) part.text,
+ ];
+ expect(whole, [
+ 'This Mac (',
+ setUp
+ ? ') is set up. Sign in to continue.'
+ : '). Sign in to continue.',
+ ]);
+ expect(drawn.where((part) => part.cut).single.text, name);
+ final rest = find.byKey(const Key('sign-in-step-ready-rest'));
+ expect(tester.getRect(rest).right, lessThanOrEqualTo(900));
+ });
+ }
+
+ for (final (width, scale) in [
+ (340.0, 1.0),
+ (340.0, 1.2),
+ (420.0, 1.5),
+ (520.0, 2.0),
+ (640.0, 2.5),
+ ]) {
+ testWidgets('a ${width.round()}px window at ${scale}x text never '
+ 'overflows the bar, long name or short', (tester) async {
+ tester.platformDispatcher.textScaleFactorTestValue = scale;
+ addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
+ for (final name in ['Studio', 'Studio-${'very-long-name-' * 20}end']) {
+ for (final setUp in [true, false]) {
+ final line = signInStepReadyParts(computerName: name, setUp: setUp);
+ await _mountPage(tester, width: width, readyLine: line);
+ final error = tester.takeException();
+ expect(error, isNull, reason: '$name, set up: $setUp');
+ expect(
+ _lineText(tester),
+ signInStepReadyLine(computerName: name, setUp: setUp),
+ );
+ // Drawn in parts, the sentence after the name is whole; else
+ // the line is one text, cut at its end as it always was.
+ final drawn = _drawn(tester);
+ if (drawn.length > 1) {
+ expect(drawn.first.cut, isFalse);
+ expect(drawn.last.cut, isFalse);
+ }
+ }
+ }
+ });
+ }
+
testWidgets('what is under way still wins over it', (tester) async {
- const line = 'This Mac: Studio. Sign in to continue.';
+ final line = signInStepReadyParts(computerName: 'Studio');
await _mountPage(tester, readyLine: line, finishing: true);
expect(_lineText(tester), 'Signing in…');
await _mountPage(tester, readyLine: line, signingOut: true);
@@ -164,16 +246,19 @@ void main() {
for (final brightness in Brightness.values) {
for (final (name, line) in [
- ('set-up', signInStepReadyLine(computerName: 'Studio', setUp: true)),
- ('first-run', signInStepReadyLine(computerName: 'Studio')),
- ('no-name', signInStepReadyLine()),
+ ('set-up', signInStepReadyParts(computerName: 'Studio', setUp: true)),
+ ('first-run', signInStepReadyParts(computerName: 'Studio')),
+ ('no-name', signInStepReadyParts()),
]) {
testWidgets('draws the $name line in ${brightness.name}', (
tester,
) async {
await _mountPage(tester, readyLine: line, brightness: brightness);
expect(tester.takeException(), isNull);
- expect(_lineText(tester), line);
+ expect(
+ _lineText(tester),
+ '${line.lead}${line.name ?? ''}${line.rest}',
+ );
await captureBoundary(
tester,
_boundary.currentContext!.findRenderObject()!
diff --git a/desktop/test/super_tab_activity_test.dart b/desktop/test/super_tab_activity_test.dart
index c6ec73544..f614ed225 100644
--- a/desktop/test/super_tab_activity_test.dart
+++ b/desktop/test/super_tab_activity_test.dart
@@ -237,6 +237,29 @@ void main() {
expect(c.unreadShown(group), isFalse);
expect(attention.mentionsIn('offline'), 0);
});
+
+ test('a muted chat\'s thread tags never count on Threads either; '
+ 'unmuted, they count again', () async {
+ final server = projectServer();
+ server.followedThreads = {'unread': [], 'read': [], 'more': false};
+ fromLead(server, 'Root', conversationId: 'offline');
+ server.tag(
+ 'message-1',
+ conversationId: 'offline',
+ threadId: 'message-1',
+ messageSequence: 2,
+ );
+ server.tag('message-1', threadId: 'message-1', messageSequence: 2);
+ final c = await open(server);
+ final attention = SuperTabAttention.of(c);
+ await attention.mentions.load();
+ expect(attention.threadMentions, 2);
+ await c.setNotify('offline', SuperTabNotify.muted);
+ // Only the tag in the chat that is not muted.
+ expect(attention.threadMentions, 1);
+ await c.setNotify('offline', SuperTabNotify.all);
+ expect(attention.threadMentions, 2);
+ });
});
group('Mark all read (Shift+Esc) holds its write for Undo', () {
diff --git a/desktop/test/super_tab_attention_wave2_test.dart b/desktop/test/super_tab_attention_wave2_test.dart
index 11aff35f2..1cfc16ea2 100644
--- a/desktop/test/super_tab_attention_wave2_test.dart
+++ b/desktop/test/super_tab_attention_wave2_test.dart
@@ -300,6 +300,43 @@ void main() {
variant: TargetPlatformVariant.only(TargetPlatform.macOS),
);
+ testWidgets(
+ 'Option+Shift+Down and Up stop at the ends: nothing moves past the '
+ 'last unread chat or before the first',
+ (tester) async {
+ final (c, _) = await _show(tester, Brightness.dark, selected: 'lead');
+ final order = [
+ for (final id in ['lead', 'offline', 'routing', 'roster', 'web-lead'])
+ if (c.unreadShown(c.snapshot!.conversation(id)!)) id,
+ ];
+ expect(order.length, greaterThan(1));
+ Future<void> jump(LogicalKeyboardKey arrow) => _keys(tester, [
+ LogicalKeyboardKey.altLeft,
+ LogicalKeyboardKey.shiftLeft,
+ ], arrow);
+
+ // At the last unread chat, Down twice stays there.
+ await tester.tap(find.byKey(ValueKey('super-group-${order.last}')));
+ await tester.pumpAndSettle();
+ expect(c.selectedId, order.last);
+ await jump(LogicalKeyboardKey.arrowDown);
+ expect(c.selectedId, order.last);
+ await jump(LogicalKeyboardKey.arrowDown);
+ expect(c.selectedId, order.last);
+
+ // At the first, Up twice stays there.
+ await tester.tap(find.byKey(ValueKey('super-group-${order.first}')));
+ await tester.pumpAndSettle();
+ expect(c.selectedId, order.first);
+ await jump(LogicalKeyboardKey.arrowUp);
+ expect(c.selectedId, order.first);
+ await jump(LogicalKeyboardKey.arrowUp);
+ expect(c.selectedId, order.first);
+ await _done(tester, c);
+ },
+ variant: TargetPlatformVariant.only(TargetPlatform.macOS),
+ );
+
testWidgets('Shift+Esc marks every chat read with an Undo toast; Undo puts '
'them back', (tester) async {
final (c, _) = await _show(tester, Brightness.dark);
diff --git a/desktop/test/super_tab_personal_projects_test.dart b/desktop/test/super_tab_personal_projects_test.dart
index 0c80a232f..3e832f305 100644
--- a/desktop/test/super_tab_personal_projects_test.dart
+++ b/desktop/test/super_tab_personal_projects_test.dart
@@ -695,6 +695,63 @@ void main() {
},
);
+ testWidgets(
+ 'closing a tab while [term] shows its pane leaves one recently closed '
+ 'entry, the tab\'s',
+ (tester) async {
+ await tester.binding.setSurfaceSize(const Size(1280, 800));
+ addTearDown(() => tester.binding.setSurfaceSize(null));
+ final f = SuperTabLaunchFixture();
+ final p = _desk(f);
+ late SuperTabController c;
+ c = await _personal(f);
+ await PersonalProjects.of(f.app).sync(c);
+ final before = f.app.closedHistory.length;
+ final api = c.snapshot!.projects
+ .firstWhere((p) => p.name == 'api')
+ .leadConversationId;
+ c
+ ..select(api)
+ ..selectGroupTerminals(api);
+ await tester.pumpWidget(
+ MaterialApp(
+ home: Scaffold(
+ body: ListenableBuilder(
+ listenable: f.app,
+ builder: (_, _) => SuperTabWorkspace(
+ app: f.app,
+ canvas: const Text('Native terminals'),
+ onAddAgent: (_) {},
+ ),
+ ),
+ ),
+ ),
+ );
+ for (var i = 0; i < 20; i++) {
+ await tester.pump(const Duration(milliseconds: 20));
+ }
+ final swarm = f.app.swarms.firstWhere((s) => s.superTabId == tabId);
+ expect(swarm.panes, [p.api, p.api2]);
+
+ // Tab `one` holds the api pane [term] is showing.
+ await f.app.closeSwarm('one');
+ for (var i = 0; i < 20; i++) {
+ await tester.pump(const Duration(milliseconds: 20));
+ }
+ expect(swarm.panes, [p.api2]);
+ final added = f.app.closedHistory.take(
+ f.app.closedHistory.length - before,
+ );
+ expect(added, hasLength(1));
+ expect(added.single, isA<ClosedSwarm>());
+ expect((added.single as ClosedSwarm).id, 'one');
+ await tester.pumpWidget(const SizedBox());
+ await c.flush();
+ f.app.superTabs.dispose();
+ await tester.pump();
+ },
+ );
+
testWidgets('a project of one tab\'s panes keeps that tab\'s sizes', (
tester,
) async {