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.

Web: shared-link states, quiet store bar on sign-in, browser-copy note with Clear now (#1738)

Jacob Pham1fa94d8a2df1
diff --git a/desktop/lib/screens/swarm_screen.dart b/desktop/lib/screens/swarm_screen.dart
index 5ab98d078..ff05e1762 100644
--- a/desktop/lib/screens/swarm_screen.dart
+++ b/desktop/lib/screens/swarm_screen.dart
@@ -8619,6 +8619,18 @@ class _SwarmScreenState extends State<SwarmScreen> {
return _fullStatusBar();
}
+ /// The host offers subscriptions once the account has a computer
+ /// ([WorkspaceChrome.subscriptionsNeedComputer]): the machine list has
+ /// answered, and none of the account's own is in it. Never while it loads.
+ bool get _subscriptionsWaitForComputer =>
+ widget.chrome?.subscriptionsNeedComputer == true &&
+ _machineInventorySettled &&
+ !app.machineStates.values.any(
+ (machine) =>
+ !machine.machine.isShared &&
+ !app.removedMachines.containsKey(machine.machine.machineId),
+ );
+
/// The status bar's content for a host that draws its own compact footer.
WorkspaceFooter _workspaceFooter() {
final focused = WorkspacePaneContext.focused(app);
@@ -8635,9 +8647,10 @@ class _SwarmScreenState extends State<SwarmScreen> {
detail: detail,
onPressed: links![field]!.onPressed,
);
+ final subscriptions = !_subscriptionsWaitForComputer;
return WorkspaceFooter(
summary: focused == null
- ? _subscriptionUsage.text
+ ? (subscriptions ? _subscriptionUsage.text : _footerMachineLabel)
: [
focused.machineName,
focused.branch ?? focused.projectName,
@@ -8662,21 +8675,23 @@ class _SwarmScreenState extends State<SwarmScreen> {
? () => _toggleModels(initialTab: ModelsTab.local)
: null,
),
- for (final account in _subscriptionUsage.accounts)
+ if (subscriptions) ...[
+ for (final account in _subscriptionUsage.accounts)
+ WorkspaceFooterItem(
+ title: '${account.name} ${account.figure}',
+ detail: account.detail,
+ onPressed: _shortcutsEnabled
+ ? () => _openSubscription(account.searchId)
+ : null,
+ ),
WorkspaceFooterItem(
- title: '${account.name} ${account.figure}',
- detail: account.detail,
+ title: 'Subscriptions',
+ detail: _subscriptionUsage.text,
onPressed: _shortcutsEnabled
- ? () => _openSubscription(account.searchId)
+ ? () => _toggleModels(initialTab: ModelsTab.subscriptions)
: null,
),
- WorkspaceFooterItem(
- title: 'Subscriptions',
- detail: _subscriptionUsage.text,
- onPressed: _shortcutsEnabled
- ? () => _toggleModels(initialTab: ModelsTab.subscriptions)
- : null,
- ),
+ ],
?link(StatusLineField.machine, 'Machine', focused?.machineName),
?link(StatusLineField.project, 'Project', focused?.projectName),
?link(StatusLineField.branch, 'Branch', focused?.branch),
diff --git a/desktop/lib/settings/sections/account_section.dart b/desktop/lib/settings/sections/account_section.dart
index acb7073a6..3e89dbb98 100644
--- a/desktop/lib/settings/sections/account_section.dart
+++ b/desktop/lib/settings/sections/account_section.dart
@@ -5,6 +5,7 @@ import '../../screens/login_screen.dart';
import '../../shared/widgets/section_scaffold.dart';
import '../../shared/widgets/setting_row.dart';
import '../../state/app_state.dart';
+import 'saved_super_tabs_row.dart';
class AccountSection extends StatelessWidget {
const AccountSection({super.key, required this.notifier});
@@ -55,6 +56,24 @@ class AccountSection extends StatelessWidget {
),
);
}
+ final account = SettingRow(
+ // An account with no name is called by its email, and the email is
+ // the line under it: signing up by email showed the address twice.
+ title: profile != null && profile.displayName != profile.email
+ ? profile.displayName
+ : (local && profile == null ? 'Local session' : 'Signed in'),
+ detail:
+ profile?.email ??
+ (local ? 'Loopback backend' : 'Profile unavailable'),
+ control: OutlinedButton(
+ key: const Key('settings-sign-out-button'),
+ onPressed: () {
+ Navigator.of(context).pop();
+ notifier.logout();
+ },
+ child: Text(local ? 'Disconnect local session' : 'Sign out'),
+ ),
+ );
return SectionScaffold(
title: 'Account',
subtitle: local
@@ -64,24 +83,18 @@ class AccountSection extends StatelessWidget {
? 'Your Harness sign-in in this browser.'
: 'Your Harness sign-in on this computer.',
child: SingleChildScrollView(
- child: SettingRow(
- // An account with no name is called by its email, and the email is
- // the line under it: signing up by email showed the address twice.
- title: profile != null && profile.displayName != profile.email
- ? profile.displayName
- : (local && profile == null ? 'Local session' : 'Signed in'),
- detail:
- profile?.email ??
- (local ? 'Loopback backend' : 'Profile unavailable'),
- control: OutlinedButton(
- key: const Key('settings-sign-out-button'),
- onPressed: () {
- Navigator.of(context).pop();
- notifier.logout();
- },
- child: Text(local ? 'Disconnect local session' : 'Sign out'),
- ),
- ),
+ // Only where Super Tabs are kept on this device (the web's) does
+ // Account say so; Desktop keeps none and its page is as it was.
+ child: notifier.superTabs.reading.drawsSaved
+ ? Column(
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ account,
+ const SizedBox(height: 12),
+ SavedSuperTabsRow(superTabs: notifier.superTabs),
+ ],
+ )
+ : account,
),
);
},
diff --git a/desktop/lib/settings/sections/saved_super_tabs_row.dart b/desktop/lib/settings/sections/saved_super_tabs_row.dart
new file mode 100644
index 000000000..e60887207
--- /dev/null
+++ b/desktop/lib/settings/sections/saved_super_tabs_row.dart
@@ -0,0 +1,81 @@
+import 'dart:async';
+
+import 'package:flutter/material.dart';
+
+import '../../shared/theme/app_theme.dart' as grid;
+import '../../shared/widgets/setting_row.dart';
+import '../../super_tabs/client.dart';
+
+/// Where views of Super Tabs are kept on this device (the web's reading,
+/// `SuperTabReading.drawsSaved`), Account says so in plain words, says when
+/// they go, and clears them now. It says Cleared only when they went, and
+/// only until a Super Tab is kept again.
+class SavedSuperTabsRow extends StatefulWidget {
+ const SavedSuperTabsRow({super.key, required this.superTabs});
+
+ final SuperTabClient superTabs;
+
+ @override
+ State<SavedSuperTabsRow> createState() => _SavedSuperTabsRowState();
+}
+
+enum _Clearing { idle, busy, cleared, refused }
+
+class _SavedSuperTabsRowState extends State<SavedSuperTabsRow> {
+ var _state = _Clearing.idle;
+
+ @override
+ void initState() {
+ super.initState();
+ widget.superTabs.viewsKept.addListener(_keptAgain);
+ }
+
+ @override
+ void dispose() {
+ widget.superTabs.viewsKept.removeListener(_keptAgain);
+ super.dispose();
+ }
+
+ void _keptAgain() {
+ if (_state == _Clearing.cleared) setState(() => _state = _Clearing.idle);
+ }
+
+ Future<void> _clear() async {
+ setState(() => _state = _Clearing.busy);
+ var cleared = true;
+ try {
+ await widget.superTabs.clearSavedViews();
+ } catch (_) {
+ // A browser that refuses its storage (full, private mode).
+ cleared = false;
+ }
+ if (!mounted) return;
+ setState(() => _state = cleared ? _Clearing.cleared : _Clearing.refused);
+ }
+
+ @override
+ Widget build(BuildContext context) => SettingRow(
+ title: 'Super Tabs in this browser',
+ detail:
+ 'This browser keeps a copy of the Super Tabs you open, so they show '
+ 'at once. Signing out removes it.',
+ control: OutlinedButton(
+ key: const Key('settings-clear-saved-super-tabs'),
+ // A thumb's target on a phone.
+ style: const ButtonStyle(tapTargetSize: MaterialTapTargetSize.padded),
+ onPressed: switch (_state) {
+ _Clearing.busy || _Clearing.cleared => null,
+ _ => () => unawaited(_clear()),
+ },
+ child: Text(_state == _Clearing.cleared ? 'Cleared' : 'Clear now'),
+ ),
+ footer: _state == _Clearing.refused
+ ? Text(
+ 'This browser did not let Harness clear it. Try again.',
+ style: grid.AppType.body(
+ color: Theme.of(context).colorScheme.error,
+ ),
+ )
+ : null,
+ );
+}
diff --git a/desktop/lib/sharing/shared_agent_location.dart b/desktop/lib/sharing/shared_agent_location.dart
index e869805c2..a949e334a 100644
--- a/desktop/lib/sharing/shared_agent_location.dart
+++ b/desktop/lib/sharing/shared_agent_location.dart
@@ -20,6 +20,9 @@ class SharedAgentLocation {
return SharedAgentLocation(match[1]!, key, env);
}
+ /// Where a link's Open Harness goes: the root of the site it came from.
+ static Uri workspaceOf(Uri link) => Uri.parse('${link.origin}/');
+
/// Only a local share path can be restored after OAuth. Never accept an external redirect.
static String? returnPath(Object? value) {
if (value is! String) return null;
diff --git a/desktop/lib/sharing/shared_agent_page.dart b/desktop/lib/sharing/shared_agent_page.dart
index 1baf80ac4..a98c5bbbc 100644
--- a/desktop/lib/sharing/shared_agent_page.dart
+++ b/desktop/lib/sharing/shared_agent_page.dart
@@ -3,16 +3,20 @@ import 'dart:async';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:url_launcher/link.dart';
+import 'package:url_launcher/url_launcher.dart';
import '../core/models.dart';
import '../measurement/hub_usage.dart';
+import '../shared/theme/app_icons.dart';
import '../shared/theme/app_theme.dart' as grid;
+import '../shared/widgets/empty_state.dart';
import '../state/app_state.dart';
import '../state/terminal_pane.dart';
import '../widgets/desktop_chrome.dart';
import '../widgets/web_download_button.dart';
import 'shared_agent_location.dart';
import 'shared_harness_panel.dart';
+import 'shared_link_state.dart';
/// Public landing and private recipient view, using the same encrypted renderer as desktop.
/// It does not add a machine, receive a peer key, or restore the visitor's workspace.
@@ -25,6 +29,7 @@ class SharedAgentPage extends StatefulWidget {
required this.location,
this.dio,
this.usage,
+ this.openHarness,
});
final AppNotifier app;
final SharedAgentLocation location;
@@ -32,6 +37,9 @@ class SharedAgentPage extends StatefulWidget {
/// Tests pass their own; the page otherwise counts into the app's [hubUsage].
final HubUsage? usage;
+
+ /// Opens the Harness app at this site's root; a test passes its own.
+ final Future<void> Function()? openHarness;
@override
State<SharedAgentPage> createState() => _SharedAgentPageState();
}
@@ -47,8 +55,8 @@ class _SharedAgentPageState extends State<SharedAgentPage> {
),
);
Map<String, dynamic>? _data;
- String? _error;
- bool _loading = true, _signInRequired = false;
+ SharedLinkProblem? _problem;
+ bool _loading = true;
int _revision = 0;
Timer? _offlineRetry;
late bool _signedIn = widget.app.status == AppStatus.authenticated;
@@ -115,6 +123,15 @@ class _SharedAgentPageState extends State<SharedAgentPage> {
unawaited(_load());
}
+ void _openHarness() => unawaited(
+ (widget.openHarness ?? _openHarnessHere)().catchError((Object _) {}),
+ );
+
+ static Future<void> _openHarnessHere() => launchUrl(
+ SharedAgentLocation.workspaceOf(Uri.base),
+ webOnlyWindowName: '_self',
+ );
+
@override
void didUpdateWidget(SharedAgentPage oldWidget) {
super.didUpdateWidget(oldWidget);
@@ -136,22 +153,32 @@ class _SharedAgentPageState extends State<SharedAgentPage> {
super.dispose();
}
- Future<void> _load() async {
+ void _show(SharedLinkProblem problem) => setState(() {
+ _loading = false;
+ _problem = problem;
+ });
+
+ /// Reads the link. [quietly] keeps the page as it is until the answer
+ /// differs: the offline page's own re-read neither flashes Opening nor
+ /// says its state again.
+ Future<void> _load({bool quietly = false}) async {
_offlineRetry?.cancel();
final revision = ++_revision;
- setState(() {
- _loading = true;
- _data = null;
- _error = null;
- _signInRequired = false;
- });
+ if (!quietly) {
+ setState(() {
+ _loading = true;
+ _data = null;
+ _problem = null;
+ });
+ }
+ final key = widget.location.ownerKey;
+ if (key == null || !RegExp(r'^[A-Za-z0-9+/]{43}=$').hasMatch(key)) {
+ // Nothing to ask the server: only a whole link can open.
+ _countOpen(SharedOpen.failed);
+ _show(SharedLinkProblem.incomplete);
+ return;
+ }
try {
- final key = widget.location.ownerKey;
- if (key == null || !RegExp(r'^[A-Za-z0-9+/]{43}=$').hasMatch(key)) {
- throw const FormatException(
- 'This link is incomplete. Ask the owner to copy the full link again.',
- );
- }
final token = await _accessToken();
final response = await _dio.get(
'${widget.app.config.apiBaseUrl}/api/shared-agents/${widget.location.id}',
@@ -163,34 +190,33 @@ class _SharedAgentPageState extends State<SharedAgentPage> {
),
);
if (!mounted || revision != _revision) return;
- if (response.statusCode != 200) {
- _countOpen(
- response.statusCode == 401 ? SharedOpen.private : SharedOpen.noAccess,
- );
- setState(() {
- _signInRequired = response.statusCode == 401;
- _error = _signInRequired
- ? 'This link is private. Sign in with an invited email.'
- : 'This link is unavailable or your email has not been invited. Ask the owner for access.';
- _loading = false;
+ final status = response.statusCode;
+ if (status == 401 || status == 403 || status == 404) {
+ _countOpen(status == 401 ? SharedOpen.private : SharedOpen.noAccess);
+ // A refusal to someone signed in is never a reason to sign in again:
+ // that would send the reader round the sign-in for the same answer.
+ // A 401 is not a refusal: the server took no session at all, and a
+ // fresh sign-in gets the link or a refusal, so it cannot loop.
+ _show(switch ((status, _signedIn)) {
+ (401, false) => SharedLinkProblem.signIn,
+ (401, true) => SharedLinkProblem.signInEnded,
+ _ => SharedLinkProblem.refused,
});
return;
}
+ if (status != 200) throw StateError('shared link read: $status');
final data = Map<String, dynamic>.from(response.data['data'] as Map);
if (data['ownerPublicKey'] != key) {
- throw const FormatException(
- 'The owner identity has changed. Ask the owner for a new link.',
- );
+ _countOpen(SharedOpen.failed);
+ _show(SharedLinkProblem.changed);
+ return;
}
if (data['online'] != true) {
_countOpen(SharedOpen.offline);
- setState(() {
- _loading = false;
- _error = 'The owner’s machine is offline. This page reconnects when it comes back.';
- });
+ _show(SharedLinkProblem.offline);
_offlineRetry = Timer(
const Duration(seconds: 10),
- () => unawaited(_load()),
+ () => unawaited(_load(quietly: true)),
);
return;
}
@@ -199,13 +225,10 @@ class _SharedAgentPageState extends State<SharedAgentPage> {
_data = data;
_loading = false;
});
- } catch (error) {
+ } catch (_) {
if (mounted && revision == _revision) {
_countOpen(SharedOpen.failed);
- setState(() {
- _loading = false;
- _error = error is FormatException ? error.message : 'Could not open this link. Check your connection and try again.';
- });
+ _show(SharedLinkProblem.failed);
}
}
}
@@ -245,12 +268,14 @@ class _SharedAgentPageState extends State<SharedAgentPage> {
},
),
),
- WebDownloadButton(
- open: (uri) {
- _countAction(SharedAction.getApp);
- return openInNewTab(uri);
- },
- ),
+ // A phone's download is the store bar's.
+ if (!browserHasAppStore())
+ WebDownloadButton(
+ open: (uri) {
+ _countAction(SharedAction.getApp);
+ return openInNewTab(uri);
+ },
+ ),
],
),
),
@@ -279,83 +304,25 @@ class _SharedAgentPageState extends State<SharedAgentPage> {
linkEnvironment: widget.location.environment,
onClose: () => setState(() {
_data = null;
- _error = 'Viewing paused.';
+ _problem = SharedLinkProblem.paused;
}),
onSignIn: _signedIn ? null : _signIn,
onUsage: _countAction,
)
- : Center(
- child: SingleChildScrollView(
- padding: const EdgeInsets.all(24),
- child: ConstrainedBox(
- constraints: const BoxConstraints(maxWidth: 440),
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- Text(
- _loading
- ? 'Opening shared harness…'
- : 'Shared harness',
- style: DesktopChrome.heading(),
- textAlign: TextAlign.center,
- ),
- if (!_loading) ...[
- const SizedBox(height: 12),
- Semantics(
- liveRegion: true,
- child: Text(
- _error ?? 'Shared harness',
- style: DesktopChrome.text(
- size: 13,
- color: DesktopChrome.muted,
- ),
- textAlign: TextAlign.center,
- ),
- ),
- ],
- if (widget.app.lastError != null) ...[
- const SizedBox(height: 12),
- Text(
- widget.app.lastError!,
- style: DesktopChrome.text(
- size: 13,
- color: Theme.of(context).colorScheme.error,
- ),
- textAlign: TextAlign.center,
- ),
- ],
- const SizedBox(height: 20),
- Wrap(
- spacing: 8,
- runSpacing: 8,
- alignment: WrapAlignment.center,
- children: [
- if (_signInRequired)
- DesktopPill(
- label: widget.app.signingIn
- ? 'Signing in…'
- : 'Sign in',
- onPressed: widget.app.signingIn
- ? null
- : _signIn,
- ),
- if (!_loading && !_signInRequired)
- DesktopPill(
- label: 'Retry',
- onPressed: _retry,
- ),
- if (!_loading && _signedIn && _data == null)
- DesktopPill(
- label: 'Switch account',
- onPressed: () =>
- unawaited(widget.app.logout()),
- ),
- ],
- ),
- ],
- ),
- ),
- ),
+ : _loading
+ ? const EmptyState(
+ icon: AppIcons.link2,
+ title: 'Opening shared harness…',
+ )
+ : SharedLinkState(
+ problem: _problem ?? SharedLinkProblem.failed,
+ email: widget.app.currentUser?.email,
+ signingIn: widget.app.signingIn,
+ signInError: widget.app.lastError,
+ onSignIn: _signIn,
+ onSwitchAccount: () => unawaited(widget.app.logout()),
+ onRetry: _retry,
+ onOpenHarness: _openHarness,
),
),
],
diff --git a/desktop/lib/sharing/shared_link_state.dart b/desktop/lib/sharing/shared_link_state.dart
new file mode 100644
index 000000000..9e4bc6663
--- /dev/null
+++ b/desktop/lib/sharing/shared_link_state.dart
@@ -0,0 +1,183 @@
+import 'package:flutter/material.dart';
+
+import '../shared/theme/app_icons.dart';
+import '../shared/theme/app_theme.dart' as grid;
+import '../shared/widgets/empty_state.dart';
+
+/// Why a shared harness link (`/s/…`) shows a page instead of the harness.
+enum SharedLinkProblem {
+ /// The link lost its owner key: copied short, or cut off in a message.
+ incomplete,
+
+ /// Nobody is signed in, and the server wants someone: a private link, or
+ /// one that is gone. It answers both alike, so the page only asks.
+ signIn,
+
+ /// Signed in, and the server took no session: it ended.
+ signInEnded,
+
+ /// Signed in, and the server refused: expired, turned off, or shared with
+ /// another email. It answers all three alike, so the page does too.
+ refused,
+
+ /// The owner's computer is offline; the page reads again by itself.
+ offline,
+
+ /// The server names another owner key than the link pins.
+ changed,
+
+ /// No answer, or one that is not about access.
+ failed,
+
+ /// The reader closed the harness.
+ paused,
+}
+
+/// One state of a shared link as the app's empty state: an icon, a title, one
+/// sentence and a way forward. Never Sign in to someone already signed in, so
+/// a refused link cannot send anyone round the sign-in again, and never
+/// "try again" where trying again cannot help.
+class SharedLinkState extends StatelessWidget {
+ const SharedLinkState({
+ super.key,
+ required this.problem,
+ required this.onSignIn,
+ required this.onSwitchAccount,
+ required this.onRetry,
+ required this.onOpenHarness,
+ this.email,
+ this.signingIn = false,
+ this.signInError,
+ });
+
+ final SharedLinkProblem problem;
+
+ /// The signed-in reader's email, named when a link was refused to it.
+ final String? email;
+ final bool signingIn;
+
+ /// Why the last sign-in failed, under the way forward.
+ final String? signInError;
+ final VoidCallback onSignIn, onSwitchAccount, onRetry, onOpenHarness;
+
+ @override
+ Widget build(BuildContext context) {
+ grid.AppTheme.watch(context);
+ final (icon, title, message) = _words;
+ final (primary, secondary) = _actions;
+ final error = signInError;
+ // In the middle of the window, scrolling only when it is too short.
+ return Center(
+ child: SingleChildScrollView(
+ child: Semantics(
+ liveRegion: true,
+ child: EmptyState(
+ icon: icon,
+ title: title,
+ message: message,
+ action: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ primary,
+ if (secondary != null) ...[
+ const SizedBox(height: 4),
+ secondary,
+ ],
+ if (error != null) ...[
+ const SizedBox(height: 12),
+ ConstrainedBox(
+ constraints: const BoxConstraints(maxWidth: 320),
+ child: Text(
+ error,
+ textAlign: TextAlign.center,
+ style: grid.AppType.body(
+ color: Theme.of(context).colorScheme.error,
+ ),
+ ),
+ ),
+ ],
+ ],
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+
+ (IconData, String, String) get _words => switch (problem) {
+ SharedLinkProblem.incomplete => (
+ AppIcons.unlink,
+ 'This shared link is incomplete',
+ 'Ask the owner to copy the whole link again.',
+ ),
+ SharedLinkProblem.signIn => (
+ AppIcons.lock,
+ 'Sign in to open this shared harness',
+ 'If it was shared with you, sign in with that email.',
+ ),
+ SharedLinkProblem.signInEnded => (
+ AppIcons.lock,
+ 'Your sign-in has ended',
+ 'Sign in again to open this shared harness.',
+ ),
+ SharedLinkProblem.refused => (
+ AppIcons.lock,
+ 'You can’t open this shared harness',
+ 'It may have expired or been turned off, or it was shared with '
+ '${email == null ? 'another email' : 'an email other than $email'}.',
+ ),
+ SharedLinkProblem.offline => (
+ AppIcons.cloudOff,
+ 'The owner’s computer is offline',
+ 'This page opens the harness by itself when it is back.',
+ ),
+ SharedLinkProblem.changed => (
+ AppIcons.shieldOff,
+ 'This link no longer matches its owner',
+ 'It will not open, to keep you safe. Ask the owner for a new link.',
+ ),
+ SharedLinkProblem.failed => (
+ AppIcons.cloudOff,
+ 'Couldn’t open this shared harness',
+ 'Check your connection and try again.',
+ ),
+ SharedLinkProblem.paused => (
+ AppIcons.eye,
+ 'Viewing paused',
+ 'The harness keeps running for its owner.',
+ ),
+ };
+
+ (Widget, Widget?) get _actions {
+ final openHarness = _quiet('Open Harness', onOpenHarness);
+ return switch (problem) {
+ SharedLinkProblem.incomplete || SharedLinkProblem.changed => (
+ _filled('Open Harness', onOpenHarness),
+ null,
+ ),
+ SharedLinkProblem.signIn => (_signInButton('Sign in'), null),
+ SharedLinkProblem.signInEnded => (_signInButton('Sign in again'), null),
+ SharedLinkProblem.refused => (
+ _filled('Switch account', onSwitchAccount),
+ openHarness,
+ ),
+ SharedLinkProblem.offline => (_filled('Check now', onRetry), null),
+ SharedLinkProblem.failed => (_filled('Try again', onRetry), null),
+ SharedLinkProblem.paused => (_filled('Watch again', onRetry), null),
+ };
+ }
+
+ Widget _signInButton(String label) =>
+ _filled(signingIn ? 'Signing in…' : label, signingIn ? null : onSignIn);
+
+ // Padded: a thumb's target on a phone, whatever the button draws.
+ static const _padded = ButtonStyle(
+ tapTargetSize: MaterialTapTargetSize.padded,
+ );
+
+ static Widget _filled(String label, VoidCallback? onPressed) =>
+ FilledButton(style: _padded, onPressed: onPressed, child: Text(label));
+
+ static Widget _quiet(String label, VoidCallback onPressed) =>
+ TextButton(style: _padded, onPressed: onPressed, child: Text(label));
+}
diff --git a/desktop/lib/state/harness_monitor.dart b/desktop/lib/state/harness_monitor.dart
index 68f982061..0410eadd5 100644
--- a/desktop/lib/state/harness_monitor.dart
+++ b/desktop/lib/state/harness_monitor.dart
@@ -6,6 +6,7 @@ import '../core/harness_resources.dart';
import '../core/models.dart';
import '../shared/theme/workspace_bar_style.dart'
show workspaceBarGroupSeparator;
+import '../widgets/pointer_words.dart';
import 'app_state.dart';
import 'harness_sessions.dart';
@@ -83,7 +84,7 @@ class HarnessMonitor extends ChangeNotifier {
String get resourceDetail => summary.resourceDetail;
String get detail =>
- '${live.length} open across connected machines. Click to open Harness Monitor.';
+ '${live.length} open across connected machines. ${clickWord()} to open Harness Monitor.';
void start() {
if (_started || _disposed) return;
@@ -264,10 +265,10 @@ class HarnessMonitorSummary {
'CPU: 100% is one core. RAM includes child processes and shared servers counted once; shared memory pages can overlap.\n'
'GPU: harness process GPU use on supported macOS and Linux NVIDIA drivers. First samples and unavailable counters show —. Cloud model GPU usage is not reported.\n'
'SSD: workspace disk space, shared and nested folders counted once per machine. Files remain after stopping.\n'
- 'Totals include available readings and may be partial. — means unavailable. Click to open Harness Monitor.';
+ 'Totals include available readings and may be partial. — means unavailable. ${clickWord()} to open Harness Monitor.';
String get detail =>
- '$liveCount open across connected machines, including idle and starting harnesses. Click to open Harness Monitor.\n'
+ '$liveCount open across connected machines, including idle and starting harnesses. ${clickWord()} to open Harness Monitor.\n'
'${HarnessResources.explanation}${sharedLabel == null ? '' : '\n$sharedLabel, included once in the session monitor.'}';
}
diff --git a/desktop/lib/state/workspace_chrome.dart b/desktop/lib/state/workspace_chrome.dart
index 6e5533122..fbdb853f8 100644
--- a/desktop/lib/state/workspace_chrome.dart
+++ b/desktop/lib/state/workspace_chrome.dart
@@ -73,6 +73,7 @@ class WorkspaceChrome {
this.compactPaneHeader = false,
this.superTabRecovers = false,
this.superTabReading = const SuperTabReading(),
+ this.subscriptionsNeedComputer = false,
});
/// What a workspace with no host chrome (Desktop) reads: every switch at
@@ -160,6 +161,11 @@ class WorkspaceChrome {
/// full read every 3 s, on screen or not. #180's report, fixes 1, 2a and 3.
final SuperTabReading superTabReading;
+ /// True leaves Subscriptions out of the compact footer while the account
+ /// has no computer, once the machine list has said so: there is no agent
+ /// account to read before one. While the list is on its way it stays.
+ final bool subscriptionsNeedComputer;
+
/// Whether a window [width] wide gets the compact pane header.
bool compactPaneHeaderAt(double width) =>
compactPaneHeader && width < compactBelow;
diff --git a/desktop/lib/super_tabs/client.dart b/desktop/lib/super_tabs/client.dart
index 50bc59b6e..08fa4a34a 100644
--- a/desktop/lib/super_tabs/client.dart
+++ b/desktop/lib/super_tabs/client.dart
@@ -2,6 +2,7 @@ import 'dart:async';
import 'dart:convert';
import 'package:clock/clock.dart';
+import 'package:flutter/foundation.dart';
import '../core/local_key_value_store.dart';
import 'attachment_upload.dart';
@@ -112,6 +113,22 @@ class SuperTabClient {
unawaited(_views.claim(_account).catchError((Object _) {}));
}
+ /// Moves each time a Swarm's view is kept on this device: Settings' Clear
+ /// now stops saying Cleared once one is kept again.
+ ValueListenable<int> get viewsKept => _viewsKept;
+ final _viewsKept = ValueNotifier(0);
+
+ /// Settings' Clear now: the views this device keeps go, and none waiting
+ /// for its 15 s turn is written after. A Swarm is kept again once what it
+ /// shows changes.
+ Future<void> clearSavedViews() {
+ for (final timer in _viewSaves.values) {
+ timer.cancel();
+ }
+ _viewSaves.clear();
+ return _views.clear(_account);
+ }
+
/// How often a Swarm's view may be written while it keeps changing: each
/// write is a few hundred KB into the browser's storage.
static const _viewSaveEvery = Duration(seconds: 15);
@@ -138,7 +155,14 @@ class SuperTabClient {
if (account == null || view == null) return;
_viewSavedAt[id] = clock.now();
_viewVersions[id] = controller!.viewVersion;
- unawaited(_views.write(account, id, view).catchError((Object _) {}));
+ unawaited(
+ _views
+ .write(account, id, view)
+ .then((kept) {
+ if (kept) _viewsKept.value++;
+ })
+ .catchError((Object _) {}),
+ );
}
void _applyAway() {
diff --git a/desktop/lib/super_tabs/saved_view.dart b/desktop/lib/super_tabs/saved_view.dart
index 6ae7560a3..5157db943 100644
--- a/desktop/lib/super_tabs/saved_view.dart
+++ b/desktop/lib/super_tabs/saved_view.dart
@@ -102,13 +102,14 @@ class SuperTabSavedViews {
}
});
- /// Keeps [view] for [tabId]; one over the cap is not kept, and the older
- /// one goes with it rather than staying behind, older still.
- Future<void> write(String account, String tabId, Map<String, dynamic> view) =>
+ /// Keeps [view] for [tabId], and says whether it was kept; one over the
+ /// cap is not kept, and the older one goes with it rather than staying
+ /// behind, older still.
+ Future<bool> write(String account, String tabId, Map<String, dynamic> view) =>
_serial(() async {
// Only for the account using this device: after a sign-out in
// another tab, or another account's claim, a late write keeps nothing.
- if (await storage.read(_owner) != account) return;
+ if (await storage.read(_owner) != account) return false;
final state = view['state'] as Map<String, dynamic>;
final text = jsonEncode({
...view,
@@ -119,10 +120,11 @@ class SuperTabSavedViews {
});
if (_utf8Length(text) > maxBytes) {
await _forget(account, tabId);
- return;
+ return false;
}
await storage.write(_key(account, tabId), text);
await _use(account, tabId);
+ return true;
});
Future<void> forget(String account, String tabId) =>
@@ -145,6 +147,16 @@ class SuperTabSavedViews {
await storage.delete(_index(account));
}
+ /// Clear now: every view this device keeps, for [account] and for any
+ /// account that used it before and was not forgotten yet. Whose device it
+ /// is stays as it was, so the Swarms [account] opens next are kept again.
+ Future<void> clear(String? account) => _serial(() async {
+ final owner = await storage.read(_owner);
+ for (final kept in {owner, account}.whereType<String>()) {
+ await _forgetAccount(kept);
+ }
+ });
+
/// [account] (null when signed out) is the one using this device now: the
/// views of any other account that used it, before a reload too, go.
Future<void> claim(String? account) => _serial(() async {
diff --git a/desktop/lib/super_tabs/view.dart b/desktop/lib/super_tabs/view.dart
index d42d4dea1..c6b9ccfc2 100644
--- a/desktop/lib/super_tabs/view.dart
+++ b/desktop/lib/super_tabs/view.dart
@@ -910,10 +910,22 @@ class _SuperTabViewState extends State<SuperTabView>
children: [
Flexible(child: _title(group)),
const SizedBox(width: 8),
- Text(
- 'Updating…',
- key: const ValueKey('super-updating'),
- style: DesktopChrome.metadata(),
+ // Where the copy is; how long it stays and where
+ // it is cleared, a hover or a long press away.
+ Flexible(
+ child: Tooltip(
+ message:
+ 'This browser keeps a copy of the Super '
+ 'Tabs you open until you sign out. '
+ 'Settings ▸ Account clears it now.',
+ child: Text(
+ 'Saved in this browser · Updating…',
+ key: const ValueKey('super-updating'),
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: DesktopChrome.metadata(),
+ ),
+ ),
),
],
)
diff --git a/desktop/lib/web/shell/web_chrome.dart b/desktop/lib/web/shell/web_chrome.dart
index f72bb857c..bdcfc67be 100644
--- a/desktop/lib/web/shell/web_chrome.dart
+++ b/desktop/lib/web/shell/web_chrome.dart
@@ -56,4 +56,5 @@ WorkspaceChrome _webWorkspaceChrome(AppNotifier app) => WorkspaceChrome(
messagesWithState: true,
drawsSaved: true,
),
+ subscriptionsNeedComputer: true,
);
diff --git a/desktop/lib/web/shell/web_store_banner.dart b/desktop/lib/web/shell/web_store_banner.dart
index ebd99afa1..36d3d616a 100644
--- a/desktop/lib/web/shell/web_store_banner.dart
+++ b/desktop/lib/web/shell/web_store_banner.dart
@@ -2,6 +2,7 @@ import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
+import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../core/harness_file_store.dart';
import '../../core/local_key_value_store.dart';
@@ -9,6 +10,7 @@ import '../../core/phone_app_links.dart';
import '../../shared/theme/app_icons.dart';
import '../../shared/theme/app_theme.dart' as grid;
import '../../shared/theme/app_type.dart';
+import '../../state/app_state.dart';
import '../../widgets/web_download_button.dart' show openInNewTab;
import 'web_hidden_under_keyboard.dart';
@@ -34,10 +36,15 @@ class WebStoreFrame extends StatefulWidget {
required this.child,
this.storage,
this.open = openInNewTab,
+ this.quiet = false,
});
final Widget child;
+ /// True draws Get the app outlined rather than filled, so it does not
+ /// compete with the page's own primary action (sign-in).
+ final bool quiet;
+
/// Where a closed bar is remembered; the browser's own store when absent.
final LocalKeyValueStore? storage;
@@ -88,6 +95,7 @@ class _WebStoreFrameState extends State<WebStoreFrame> {
if (shown)
WebHiddenUnderKeyboard(
child: _WebStoreBar(
+ quiet: widget.quiet,
onOpen: () => unawaited(widget.open(link)),
onDismiss: _dismiss,
),
@@ -107,8 +115,13 @@ class _WebStoreFrameState extends State<WebStoreFrame> {
/// Close, what the app is for, and the way to it.
class _WebStoreBar extends StatelessWidget {
- const _WebStoreBar({required this.onOpen, required this.onDismiss});
+ const _WebStoreBar({
+ required this.quiet,
+ required this.onOpen,
+ required this.onDismiss,
+ });
+ final bool quiet;
final VoidCallback onOpen;
final VoidCallback onDismiss;
@@ -180,16 +193,28 @@ class _WebStoreBar extends StatelessWidget {
),
),
const SizedBox(width: 8),
- FilledButton(
- key: const ValueKey('web-store-banner-open'),
- onPressed: onOpen,
- // Narrower than a form's button: the words beside it need
- // the width on a phone.
- style: FilledButton.styleFrom(
- padding: const EdgeInsets.symmetric(horizontal: 16),
+ // Narrower than a form's button: the words beside it need
+ // the width on a phone. Padded: a thumb's target.
+ if (quiet)
+ OutlinedButton(
+ key: const ValueKey('web-store-banner-open'),
+ onPressed: onOpen,
+ style: OutlinedButton.styleFrom(
+ padding: const EdgeInsets.symmetric(horizontal: 16),
+ tapTargetSize: MaterialTapTargetSize.padded,
+ ),
+ child: const Text('Get the app'),
+ )
+ else
+ FilledButton(
+ key: const ValueKey('web-store-banner-open'),
+ onPressed: onOpen,
+ style: FilledButton.styleFrom(
+ padding: const EdgeInsets.symmetric(horizontal: 16),
+ tapTargetSize: MaterialTapTargetSize.padded,
+ ),
+ child: const Text('Get the app'),
),
- child: const Text('Get the app'),
- ),
],
),
),
@@ -198,3 +223,31 @@ class _WebStoreBar extends StatelessWidget {
);
}
}
+
+/// [WebStoreFrame] as the app draws it: quiet until someone is signed in, so
+/// on a first visit the sign-in buttons are the page's only filled actions.
+/// The bar keeps its place at the top, where a phone's app banner is looked
+/// for and closed; below the sign-in it would sit under Safari's toolbar and
+/// push the page's own words off a small phone.
+class WebAppStoreFrame extends ConsumerWidget {
+ const WebAppStoreFrame({super.key, required this.child, this.storage});
+
+ final Widget child;
+
+ /// Where a closed bar is remembered; the browser's own store when absent.
+ final LocalKeyValueStore? storage;
+
+ @override
+ Widget build(BuildContext context, WidgetRef ref) {
+ final app = ref.watch(appStateProvider);
+ return ListenableBuilder(
+ listenable: app,
+ builder: (context, child) => WebStoreFrame(
+ storage: storage,
+ quiet: app.status != AppStatus.authenticated,
+ child: child!,
+ ),
+ child: child,
+ );
+ }
+}
diff --git a/desktop/lib/web/web_entry.dart b/desktop/lib/web/web_entry.dart
index 13f57214b..7fedc6c3a 100644
--- a/desktop/lib/web/web_entry.dart
+++ b/desktop/lib/web/web_entry.dart
@@ -26,7 +26,7 @@ void prepareConsole() => prepareWebConsole();
/// sends it to the Harness app in its store. Above the Navigator, so every
/// screen and route under it shows no key hints: the web is mouse-first.
Widget appFrame(Widget app) => WebFocusRing(
- child: WebStoreFrame(child: KeyHints(visible: false, child: app)),
+ child: WebAppStoreFrame(child: KeyHints(visible: false, child: app)),
);
/// A browser reaches a machine through the relay, so each connection gets a
diff --git a/desktop/lib/widgets/machines_panel.dart b/desktop/lib/widgets/machines_panel.dart
index 38986d5c0..32b59a4c4 100644
--- a/desktop/lib/widgets/machines_panel.dart
+++ b/desktop/lib/widgets/machines_panel.dart
@@ -27,6 +27,7 @@ import 'link_another_machine_dialog.dart'
import 'link_machine_dialog.dart';
import 'machine_actions.dart';
import 'new_device_notice.dart' show DeviceListReviewLine;
+import 'pointer_words.dart';
import 'terminal_name_prompt.dart';
import 'terminal_prompt.dart';
import 'transient_menus.dart';
@@ -612,7 +613,10 @@ class _MachinesPanelState extends State<_MachinesPanel>
const SizedBox(height: 16),
const Text('2. Open Machines and choose Set password.'),
const SizedBox(height: 6),
- const _Detail('Back here, click Connect and enter that password.'),
+ _Detail(
+ 'Back here, ${clickWord(capital: false)} Connect and enter that '
+ 'password.',
+ ),
const SizedBox(height: 12),
_button(_server ? 'Hide server setup' : 'Set up a server…', () {
setState(() => _server = !_server);
diff --git a/desktop/lib/widgets/pointer_words.dart b/desktop/lib/widgets/pointer_words.dart
new file mode 100644
index 000000000..2af2bd871
--- /dev/null
+++ b/desktop/lib/widgets/pointer_words.dart
@@ -0,0 +1,20 @@
+import 'package:flutter/foundation.dart';
+
+/// What a person does to a control, said as they do it: "Click" with a mouse,
+/// "Tap" on a phone or tablet's browser. Desktop runs on macOS, Linux and
+/// Windows only, so its wording never changes.
+String clickWord({TargetPlatform? platform, bool capital = true}) =>
+ switch ((isPhoneOrTablet(platform), capital)) {
+ (true, true) => 'Tap',
+ (true, false) => 'tap',
+ (false, true) => 'Click',
+ (false, false) => 'click',
+ };
+
+/// Whether [platform] (this one when absent) is a phone's or a tablet's, iOS
+/// or Android: a browser there is used by touch. Desktop never is.
+bool isPhoneOrTablet([TargetPlatform? platform]) =>
+ switch (platform ?? defaultTargetPlatform) {
+ TargetPlatform.iOS || TargetPlatform.android => true,
+ _ => false,
+ };
diff --git a/desktop/lib/widgets/web_download_button.dart b/desktop/lib/widgets/web_download_button.dart
index 3022999fe..77271c0f3 100644
--- a/desktop/lib/widgets/web_download_button.dart
+++ b/desktop/lib/widgets/web_download_button.dart
@@ -1,10 +1,10 @@
-import 'package:flutter/foundation.dart' show defaultTargetPlatform;
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
import '../core/desktop_download.dart';
import '../shared/theme/app_theme.dart' as grid;
import '../shared/theme/workspace_bar_style.dart';
+import 'pointer_words.dart';
import 'workspace_bar_control.dart';
import 'workspace_share_button.dart';
@@ -19,10 +19,7 @@ Future<bool> openInNewTab(Uri uri) =>
/// (`web/shell/web_store_banner.dart`): a computer's download is no use there,
/// so [WebDownloadButton] is left out (audit finding S9).
bool browserHasAppStore([TargetPlatform? platform]) =>
- switch (platform ?? defaultTargetPlatform) {
- TargetPlatform.iOS || TargetPlatform.android => true,
- _ => false,
- };
+ isPhoneOrTablet(platform);
/// The Harness product page.
final harnessAppPage = Uri.parse('https://www.autonomous.ai/harness-app');
diff --git a/desktop/test/harness_monitor_summary_test.dart b/desktop/test/harness_monitor_summary_test.dart
index bb94f5f74..796079d86 100644
--- a/desktop/test/harness_monitor_summary_test.dart
+++ b/desktop/test/harness_monitor_summary_test.dart
@@ -1,3 +1,4 @@
+import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:harness/auth/auth_session.dart';
@@ -76,7 +77,13 @@ void main() {
await monitor.refresh();
app.changed();
expect(monitor.label, 'Harnesses 1');
+ // A computer clicks; a phone's browser taps (audit finding S8).
+ debugDefaultTargetPlatformOverride = TargetPlatform.macOS;
expect(monitor.detail, contains('Click to open Harness Monitor'));
+ debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
+ expect(monitor.detail, contains('Tap to open Harness Monitor'));
+ expect(monitor.detail, isNot(contains('Click')));
+ debugDefaultTargetPlatformOverride = null;
expect(app.requests, isEmpty);
});
test('one snapshot preserves partial totals, shared servers, machine scope and nested storage', () async {
diff --git a/desktop/test/machines_panel_test.dart b/desktop/test/machines_panel_test.dart
index a48c80fee..af54b34aa 100644
--- a/desktop/test/machines_panel_test.dart
+++ b/desktop/test/machines_panel_test.dart
@@ -330,6 +330,8 @@ void main() {
visible(find.text('1. Open Harness on your other computer.'));
visible(find.text('Download Harness'));
visible(find.text('2. Open Machines and choose Set password.'));
+ // flutter_test runs as Android: a phone's word (audit finding S8).
+ visible(find.text('Back here, tap Connect and enter that password.'));
visible(find.text('Set up a server…'));
await capture(tester, 'machines-clean-setup', panelOnly: true);
diff --git a/desktop/test/pointer_words_test.dart b/desktop/test/pointer_words_test.dart
new file mode 100644
index 000000000..0ee476beb
--- /dev/null
+++ b/desktop/test/pointer_words_test.dart
@@ -0,0 +1,25 @@
+// What a person does to a control, in words: Click with a mouse, Tap on a
+// phone or tablet's browser. Desktop runs on macOS, Linux and Windows only,
+// so its wording never changes (audit finding S8).
+import 'package:flutter/foundation.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness/widgets/pointer_words.dart';
+
+void main() {
+ tearDown(() => debugDefaultTargetPlatformOverride = null);
+
+ test('a phone or tablet taps; a computer clicks', () {
+ for (final touch in [TargetPlatform.iOS, TargetPlatform.android]) {
+ expect(clickWord(platform: touch), 'Tap', reason: '$touch');
+ expect(clickWord(platform: touch, capital: false), 'tap');
+ }
+ for (final computer in [
+ TargetPlatform.macOS,
+ TargetPlatform.linux,
+ TargetPlatform.windows,
+ ]) {
+ expect(clickWord(platform: computer), 'Click', reason: '$computer');
+ expect(clickWord(platform: computer, capital: false), 'click');
+ }
+ });
+}
diff --git a/desktop/test/settings_saved_super_tabs_test.dart b/desktop/test/settings_saved_super_tabs_test.dart
new file mode 100644
index 000000000..038d47043
--- /dev/null
+++ b/desktop/test/settings_saved_super_tabs_test.dart
@@ -0,0 +1,174 @@
+// Settings ▸ Account says, where a person looks for it, that this browser
+// keeps a copy of the Super Tabs it opened until sign-out, and clears it now.
+// Only where views are kept (the web's reading): Desktop keeps none, and its
+// Account page is as it was.
+import 'dart:async';
+import 'dart:io' show FileSystemException;
+
+import 'package:flutter/material.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness/auth/auth_session.dart';
+import 'package:harness/core/config.dart';
+import 'package:harness/settings/sections/account_section.dart';
+import 'package:harness/settings/sections/saved_super_tabs_row.dart';
+import 'package:harness/state/app_state.dart';
+import 'package:harness/state/pane_layout_store.dart';
+import 'package:harness/super_tabs/client.dart';
+import 'package:harness/super_tabs/reading.dart';
+import 'package:harness/super_tabs/saved_view.dart';
+
+import 'support/super_tab_fixture.dart';
+import 'super_tab_saved_view_test.dart' show savedViewForTest;
+import 'swarm_state_test.dart' show MemoryStore;
+
+void main() {
+ late MemoryStore store;
+ setUp(() => store = MemoryStore());
+
+ Future<AppNotifier> mount(
+ WidgetTester tester, {
+ SuperTabReading reading = const SuperTabReading(drawsSaved: true),
+ }) async {
+ final app = AppNotifier(
+ config: AppConfig.dev,
+ authSession: AuthSession(),
+ configStore: null,
+ paneLayoutStore: PaneLayoutStore(storage: store),
+ )..signedIn = true;
+ addTearDown(app.dispose);
+ app.superTabs.reading = reading;
+ await tester.pumpWidget(
+ MaterialApp(
+ home: Scaffold(body: AccountSection(notifier: app)),
+ ),
+ );
+ return app;
+ }
+
+ Iterable<String> viewKeys() =>
+ store.values.keys.where((k) => k.startsWith('super_tab.view'));
+
+ testWidgets('says what this browser keeps, and until when', (tester) async {
+ await mount(tester);
+ expect(find.text('Super Tabs in this browser'), findsOneWidget);
+ expect(
+ find.text(
+ 'This browser keeps a copy of the Super Tabs you open, so they show '
+ 'at once. Signing out removes it.',
+ ),
+ findsOneWidget,
+ );
+ });
+
+ testWidgets('Clear now removes the copy, and says it did', (tester) async {
+ await tester.runAsync(() async {
+ final views = SuperTabSavedViews(store);
+ await views.claim('owner');
+ await views.write('owner', 'tab', savedViewForTest());
+ });
+ await mount(tester);
+ expect(viewKeys(), isNotEmpty);
+ final clear = find.widgetWithText(OutlinedButton, 'Clear now');
+ expect(tester.getSize(clear).height, greaterThanOrEqualTo(44));
+ await tester.tap(clear);
+ await tester.runAsync(() => Future<void>.delayed(Duration.zero));
+ await tester.pump();
+ expect(viewKeys(), isEmpty);
+ expect(find.widgetWithText(OutlinedButton, 'Cleared'), findsOneWidget);
+ });
+
+ testWidgets('Desktop keeps no copy, and its Account page has no such row', (
+ tester,
+ ) async {
+ await mount(tester, reading: const SuperTabReading());
+ expect(find.text('Super Tabs in this browser'), findsNothing);
+ expect(find.text('Clear now'), findsNothing);
+ expect(find.text('Your Harness sign-in on this computer.'), findsOneWidget);
+ });
+
+ group('Clear now says only what happened', () {
+ /// The row on its own, over [client].
+ Future<void> row(WidgetTester tester, SuperTabClient client) =>
+ tester.pumpWidget(
+ MaterialApp(
+ home: Scaffold(body: SavedSuperTabsRow(superTabs: client)),
+ ),
+ );
+
+ Future<void> clear(WidgetTester tester) async {
+ await tester.tap(find.widgetWithText(OutlinedButton, 'Clear now'));
+ await tester.pump();
+ await tester.pump();
+ }
+
+ testWidgets('a browser that refuses says so, and keeps Clear now', (
+ tester,
+ ) async {
+ final client = SuperTabClient(
+ transport: (method, path, {body}) async => null,
+ storage: _RefusingStore(),
+ discoveryInterval: Duration.zero,
+ )..reading = const SuperTabReading(drawsSaved: true);
+ addTearDown(client.dispose);
+ await row(tester, client);
+ await clear(tester);
+ expect(find.text('Cleared'), findsNothing);
+ expect(
+ find.text('This browser did not let Harness clear it. Try again.'),
+ findsOneWidget,
+ );
+ expect(find.widgetWithText(OutlinedButton, 'Clear now'), findsOneWidget);
+ });
+
+ testWidgets('Cleared goes once a Super Tab is kept again', (tester) async {
+ final server = ConversationServer()..append('Hello');
+ final client = SuperTabClient(
+ transport: (method, path, {body}) async =>
+ Uri.parse(path).path == '/api/super-tabs'
+ ? {
+ 'tabs': [
+ {'id': 'tab', 'name': 'Pilot'},
+ ],
+ 'next': null,
+ }
+ : server.request(method, path, body: body),
+ storage: store,
+ discoveryInterval: Duration.zero,
+ )..reading = _web;
+ addTearDown(client.dispose);
+ client
+ ..bind('owner')
+ ..show('tab');
+ unawaited(client.open('tab'));
+ await tester.pump(const Duration(seconds: 1));
+ await row(tester, client);
+ await clear(tester);
+ expect(find.widgetWithText(OutlinedButton, 'Cleared'), findsOneWidget);
+ expect(viewKeys(), isEmpty);
+ // The open Super Tab changes, and its copy is kept again.
+ server.append('Later');
+ await tester.pump(const Duration(seconds: 20));
+ client.show(null);
+ await tester.pump();
+ await tester.pump();
+ expect(viewKeys(), isNotEmpty);
+ expect(find.text('Cleared'), findsNothing);
+ expect(find.widgetWithText(OutlinedButton, 'Clear now'), findsOneWidget);
+ });
+ });
+}
+
+/// A browser that refuses its storage (full, or private mode).
+class _RefusingStore extends MemoryStore {
+ @override
+ Future<String?> read(String key) async =>
+ throw const FileSystemException('refused');
+}
+
+/// The web's reading, as `web_chrome.dart` sets it.
+const _web = SuperTabReading(
+ quietPoll: Duration(seconds: 15),
+ pausesAway: true,
+ messagesWithState: true,
+ drawsSaved: true,
+);
diff --git a/desktop/test/shared_agent_page_test.dart b/desktop/test/shared_agent_page_test.dart
index 36b23fe6e..67c6d0abd 100644
--- a/desktop/test/shared_agent_page_test.dart
+++ b/desktop/test/shared_agent_page_test.dart
@@ -1,48 +1,70 @@
+import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'dart:ui' as ui;
import 'package:dio/dio.dart';
+import 'package:flutter/foundation.dart';
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/auth/sign_in_provider.dart';
import 'package:harness/core/config.dart';
import 'package:harness/measurement/hub_usage.dart';
import 'package:harness/sharing/shared_agent_location.dart';
import 'package:harness/sharing/shared_agent_page.dart';
import 'package:harness/sharing/shared_harness_panel.dart';
+import 'package:harness/core/models.dart';
+import 'package:harness/shared/theme/app_icons.dart';
import 'package:harness/shared/theme/app_theme.dart' as grid;
+import 'package:harness/shared/widgets/empty_state.dart';
import 'package:harness/state/app_state.dart';
import 'package:harness/widgets/web_download_button.dart';
import 'package:url_launcher/link.dart';
import 'support/real_fonts.dart';
+/// Counts sign-ins instead of starting one.
+class _App extends AppNotifier {
+ _App()
+ : super(
+ config: AppConfig.dev,
+ authSession: AuthSession(),
+ configStore: null,
+ );
+
+ int logins = 0;
+ @override
+ Future<void> login([SignInProvider? provider]) async => logins++;
+}
+
void main() {
setUpAll(loadRealFonts);
const id = '11111111-1111-4111-8111-111111111111';
final key = base64Encode(List.filled(32, 1));
- late AppNotifier app;
+ late _App app;
late Dio dio;
+ // While set, the next read waits for it: a slow answer.
+ Completer<void>? hold;
late List<RequestOptions> requests;
late int status;
late Map<String, dynamic> metadata;
+ late int harnessOpens;
setUp(() {
- app = AppNotifier(
- config: AppConfig.dev,
- authSession: AuthSession(),
- configStore: null,
- );
+ app = _App();
+ hold = null;
requests = [];
status = 200;
metadata = {'ownerPublicKey': key, 'online': false};
+ harnessOpens = 0;
dio = Dio()
..interceptors.add(
InterceptorsWrapper(
- onRequest: (request, handler) {
+ onRequest: (request, handler) async {
requests.add(request);
+ if (hold case final wait?) await wait.future;
handler.resolve(
Response(
requestOptions: request,
@@ -90,6 +112,7 @@ void main() {
dio: dio,
location: SharedAgentLocation(id, pinnedKey, environment),
usage: usage,
+ openHarness: () async => harnessOpens++,
),
),
),
@@ -136,54 +159,201 @@ void main() {
await tester.pumpWidget(const SizedBox());
});
- testWidgets('incomplete and changed owner identities never open a viewer', (
+ /// The state's one way forward: a filled button a thumb can hit.
+ Finder primary(String label) => find.widgetWithText(FilledButton, label);
+
+ void expectThumbSized(WidgetTester tester, Finder button) {
+ expect(button, findsOneWidget);
+ final size = tester.getSize(button);
+ expect(size.height, greaterThanOrEqualTo(44));
+ expect(size.width, greaterThanOrEqualTo(44));
+ }
+
+ /// No state that cannot be helped by trying again offers it.
+ void expectNoRetry() {
+ for (final label in ['Retry', 'Try again', 'Check now']) {
+ expect(find.text(label), findsNothing, reason: label);
+ }
+ }
+
+ group('an incomplete link', () {
+ testWidgets('says what to do in one sentence and offers Open Harness', (
+ tester,
+ ) async {
+ await show(tester);
+ expect(find.text('This shared link is incomplete'), findsOneWidget);
+ expect(
+ find.text('Ask the owner to copy the whole link again.'),
+ findsOneWidget,
+ );
+ expectNoRetry();
+ expect(find.text('Sign in'), findsNothing);
+ expect(requests, isEmpty);
+ expect(find.byType(SharedHarnessPanel), findsNothing);
+ expectThumbSized(tester, primary('Open Harness'));
+ await tester.tap(primary('Open Harness'));
+ await tester.pump();
+ expect(harnessOpens, 1);
+ await tester.pumpWidget(const SizedBox());
+ });
+
+ testWidgets('is drawn as the app\'s empty state, with its icon', (
+ tester,
+ ) async {
+ await show(tester);
+ expect(
+ find.descendant(
+ of: find.byType(EmptyState),
+ matching: find.text('This shared link is incomplete'),
+ ),
+ findsOneWidget,
+ );
+ expect(find.byIcon(AppIcons.unlink), findsOneWidget);
+ await tester.pumpWidget(const SizedBox());
+ });
+ });
+
+ testWidgets('a changed owner identity never opens a viewer', (tester) async {
+ metadata['ownerPublicKey'] = base64Encode(List.filled(32, 2));
+ await show(tester, pinnedKey: key);
+ expect(find.text('This link no longer matches its owner'), findsOneWidget);
+ expect(find.byType(SharedHarnessPanel), findsNothing);
+ expect(requests.single.headers['x-autonomous-env'], 'stag');
+ expect(requests.single.headers.containsKey('Authorization'), isFalse);
+ expectNoRetry();
+ expectThumbSized(tester, primary('Open Harness'));
+ await tester.pumpWidget(const SizedBox());
+ });
+
+ testWidgets('a signed-out visitor is asked to sign in, not told why', (
tester,
) async {
- await show(tester);
- expect(find.textContaining('This link is incomplete'), findsOneWidget);
- expect(requests, isEmpty);
+ // A 401 to nobody signed in: private, or gone; the server says alike.
+ status = 401;
+ app.status = AppStatus.unauthenticated;
+ await show(tester, pinnedKey: key);
+ expect(find.text('Sign in to open this shared harness'), findsOneWidget);
+ expect(
+ find.text('If it was shared with you, sign in with that email.'),
+ findsOneWidget,
+ );
+ expect(find.textContaining('private'), findsNothing);
+ expect(find.byIcon(AppIcons.lock), findsOneWidget);
+ expectThumbSized(tester, primary('Sign in'));
+ expectNoRetry();
expect(find.byType(SharedHarnessPanel), findsNothing);
+ await tester.tap(primary('Sign in'));
+ await tester.pump();
+ expect(app.logins, 1);
await tester.pumpWidget(const SizedBox());
- metadata['ownerPublicKey'] = base64Encode(List.filled(32, 2));
+ });
+
+ testWidgets('a signed-in 401 says the sign-in ended, and signs in again', (
+ tester,
+ ) async {
+ // The server answers 401 only when it took no session at all.
+ status = 401;
+ app
+ ..status = AppStatus.authenticated
+ ..currentUser = const CurrentUserProfile(
+ name: 'Jamie',
+ email: '[email protected]',
+ );
await show(tester, pinnedKey: key);
+ expect(find.text('Your sign-in has ended'), findsOneWidget);
expect(
- find.textContaining('The owner identity has changed'),
+ find.text('Sign in again to open this shared harness.'),
findsOneWidget,
);
- expect(find.byType(SharedHarnessPanel), findsNothing);
- expect(requests.single.headers['x-autonomous-env'], 'stag');
- expect(requests.single.headers.containsKey('Authorization'), isFalse);
+ expect(find.textContaining('another email'), findsNothing);
+ expect(find.textContaining('an email other than'), findsNothing);
+ expectThumbSized(tester, primary('Sign in again'));
+ expectNoRetry();
+ await tester.tap(primary('Sign in again'));
+ await tester.pump();
+ expect(app.logins, 1);
+ await tester.pumpWidget(const SizedBox());
+ });
+
+ group('a link refused to a signed-in reader', () {
+ for (final refusal in [403, 404]) {
+ testWidgets('($refusal) never asks to sign in again', (tester) async {
+ status = refusal;
+ app
+ ..status = AppStatus.authenticated
+ ..currentUser = const CurrentUserProfile(
+ name: 'Jamie',
+ email: '[email protected]',
+ );
+ await show(tester, pinnedKey: key);
+ expect(
+ find.text('You can\u2019t open this shared harness'),
+ findsOneWidget,
+ );
+ // Expired, turned off or another email: the server answers alike.
+ expect(
+ find.text(
+ 'It may have expired or been turned off, or it was shared with '
+ 'an email other than [email protected].',
+ ),
+ findsOneWidget,
+ );
+ expect(find.text('Sign in'), findsNothing);
+ expectNoRetry();
+ expectThumbSized(tester, primary('Switch account'));
+ final open = find.widgetWithText(TextButton, 'Open Harness');
+ expectThumbSized(tester, open);
+ await tester.tap(open);
+ await tester.pump();
+ expect(harnessOpens, 1);
+ await tester.pumpWidget(const SizedBox());
+ });
+ }
+ });
+
+ testWidgets('a server error is a failed read, not a refusal', (tester) async {
+ status = 502;
+ await show(tester, pinnedKey: key);
+ expect(find.text('Couldn\u2019t open this shared harness'), findsOneWidget);
+ expect(find.text('Check your connection and try again.'), findsOneWidget);
+ expectThumbSized(tester, primary('Try again'));
+ await tester.tap(primary('Try again'));
+ await tester.pump(const Duration(milliseconds: 50));
+ expect(requests.length, 2);
+ await tester.pumpWidget(const SizedBox());
+ });
+
+ testWidgets('the offline page re-reads quietly, without Opening', (
+ tester,
+ ) async {
+ await show(tester, pinnedKey: key);
+ expect(find.text('The owner\u2019s computer is offline'), findsOneWidget);
+ hold = Completer<void>();
+ await tester.pump(const Duration(seconds: 10));
+ await tester.pump();
+ expect(requests.length, 2);
+ // Waiting on the second read, the page is as it was: nothing new to say.
+ expect(find.text('Opening shared harness…'), findsNothing);
+ expect(find.text('The owner\u2019s computer is offline'), findsOneWidget);
+ hold!.complete();
+ hold = null;
+ await tester.pump();
+ await tester.pump();
+ expect(find.text('The owner\u2019s computer is offline'), findsOneWidget);
await tester.pumpWidget(const SizedBox());
});
testWidgets(
- 'private and denied links show access guidance without opening a viewer',
+ 'offline links retry automatically and stop retrying when closed',
(tester) async {
- status = 401;
- await show(tester, pinnedKey: key);
- expect(
- find.textContaining('Sign in with an invited email'),
- findsOneWidget,
- );
- expect(find.widgetWithText(TextButton, 'Sign in'), findsOneWidget);
- expect(find.byType(SharedHarnessPanel), findsNothing);
- await tester.pumpWidget(const SizedBox());
- status = 403;
await show(tester, pinnedKey: key);
+ expect(find.text('The owner\u2019s computer is offline'), findsOneWidget);
expect(
- find.textContaining('your email has not been invited'),
+ find.text('This page opens the harness by itself when it is back.'),
findsOneWidget,
);
- expect(find.byType(SharedHarnessPanel), findsNothing);
- await tester.pumpWidget(const SizedBox());
- },
- );
-
- testWidgets(
- 'offline links retry automatically and stop retrying when closed',
- (tester) async {
- await show(tester, pinnedKey: key);
- expect(find.textContaining('machine is offline'), findsOneWidget);
+ expect(find.byIcon(AppIcons.cloudOff), findsOneWidget);
+ expectThumbSized(tester, primary('Check now'));
expect(find.byType(SharedHarnessPanel), findsNothing);
expect(requests.length, 1);
await tester.pump(const Duration(seconds: 10));
@@ -202,6 +372,37 @@ void main() {
},
);
+ testWidgets('a state sits in the middle of a computer\'s window', (
+ tester,
+ ) async {
+ await show(tester, size: const Size(1440, 900));
+ final title = tester.getCenter(find.text('This shared link is incomplete'));
+ expect(title.dy, inInclusiveRange(300, 600));
+ expect(title.dx, closeTo(720, 1));
+ await tester.pumpWidget(const SizedBox());
+ });
+
+ testWidgets('a phone gets one download, the store bar\'s', (tester) async {
+ debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
+ await show(tester);
+ expect(find.byType(WebDownloadButton), findsNothing);
+ await tester.pumpWidget(const SizedBox());
+ debugDefaultTargetPlatformOverride = TargetPlatform.macOS;
+ await show(tester);
+ expect(find.byType(WebDownloadButton), findsOneWidget);
+ await tester.pumpWidget(const SizedBox());
+ debugDefaultTargetPlatformOverride = null;
+ });
+
+ test('Open Harness goes to the root of the link\'s own site', () {
+ expect(
+ SharedAgentLocation.workspaceOf(
+ Uri.parse('https://harness.example/s/$id?env=stag#key=$key'),
+ ),
+ Uri.parse('https://harness.example/'),
+ );
+ });
+
for (final brightness in Brightness.values) {
for (final scale in [1.0, 2.0]) {
testWidgets(
@@ -217,10 +418,10 @@ void main() {
);
await tester.pumpAndSettle();
expect(
- find.textContaining('Sign in with an invited email'),
+ find.text('Sign in to open this shared harness'),
findsOneWidget,
);
- final signIn = find.widgetWithText(TextButton, 'Sign in');
+ final signIn = find.widgetWithText(FilledButton, 'Sign in');
await tester.ensureVisible(signIn);
await tester.pumpAndSettle();
expect(signIn.hitTestable(), findsOneWidget);
@@ -245,7 +446,7 @@ void main() {
await show(tester, pinnedKey: key, environment: 'prod', usage: usage);
await tester.pump(const Duration(seconds: 10));
await tester.pump(const Duration(milliseconds: 50));
- await tester.tap(find.widgetWithText(TextButton, 'Retry'));
+ await tester.tap(find.widgetWithText(FilledButton, 'Check now'));
await tester.pump(const Duration(milliseconds: 50));
usage.flush();
expect(requests.length, greaterThanOrEqualTo(3));
diff --git a/desktop/test/super_tab_saved_view_test.dart b/desktop/test/super_tab_saved_view_test.dart
index 9fe843ba9..14c7782cb 100644
--- a/desktop/test/super_tab_saved_view_test.dart
+++ b/desktop/test/super_tab_saved_view_test.dart
@@ -33,11 +33,15 @@ Map<String, dynamic> _view({String tab = 'tab', int pad = 0}) {
};
}
+/// A view as a controller hands it over, for other tests.
+Map<String, dynamic> savedViewForTest() => _view();
+
void main() {
group('a controller', _controllerTests);
group('the client', _clientTests);
group('review of #1723', _reviewTests);
group('re-review of #1727', _reReviewTests);
+ group('Clear now', _clearTests);
test('keeps what the Swarm draws, not what it never shows', () async {
final store = MemoryStore();
@@ -872,3 +876,59 @@ void _reviewTests() {
});
});
}
+
+/// Settings ▸ Account's Clear now, on the web: every copy this browser keeps
+/// goes, whoever it was kept for, and the Swarms opened next are kept again.
+void _clearTests() {
+ Iterable<String> viewKeys(MemoryStore store) =>
+ store.values.keys.where((k) => k.startsWith('super_tab.view'));
+
+ test('clears every view kept here, and keeps the next one', () async {
+ final store = MemoryStore();
+ final views = SuperTabSavedViews(store);
+ await views.claim('owner');
+ for (final tab in ['a', 'b']) {
+ await views.write('owner', tab, _view(tab: tab));
+ }
+ await views.clear('owner');
+ expect(viewKeys(store), isEmpty);
+ expect(await views.read('owner', 'a'), isNull);
+ // Still this account's device: what it opens next is kept again.
+ await views.write('owner', 'c', _view(tab: 'c'));
+ expect(await views.read('owner', 'c'), isNotNull);
+ });
+
+ test('a view left by an account before this one goes too', () async {
+ final store = MemoryStore();
+ final views = SuperTabSavedViews(store);
+ await views.claim('before');
+ await views.write('before', 'tab', _view());
+ // The next account has not claimed the device yet (a boot signed out).
+ await views.clear('owner');
+ expect(viewKeys(store), isEmpty);
+ });
+
+ test('the client clears, and nothing waiting to be written comes back', () {
+ fakeAsync((async) {
+ final server = ConversationServer()..append('Hello');
+ final store = MemoryStore();
+ final client = _client(_Transport(server), store)
+ ..bind('owner')
+ ..show('tab');
+ client.open('tab');
+ async.elapse(const Duration(seconds: 1));
+ // A change whose write waits for the 15 s pace.
+ server.append('Pending');
+ async.elapse(const Duration(seconds: 3));
+ client.clearSavedViews();
+ async.flushMicrotasks();
+ expect(viewKeys(store), isEmpty);
+ async.elapse(const Duration(seconds: 20));
+ expect(viewKeys(store), isEmpty);
+ // The Swarm still opens, and draws from its read.
+ final c = client.peek('tab')!;
+ expect(c.messages('lead').last.text, 'Pending');
+ client.dispose();
+ });
+ });
+}
diff --git a/desktop/test/super_tab_saved_view_widget_test.dart b/desktop/test/super_tab_saved_view_widget_test.dart
index ff51d1733..8e3b855e6 100644
--- a/desktop/test/super_tab_saved_view_widget_test.dart
+++ b/desktop/test/super_tab_saved_view_widget_test.dart
@@ -1,5 +1,7 @@
-// The saved view on screen (#180 fix 4): a quiet "Updating…" beside the
-// Super Tab's title until the first read lands; the send box stays usable.
+// The saved view on screen (#180 fix 4): a quiet "Saved in this browser ·
+// Updating…" beside the Super Tab's title until the first read lands; the
+// send box stays usable. It says where the copy is, and the tooltip how long
+// it stays and where it is cleared.
import 'dart:async';
import 'dart:convert';
@@ -12,6 +14,8 @@ import 'package:harness/super_tabs/view.dart';
import 'support/super_tab_fixture.dart';
+const _label = 'Saved in this browser · Updating…';
+
const _web = SuperTabReading(
quietPoll: Duration(seconds: 15),
pausesAway: true,
@@ -63,7 +67,14 @@ void main() {
addTearDown(c.dispose);
await _mount(tester, c);
expect(find.text('Hello'), findsOneWidget);
- expect(find.text('Updating…'), findsOneWidget);
+ expect(find.text(_label), findsOneWidget);
+ expect(
+ find.byTooltip(
+ 'This browser keeps a copy of the Super Tabs you open until you sign '
+ 'out. Settings ▸ Account clears it now.',
+ ),
+ findsOneWidget,
+ );
// The send box takes a draft meanwhile.
await tester.enterText(find.byType(TextField).last, 'Go ahead.');
expect(c.draft('lead'), 'Go ahead.');
@@ -74,7 +85,7 @@ void main() {
server.holdReads = null;
await tester.pump();
await tester.pump();
- expect(find.text('Updating…'), findsNothing);
+ expect(find.text(_label), findsNothing);
expect(find.text('Hello'), findsOneWidget);
// Reading the transcript saves where it was read to, a moment later.
await tester.pump(const Duration(seconds: 1));
@@ -86,7 +97,7 @@ void main() {
addTearDown(c.dispose);
await c.refresh();
await _mount(tester, c);
- expect(find.text('Updating…'), findsNothing);
+ expect(find.text(_label), findsNothing);
await tester.pump(const Duration(seconds: 1));
});
}
diff --git a/desktop/test/web/web_focus_ring_web_test.dart b/desktop/test/web/web_focus_ring_web_test.dart
index c9a257236..b72399f92 100644
--- a/desktop/test/web/web_focus_ring_web_test.dart
+++ b/desktop/test/web/web_focus_ring_web_test.dart
@@ -4,7 +4,11 @@ library;
// The browser build's frame draws the keyboard focus ring (P8).
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/auth/auth_session.dart';
+import 'package:harness/core/config.dart';
+import 'package:harness/state/app_state.dart';
import 'package:harness/shared/theme/app_theme.dart' as grid;
import 'package:harness/web/web_entry.dart';
@@ -12,20 +16,30 @@ void main() {
testWidgets('Tab in the web app draws the ring; a click puts it away', (
tester,
) async {
+ final app = AppNotifier(
+ config: AppConfig.dev,
+ authSession: AuthSession(),
+ configStore: null,
+ );
+ addTearDown(app.dispose);
+ // Under the app's ProviderScope, as `startHarness` runs it.
await tester.pumpWidget(
- appFrame(
- MaterialApp(
- theme: grid.buildAppTheme(brightness: Brightness.dark),
- home: Scaffold(
- body: Column(
- children: [
- FilledButton(
- autofocus: true,
- onPressed: () {},
- child: const Text('First'),
- ),
- OutlinedButton(onPressed: () {}, child: const Text('Second')),
- ],
+ ProviderScope(
+ overrides: [appStateProvider.overrideWithValue(app)],
+ child: appFrame(
+ MaterialApp(
+ theme: grid.buildAppTheme(brightness: Brightness.dark),
+ home: Scaffold(
+ body: Column(
+ children: [
+ FilledButton(
+ autofocus: true,
+ onPressed: () {},
+ child: const Text('First'),
+ ),
+ OutlinedButton(onPressed: () {}, child: const Text('Second')),
+ ],
+ ),
),
),
),
diff --git a/desktop/test/web/web_frame_key_hints_test.dart b/desktop/test/web/web_frame_key_hints_test.dart
index d95611ef9..59c6bdc39 100644
--- a/desktop/test/web/web_frame_key_hints_test.dart
+++ b/desktop/test/web/web_frame_key_hints_test.dart
@@ -4,7 +4,11 @@ library;
import 'dart:async';
import 'package:flutter/material.dart';
+import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
+import 'package:harness/auth/auth_session.dart';
+import 'package:harness/core/config.dart';
+import 'package:harness/state/app_state.dart';
import 'package:harness/shortcuts/shortcuts_browser.dart';
import 'package:harness/web/web_entry.dart';
import 'package:harness/widgets/key_hints.dart';
@@ -17,15 +21,26 @@ void main() {
) async {
final hints = <bool>[];
final navigator = GlobalKey<NavigatorState>();
+ final app = AppNotifier(
+ config: AppConfig.dev,
+ authSession: AuthSession(),
+ configStore: null,
+ );
+ addTearDown(app.dispose);
+ // Under the app's ProviderScope, as `startHarness` runs it: the frame
+ // reads whether anyone is signed in.
await tester.pumpWidget(
- MaterialApp(
- navigatorKey: navigator,
- builder: (context, child) => appFrame(child!),
- home: Builder(
- builder: (context) {
- hints.add(KeyHints.visibleOf(context));
- return const SizedBox.shrink();
- },
+ ProviderScope(
+ overrides: [appStateProvider.overrideWithValue(app)],
+ child: MaterialApp(
+ navigatorKey: navigator,
+ builder: (context, child) => appFrame(child!),
+ home: Builder(
+ builder: (context) {
+ hints.add(KeyHints.visibleOf(context));
+ return const SizedBox.shrink();
+ },
+ ),
),
),
);
diff --git a/desktop/test/web_footer_subscriptions_test.dart b/desktop/test/web_footer_subscriptions_test.dart
new file mode 100644
index 000000000..c020d0eb6
--- /dev/null
+++ b/desktop/test/web_footer_subscriptions_test.dart
@@ -0,0 +1,135 @@
+// The phone footer offers Subscriptions only once the account has a computer:
+// before one, there is no agent account to read and the row leads nowhere.
+// While the machine list is still on its way it stays, so an account that has
+// computers never loses it to a slow read.
+import 'package:flutter/material.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness/auth/auth_session.dart';
+import 'package:harness/core/config.dart';
+import 'package:harness/core/models.dart';
+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/web/footer/web_footer_bar.dart';
+import 'package:harness/web/shell/web_chrome.dart';
+import 'package:harness/web/shell/web_layout.dart';
+import 'package:harness/web/tabs/web_tab_switcher.dart';
+
+class _Account extends AppNotifier {
+ _Account()
+ : super(
+ config: AppConfig.dev,
+ authSession: AuthSession(),
+ configStore: null,
+ );
+
+ bool loaded = true;
+ @override
+ bool get machineInventoryLoaded => loaded;
+}
+
+const _menuButton = ValueKey('web-footer-menu-button');
+const _subscriptionsRow = ValueKey('web-footer:Subscriptions');
+
+void main() {
+ Future<_Account> mount(
+ WidgetTester tester, {
+ bool loaded = true,
+ bool computer = false,
+ WorkspaceChrome Function(AppNotifier app) chrome = webWorkspaceChrome,
+ }) async {
+ final app = _Account()..loaded = loaded;
+ addTearDown(app.dispose);
+ app.currentUser = const CurrentUserProfile(email: '[email protected]');
+ app.newSwarm(newTabPage: true);
+ if (computer) {
+ const machine = Machine(
+ machineId: 'm',
+ name: 'Studio Mac',
+ authMode: MachineAuthMode.remote,
+ );
+ app.machines.add(machine);
+ app.machineStates['m'] = MachineState(machine)
+ ..nodeOnline = true
+ ..connectionStatus = ConnectionStatus.connected;
+ }
+ tester.view.devicePixelRatio = 1;
+ tester.view.physicalSize = const Size(390, 844);
+ addTearDown(tester.view.reset);
+ await tester.pumpWidget(
+ MaterialApp(
+ theme: grid.buildAppTheme(brightness: Brightness.dark),
+ home: SwarmScreen(
+ notifier: app,
+ nativeTabs: false,
+ chrome: chrome(app),
+ ),
+ ),
+ );
+ await tester.pump(const Duration(milliseconds: 200));
+ return app;
+ }
+
+ /// Every row the footer's menu holds, by its title.
+ Future<bool> menuOffersSubscriptions(WidgetTester tester) async {
+ await tester.tap(find.byKey(_menuButton));
+ await tester.pump(const Duration(milliseconds: 200));
+ final offered = find.byKey(_subscriptionsRow).evaluate().isNotEmpty;
+ await tester.tapAt(const Offset(5, 5));
+ await tester.pump(const Duration(milliseconds: 200));
+ return offered;
+ }
+
+ Finder footerLabel(String text) =>
+ find.descendant(of: find.byKey(_menuButton), matching: find.text(text));
+
+ testWidgets('an account with no computer is not offered Subscriptions', (
+ tester,
+ ) async {
+ await mount(tester);
+ // No subscription figures either: there is no computer to read them on.
+ expect(footerLabel('Subscriptions'), findsNothing);
+ expect(find.textContaining('Claude Code'), findsNothing);
+ // The footer still says something true, and leads to Machines.
+ expect(footerLabel('Machines 0'), findsOneWidget);
+ expect(await menuOffersSubscriptions(tester), isFalse);
+ await tester.pumpWidget(const SizedBox.shrink());
+ });
+
+ testWidgets('while the machine list is on its way, Subscriptions stays', (
+ tester,
+ ) async {
+ await mount(tester, loaded: false);
+ expect(footerLabel('Machines 0'), findsNothing);
+ expect(await menuOffersSubscriptions(tester), isTrue);
+ await tester.pumpWidget(const SizedBox.shrink());
+ });
+
+ testWidgets('an account with a computer is offered Subscriptions', (
+ tester,
+ ) async {
+ await mount(tester, computer: true);
+ expect(await menuOffersSubscriptions(tester), isTrue);
+ await tester.pumpWidget(const SizedBox.shrink());
+ });
+
+ testWidgets('a host that leaves the switch off keeps Subscriptions', (
+ tester,
+ ) async {
+ await mount(
+ tester,
+ chrome: (app) => WorkspaceChrome(
+ leadingWidth: (_) => 0,
+ leading: (_, _) => const SizedBox.shrink(),
+ compactTabs: (context, commands) =>
+ WebTabSwitcher(app: app, commands: commands),
+ compactFooter: (context, footer) => WebFooterBar(footer: footer),
+ compactBelow: kWebCompactBelow,
+ ),
+ );
+ expect(footerLabel('Machines 0'), findsNothing);
+ expect(await menuOffersSubscriptions(tester), isTrue);
+ await tester.pumpWidget(const SizedBox.shrink());
+ });
+}
diff --git a/desktop/test/web_store_banner_test.dart b/desktop/test/web_store_banner_test.dart
index 8f0f77ae8..5e4bee464 100644
--- a/desktop/test/web_store_banner_test.dart
+++ b/desktop/test/web_store_banner_test.dart
@@ -4,6 +4,10 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:harness/core/local_key_value_store.dart';
import 'package:harness/core/phone_app_links.dart';
import 'package:harness/shared/theme/app_theme.dart' as grid;
+import 'package:flutter_riverpod/flutter_riverpod.dart';
+import 'package:harness/auth/auth_session.dart';
+import 'package:harness/core/config.dart';
+import 'package:harness/state/app_state.dart';
import 'package:harness/web/shell/web_store_banner.dart';
class _MemoryStore implements LocalKeyValueStore {
@@ -128,6 +132,72 @@ void main() {
debugDefaultTargetPlatformOverride = null;
});
+ // Trust: on a first visit the sign-in buttons are the page's only filled
+ // actions; the bar stays where a phone's app banner is, quieter.
+ Finder getTheApp<T>() => find.descendant(
+ of: find.byKey(const ValueKey('web-store-banner-open')),
+ matching: find.text('Get the app'),
+ );
+
+ Finder button<T extends ButtonStyleButton>() =>
+ find.ancestor(of: find.text('Get the app'), matching: find.byType(T));
+
+ Future<AppNotifier> mountApp(WidgetTester tester, AppStatus status) async {
+ debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
+ final app = AppNotifier(
+ config: AppConfig.dev,
+ authSession: AuthSession(),
+ configStore: null,
+ )..status = status;
+ addTearDown(app.dispose);
+ tester.view.devicePixelRatio = 1;
+ tester.view.physicalSize = const Size(390, 844);
+ addTearDown(tester.view.reset);
+ await tester.pumpWidget(
+ ProviderScope(
+ overrides: [appStateProvider.overrideWithValue(app)],
+ child: MaterialApp(
+ theme: grid.buildAppTheme(brightness: Brightness.dark),
+ builder: (context, child) =>
+ WebAppStoreFrame(storage: _MemoryStore(), child: child!),
+ home: const _CountedApp(key: _app),
+ ),
+ ),
+ );
+ await tester.pump();
+ return app;
+ }
+
+ testWidgets('before sign-in, Get the app is quiet beside the sign-in', (
+ tester,
+ ) async {
+ await mountApp(tester, AppStatus.unauthenticated);
+ expect(getTheApp(), findsOneWidget);
+ expect(button<FilledButton>(), findsNothing);
+ expect(button<OutlinedButton>(), findsOneWidget);
+ // Still a thumb's target.
+ expect(
+ tester.getSize(button<OutlinedButton>()).height,
+ greaterThanOrEqualTo(44),
+ );
+ debugDefaultTargetPlatformOverride = null;
+ });
+
+ testWidgets('signed in, Get the app is filled, and the app stays mounted', (
+ tester,
+ ) async {
+ final app = await mountApp(tester, AppStatus.unauthenticated);
+ final mounted = _CountedApp.mounts;
+ app
+ ..status = AppStatus.authenticated
+ ..notifyListeners();
+ await tester.pump();
+ expect(button<FilledButton>(), findsOneWidget);
+ expect(button<OutlinedButton>(), findsNothing);
+ expect(_CountedApp.mounts, mounted);
+ debugDefaultTargetPlatformOverride = null;
+ });
+
testWidgets('a computer never sees the bar', (tester) async {
await mount(tester, TargetPlatform.macOS, _MemoryStore());
expect(find.byKey(_banner), findsNothing);
diff --git a/desktop/tool/web_ux/capture.mjs b/desktop/tool/web_ux/capture.mjs
index 74bd41dc7..0a564111c 100644
--- a/desktop/tool/web_ux/capture.mjs
+++ b/desktop/tool/web_ux/capture.mjs
@@ -71,6 +71,24 @@ export async function settle(page) {
await page.waitForTimeout(1500);
}
+/// A flow's `api` answers the app's backend reads in the browser, so a state
+/// that needs a server reply (a private or offline shared link) is drawn by
+/// the real page: { '/api/shared-agents/': { status, body } }. Everything else
+/// stays blocked by [contextFor].
+export async function answerApi(page, flow) {
+ for (const [path, { status = 200, body = {} }] of Object.entries(flow.api ?? {})) {
+ await page.route(`**${path}**`, (route) => {
+ const headers = {
+ 'access-control-allow-origin': '*',
+ 'access-control-allow-headers': 'authorization, x-autonomous-env',
+ 'access-control-allow-methods': 'GET, OPTIONS',
+ };
+ if (route.request().method() === 'OPTIONS') return route.fulfill({ status: 204, headers });
+ return route.fulfill({ status, headers, contentType: 'application/json', body: JSON.stringify(body) });
+ });
+ }
+}
+
export async function runStep(page, [kind, target], touch) {
const press = touch ? 'tap' : 'click';
const button = (exact) => page.getByRole('button', { name: target, exact }).first();
@@ -101,6 +119,7 @@ async function shoot(context, origin, flow, viewport, theme, outDir) {
const shot = `screens/${flow.name}/${viewport.name}-${theme}.png`;
let failed = null;
try {
+ await answerApi(page, flow);
await page.goto(urlFor(origin, flow, theme));
await settle(page);
for (const step of steps) {
diff --git a/desktop/tool/web_ux/checks.mjs b/desktop/tool/web_ux/checks.mjs
index 5b38725f3..364d90f9f 100644
--- a/desktop/tool/web_ux/checks.mjs
+++ b/desktop/tool/web_ux/checks.mjs
@@ -15,7 +15,7 @@ import { createHash } from 'node:crypto';
import { mkdirSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { loadFlows } from './load-flows.mjs';
-import { VIEWPORTS, contextFor, runStep, settle, urlFor } from './capture.mjs';
+import { VIEWPORTS, answerApi, contextFor, runStep, settle, urlFor } from './capture.mjs';
import { serve } from './serve.mjs';
const FLOWS = await loadFlows();
@@ -29,6 +29,8 @@ const TAP_FLOWS = [
'footer-menu', 'notifications', 'open-harness', 'machines', 'all-commands',
'appearance', 'split-pane', 'store', 'settings', 'settings-notifications',
'settings-keyboard-shortcuts', 'new-tab', 'error-banner', 'new-device', 'link-password',
+ 'shared-link', 'shared-link-private', 'shared-link-refused', 'shared-link-offline',
+ 'shared-link-failed', 'settings-account',
];
// Scrolling areas: the flow that shows one, and where it is.
@@ -82,6 +84,7 @@ async function open(context, origin, name, viewport, theme = 'dark') {
if (!f) throw new Error(`no flow "${name}"`);
const page = await context.newPage();
try {
+ await answerApi(page, f);
await page.goto(urlFor(origin, f, theme));
await settle(page);
const compact = viewport.width < 720;
diff --git a/desktop/tool/web_ux/flows/sharing.mjs b/desktop/tool/web_ux/flows/sharing.mjs
new file mode 100644
index 000000000..6ac8b400a
--- /dev/null
+++ b/desktop/tool/web_ux/flows/sharing.mjs
@@ -0,0 +1,23 @@
+// Flows for a shared harness link (/s/…) in each state a visitor can meet.
+//
+// Fix group: shared links, clarity and trust. Each group keeps its flows here, so parallel groups never
+// edit the same file; load-flows.mjs reads every file in this folder. The incomplete link is
+// `shared-link` in states.mjs; these answer the link's read in the browser (capture.mjs `answerApi`).
+
+const id = '0b6f6a8e-2c1d-4f3e-9a7b-5d4c3b2a1f00';
+// 32 bytes, as a real owner key is pinned in the link's fragment.
+const key = 'AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE=';
+const path = `/s/${id}#key=${key}`;
+const read = (status, data) => ({ '/api/shared-agents/': { status, body: data ? { success: true, data } : { success: false } } });
+const link = { id, machineId: 'm1', agentId: 'a1', name: 'Release notes', engine: 'claude', ownerPublicKey: key };
+
+export const FLOWS = [
+ // Signed out, on a private link.
+ { name: 'shared-link-private', scenario: 'signin', path, api: read(401) },
+ // Signed in, and refused: expired, turned off, or shared with another email.
+ { name: 'shared-link-refused', scenario: 'workspace', path, api: read(403) },
+ { name: 'shared-link-offline', scenario: 'signin', path, api: read(200, { ...link, online: false }) },
+ { name: 'shared-link-changed', scenario: 'signin', path, api: read(200, { ...link, ownerPublicKey: 'AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI=', online: true }) },
+ // No answer at all: the read is blocked like any request off the served origin.
+ { name: 'shared-link-failed', scenario: 'signin', path },
+];