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): add a + after Find's tab chips that opens the new harness in a tab of its own

tony1ee27f7d70b5
diff --git a/mobile/lib/phone/agents_page.dart b/mobile/lib/phone/agents_page.dart
index 56d13be77..3556f3618 100644
--- a/mobile/lib/phone/agents_page.dart
+++ b/mobile/lib/phone/agents_page.dart
@@ -283,13 +283,15 @@ Future<void> showAgentActions(
/// (see `terminal_page.dart`). Callers that do not care can ignore it.
///
/// [deskTabId] is the tab the new agent joins, for a door that picked one — see
-/// [NewAgentPage.deskTabId].
+/// [NewAgentPage.deskTabId]. [newDeskTab] gives it a tab of its own — see
+/// [NewAgentPage.newDeskTab].
Future<void> openNewAgent(
BuildContext context,
AppNotifier notifier,
String machineId, {
String? folder,
String? deskTabId,
+ bool newDeskTab = false,
VoiceInputController? voice,
}) => Navigator.of(context).push(
phoneRoute(
@@ -298,6 +300,7 @@ Future<void> openNewAgent(
machineId: machineId,
folder: folder,
deskTabId: deskTabId,
+ newDeskTab: newDeskTab,
voice: voice,
),
),
diff --git a/mobile/lib/phone/desk_tab_filter_bar.dart b/mobile/lib/phone/desk_tab_filter_bar.dart
index 408f06198..c0e399ea5 100644
--- a/mobile/lib/phone/desk_tab_filter_bar.dart
+++ b/mobile/lib/phone/desk_tab_filter_bar.dart
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
+import 'package:lucide_icons_flutter/lucide_icons.dart';
import 'package:harness_mobile/shared/theme/app_theme.dart';
import 'package:harness_mobile/shared/widgets/touch_target.dart';
@@ -34,12 +35,17 @@ class DeskTabFilterChoice {
/// ⚠️ **A chip with nothing behind it is dimmed, never hidden.** A tab whose
/// machine is asleep holds nothing this phone can open, and a chip that vanished
/// with it would read as a tab that was closed.
+///
+/// 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.
class DeskTabFilterBar extends StatefulWidget {
const DeskTabFilterBar({
super.key,
required this.choices,
required this.selected,
required this.onSelected,
+ this.onNewTab,
});
final List<DeskTabFilterChoice> choices;
@@ -49,6 +55,9 @@ class DeskTabFilterBar extends StatefulWidget {
final ValueChanged<String?> onSelected;
+ /// The `+` after the last chip. Null leaves it out.
+ final VoidCallback? onNewTab;
+
/// 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;
@@ -190,6 +199,10 @@ class _DeskTabFilterBarState extends State<DeskTabFilterBar> {
onTap: () => widget.onSelected(choices[i].id),
),
],
+ if (widget.onNewTab case final onNewTab?) ...[
+ const SizedBox(width: 6),
+ _NewTabChip(onTap: onNewTab),
+ ],
],
),
),
@@ -303,3 +316,58 @@ class _FilterChipState extends State<_FilterChip> {
);
}
}
+
+/// The `+` after the last tab: a chip's own outline around a plus, as wide as
+/// it is tall, so it reads as one more place on the rail rather than a tab.
+class _NewTabChip extends StatefulWidget {
+ const _NewTabChip({required this.onTap});
+
+ final VoidCallback onTap;
+
+ @override
+ State<_NewTabChip> createState() => _NewTabChipState();
+}
+
+class _NewTabChipState extends State<_NewTabChip> {
+ bool _pressed = false;
+
+ void _press(bool pressed) {
+ if (_pressed == pressed) return;
+ setState(() => _pressed = pressed);
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final tty = Tty.of(context);
+ return Semantics(
+ button: true,
+ label: 'New Tab',
+ excludeSemantics: true,
+ child: TouchTarget(
+ child: GestureDetector(
+ key: const ValueKey('find-new-tab'),
+ behavior: HitTestBehavior.opaque,
+ onTapDown: (_) => _press(true),
+ onTapUp: (_) => _press(false),
+ onTapCancel: () => _press(false),
+ onTap: () {
+ HapticFeedback.selectionClick();
+ widget.onTap();
+ },
+ child: AnimatedContainer(
+ duration: AppMotion.press,
+ curve: AppMotion.curve,
+ width: DeskTabFilterBar._chipHeight,
+ height: DeskTabFilterBar._chipHeight,
+ decoration: BoxDecoration(
+ color: _pressed ? ttyRaised(tty) : Colors.transparent,
+ borderRadius: BorderRadius.circular(6),
+ border: Border.all(color: tty.text.withValues(alpha: 0.16)),
+ ),
+ child: Icon(LucideIcons.plus300, size: 16, color: tty.faint),
+ ),
+ ),
+ ),
+ );
+ }
+}
diff --git a/mobile/lib/phone/new_agent_page.dart b/mobile/lib/phone/new_agent_page.dart
index 246a82e0c..230566db9 100644
--- a/mobile/lib/phone/new_agent_page.dart
+++ b/mobile/lib/phone/new_agent_page.dart
@@ -47,6 +47,7 @@ class NewAgentPage extends StatefulWidget {
required this.machineId,
this.folder,
this.deskTabId,
+ this.newDeskTab = false,
this.voice,
});
@@ -65,6 +66,10 @@ class NewAgentPage extends StatefulWidget {
/// Null joins the tab the phone is in. See `PhoneDesk.adopt`.
final String? deskTabId;
+ /// The new harness opens a desk tab of its own — the `+` at the end of Find's tab chips, the
+ /// desktop's New Tab. Wins over [deskTabId]. See `PhoneDesk.adopt`.
+ final bool newDeskTab;
+
@override
State<NewAgentPage> createState() => _NewAgentPageState();
}
@@ -837,6 +842,7 @@ class _NewAgentPageState extends State<NewAgentPage> {
// The folder chosen, or none for home — never [_project], which a terminal cannot make.
folder: _folder,
deskTabId: widget.deskTabId,
+ newDeskTab: widget.newDeskTab,
attempt: creation,
);
_answered(creation, engine, error);
@@ -939,6 +945,7 @@ class _NewAgentPageState extends State<NewAgentPage> {
codexHome: _showsCodexProfile ? _codexProfile?.path : null,
model: _model,
deskTabId: widget.deskTabId,
+ newDeskTab: widget.newDeskTab,
attempt: creation,
prompt: task.isEmpty || files.isNotEmpty ? null : task,
// Whenever a first task is sent, the harness is called by its words until the engine titles
diff --git a/mobile/lib/phone/phone_search_results.dart b/mobile/lib/phone/phone_search_results.dart
index b807762c0..936ed4941 100644
--- a/mobile/lib/phone/phone_search_results.dart
+++ b/mobile/lib/phone/phone_search_results.dart
@@ -52,6 +52,7 @@ class PhoneSearchResults extends StatefulWidget {
this.onOpen,
this.showing,
this.onNewHarness,
+ this.onNewTab,
this.opening,
});
@@ -64,6 +65,11 @@ class PhoneSearchResults extends StatefulWidget {
final void Function(({String machineId, String folder, String label})? place)?
onNewHarness;
+ /// The `+` after the last tab chip: a New Tab, the desktop's — the new-agent form, and the
+ /// harness it makes opens a tab of its own. Drawn only where the chips are and the desk takes
+ /// writes ([AppNotifier.deskWritable]). Null leaves it out.
+ final VoidCallback? onNewTab;
+
final AppNotifier notifier;
final PhoneSearchController controller;
@@ -244,6 +250,7 @@ class PhoneSearchResultsState extends State<PhoneSearchResults> {
],
selected: tab?.id,
onSelected: (id) => setState(() => _tabId = id),
+ onNewTab: widget.notifier.deskWritable ? widget.onNewTab : null,
),
Expanded(
child: _rowsDue
diff --git a/mobile/lib/phone/terminal_search.dart b/mobile/lib/phone/terminal_search.dart
index 677ec449b..11673e205 100644
--- a/mobile/lib/phone/terminal_search.dart
+++ b/mobile/lib/phone/terminal_search.dart
@@ -273,7 +273,13 @@ class _TerminalSearchOverlayState extends State<TerminalSearchOverlay>
/// picked tab before the form opens would be undone while the form is up. The picked tab
/// travels with the request instead (`NewAgentPage.deskTabId`); on All it is null and the tab
/// the phone is in still decides.
- void Function(({String machineId, String folder, String label})? place)?
+ ///
+ /// [newTab] — the `+` after the last tab chip — puts it in a tab of its own instead, the desktop's
+ /// New Tab (`NewAgentPage.newDeskTab`); the tab the chips are narrowed to is not read then.
+ void Function(
+ ({String machineId, String folder, String label})? place, {
+ bool newTab,
+ })?
_newAgent() {
final showing = widget.showing;
final here = showing == null
@@ -291,9 +297,9 @@ class _TerminalSearchOverlayState extends State<TerminalSearchOverlay>
)
.firstOrNull;
if (!ready && first == null) return null;
- return (place) {
+ return (place, {newTab = false}) {
// Read before Find goes away with the chips.
- final deskTabId = _results.currentState?.deskTabId;
+ final deskTabId = newTab ? null : _results.currentState?.deskTabId;
_close();
if (place != null) {
unawaited(
@@ -303,6 +309,7 @@ class _TerminalSearchOverlayState extends State<TerminalSearchOverlay>
place.machineId,
folder: place.folder,
deskTabId: deskTabId,
+ newDeskTab: newTab,
voice: widget.voice,
),
);
@@ -313,6 +320,7 @@ class _TerminalSearchOverlayState extends State<TerminalSearchOverlay>
widget.notifier,
showing!.machineId,
deskTabId: deskTabId,
+ newDeskTab: newTab,
voice: widget.voice,
),
);
@@ -323,6 +331,7 @@ class _TerminalSearchOverlayState extends State<TerminalSearchOverlay>
widget.notifier,
first!.machine.machineId,
deskTabId: deskTabId,
+ newDeskTab: newTab,
),
);
}
@@ -555,6 +564,9 @@ class _TerminalSearchOverlayState extends State<TerminalSearchOverlay>
onNewHarness: newAgent == null
? null
: (place) => newAgent(place),
+ onNewTab: newAgent == null
+ ? null
+ : () => newAgent(null, newTab: true),
),
},
),
diff --git a/mobile/lib/state/app_state.dart b/mobile/lib/state/app_state.dart
index e2ea71d69..6ca3a7b9c 100644
--- a/mobile/lib/state/app_state.dart
+++ b/mobile/lib/state/app_state.dart
@@ -195,6 +195,10 @@ class AgentCreationAttempt {
/// The desk tab the agent joins once started, picked before it was asked for — see
/// [PhoneDesk.adopt]. Null joins the tab the phone is in.
String? _deskTabId;
+
+ /// The agent opens a desk tab of its own once started — the `+` at the end of Find's tab chips.
+ /// See [PhoneDesk.adopt].
+ bool _newDeskTab = false;
Map<String, dynamic>? _choices;
Future<String?>? _inFlight;
bool _awaitingConfirmation = false, _finished = false;
@@ -6249,7 +6253,8 @@ class AppNotifier extends ChangeNotifier {
/// picked — cannot be forgotten.
///
/// [deskTabId] is the desk tab the agent joins once started — the one Find was narrowed to —
- /// instead of the tab the phone is in. See [PhoneDesk.adopt].
+ /// instead of the tab the phone is in. [newDeskTab] opens a desk tab of its own for it instead —
+ /// Find's `+` at the end of the tab chips. See [PhoneDesk.adopt].
Future<String?> createAgent(
String machineId, {
required String engine,
@@ -6264,6 +6269,7 @@ class AppNotifier extends ChangeNotifier {
GridModel? model,
String? swarmId,
String? deskTabId,
+ bool newDeskTab = false,
AgentCreationAttempt? attempt,
String? prompt,
String? name,
@@ -6301,6 +6307,7 @@ class AppNotifier extends ChangeNotifier {
choices,
swarmId: swarmId,
deskTabId: deskTabId,
+ newDeskTab: newDeskTab,
attempt: creation,
);
}
@@ -6462,6 +6469,7 @@ class AppNotifier extends ChangeNotifier {
Map<String, dynamic> choices, {
String? swarmId,
String? deskTabId,
+ bool newDeskTab = false,
AgentCreationAttempt? attempt,
}) {
final creation = attempt ?? AgentCreationAttempt();
@@ -6480,6 +6488,7 @@ class AppNotifier extends ChangeNotifier {
creation._targetId = swarmId ?? activeSwarmId;
// With the request, not read again on a Check status: the tab picked is the one asked for.
creation._deskTabId = deskTabId;
+ creation._newDeskTab = newDeskTab;
}
final work = _createAgentWithReceipt(creation);
creation._inFlight = work;
@@ -6854,12 +6863,14 @@ class AppNotifier extends ChangeNotifier {
return null;
}
// Created HERE, so it joins the tab this phone is in — the way an agent
- // created in a window joins that window's tab — or the tab picked for it.
- // See [PhoneDesk.adopt] for what happens when the phone is in no tab.
+ // created in a window joins that window's tab — or the tab picked for it,
+ // or a tab of its own. See [PhoneDesk.adopt] for what happens when the
+ // phone is in no tab.
_desk.adopt(
(machineId: machineId, agentId: agent.id),
name: agent.displayName,
tabId: creation._deskTabId,
+ newTab: creation._newDeskTab,
);
await assignAgentToPane(null, machineId, agent.id, swarmId: targetId);
return null;
diff --git a/mobile/lib/state/phone_desk.dart b/mobile/lib/state/phone_desk.dart
index a7b6b03b4..9812a8e4e 100644
--- a/mobile/lib/state/phone_desk.dart
+++ b/mobile/lib/state/phone_desk.dart
@@ -222,9 +222,9 @@ class PhoneDesk {
/// (the desk is empty, or the person is in the group for agents no tab holds):
/// the agent is then exactly where it would have been anyway.
///
- /// [name] is the agent's own, and it is used only by [openNextAgentInNewTab]
- /// — a tab made for one agent is named after it, which is what a window does
- /// with a tab it opens.
+ /// [name] is the agent's own, and it is used only for a tab of its own
+ /// ([newTab], [openNextAgentInNewTab]) — a tab made for one agent is named
+ /// after it, which is what a window does with a tab it opens.
///
/// [tabId] is a tab the person picked for this agent before asking for it —
/// Find narrowed to a tab when New Harness was tapped — and it wins over the
@@ -232,9 +232,20 @@ class PhoneDesk {
/// so still names the tab Find was opened over. The phone is in the picked tab
/// from here, as it is after [createTabFor]. A tab closed on another computer
/// while the form was open falls back to the tab the phone is in.
- void adopt(AgentRef agent, {String? name, String? tabId}) {
+ ///
+ /// [newTab] is the `+` at the end of Find's tab chips: the agent opens a tab
+ /// of its own ([createTabFor]), the way the desktop's `+` opens a New Tab that
+ /// becomes everyone's tab once its first harness is in it. It travels with
+ /// the request rather than being armed here, so only the agent asked for
+ /// from that `+` gets the tab — never a fork or a form opened later.
+ void adopt(
+ AgentRef agent, {
+ String? name,
+ String? tabId,
+ bool newTab = false,
+ }) {
if (!_state.enabled) return;
- final wanted = _newTabForNextAgent;
+ final wanted = newTab || _newTabForNextAgent;
_newTabForNextAgent = false;
final pane = DeskPaneRef(
machineId: agent.machineId,
diff --git a/mobile/test/desk_tab_filter_bar_test.dart b/mobile/test/desk_tab_filter_bar_test.dart
new file mode 100644
index 000000000..2d2c2ca01
--- /dev/null
+++ b/mobile/test/desk_tab_filter_bar_test.dart
@@ -0,0 +1,68 @@
+import 'package:flutter/material.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness_mobile/phone/desk_tab_filter_bar.dart';
+
+/// The chips under Find's field, and the `+` after the last of them — the desktop's New Tab.
+void main() {
+ const choices = [
+ DeskTabFilterChoice(id: null, name: 'All', count: 3),
+ DeskTabFilterChoice(id: 't1', name: 'Desktop', count: 2),
+ DeskTabFilterChoice(id: 't2', name: 'Docker', count: 1),
+ ];
+ final newTab = find.byKey(const ValueKey('find-new-tab'));
+
+ Future<void> pumpBar(
+ WidgetTester tester, {
+ VoidCallback? onNewTab,
+ ValueChanged<String?>? onSelected,
+ }) => tester.pumpWidget(
+ MaterialApp(
+ home: Scaffold(
+ body: DeskTabFilterBar(
+ choices: choices,
+ selected: null,
+ onSelected: onSelected ?? (_) {},
+ onNewTab: onNewTab,
+ ),
+ ),
+ ),
+ );
+
+ testWidgets('a tap on the + asks for a new tab, and picks no chip', (
+ tester,
+ ) async {
+ var asked = 0;
+ final picked = <String?>[];
+ await pumpBar(tester, onNewTab: () => asked++, onSelected: picked.add);
+
+ await tester.tap(newTab);
+ await tester.pump();
+
+ expect(asked, 1);
+ expect(picked, isEmpty);
+ });
+
+ testWidgets('the + comes after every chip', (tester) async {
+ await pumpBar(tester, onNewTab: () {});
+
+ for (final name in ['All', 'Desktop', 'Docker']) {
+ expect(
+ tester.getTopLeft(newTab).dx,
+ greaterThan(tester.getTopRight(find.text(name)).dx),
+ reason: name,
+ );
+ }
+ // As tall as a chip, and square.
+ final size = tester.getSize(
+ find.descendant(of: newTab, matching: find.byType(AnimatedContainer)),
+ );
+ expect(size.width, size.height);
+ });
+
+ testWidgets('no + without somewhere to send it', (tester) async {
+ await pumpBar(tester);
+
+ expect(newTab, findsNothing);
+ expect(find.bySemanticsLabel('New Tab'), findsNothing);
+ });
+}
diff --git a/mobile/test/desk_writes_test.dart b/mobile/test/desk_writes_test.dart
index 19111a192..bdfe5a4e2 100644
--- a/mobile/test/desk_writes_test.dart
+++ b/mobile/test/desk_writes_test.dart
@@ -142,6 +142,75 @@ void main() {
expect(agentsOf(app, 't2'), ['c', 'new']);
});
+ test(
+ 'an agent created for a new tab opens a tab of its own, not the tab picked',
+ () async {
+ final app = await deskApp(
+ _Conn(),
+ opensTerminals: false,
+ tabs: [
+ deskTab('t1', 'Desktop', ['a']),
+ deskTab('t2', 'Docker', ['c']),
+ ],
+ );
+ addTearDown(app.dispose);
+ app.noteDeskTab('t1');
+
+ final error = await app.createAgent(
+ 'm',
+ engine: 'claude',
+ folder: '/work',
+ deskTabId: 't2',
+ newDeskTab: true,
+ );
+ await pumpEventQueue();
+
+ expect(error, isNull);
+ expect(app.deskTabs, hasLength(3));
+ final made = app.deskTabs.last;
+ expect(agentsOf(app, 't1'), ['a']);
+ expect(agentsOf(app, 't2'), ['c']);
+ expect(agentsOf(app, made.id), ['new']);
+ expect(app.activeDeskTabId, made.id);
+ expect(deskApiOf(app).written.map((op) => op['op']), [
+ 'tab.create',
+ 'pane.add',
+ ]);
+ },
+ );
+
+ test('a Check status after a lost reply keeps the new tab', () async {
+ final app = await deskApp(
+ _Conn(losesFirstReply: true),
+ opensTerminals: false,
+ tabs: [
+ deskTab('t1', 'Desktop', ['a']),
+ ],
+ );
+ addTearDown(app.dispose);
+ app.noteDeskTab('t1');
+ final attempt = AgentCreationAttempt();
+
+ final lost = await app.createAgent(
+ 'm',
+ engine: 'claude',
+ folder: '/work',
+ newDeskTab: true,
+ attempt: attempt,
+ );
+ expect(lost, contains('has not confirmed the new harness yet'));
+ expect(deskApiOf(app).written, isEmpty);
+
+ // Asked about with what it was first made with — the new tab is not asked for again.
+ final checked = await app.checkAgentCreation(attempt);
+ await pumpEventQueue();
+
+ expect(checked, isNull);
+ expect(app.deskTabs, hasLength(2));
+ expect(agentsOf(app, 't1'), ['a']);
+ expect(agentsOf(app, app.deskTabs.last.id), ['new']);
+ });
+
test('an agent deleted on the phone leaves the tabs it was on', () async {
final app = await deskApp(
_Conn(),
diff --git a/mobile/test/find_tab_new_harness_test.dart b/mobile/test/find_tab_new_harness_test.dart
index 5a6a14c18..b7d9e4502 100644
--- a/mobile/test/find_tab_new_harness_test.dart
+++ b/mobile/test/find_tab_new_harness_test.dart
@@ -66,6 +66,11 @@ void main() {
String? formTab(WidgetTester tester) =>
tester.widget<NewAgentPage>(find.byType(NewAgentPage)).deskTabId;
+ bool formNewTab(WidgetTester tester) =>
+ tester.widget<NewAgentPage>(find.byType(NewAgentPage)).newDeskTab;
+
+ final newTab = find.byKey(const ValueKey('find-new-tab'));
+
/// Takes the form down and runs its clocks out, so no timer outlives the test.
Future<void> unmount(WidgetTester tester) async {
await tester.pumpWidget(const SizedBox());
@@ -106,6 +111,72 @@ void main() {
await unmount(tester);
});
+ // Find's `+` after the last tab chip is the desktop's New Tab: the harness made opens a tab of
+ // its own, whatever tab the chips are narrowed to.
+ testWidgets('the + after the last tab makes it in a tab of its own', (
+ tester,
+ ) async {
+ await openFind(tester);
+ await pickTab(tester, 'Docker');
+
+ await openForm(tester, newTab);
+
+ expect(find.byType(NewAgentPage), findsOneWidget);
+ expect(formNewTab(tester), isTrue);
+ expect(formTab(tester), isNull);
+ await unmount(tester);
+ });
+
+ testWidgets('the + sits after the last tab, on the chips row', (
+ tester,
+ ) async {
+ await openFind(tester);
+
+ expect(newTab, findsOneWidget);
+ expect(
+ find.descendant(of: find.byType(DeskTabFilterBar), matching: newTab),
+ findsOneWidget,
+ );
+ final docker = find.descendant(
+ of: find.byType(DeskTabFilterBar),
+ matching: find.text('Docker'),
+ );
+ expect(
+ tester.getTopLeft(newTab).dx,
+ greaterThan(tester.getTopRight(docker).dx),
+ );
+ expect(
+ tester.getCenter(newTab).dy,
+ closeTo(tester.getCenter(docker).dy, 1),
+ );
+ expect(find.bySemanticsLabel('New Tab'), findsOneWidget);
+ });
+
+ testWidgets('the foot and the row still join the tab picked, not a new one', (
+ tester,
+ ) async {
+ await openFind(tester);
+ await pickTab(tester, 'Docker');
+
+ await openForm(tester, find.byKey(const ValueKey('find-new-harness')));
+
+ expect(formNewTab(tester), isFalse);
+ expect(formTab(tester), 't2');
+ await unmount(tester);
+ });
+
+ testWidgets('no + while no computer can take a new harness', (tester) async {
+ final app = await openFind(tester);
+ app.stateOf('m')!.nodeOnline = false;
+ app.notifyListeners();
+ await tester.pump();
+
+ // The chips stay; only the doors to a new harness go.
+ expect(find.byType(DeskTabFilterBar), findsOneWidget);
+ expect(newTab, findsNothing);
+ expect(find.byKey(const ValueKey('find-new-harness')), findsNothing);
+ });
+
// The first screen after pairing draws Find's own list, chips and `+ New Harness` included.
testWidgets('the pick-up screen makes it in the tab picked too', (
tester,
diff --git a/mobile/test/phone_desk_test.dart b/mobile/test/phone_desk_test.dart
index 51e44fcee..835c3e60f 100644
--- a/mobile/test/phone_desk_test.dart
+++ b/mobile/test/phone_desk_test.dart
@@ -221,6 +221,75 @@ void main() {
},
);
+ // Find's `+` after the last tab chip: the desktop's New Tab.
+ test(
+ 'an agent made from the + after the tabs opens a tab of its own, and the phone is in it',
+ () async {
+ await join();
+ desk.note('t1');
+
+ desk.adopt(
+ (machineId: 'm', agentId: 'new'),
+ name: 'Fix login',
+ newTab: true,
+ );
+
+ expect([for (final tab in desk.tabs) tab.name], [
+ 'Desktop',
+ 'Docker',
+ 'Fix login',
+ ]);
+ final made = desk.tabs.last;
+ expect(_agentsOf(desk, made.id), ['new']);
+ expect(made.nameIsCustom, isFalse);
+ expect(_agentsOf(desk, 't1'), ['a', 'b']);
+ expect(desk.activeTabId, made.id);
+ await pumpEventQueue();
+ expect(backend.received.map((op) => op['op']), [
+ 'tab.create',
+ 'pane.add',
+ ]);
+ expect(backend.received.last['agentId'], 'new');
+ },
+ );
+
+ test('a tab of its own wins over a tab picked by hand', () async {
+ await join();
+ desk.note('t1');
+
+ desk.adopt((machineId: 'm', agentId: 'new'), tabId: 't2', newTab: true);
+ await pumpEventQueue();
+
+ expect(desk.tabs, hasLength(3));
+ expect(_agentsOf(desk, 't2'), ['c']);
+ expect(_agentsOf(desk, desk.tabs.last.id), ['new']);
+ expect(desk.activeTabId, desk.tabs.last.id);
+ });
+
+ test('a tab of its own is for that agent alone, not the next', () async {
+ await join();
+ desk.note('t2');
+
+ desk.adopt((machineId: 'm', agentId: 'new'), newTab: true);
+ final made = desk.tabs.last.id;
+ // The next agent made on the phone — a fork, a form opened later — joins the tab the phone
+ // is in, which is the new one now.
+ desk.adopt((machineId: 'm', agentId: 'next'));
+ await pumpEventQueue();
+
+ expect(desk.tabs, hasLength(3));
+ expect(_agentsOf(desk, made), ['new', 'next']);
+ });
+
+ test('a phone with no desk makes no tab for a new agent', () async {
+ // Never joined: the desk has not answered, so nothing can be written.
+ desk.adopt((machineId: 'm', agentId: 'new'), newTab: true);
+ await pumpEventQueue();
+
+ expect(desk.tabs, isEmpty);
+ expect(backend.received, isEmpty);
+ });
+
test('a tab picked by hand counts with the phone in no tab too', () async {
await join();
desk.note(null);