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.

feat(mobile): rename or close a desk tab by holding its chip in Find

tony7c10c05c60a8
diff --git a/mobile/lib/phone/desk_tab_filter_bar.dart b/mobile/lib/phone/desk_tab_filter_bar.dart
index c0e399ea5..56385b40f 100644
--- a/mobile/lib/phone/desk_tab_filter_bar.dart
+++ b/mobile/lib/phone/desk_tab_filter_bar.dart
@@ -39,6 +39,9 @@ class DeskTabFilterChoice {
/// A `+` after the last tab ([onNewTab]) is the desktop's `+` after its tabs:
/// a New Tab, which becomes a tab on every computer once its first harness is
/// in it.
+///
+/// Holding a tab's chip ([onLongPress]) is the desktop's right-click on a tab:
+/// Rename Tab and Close Tab. All is no tab, and holding it does nothing.
class DeskTabFilterBar extends StatefulWidget {
const DeskTabFilterBar({
super.key,
@@ -46,6 +49,7 @@ class DeskTabFilterBar extends StatefulWidget {
required this.selected,
required this.onSelected,
this.onNewTab,
+ this.onLongPress,
});
final List<DeskTabFilterChoice> choices;
@@ -58,6 +62,10 @@ class DeskTabFilterBar extends StatefulWidget {
/// The `+` after the last chip. Null leaves it out.
final VoidCallback? onNewTab;
+ /// A tab's chip held, with its [DeskTabFilterChoice.id]. Never for All. Null
+ /// leaves a held chip a slow tap.
+ final ValueChanged<String>? onLongPress;
+
/// Drawn height: a chip, with a gap over it that parts it from the field
/// and one under it that parts it from the first row.
static const double height = _gapAbove + _chipHeight + _gapBelow;
@@ -127,6 +135,14 @@ class _DeskTabFilterBarState extends State<DeskTabFilterBar> {
}
}
+ /// What holding the chip for [id] does: nothing for All, nor without a
+ /// [DeskTabFilterBar.onLongPress].
+ VoidCallback? _held(String? id) {
+ final held = widget.onLongPress;
+ if (id == null || held == null) return null;
+ return () => held(id);
+ }
+
void _readEdges([ScrollMetrics? metrics]) {
if (!mounted) return;
final read = metrics ?? (_scroll.hasClients ? _scroll.position : null);
@@ -197,6 +213,7 @@ class _DeskTabFilterBarState extends State<DeskTabFilterBar> {
choice: choices[i],
selected: choices[i].id == widget.selected,
onTap: () => widget.onSelected(choices[i].id),
+ onLongPress: _held(choices[i].id),
),
],
if (widget.onNewTab case final onNewTab?) ...[
@@ -219,11 +236,13 @@ class _FilterChip extends StatefulWidget {
required this.choice,
required this.selected,
required this.onTap,
+ this.onLongPress,
});
final DeskTabFilterChoice choice;
final bool selected;
final VoidCallback onTap;
+ final VoidCallback? onLongPress;
@override
State<_FilterChip> createState() => _FilterChipState();
@@ -256,10 +275,15 @@ class _FilterChipState extends State<_FilterChip> {
: empty
? tty.dim
: tty.faint;
+ final held = widget.onLongPress;
return Semantics(
button: true,
selected: selected,
label: '${choice.name}, ${choice.count}',
+ // The chip's own semantics are excluded below, its gesture's with them: a screen reader's
+ // hold reaches the menu through this.
+ onLongPress: held,
+ onLongPressHint: held == null ? null : 'Rename or close',
excludeSemantics: true,
child: TouchTarget(
child: GestureDetector(
@@ -271,6 +295,15 @@ class _FilterChipState extends State<_FilterChip> {
HapticFeedback.selectionClick();
widget.onTap();
},
+ // Released here as well as in `onTapCancel`: the chip must not stay sunk under the sheet
+ // this opens, which outlives the gesture that opened it.
+ onLongPress: held == null
+ ? null
+ : () {
+ _press(false);
+ HapticFeedback.mediumImpact();
+ held();
+ },
child: AnimatedContainer(
duration: AppMotion.press,
curve: AppMotion.curve,
diff --git a/mobile/lib/phone/phone_search_results.dart b/mobile/lib/phone/phone_search_results.dart
index c0e37755f..c9816ec04 100644
--- a/mobile/lib/phone/phone_search_results.dart
+++ b/mobile/lib/phone/phone_search_results.dart
@@ -8,6 +8,8 @@ import 'package:harness_mobile/shared/theme/app_theme.dart';
import 'package:harness_mobile/notify/agent_notice.dart' show NoticeKind;
import 'package:harness_mobile/state/app_state.dart';
import 'package:harness_mobile/state/external_session.dart';
+import 'package:harness_mobile/widgets/rename_agent_dialog.dart'
+ show showDeskTabRenameDialog;
import 'agent_index.dart';
import 'agents_page.dart' show showAgentActions;
@@ -254,6 +256,7 @@ class PhoneSearchResultsState extends State<PhoneSearchResults> {
selected: tab?.id,
onSelected: (id) => setState(() => _tabId = id),
onNewTab: widget.notifier.deskWritable ? widget.onNewTab : null,
+ onLongPress: widget.notifier.deskWritable ? _holdTab : null,
),
Expanded(
child: _rowsDue
@@ -270,6 +273,46 @@ class PhoneSearchResultsState extends State<PhoneSearchResults> {
},
);
+ /// Holding a tab's chip: the desktop's tab menu — Rename Tab… and Close Tab.
+ ///
+ /// Close asks nothing first: it takes the tab off the desk, and so off every computer's tab row,
+ /// but stops none of its harnesses — they keep running, under All and in search
+ /// ([AppNotifier.closeDeskTab]).
+ void _holdTab(String tabId) {
+ final notifier = widget.notifier;
+ final tab = deskTabFilters(notifier)
+ .where((each) => each.id == tabId)
+ .firstOrNull;
+ if (tab == null) return;
+ unawaited(
+ showPhoneSheet(
+ context,
+ title: tab.name,
+ actions: [
+ PhoneSheetAction(
+ icon: LucideIcons.pencil300,
+ label: 'Rename Tab…',
+ onTap: () {
+ if (!mounted) return;
+ unawaited(
+ showDeskTabRenameDialog(context, notifier, tabId, tab.name),
+ );
+ },
+ ),
+ PhoneSheetAction(
+ icon: LucideIcons.x300,
+ label: 'Close Tab',
+ onTap: () {
+ notifier.closeDeskTab(tabId);
+ // The list was narrowed to it: back to All, as for a tab closed on another computer.
+ if (mounted && _tabId == tabId) setState(() => _tabId = null);
+ },
+ ),
+ ],
+ ),
+ );
+ }
+
/// Whether this is Find's plain list of harnesses — no mode (`>`, `?`, a group, `:`) and not
/// walked into one project or machine. The only list the tab chips narrow.
static bool _plain(PhoneSearchController search) =>
diff --git a/mobile/lib/state/app_state.dart b/mobile/lib/state/app_state.dart
index 2b58a57e0..d357139f8 100644
--- a/mobile/lib/state/app_state.dart
+++ b/mobile/lib/state/app_state.dart
@@ -758,10 +758,14 @@ class AppNotifier extends ChangeNotifier {
void addAgentToDeskTab(String tabId, AgentRef agent) =>
_desk.addToTab(tabId, agent);
- /// A tab renamed by hand, from a double tap on its name in the tabs panel.
+ /// A tab renamed by hand, from holding its chip in Find.
/// See [PhoneDesk.renameTab].
void renameDeskTab(String tabId, String name) => _desk.renameTab(tabId, name);
+ /// A tab closed by hand, from holding its chip in Find. Its harnesses keep
+ /// running. See [PhoneDesk.closeTab].
+ void closeDeskTab(String tabId) => _desk.closeTab(tabId);
+
/// An agent that already exists opens a tab of its own — the `+` on the tab
/// row. See [PhoneDesk.createTabFor].
String? createDeskTabFor(AgentRef agent, {String? name}) =>
diff --git a/mobile/lib/state/phone_desk.dart b/mobile/lib/state/phone_desk.dart
index 1a71f2414..847f1c8c8 100644
--- a/mobile/lib/state/phone_desk.dart
+++ b/mobile/lib/state/phone_desk.dart
@@ -23,8 +23,8 @@ import 'desk_sync.dart';
/// phone happened to be in, on every computer the person owns. So nothing here
/// is derived from `swarms`: the tabs are read, and every write is one a person
/// made by hand on the phone — [adopt] for an agent created here, [drop] for one
-/// deleted here, and [createTabFor]/[addToTab] for the two `+`s on the tabs
-/// panel.
+/// deleted here, [createTabFor]/[addToTab] for the two `+`s on the tabs
+/// panel, and [renameTab]/[closeTab] for holding a tab's chip in Find.
///
/// What is NOT on the desk stays per device, as it does on a window: which tab
/// is open ([activeTabId]) is this phone's own, and so is the agent within it.
@@ -60,6 +60,10 @@ class PhoneDesk {
/// The app has tabs it did not have a moment ago: rebuild.
final VoidCallback onChanged;
+ /// The longest tab name the desk takes — backend `DESK_NAME_MAX`, in UTF-16
+ /// units like [String.length].
+ static const int nameMaxLength = 80;
+
final DeskSyncState _state = DeskSyncState();
Timer? _retry;
Timer? _poll;
@@ -327,7 +331,9 @@ class PhoneDesk {
void renameTab(String tabId, String name) {
if (!_state.enabled) return;
final trimmed = name.trim();
- if (trimmed.isEmpty) return;
+ // A name the backend refuses would fail the whole batch, and a refused
+ // write stops this phone writing to the desk at all.
+ if (trimmed.isEmpty || trimmed.length > nameMaxLength) return;
final tab = _state.synced.where((t) => t.id == tabId).firstOrNull;
if (tab == null || (tab.name == trimmed && tab.nameIsCustom)) return;
_queue([
@@ -335,6 +341,26 @@ class PhoneDesk {
]);
}
+ /// A tab closed by hand on this phone: it leaves the desk, and so every
+ /// computer's tab row.
+ ///
+ /// ⚠️ **The tab, not its harnesses.** A window that hears the desk closed a
+ /// tab releases its views and stops nothing (desktop `_deskReconcile`); the
+ /// agents keep running and stay under All and in search. Stopping one is the
+ /// harness's own Stop, which says what it ends.
+ ///
+ /// The phone was in it: from here it is in no tab, and the agent on screen
+ /// decides again which one it is in (`activeDeskGroup`).
+ void closeTab(String tabId) {
+ if (!_state.enabled) return;
+ if (!_state.synced.any((t) => t.id == tabId)) return;
+ // Before the write, so the notice it makes already has the phone out of it.
+ if (_activeTabId == tabId) _activeTabId = null;
+ _queue([
+ {'op': 'tab.close', 'id': tabId},
+ ]);
+ }
+
/// An agent that already exists joins a tab the person picked — which need
/// not be the tab the phone is in. Silent where the tab has it already: the
/// panel offers agents a tab lacks, but the desk can have moved underneath.
diff --git a/mobile/lib/widgets/rename_agent_dialog.dart b/mobile/lib/widgets/rename_agent_dialog.dart
index dd31dfa19..d2e68d8c6 100644
--- a/mobile/lib/widgets/rename_agent_dialog.dart
+++ b/mobile/lib/widgets/rename_agent_dialog.dart
@@ -8,6 +8,7 @@ import '../core/models.dart' show Agent;
import '../shared/theme/app_theme.dart' as grid;
import '../shared/widgets/app_dialog.dart';
import '../state/app_state.dart';
+import '../state/phone_desk.dart' show PhoneDesk;
import 'engine_identity.dart';
/// The one "Edit name" dialog, opened from every place a name is shown.
@@ -80,6 +81,40 @@ Future<void> showMachineRenameDialog(
);
}
+/// The same dialog for a desk tab — held from its chip in Find. The desktop's "Rename Tab", and
+/// the name every computer's tab row then shows ([AppNotifier.renameDeskTab]).
+///
+/// [currentName] is the name the chip shows, which for a tab nobody named is the one its
+/// harnesses give it (`deskTabNames`) — what the person is looking at when they hold it.
+Future<void> showDeskTabRenameDialog(
+ BuildContext context,
+ AppNotifier notifier,
+ String tabId,
+ String currentName,
+) => showAppDialog<void>(
+ context: context,
+ builder: (_) => _RenameDialog(
+ title: 'Rename Tab',
+ currentName: currentName,
+ detail: '',
+ maxLength: PhoneDesk.nameMaxLength,
+ onSave: (name) async {
+ final trimmed = name.trim();
+ if (trimmed.isEmpty) return 'Name cannot be empty';
+ if (trimmed.length > PhoneDesk.nameMaxLength) {
+ return 'Use ${PhoneDesk.nameMaxLength} characters or fewer.';
+ }
+ // Closed on another computer while the dialog was open: a rename now would change nothing.
+ if (!notifier.deskTabs.any((tab) => tab.id == tabId)) {
+ return 'This tab has been closed.';
+ }
+ if (!notifier.deskWritable) return 'Rename failed. Try again later.';
+ notifier.renameDeskTab(tabId, trimmed);
+ return null;
+ },
+ ),
+);
+
/// The field's corner — the buttons' too. Its focus ring stands 4 outside it,
/// on the same curve.
const double _fieldRadius = kDialogControlRadius;
diff --git a/mobile/test/desk_tab_filter_bar_test.dart b/mobile/test/desk_tab_filter_bar_test.dart
index 2d2c2ca01..f83a4baf0 100644
--- a/mobile/test/desk_tab_filter_bar_test.dart
+++ b/mobile/test/desk_tab_filter_bar_test.dart
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
+import 'package:flutter/semantics.dart' show SemanticsAction;
import 'package:flutter_test/flutter_test.dart';
import 'package:harness_mobile/phone/desk_tab_filter_bar.dart';
@@ -15,6 +16,7 @@ void main() {
WidgetTester tester, {
VoidCallback? onNewTab,
ValueChanged<String?>? onSelected,
+ ValueChanged<String>? onLongPress,
}) => tester.pumpWidget(
MaterialApp(
home: Scaffold(
@@ -23,11 +25,66 @@ void main() {
selected: null,
onSelected: onSelected ?? (_) {},
onNewTab: onNewTab,
+ onLongPress: onLongPress,
),
),
),
);
+ bool canHold(WidgetTester tester, String label) => tester
+ .getSemantics(find.bySemanticsLabel(label))
+ .getSemanticsData()
+ .hasAction(SemanticsAction.longPress);
+
+ testWidgets('holding a tab chip hands back its tab, and picks nothing', (
+ tester,
+ ) async {
+ final held = <String>[];
+ final picked = <String?>[];
+ await pumpBar(tester, onLongPress: held.add, onSelected: picked.add);
+
+ await tester.longPress(find.text('Docker'));
+ await tester.pump();
+
+ expect(held, ['t2']);
+ expect(picked, isEmpty);
+ });
+
+ testWidgets('holding All does nothing: it is no tab', (tester) async {
+ final held = <String>[];
+ final picked = <String?>[];
+ await pumpBar(tester, onLongPress: held.add, onSelected: picked.add);
+
+ await tester.longPress(find.text('All'));
+ await tester.pump();
+
+ expect(held, isEmpty);
+ });
+
+ testWidgets('a screen reader reaches the hold on a tab chip, not on All', (
+ tester,
+ ) async {
+ final semantics = tester.ensureSemantics();
+ await pumpBar(tester, onLongPress: (_) {});
+
+ expect(canHold(tester, 'Desktop, 2'), isTrue);
+ expect(canHold(tester, 'All, 3'), isFalse);
+ semantics.dispose();
+ });
+
+ testWidgets('with nothing to hold for, a held chip is still a tap', (
+ tester,
+ ) async {
+ final picked = <String?>[];
+ await pumpBar(tester, onSelected: picked.add);
+
+ await tester.longPress(find.text('Docker'));
+ await tester.pump();
+
+ expect(picked, ['t2']);
+ expect(canHold(tester, 'Docker, 1'), isFalse);
+ });
+
testWidgets('a tap on the + asks for a new tab, and picks no chip', (
tester,
) async {
diff --git a/mobile/test/find_tab_actions_test.dart b/mobile/test/find_tab_actions_test.dart
new file mode 100644
index 000000000..105520386
--- /dev/null
+++ b/mobile/test/find_tab_actions_test.dart
@@ -0,0 +1,244 @@
+import 'package:flutter/material.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness_mobile/phone/desk_tab_filter_bar.dart';
+import 'package:harness_mobile/phone/phone_search_results.dart';
+import 'package:harness_mobile/phone/terminal_search.dart';
+import 'package:harness_mobile/state/app_state.dart';
+import 'package:harness_mobile/state/phone_desk.dart';
+
+import 'agent_pager_fixture.dart';
+import 'desk_fixture.dart';
+
+/// A desk that answers its first read and then takes no write — the backend refusing every op,
+/// which leaves the phone showing the tabs but no longer writing to them.
+class _RefusingDeskApi extends DeskApi {
+ _RefusingDeskApi({super.tabs});
+
+ @override
+ Future<Map<String, dynamic>?> deskOps(List<Map<String, dynamic>> ops) async {
+ written.addAll(ops);
+ return null;
+ }
+}
+
+/// Holding a tab's chip in Find: the desktop's tab menu, Rename Tab… and Close Tab.
+void main() {
+ Future<AppNotifier> openFind(WidgetTester tester, {AppNotifier? app}) async {
+ final shown =
+ app ??
+ await deskApp(
+ PagerConn(),
+ opensTerminals: false,
+ tabs: [
+ deskTab('t1', 'Desktop', ['a', 'b']),
+ deskTab('t2', 'Docker', ['c']),
+ ],
+ );
+ addTearDown(shown.dispose);
+ shown.noteDeskTab('t1');
+ await tester.pumpWidget(
+ MaterialApp(
+ home: Scaffold(
+ body: TerminalSearchOverlay(
+ notifier: shown,
+ animation: const AlwaysStoppedAnimation(1),
+ onClose: () {},
+ showing: (machineId: 'm', agentId: 'a'),
+ ),
+ ),
+ ),
+ );
+ await tester.pump();
+ return shown;
+ }
+
+ Finder chip(String name) => find.descendant(
+ of: find.byType(DeskTabFilterBar),
+ matching: find.text(name),
+ );
+
+ /// A sheet or dialog sliding in or out, run to its end.
+ Future<void> settle(WidgetTester tester) async {
+ await tester.pump();
+ await tester.pump(const Duration(milliseconds: 500));
+ }
+
+ Future<void> hold(WidgetTester tester, String name) async {
+ await tester.longPress(chip(name));
+ await settle(tester);
+ }
+
+ String? pickedTab(WidgetTester tester) => tester
+ .state<PhoneSearchResultsState>(find.byType(PhoneSearchResults))
+ .deskTabId;
+
+ /// Takes Find down and runs its clocks out, so no timer outlives the test.
+ Future<void> unmount(WidgetTester tester) async {
+ await tester.pumpWidget(const SizedBox());
+ await tester.pump(const Duration(seconds: 30));
+ }
+
+ testWidgets('holding a tab chip offers Rename Tab… and Close Tab', (
+ tester,
+ ) async {
+ await openFind(tester);
+
+ await hold(tester, 'Docker');
+
+ expect(find.text('Rename Tab…'), findsOneWidget);
+ expect(find.text('Close Tab'), findsOneWidget);
+ await unmount(tester);
+ });
+
+ testWidgets('holding All offers nothing: it is no tab', (tester) async {
+ await openFind(tester);
+
+ await hold(tester, 'All');
+
+ expect(find.text('Rename Tab…'), findsNothing);
+ expect(find.text('Close Tab'), findsNothing);
+ await unmount(tester);
+ });
+
+ testWidgets(
+ 'Close Tab takes the tab off the desk at once, and the list back to All',
+ (tester) async {
+ final app = await openFind(tester);
+ await tester.tap(chip('Docker'));
+ await tester.pump();
+ expect(pickedTab(tester), 't2');
+
+ await hold(tester, 'Docker');
+ await tester.tap(find.text('Close Tab'));
+ await settle(tester);
+
+ // No question first: the desk took it, and the chip is gone.
+ expect(find.text('Close Tab'), findsNothing);
+ expect(deskApiOf(app).written, [
+ {'op': 'tab.close', 'id': 't2'},
+ ]);
+ expect([for (final tab in app.deskTabs) tab.id], ['t1']);
+ expect(chip('Docker'), findsNothing);
+ expect(chip('Desktop'), findsOneWidget);
+ expect(pickedTab(tester), isNull);
+ // Its harness is stopped by nothing: still on the machine, still under All.
+ expect(app.stateOf('m')!.agents.map((agent) => agent.id), contains('c'));
+ await unmount(tester);
+ },
+ );
+
+ testWidgets('Rename Tab… opens on the name the chip shows, and saves it', (
+ tester,
+ ) async {
+ final app = await openFind(tester);
+
+ await hold(tester, 'Docker');
+ await tester.tap(find.text('Rename Tab…'));
+ await settle(tester);
+
+ expect(find.text('Rename Tab'), findsOneWidget);
+ final field = find.byType(TextField).last;
+ expect(tester.widget<TextField>(field).controller!.text, 'Docker');
+
+ await tester.enterText(field, ' Deep work ');
+ await tester.pump();
+ await tester.tap(find.text('Save'));
+ await settle(tester);
+
+ expect(find.text('Rename Tab'), findsNothing);
+ expect(deskApiOf(app).written, [
+ {
+ 'op': 'tab.rename',
+ 'id': 't2',
+ 'name': 'Deep work',
+ 'nameIsCustom': true,
+ },
+ ]);
+ expect(chip('Deep work'), findsOneWidget);
+ expect(chip('Docker'), findsNothing);
+ await unmount(tester);
+ });
+
+ testWidgets('Save waits for a name that is there and new', (tester) async {
+ final app = await openFind(tester);
+
+ await hold(tester, 'Docker');
+ await tester.tap(find.text('Rename Tab…'));
+ await settle(tester);
+
+ FilledButton save() => tester.widget<FilledButton>(
+ find.ancestor(of: find.text('Save'), matching: find.byType(FilledButton)),
+ );
+ expect(save().onPressed, isNull);
+ await tester.enterText(find.byType(TextField).last, ' ');
+ await tester.pump();
+ expect(save().onPressed, isNull);
+
+ // Longer than the desk takes: the field stops at its limit.
+ await tester.enterText(
+ find.byType(TextField).last,
+ 'x' * (PhoneDesk.nameMaxLength + 5),
+ );
+ await tester.pump();
+ expect(
+ tester.widget<TextField>(find.byType(TextField).last).controller!.text,
+ hasLength(PhoneDesk.nameMaxLength),
+ );
+
+ await tester.tap(find.text('Cancel'));
+ await settle(tester);
+ expect(deskApiOf(app).written, isEmpty);
+ await unmount(tester);
+ });
+
+ testWidgets(
+ 'a tab closed while its rename is open says so, and keeps it open',
+ (tester) async {
+ final app = await openFind(tester);
+
+ await hold(tester, 'Docker');
+ await tester.tap(find.text('Rename Tab…'));
+ await settle(tester);
+ // Gone from under the dialog — another computer's close, as this phone hears it.
+ app.closeDeskTab('t2');
+ await tester.pump();
+
+ await tester.enterText(find.byType(TextField).last, 'Deep work');
+ await tester.pump();
+ await tester.tap(find.text('Save'));
+ await settle(tester);
+
+ expect(find.text('Rename Tab'), findsOneWidget);
+ expect(find.text('This tab has been closed.'), findsOneWidget);
+ expect(
+ deskApiOf(app).written.where((op) => op['op'] == 'tab.rename'),
+ isEmpty,
+ );
+ await unmount(tester);
+ },
+ );
+
+ testWidgets('no menu while the desk takes no writes', (tester) async {
+ final app = pagerApp(PagerConn());
+ app.api = _RefusingDeskApi(
+ tabs: [
+ deskTab('t1', 'Desktop', ['a', 'b']),
+ deskTab('t2', 'Docker', ['c']),
+ ],
+ );
+ app.stateOf('m')!.terminalCapabilityAvailable = false;
+ await syncDesk(app);
+ // A write refused: the phone stops writing to the desk, and still shows its tabs.
+ app.closeDeskTab('t1');
+ await tester.pump();
+ expect(app.deskWritable, isFalse);
+ await openFind(tester, app: app);
+ expect(chip('Docker'), findsOneWidget);
+
+ await hold(tester, 'Docker');
+
+ expect(find.text('Rename Tab…'), findsNothing);
+ expect(find.text('Close Tab'), findsNothing);
+ await unmount(tester);
+ });
+}
diff --git a/mobile/test/phone_desk_test.dart b/mobile/test/phone_desk_test.dart
index 835c3e60f..34121e573 100644
--- a/mobile/test/phone_desk_test.dart
+++ b/mobile/test/phone_desk_test.dart
@@ -341,6 +341,88 @@ void main() {
expect(backend.received.map((op) => op['tabId']), ['t1', 't2']);
});
+ test(
+ 'a tab closed on the phone leaves the desk, and the phone with it',
+ () async {
+ await join();
+ desk.note('t1');
+
+ desk.closeTab('t1');
+ await pumpEventQueue();
+
+ expect([for (final tab in desk.tabs) tab.id], ['t2']);
+ expect(backend.received, [
+ {'op': 'tab.close', 'id': 't1'},
+ ]);
+ expect([for (final tab in backend.tabs) tab.id], ['t2']);
+ // Out of it: the agent on screen decides again which tab the phone is in.
+ expect(desk.activeTabId, isNull);
+ },
+ );
+
+ test('closing another tab leaves the phone in the one it is in', () async {
+ await join();
+ desk.note('t1');
+
+ desk.closeTab('t2');
+ await pumpEventQueue();
+
+ expect([for (final tab in desk.tabs) tab.id], ['t1']);
+ expect(desk.activeTabId, 't1');
+ });
+
+ test('closing a tab that is gone, or with no desk, writes nothing', () async {
+ desk.closeTab('t1');
+ await pumpEventQueue();
+ expect(backend.received, isEmpty);
+
+ await join();
+ desk.closeTab('gone');
+ await pumpEventQueue();
+
+ expect(backend.received, isEmpty);
+ expect(desk.tabs, hasLength(2));
+ });
+
+ test(
+ 'a tab renamed on the phone keeps the name every computer shows',
+ () async {
+ await join();
+
+ desk.renameTab('t2', ' Deep work ');
+ await pumpEventQueue();
+
+ expect(backend.received, [
+ {
+ 'op': 'tab.rename',
+ 'id': 't2',
+ 'name': 'Deep work',
+ 'nameIsCustom': true,
+ },
+ ]);
+ final renamed = desk.tabs.firstWhere((tab) => tab.id == 't2');
+ expect(renamed.name, 'Deep work');
+ expect(renamed.nameIsCustom, isTrue);
+ },
+ );
+
+ test('a name the desk would refuse is never sent', () async {
+ await join();
+
+ // The backend takes 80 at most (`DESK_NAME_MAX`), and a refused write
+ // would stop this phone writing to the desk at all.
+ desk.renameTab('t2', 'x' * (PhoneDesk.nameMaxLength + 1));
+ desk.renameTab('t2', ' ');
+ await pumpEventQueue();
+
+ expect(backend.received, isEmpty);
+ expect(desk.enabled, isTrue);
+
+ desk.renameTab('t2', 'x' * PhoneDesk.nameMaxLength);
+ await pumpEventQueue();
+ expect(backend.received, hasLength(1));
+ });
+
test(
'a write held up by the network is kept and replayed, not dropped',
() async {