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.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
Web UX: first computer and the offline workspace (S5, S6, S14, P3 plural) (#1676)
Jacob Phamdeaaee0485c3
diff --git a/desktop/lib/screens/swarm_screen.dart b/desktop/lib/screens/swarm_screen.dartindex 78fb5ed1b..ef0bd8c34 100644--- a/desktop/lib/screens/swarm_screen.dart+++ b/desktop/lib/screens/swarm_screen.dart@@ -694,6 +694,8 @@ class _SwarmScreenState extends State<SwarmScreen> {_recordNavigation();app.addListener(_recordNavigation);app.addListener(_observeLearning);+ _syncMachineListWatch();+ app.addListener(_syncMachineListWatch);// Its own notifier, so marking one agent does not rebuild the workspace —// which means the badge has to ask for its own redraw.app.agentUnread.addListener(_unreadChanged);@@ -995,6 +997,8 @@ class _SwarmScreenState extends State<SwarmScreen> {terminalFontStore.removeListener(_fontChanged);app.removeListener(_recordNavigation);app.removeListener(_observeLearning);+ app.removeListener(_syncMachineListWatch);+ _machineListWatch?.cancel();app.removeListener(_followTabStripFocus);_tabStripFocus.removeListener(_tabStripFocusChanged);_tabStripFocus.dispose();@@ -1679,7 +1683,8 @@ class _SwarmScreenState extends State<SwarmScreen> {!machine.isOffline,).length;- return '${machines.length} linked machines · $online online · ${machines.length - online} offline.\n'+ final linked = machines.length == 1 ? 'machine' : 'machines';+ return '${machines.length} linked $linked · $online online · ${machines.length - online} offline.\n''${_commandTooltip('Open Machines', 'machines.list')}';}@@ -7436,11 +7441,18 @@ class _SwarmScreenState extends State<SwarmScreen> {/// No computer of the account's is connected, and none is on its way: the/// inventory has answered, and every one is missing, offline or waiting to- /// be linked — what the host's [WorkspaceChrome.firstMachine] is for.+ /// be linked — what the host's [WorkspaceChrome.firstMachine] is for. Not+ /// when every one is only asleep ([_asleepComputers]): that account has set+ /// one up, and keeps its panes.bool get _needsFirstConnection =>_machineInventorySettled &&- !_hasConnectedBrowserMachine &&- !app.machineStates.values.any(+ !_computerConnectedOrComing &&+ _asleepComputers.isEmpty;++ /// A computer of the account's is connected, or on its way.+ bool get _computerConnectedOrComing =>+ _hasConnectedBrowserMachine ||+ app.machineStates.values.any((machine) =>!machine.machine.isShared &&!machine.needsLink &&@@ -7449,12 +7461,98 @@ class _SwarmScreenState extends State<SwarmScreen> {machine.connectionStatus == ConnectionStatus.reconnecting),);+ /// The account's own computers, all of them offline and none waiting on this+ /// one to be linked: set up before, asleep now. Empty for an account with+ /// none (a computer taken out of it does not count) — that one needs setting+ /// up — and while any is connected, on its way, or waiting to be linked.+ List<MachineState> get _asleepComputers {+ final own = [+ for (final machine in app.machineStates.values)+ if (!machine.machine.isShared &&+ !app.removedMachines.containsKey(machine.machine.machineId))+ machine,+ ];+ if (own.any((machine) => machine.needsLink || !machine.isOffline)) {+ return const [];+ }+ return own;+ }++ /// The host's connect page covers the canvas: before the machine list first+ /// answers — the page says it is looking, instead of a New tab page that+ /// then gives way — and while there is no computer to use. Never over a+ /// computer that is connected or on its way.+ bool get _firstMachineCovers =>+ widget.chrome?.firstMachine != null &&+ (_needsFirstConnection ||+ (!app.machineInventoryLoaded && !_computerConnectedOrComing));++ /// Under the host's connect page, the canvas is out of sight, out of the+ /// accessibility tree and out of Tab's reach: its buttons cannot be pressed.+ /// A host without one (Desktop) gets the canvas itself, its focus tree as is.+ Widget _underFirstMachine(Widget canvas) {+ if (widget.chrome?.firstMachine == null) return canvas;+ final covered = _firstMachineCovers;+ return Offstage(+ offstage: covered,+ child: ExcludeFocus(excluding: covered, child: canvas),+ );+ }++ /// On a host with a connect page (the browser's), which no longer covers+ /// the panes of an account whose computers are all asleep: says which, and+ /// that their panes come back with them. Never on Desktop.+ bool get _showsAsleepBand =>+ widget.chrome?.firstMachine != null &&+ _machineInventorySettled &&+ _asleepComputers.isNotEmpty;++ Widget? _asleepBand() => _showsAsleepBand+ ? _AsleepBand(+ names: [+ for (final machine in _asleepComputers) machine.machine.displayName,+ ],+ )+ : null;++ /// The one timer asking for the machine list while the host's connect page+ /// or the asleep band shows: a browser with no computer connected hears of+ /// one signing in, or waking up, no other way — its connections to+ /// computers are what carry that news. Stopped once one is connected or on+ /// its way, and with the workspace.+ Timer? _machineListWatch;+ static const _machineListWatchEvery = Duration(seconds: 4);++ void _syncMachineListWatch() {+ if (!_firstMachineCovers && !_showsAsleepBand) {+ _machineListWatch?.cancel();+ _machineListWatch = null;+ return;+ }+ _machineListWatch ??= Timer.periodic(+ _machineListWatchEvery,+ (_) => unawaited(app.rereadMachines()),+ );+ }++ /// The shared error banner shows — except when its only message is the+ /// machine list's failure, which the host's connect page already shows with+ /// its own Retry: a phone would read it twice.+ bool get _showsErrorBanner {+ if (_projects.error != null) return true;+ final error = app.lastError;+ if (error == null) return false;+ return !(_firstMachineCovers &&+ !app.machineInventoryLoaded &&+ error == app.machineListError);+ }+/// The host's connect-a-computer page over the whole workspace — tabs synced/// from the account's desk would otherwise show panes for computers this/// browser cannot reach yet. Null when not needed, and for a host without one.Widget? _firstConnection(BuildContext context) {final page = widget.chrome?.firstMachine;- if (page == null || !_needsFirstConnection) return null;+ if (page == null || !_firstMachineCovers) return null;return ColoredBox(color: grid.AppPalette.swarmTabBar,child: Center(@@ -8092,7 +8190,8 @@ class _SwarmScreenState extends State<SwarmScreen> {),),),- if (_projects.error != null || app.lastError != null)+ ?_asleepBand(),+ if (_showsErrorBanner)Material(color: grid.AppPalette.panelBg,child: Padding(@@ -8204,142 +8303,135 @@ class _SwarmScreenState extends State<SwarmScreen> {child: Stack(children: [Positioned.fill(- child: PaneShareStatus(- visible:- widget- .chrome- ?.showsShareStatus ==- true,- child: PaneOpacity(- opacity: appearancePrefsStore- .value- .effectivePaneOpacity,- child: PaneGrid(- notifier: app,- swarmMode: true,- onOpenModels:- _openPaneModels,- onSplitPane:- (paneId, axis) =>- unawaited(- _splitAgent(- axis,- paneId:- paneId,+ child: _underFirstMachine(+ PaneShareStatus(+ visible:+ widget+ .chrome+ ?.showsShareStatus ==+ true,+ child: PaneOpacity(+ opacity: appearancePrefsStore+ .value+ .effectivePaneOpacity,+ child: PaneGrid(+ notifier: app,+ swarmMode: true,+ onOpenModels:+ _openPaneModels,+ onSplitPane:+ (paneId, axis) =>+ unawaited(+ _splitAgent(+ axis,+ paneId:+ paneId,+ ),),- ),- devicesViewer:- app.devicesEnabled- ? _devicesViewer- : null,- devicesConversation:- app.devicesEnabled- ? _devicesConversation- : null,- companionViewer:- _creatureEnabled- ? _companionViewer- : null,- companionConversation:- _creatureEnabled- ? _companionConversation- : null,- soloFocused: _compact(- context,- ),- empty:- app.panes.isEmpty &&- !app- .activeSwarm- .isUtility &&- !app- .activeSwarm- .isOrchestrator- ? newHarnessOpensInBox ||- app- .activeSwarm- .isNewTabPage- ? _startGuide()- : HarnessStartPage(- key: ValueKey(- 'harness-start:${app.activeSwarmId}',- ),- focusNode:- _startSearchFocus,- createSearch: () => SwarmSearchController(- app,- _navigation- .recent,- projects:- _projects,- commands:- _searchCommands,- recentCommands:- () =>- _navigation.recentCommands,- // The first box a new- // person meets is the same- // box: its placeholder- // promises `?` and a way- // to create, so it has them.- modes:- _searchModes,- adding:- true,- offersCreate:- true,- placement:- HarnessPlacement- .currentTab,- catalog:- _searchCatalog,- ),- onNewTab:- _newTab,- onNewPane: () =>- unawaited(- _addAgent(- query: '',- ),- ),- onCommands:- _showSearchCommands,- onQuickStart:- _learning- .offer- ? _startQuickStart- : null,- onPractice:- _practiceKeyboard,- onNew: () => _newAgent(- placement:- HarnessPlacement- .currentTab,- ),- onNewWithTask:- (- task,- ) => _newAgent(- task:- task,- placement:- HarnessPlacement.currentTab,- ),- onStore:- _openStore,- onResourceSearch:- (- query,- ) => _openSearch(- adding:- true,- query:- query,+ devicesViewer:+ app.devicesEnabled+ ? _devicesViewer+ : null,+ devicesConversation:+ app.devicesEnabled+ ? _devicesConversation+ : null,+ companionViewer:+ _creatureEnabled+ ? _companionViewer+ : null,+ companionConversation:+ _creatureEnabled+ ? _companionConversation+ : null,+ soloFocused: _compact(+ context,+ ),+ empty:+ app.panes.isEmpty &&+ !app+ .activeSwarm+ .isUtility &&+ !app+ .activeSwarm+ .isOrchestrator+ ? newHarnessOpensInBox ||+ app+ .activeSwarm+ .isNewTabPage+ ? _startGuide()+ : HarnessStartPage(+ key: ValueKey(+ 'harness-start:${app.activeSwarmId}',+ ),+ focusNode:+ _startSearchFocus,+ createSearch: () => SwarmSearchController(+ app,+ _navigation+ .recent,+ projects:+ _projects,+ commands:+ _searchCommands,+ recentCommands:+ () =>+ _navigation.recentCommands,+ // The first box a new+ // person meets is the same+ // box: its placeholder+ // promises `?` and a way+ // to create, so it has them.+ modes:+ _searchModes,+ adding:+ true,+ offersCreate:+ true,+ placement:+ HarnessPlacement.currentTab,+ catalog:+ _searchCatalog,+ ),+ onNewTab:+ _newTab,+ onNewPane: () => unawaited(+ _addAgent(+ query: '',),- onChoose:- _chooseStartSearch,- )- : null,+ ),+ onCommands:+ _showSearchCommands,+ onQuickStart:+ _learning+ .offer+ ? _startQuickStart+ : null,+ onPractice:+ _practiceKeyboard,+ onNew: () => _newAgent(+ placement:+ HarnessPlacement.currentTab,+ ),+ onNewWithTask: (task) => _newAgent(+ task:+ task,+ placement:+ HarnessPlacement.currentTab,+ ),+ onStore:+ _openStore,+ onResourceSearch: (query) => _openSearch(+ adding:+ true,+ query:+ query,+ ),+ onChoose:+ _chooseStartSearch,+ )+ : null,+ ),),),),@@ -9343,3 +9435,58 @@ enum _TitlebarCover {/// A dialog, the spoken palette or another route: the whole titlebar waits.modal,}++/// Names the account's computers that are asleep, over the workspace that+/// keeps their panes ([_SwarmScreenState._asleepBand]).+class _AsleepBand extends StatelessWidget {+ const _AsleepBand({required this.names});++ final List<String> names;++ @override+ Widget build(BuildContext context) {+ final one = names.length == 1;+ final who = one+ ? names.single+ : '${names.sublist(0, names.length - 1).join(', ')} and ${names.last}';+ return Material(+ key: const ValueKey('workspace-asleep-band'),+ color: grid.AppPalette.panelBg,+ child: Semantics(+ liveRegion: true,+ child: Padding(+ padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),+ child: Row(+ children: [+ Icon(+ AppIcons.cloudOff,+ size: 16,+ color: grid.AppPalette.textSecondary,+ ),+ const SizedBox(width: 10),+ Expanded(+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ Text(+ one ? '$who is offline' : '$who are offline',+ style: grid.AppType.body(),+ ),+ Text(+ one+ ? 'Its panes reconnect when it is back.'+ : 'Their panes reconnect when they are back.',+ style: grid.AppType.body(+ color: grid.AppPalette.textSecondary,+ ),+ ),+ ],+ ),+ ),+ ],+ ),+ ),+ ),+ );+ }+}diff --git a/desktop/lib/web/onboarding/web_first_machine.dart b/desktop/lib/web/onboarding/web_first_machine.dartindex 63b7d1dc4..156d16a4d 100644--- a/desktop/lib/web/onboarding/web_first_machine.dart+++ b/desktop/lib/web/onboarding/web_first_machine.dart@@ -21,8 +21,13 @@ import 'web_your_computers.dart';/// The account's computers first, if it has any ([WebYourComputers]): one/// waiting on this browser connects right here. Then both ways to set one up,/// side by side: the app for a desktop, the CLI for a server. Either signs in-/// on that computer, which then appears here on its own; the workspace takes-/// over the moment one connects.+/// on that computer, which then appears here on its own — the workspace asks+/// for the machine list while this page shows — and the workspace takes over+/// the moment one connects.+///+/// Until the machine list first answers it only says it is looking, and if+/// that list cannot be read, says so with Retry — it never shows setup steps+/// an account may not need.class WebFirstMachine extends StatefulWidget {const WebFirstMachine({super.key,@@ -35,34 +40,16 @@ class WebFirstMachine extends StatefulWidget {/// How the download page opens; tests pass a recorder.final Future<bool> Function(Uri uri) openPage;- /// How often the page asks for the machine list while it waits. A computer- /// signing in is announced to the account's other windows over their- /// connections to its machines — and this one has none yet, so nothing- /// would tell it before the five-minute safety net.- static const watchEvery = Duration(seconds: 4);-@overrideState<WebFirstMachine> createState() => _WebFirstMachineState();}class _WebFirstMachineState extends State<WebFirstMachine> {-String? _copied;Timer? _copiedReset;- late final Timer _watch;-- @override- void initState() {- super.initState();- _watch = Timer.periodic(- WebFirstMachine.watchEvery,- (_) => unawaited(widget.app.rereadMachines()),- );- }@overridevoid dispose() {- _watch.cancel();_copiedReset?.cancel();super.dispose();}@@ -86,6 +73,13 @@ class _WebFirstMachineState extends State<WebFirstMachine> {@overrideWidget build(BuildContext context) {grid.AppTheme.watch(context);+ if (!widget.app.machineInventoryLoaded) {+ final error = widget.app.machineListError;+ if (error == null) {+ return const Center(child: _Waiting('Finding your computers…'));+ }+ return _ListFailed(error: error, onRetry: widget.app.retryMachines);+ }final email = widget.app.currentUser?.email;final account = email == null || email.isEmpty ? 'this account' : email;final options = [@@ -95,6 +89,7 @@ class _WebFirstMachineState extends State<WebFirstMachine> {detail: 'On a Mac or Linux desktop. Open it and sign in as $account.',children: [FilledButton.icon(+ style: webOnboardingButton,onPressed: () => widget.openPage(WebDownloadButton.uri),icon: const Icon(AppIcons.download, size: 16),label: const Text('Download app'),@@ -170,7 +165,7 @@ class _WebFirstMachineState extends State<WebFirstMachine> {],),const SizedBox(height: 24),- const Center(child: _Waiting()),+ const Center(child: _Waiting('Waiting for your computer…')),],);},@@ -219,10 +214,50 @@ class _Option extends StatelessWidget {);}-/// The workspace replaces this page when a computer connects; until then it-/// says so, so the page does not read as finished.+/// The machine list could not be read before it ever answered: what went+/// wrong, and a way to ask again. A failed retry lands back here.+class _ListFailed extends StatelessWidget {+ const _ListFailed({required this.error, required this.onRetry});++ final String error;+ final Future<void> Function() onRetry;++ @override+ Widget build(BuildContext context) => Column(+ mainAxisSize: MainAxisSize.min,+ children: [+ Semantics(+ header: true,+ child: Text(+ 'Could not load your computers',+ textAlign: TextAlign.center,+ style: grid.AppType.display(color: DesktopChrome.foreground),+ ),+ ),+ const SizedBox(height: 8),+ Text(+ error,+ textAlign: TextAlign.center,+ style: DesktopChrome.text(color: DesktopChrome.muted),+ ),+ const SizedBox(height: 20),+ FilledButton.icon(+ style: webOnboardingButton,+ onPressed: () => unawaited(onRetry()),+ icon: const Icon(AppIcons.rotateCw, size: 16),+ label: const Text('Retry'),+ ),+ ],+ );+}++/// The workspace replaces this page when the list answers or a computer+/// connects; until then it says what it waits for, so the page does not read+/// as finished.class _Waiting extends StatelessWidget {- const _Waiting();+ const _Waiting(this.label);++ final String label;@overrideWidget build(BuildContext context) => Semantics(@@ -238,10 +273,7 @@ class _Waiting extends StatelessWidget {),),const SizedBox(width: 10),- Text(- 'Waiting for your computer…',- style: DesktopChrome.metadata(),- ),+ Text(label, style: DesktopChrome.metadata()),],),);diff --git a/desktop/lib/web/onboarding/web_your_computers.dart b/desktop/lib/web/onboarding/web_your_computers.dartindex 8898a4377..72cb931e4 100644--- a/desktop/lib/web/onboarding/web_your_computers.dart+++ b/desktop/lib/web/onboarding/web_your_computers.dart@@ -17,6 +17,12 @@ import '../../widgets/machine_picker_form.dart';////// What used to open was the machine picker itself — a search box with `@` in/// it and tabs for harnesses and agents a browser with no computer cannot use.+/// The onboarding pages' buttons: drawn at their usual size, with the padded+/// tap target around them, so a finger on a phone gets at least 44 px.+final ButtonStyle webOnboardingButton = FilledButton.styleFrom(+ tapTargetSize: MaterialTapTargetSize.padded,+);+class WebYourComputers extends StatefulWidget {const WebYourComputers({super.key, required this.app});@@ -214,9 +220,17 @@ class _ComputerRow extends StatelessWidget {),)else if (link == ComputerLinkState.ready)- FilledButton(onPressed: onConnect, child: const Text('Connect'))+ FilledButton(+ style: webOnboardingButton,+ onPressed: onConnect,+ child: const Text('Connect'),+ )else if (link == ComputerLinkState.failed)- FilledButton(onPressed: onConnect, child: const Text('Try again')),+ FilledButton(+ style: webOnboardingButton,+ onPressed: onConnect,+ child: const Text('Try again'),+ ),],),);diff --git a/desktop/test/web/web_app_menu_test.dart b/desktop/test/web/web_app_menu_test.dartindex 69876d383..4c2003280 100644--- a/desktop/test/web/web_app_menu_test.dart+++ b/desktop/test/web/web_app_menu_test.dart@@ -121,26 +121,6 @@ void main() {app.dispose();});- testWidgets('New harness with nothing connected opens Machines', (- tester,- ) async {- final app = await _mount(tester);- // New work starts where a new tab opens: its "Start an agent" row.- await tester.tap(find.byKey(const ValueKey('welcome-agent.new')));- await tester.pump(const Duration(milliseconds: 400));- expect(find.byType(NewHarnessForm), findsNothing);- expect(- tester- .widget<SwarmSearchResults>(find.byType(SwarmSearchResults))- .search- .scopePrefix,- '@',- );- expect(tester.takeException(), isNull);- await tester.pumpWidget(const SizedBox.shrink());- app.dispose();- });-testWidgets('View on a machine picks it and closes Machines', (tester) async {final app = await _mount(tester, connectedMachine: 'remote-box');await _openMenu(tester);diff --git a/desktop/test/web_first_machine_test.dart b/desktop/test/web_first_machine_test.dartindex 4af6ecb30..9eb898574 100644--- a/desktop/test/web_first_machine_test.dart+++ b/desktop/test/web_first_machine_test.dart@@ -16,46 +16,42 @@ import 'package:harness/widgets/link_another_machine_dialog.dart'show kLinkServerInstallCommand, kLinkServerLoginCommand;import 'package:harness/widgets/web_download_button.dart';-/// A password link under way, at its first stage.-class _Linking extends AppNotifier {- _Linking()+/// An account whose machine list has answered, unless a test says otherwise.+class _Account extends AppNotifier {+ _Account(): super(config: AppConfig.dev,authSession: AuthSession(),configStore: null,);+ bool loaded = true;+ String? listError;+ var retries = 0;+@override- Future<String?>? pendingMachineLink(String machineId) =>- Completer<String?>().future;+ bool get machineInventoryLoaded => loaded;@override- String? machineLinkStage(String machineId) => 'deriving_key';-}+ String? get machineListError => listError;-/// Counts the quiet machine-list reads the page makes while it waits.-class _Watching extends AppNotifier {- _Watching()- : super(- config: AppConfig.dev,- authSession: AuthSession(),- configStore: null,- );+ @override+ Future<void> retryMachines() async => retries++;+}- var reads = 0;+/// A password link under way, at its first stage.+class _Linking extends _Account {+ @override+ Future<String?>? pendingMachineLink(String machineId) =>+ Completer<String?>().future;@override- Future<void> rereadMachines() async => reads++;+ String? machineLinkStage(String machineId) => 'deriving_key';}/// Dialing with no password: [trusted] says how the computer answers.-class _Dialing extends AppNotifier {- _Dialing({required this.trusted})- : super(- config: AppConfig.dev,- authSession: AuthSession(),- configStore: null,- );+class _Dialing extends _Account {+ _Dialing({required this.trusted});final bool trusted;final dialed = <String>[];@@ -72,11 +68,8 @@ void main() {late List<Uri> opened;setUp(() {- app = AppNotifier(- config: AppConfig.dev,- authSession: AuthSession(),- configStore: null,- )..currentUser = const CurrentUserProfile(email: '[email protected]');+ app = _Account()+ ..currentUser = const CurrentUserProfile(email: '[email protected]');opened = [];});@@ -192,21 +185,6 @@ void main() {expect((app as _Dialing).dialed, ['mac', 'mac']);});- testWidgets('keeps asking for the machine list while it waits', (- tester,- ) async {- app.dispose();- app = _Watching();- await mount(tester);-- await tester.pump(WebFirstMachine.watchEvery * 3);-- expect((app as _Watching).reads, 3);- await tester.pumpWidget(const SizedBox.shrink());- await tester.pump(WebFirstMachine.watchEvery * 2);- expect((app as _Watching).reads, 3, reason: 'stops with the page');- });-void addComputer(String id, {bool online = false}) {final machine = Machine(machineId: id,@@ -302,4 +280,63 @@ void main() {final cli = tester.getTopLeft(find.text('Command line'));expect(cli.dy, greaterThan(app.dy));});++ testWidgets('before the machine list answers: finding, not the steps', (+ tester,+ ) async {+ app = _Account()..loaded = false;++ await mount(tester);++ expect(find.text('Finding your computers…'), findsOneWidget);+ expect(find.text('Connect a computer'), findsNothing);+ expect(find.text(kLinkServerInstallCommand), findsNothing);+ });++ testWidgets('a list that keeps failing says so, and Retry asks again', (+ tester,+ ) async {+ final account = _Account()+ ..loaded = false+ ..listError = 'Could not load machines: the server did not answer.';+ app = account;++ await mount(tester);+ expect(+ find.text('Could not load machines: the server did not answer.'),+ findsOneWidget,+ );+ expect(find.text('Finding your computers…'), findsNothing);++ await tester.tap(find.widgetWithText(FilledButton, 'Retry'));+ await tester.pump();++ expect(account.retries, 1);+ expect(find.widgetWithText(FilledButton, 'Retry'), findsOneWidget);+ expect(find.text('Finding your computers…'), findsNothing);+ });++ group('on a phone, every button takes a 44 px tap', () {+ double tapHeight(WidgetTester tester, String label) =>+ tester.getSize(find.widgetWithText(FilledButton, label)).height;++ testWidgets('Download app and Connect', (tester) async {+ addComputer('mac', online: true);++ await mount(tester, width: 390);++ expect(tapHeight(tester, 'Download app'), greaterThanOrEqualTo(44));+ expect(tapHeight(tester, 'Connect'), greaterThanOrEqualTo(44));+ });++ testWidgets('Retry', (tester) async {+ app = _Account()+ ..loaded = false+ ..listError = 'Could not load machines: the server did not answer.';++ await mount(tester, width: 390);++ expect(tapHeight(tester, 'Retry'), greaterThanOrEqualTo(44));+ });+ });}diff --git a/desktop/test/workspace_first_connection_test.dart b/desktop/test/workspace_first_connection_test.dartindex 52b4428d8..7aeee0ce2 100644--- a/desktop/test/workspace_first_connection_test.dart+++ b/desktop/test/workspace_first_connection_test.dart@@ -1,4 +1,5 @@import 'package:flutter/material.dart';+import 'package:flutter/rendering.dart';import 'package:flutter_test/flutter_test.dart';import 'package:harness/auth/auth_session.dart';import 'package:harness/core/config.dart';@@ -7,14 +8,33 @@ import 'package:harness/screens/swarm_screen.dart';import 'package:harness/shared/theme/app_theme.dart' as grid;import 'package:harness/state/app_state.dart';import 'package:harness/state/workspace_chrome.dart';+import 'package:harness/terminal/terminal_session.dart';import 'package:harness/widgets/swarm_switcher.dart';+import 'package:harness/widgets/workspace_welcome.dart';class _App extends AppNotifier {- _App() : super(config: AppConfig.dev, authSession: AuthSession(), configStore: null);+ _App()+ : super(+ config: AppConfig.dev,+ authSession: AuthSession(),+ configStore: null,+ );bool loaded = false;@overridebool get machineInventoryLoaded => loaded;++ /// The first machine list's failure, as the app reports it.+ String? listError;+ @override+ String? get machineListError => listError;+ @override+ String? get lastError => listError ?? super.lastError;++ /// The quiet machine-list reads asked for while waiting on a computer.+ var rereads = 0;+ @override+ Future<void> rereadMachines() async => rereads++;}const _connectPage = Key('connect-page');@@ -25,11 +45,26 @@ void main() {Future<_App> mount(WidgetTester tester, {MachineState Function(_App app)? machine,+ bool pane = false,+ bool answers = true,+ bool connectPage = true,}) async {final app = _App();app.currentUser = const CurrentUserProfile(email: '[email protected]');machine?.call(app);app.newSwarm(newTabPage: true);+ if (pane) {+ app.adoptSessionForTest(+ TerminalSession(+ machineId: 'mac',+ agentId: 'a1',+ agentName: 'Fix checkout flow',+ engineId: 'claude',+ send: (_, _) async => true,+ sendBinary: (_) async => true,+ ),+ );+ }tester.view.physicalSize = const Size(1280, 800);tester.view.devicePixelRatio = 1;addTearDown(tester.view.reset);@@ -38,15 +73,18 @@ void main() {theme: grid.buildAppTheme(brightness: Brightness.dark),home: SwarmScreen(notifier: app,- chrome: WorkspaceChrome(- leadingWidth: (_) => 0,- leading: (_, _) => const SizedBox(),- firstMachine: (_) => const SizedBox(key: _connectPage),- ),+ chrome: connectPage+ ? WorkspaceChrome(+ leadingWidth: (_) => 0,+ leading: (_, _) => const SizedBox(),+ firstMachine: (_) => const SizedBox(key: _connectPage),+ )+ : null,),),);await tester.pump(const Duration(milliseconds: 200));+ if (!answers) return app;app.loaded = true;app.notifyListeners();await tester.pump(const Duration(milliseconds: 200));@@ -55,22 +93,66 @@ void main() {}MachineState Function(_App) computer({+ String id = 'mac',+ String name = 'Mac',bool needsLink = false,bool? online = true,ConnectionStatus status = ConnectionStatus.disconnected,}) => (app) {- const machine = Machine(- machineId: 'mac',- name: 'Mac',+ final machine = Machine(+ machineId: id,+ name: name,authMode: MachineAuthMode.remote,);app.machines.add(machine);- return app.machineStates['mac'] = MachineState(machine)+ return app.machineStates[id] = MachineState(machine)..needsLink = needsLink..nodeOnline = online..connectionStatus = status;};+ /// The only computer, set up once and now asleep.+ final asleep = computer(online: false);++ /// The canvas's own New tab page, where a person can see it.+ Finder newTabPage() => find.byType(WorkspaceWelcome);++ /// Every label in the window's accessibility tree.+ List<String> spoken(WidgetTester tester) {+ final labels = <String>[];+ bool visit(SemanticsNode node) {+ if (node.label.isNotEmpty) labels.add(node.label);+ node.visitChildren(visit);+ return true;+ }++ visit(tester.getSemantics(find.byType(SwarmScreen)));+ return labels;+ }++ /// The New tab page's controls that Tab could still reach.+ List<FocusNode> reachableUnderPage() {+ final welcome = find+ .byType(WorkspaceWelcome, skipOffstage: false)+ .evaluate()+ .single;+ bool under(BuildContext context) {+ var found = false;+ context.visitAncestorElements((ancestor) {+ found = ancestor == welcome;+ return !found;+ });+ return found;+ }++ return [+ for (final node in FocusManager.instance.rootScope.descendants)+ if (node.context case final context?+ when under(context) && node.canRequestFocus)+ node,+ ];+ }+Future<void> unmount(WidgetTester tester, _App app) async {expect(tester.takeException(), isNull);await tester.pumpWidget(const SizedBox.shrink());@@ -116,4 +198,270 @@ void main() {expect(find.byKey(_connectPage), findsNothing);await unmount(tester, app);});++ testWidgets(+ 'the only computer offline: its pane stays, under a band naming it',+ (tester) async {+ final app = await mount(tester, machine: asleep, pane: true);++ expect(find.byKey(_connectPage), findsNothing);+ expect(find.text('Mac is offline'), findsOneWidget);+ expect(+ find.byTooltip('Mac is offline. Retained output is read only.'),+ findsOneWidget,+ );+ await unmount(tester, app);+ },+ );++ testWidgets('it comes back: the band goes', (tester) async {+ final app = await mount(tester, machine: asleep, pane: true);+ expect(find.text('Mac is offline'), findsOneWidget);++ app.machineStates['mac']!+ ..nodeOnline = true+ ..connectionStatus = ConnectionStatus.connected;+ app.notifyListeners();+ await tester.pump();++ expect(find.text('Mac is offline'), findsNothing);+ expect(find.byKey(_connectPage), findsNothing);+ await unmount(tester, app);+ });++ // One timer asks for the machine list, every four seconds, while the+ // connect page or the asleep band shows: a second one would double the+ // reads, and one left running would read forever.+ const every = Duration(seconds: 4);++ testWidgets('the connect page: one read every four seconds', (tester) async {+ final app = await mount(tester);+ final before = app.rereads;++ await tester.pump(every * 3);++ expect(app.rereads - before, 3);+ await unmount(tester, app);+ });++ testWidgets('the band: one read every four seconds, none once it is back', (+ tester,+ ) async {+ final app = await mount(tester, machine: asleep, pane: true);+ final before = app.rereads;++ await tester.pump(every * 3);+ expect(app.rereads - before, 3);++ app.machineStates['mac']!+ ..nodeOnline = true+ ..connectionStatus = ConnectionStatus.connected;+ app.notifyListeners();+ await tester.pump();+ final woken = app.rereads;+ await tester.pump(every * 3);+ expect(app.rereads, woken);+ await unmount(tester, app);+ });++ testWidgets('no read once the workspace is gone', (tester) async {+ final app = await mount(tester, machine: asleep, pane: true);+ await tester.pumpWidget(const SizedBox.shrink());+ final gone = app.rereads;++ await tester.pump(every * 3);++ expect(app.rereads, gone);+ app.dispose();+ });++ testWidgets('two asleep: the band names both', (tester) async {+ final app = await mount(+ tester,+ machine: (app) {+ asleep(app);+ return computer(id: 'box', name: 'Build box', online: false)(app);+ },+ );++ expect(find.text('Mac and Build box are offline'), findsOneWidget);+ await unmount(tester, app);+ });++ testWidgets('one asleep, another connected: no band, as before', (+ tester,+ ) async {+ final app = await mount(+ tester,+ machine: (app) {+ asleep(app);+ return computer(+ id: 'box',+ name: 'Build box',+ status: ConnectionStatus.connected,+ )(app);+ },+ );++ expect(find.textContaining('is offline'), findsNothing);+ expect(find.byKey(_connectPage), findsNothing);+ await unmount(tester, app);+ });++ testWidgets('one asleep, one waiting on this browser: the connect page', (+ tester,+ ) async {+ final app = await mount(+ tester,+ machine: (app) {+ asleep(app);+ return computer(id: 'box', name: 'Build box', needsLink: true)(app);+ },+ );++ expect(find.byKey(_connectPage), findsOneWidget);+ expect(find.textContaining('is offline'), findsNothing);+ await unmount(tester, app);+ });++ testWidgets('only a computer taken out of the account: the connect page', (+ tester,+ ) async {+ final app = await mount(+ tester,+ machine: (app) {+ app.removedMachines = {'mac': 1};+ return asleep(app);+ },+ );++ expect(find.byKey(_connectPage), findsOneWidget);+ expect(find.textContaining('is offline'), findsNothing);+ await unmount(tester, app);+ });++ testWidgets(+ 'before the machine list answers: the page, not the New tab page',+ (tester) async {+ final app = await mount(tester, answers: false);++ expect(find.byKey(_connectPage), findsOneWidget);+ expect(newTabPage(), findsNothing);+ await unmount(tester, app);+ },+ );++ const failed = 'Could not load machines: the server did not answer.';++ testWidgets('a failed list: said once, by the page, not the banner too', (+ tester,+ ) async {+ final app = await mount(tester, answers: false);+ app.listError = failed;+ app.notifyListeners();+ await tester.pump();++ expect(find.byKey(_connectPage), findsOneWidget);+ expect(find.text(failed), findsNothing);+ await unmount(tester, app);+ });++ testWidgets('connected before the list answers: the workspace, no page', (+ tester,+ ) async {+ final app = await mount(+ tester,+ machine: computer(status: ConnectionStatus.connected),+ answers: false,+ );++ expect(find.byKey(_connectPage), findsNothing);+ await unmount(tester, app);+ });++ testWidgets('the covered workspace is out of the tree and out of focus', (+ tester,+ ) async {+ final handle = tester.ensureSemantics();+ final app = await mount(tester);+ expect(find.byKey(_connectPage), findsOneWidget);++ expect(newTabPage(), findsNothing);+ expect(spoken(tester), isNot(anyElement(contains('Start a harness'))));+ expect(reachableUnderPage(), isEmpty);+ handle.dispose();+ await unmount(tester, app);+ });++ testWidgets('the footer counts one linked machine in the singular', (+ tester,+ ) async {+ final app = await mount(+ tester,+ machine: computer(status: ConnectionStatus.connected),+ );++ expect(+ find.byWidgetPredicate(+ (widget) =>+ widget is Tooltip &&+ (widget.message ?? '').startsWith('1 linked machine · '),+ ),+ findsOneWidget,+ );+ await unmount(tester, app);+ });++ group('Desktop, with no connect page', () {+ testWidgets('the only computer offline: its pane, and no band', (+ tester,+ ) async {+ final app = await mount(+ tester,+ machine: asleep,+ pane: true,+ connectPage: false,+ );++ expect(find.text('Mac is offline'), findsNothing);+ expect(+ find.byTooltip('Mac is offline. Retained output is read only.'),+ findsOneWidget,+ );+ await unmount(tester, app);+ });++ testWidgets('a failed list: the banner, as before', (tester) async {+ final app = await mount(tester, answers: false, connectPage: false);+ app.listError = failed;+ app.notifyListeners();+ await tester.pump();++ expect(find.text(failed), findsOneWidget);+ await unmount(tester, app);+ });++ testWidgets('no machine-list reads', (tester) async {+ final app = await mount(tester, machine: asleep, connectPage: false);+ final before = app.rereads;++ await tester.pump(every * 3);++ expect(app.rereads, before);+ await unmount(tester, app);+ });++ testWidgets('before the machine list answers: the New tab page', (+ tester,+ ) async {+ final handle = tester.ensureSemantics();+ final app = await mount(tester, answers: false, connectPage: false);++ expect(newTabPage(), findsOneWidget);+ expect(spoken(tester), anyElement(contains('Start a harness')));+ expect(reachableUnderPage(), isNotEmpty);+ handle.dispose();+ await unmount(tester, app);+ });+ });}diff --git a/desktop/tool/web_ux/flows/first_computer.mjs b/desktop/tool/web_ux/flows/first_computer.mjsindex ae23116e8..a02415956 100644--- a/desktop/tool/web_ux/flows/first_computer.mjs+++ b/desktop/tool/web_ux/flows/first_computer.mjs@@ -5,8 +5,10 @@export const FLOWS = [{ name: 'first-machine', scenario: 'first-machine' },{ name: 'first-machine-loading', scenario: 'first-machine-loading' },+ { name: 'first-machine-failed', scenario: 'first-machine-failed' },{ name: 'link-machine', scenario: 'link-machine' },{ name: 'computers', scenario: 'computers' },{ name: 'link-password', scenario: 'link-machine', steps: [['exact', 'Connect']] },{ name: 'offline-only', scenario: 'offline-only' },+ { name: 'offline-back', scenario: 'offline-back' },];diff --git a/desktop/tool/web_ux/scenarios/first_computer.dart b/desktop/tool/web_ux/scenarios/first_computer.dartindex 9980ebea7..54dab639d 100644--- a/desktop/tool/web_ux/scenarios/first_computer.dart+++ b/desktop/tool/web_ux/scenarios/first_computer.dart@@ -4,28 +4,71 @@/// edit the same file; `tool/web_ux_scenarios.dart` merges every group's map.library;+import 'dart:async';+import 'package:harness/core/models.dart';+import 'package:harness/state/app_state.dart';+import '../../../test/support/web_ux_app.dart';import '../../web_ux_seed.dart';import 'scenario.dart';+/// The first machine list failed and has not answered since.+class _ListFails extends WebUxApp {+ static const message = 'Could not load machines: the server did not answer.';++ @override+ bool get machineInventoryLoaded => false;++ @override+ String? get machineListError => message;++ @override+ Future<void> retryMachines() async {}+}++/// The only computer, asleep until [wake].+class _Wakes extends WebUxApp {+ void wake() {+ machineStates['m1']!+ ..nodeOnline = true+ ..connectionStatus = ConnectionStatus.connected;+ notifyListeners();+ }+}++/// [app] signed in as [signedIn] is, for a fake that needs its own class.+T _signedIn<T extends WebUxApp>(T app) => app+ ..status = AppStatus.authenticated+ ..currentUser = const CurrentUserProfile(+ name: 'Jamie Rivera',+ email: webUxEmail,+ );+final Map<String, WebUxScenario> firstComputerScenarios = {'first-machine': WebUxScenario(() => signedIn()),'first-machine-loading': WebUxScenario(() => signedIn()..inventoryLoaded = false,),+ 'first-machine-failed': WebUxScenario(+ () => _signedIn(_ListFails())..error = _ListFails.message,+ ),'link-machine': WebUxScenario(() => signedIn()..addMachine('m1', 'Studio Mac', needsLink: true),),'computers': WebUxScenario(() => withComputers(signedIn())),- // The only computer offline: the workspace gives way to "Connect your- // computer". `offline` in pane.dart keeps a second computer connected.- 'offline-only': WebUxScenario(- () => withPanes(- signedIn(),- 1,- status: ConnectionStatus.disconnected,- online: false,- ),- ),+ // The only computer offline: its pane stays, Offline, under a band naming+ // it. `offline` in pane.dart keeps a second computer connected.+ 'offline-only': WebUxScenario(() => _asleep(signedIn())),+ // The same computer wakes up a second after the page opens: the band goes.+ 'offline-back': WebUxScenario(() {+ final app = _asleep(_signedIn(_Wakes()));+ Timer(const Duration(seconds: 1), app.wake);+ return app;+ }),};++T _asleep<T extends WebUxApp>(T app) {+ withPanes(app, 1, status: ConnectionStatus.disconnected, online: false);+ return app;+}