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.

Fix Super Tab Add machine UX: no silent re-registration, offline/linked state named

bitcoinbuilderc494917e449c
diff --git a/desktop/lib/super_tabs/machines.dart b/desktop/lib/super_tabs/machines.dart
index f50f55473..eb5ba300f 100644
--- a/desktop/lib/super_tabs/machines.dart
+++ b/desktop/lib/super_tabs/machines.dart
@@ -125,19 +125,45 @@ class _SuperTabMachinesState extends State<SuperTabMachines> {
Future<void> _contribute({Map<String, dynamic>? existing}) async {
final app = widget.app;
if (app == null) return;
- final choices = app.machineStates.values
+ final isConfigure = existing != null;
+ final existingId = existing?['machineId'] as String?;
+ bool isExisting(MachineState m) =>
+ existingId != null && m.machine.machineId == existingId;
+ // Only this account's own, reachable computers can be offered — a machine
+ // already in the tab would duplicate its entry, and one offline or
+ // unlinked cannot actually be contributed right now. The machine being
+ // configured is always its own exception: that is the one entry this
+ // dialog is editing, not adding.
+ final own = app.machineStates.values
+ .where((m) => !m.machine.isShared && !m.machine.isSharedMachine)
+ .toList();
+ final addable = own
.where(
(m) =>
- !m.machine.isShared &&
- !m.machine.isSharedMachine &&
- !m.needsLink &&
- m.nodeOnline != false,
+ isExisting(m) ||
+ (!_ids.contains(m.machine.machineId) &&
+ !m.needsLink &&
+ !m.isOffline),
)
.toList();
+ final alreadyInTab = own
+ .where((m) => !isExisting(m) && _ids.contains(m.machine.machineId))
+ .toList();
+ final offline = own
+ .where(
+ (m) =>
+ !isExisting(m) &&
+ !_ids.contains(m.machine.machineId) &&
+ (m.needsLink || m.isOffline),
+ )
+ .toList();
+ String labelFor(MachineState m) => m.isLocalMachine
+ ? 'This Mac (${m.machine.displayName})'
+ : m.machine.displayName;
String? machineId =
- existing?['machineId'] as String? ??
- choices.where((m) => m.isLocalMachine).firstOrNull?.machine.machineId ??
- choices.firstOrNull?.machine.machineId;
+ existingId ??
+ addable.where((m) => m.isLocalMachine).firstOrNull?.machine.machineId ??
+ addable.firstOrNull?.machine.machineId;
String? error;
var busy = false;
String? setupId;
@@ -247,33 +273,29 @@ class _SuperTabMachinesState extends State<SuperTabMachines> {
}
}
+ final canAdd = addable.isNotEmpty;
+ final String emptyStatement = own.isEmpty
+ ? 'No computer is connected to this account yet.'
+ : alreadyInTab.length == 1 && offline.isEmpty
+ ? '${labelFor(alreadyInTab.single)} is already in this tab.'
+ : 'No other computer can be added to this tab right now.';
return AlertDialog(
- title: const Text('Add machine'),
+ title: Text(isConfigure ? 'Configure machine' : 'Add machine'),
content: SizedBox(
width: 360,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
- if (choices.isEmpty)
- Text(
- 'Connect a computer to Harness first.',
- style: DesktopChrome.text(),
- )
- else
+ if (canAdd)
AbsorbPointer(
absorbing: busy,
child: AppSelectField<String>(
value: machineId!,
semanticLabel: 'Machine',
options: [
- for (final m in choices)
- SelectOption(
- value: m.machine.machineId,
- label: m.isLocalMachine
- ? 'This Mac'
- : m.machine.displayName,
- ),
+ for (final m in addable)
+ SelectOption(value: m.machine.machineId, label: labelFor(m)),
],
onChanged: (id) {
if (busy) return;
@@ -284,12 +306,47 @@ class _SuperTabMachinesState extends State<SuperTabMachines> {
});
},
),
+ )
+ else
+ Text(emptyStatement, style: DesktopChrome.text()),
+ if (alreadyInTab.isNotEmpty) ...[
+ const SizedBox(height: 12),
+ Text(
+ 'Already in this tab: ${alreadyInTab.map(labelFor).join(', ')}',
+ style: DesktopChrome.metadata(),
),
+ ],
+ for (final m in offline) ...[
+ const SizedBox(height: 4),
+ Text(
+ 'Offline: ${labelFor(m)}. Start Harness on it to add it.',
+ style: DesktopChrome.metadata(),
+ ),
+ ],
const SizedBox(height: 16),
- Text(
- 'Let the lead run agents here using this machine’s signed-in accounts.',
- style: DesktopChrome.text(),
- ),
+ if (canAdd)
+ Text(
+ 'Let the lead run agents here using this machine’s signed-in accounts.',
+ style: DesktopChrome.text(),
+ )
+ else ...[
+ Text(
+ 'To add another computer, install Harness on it and sign in with '
+ 'this account, or approve a device with no screen from Machines.',
+ style: DesktopChrome.text(),
+ ),
+ const SizedBox(height: 4),
+ Align(
+ alignment: Alignment.centerLeft,
+ child: TextButton(
+ onPressed: () {
+ Navigator.pop(context);
+ app.requestMachines();
+ },
+ child: const Text('Open Machines'),
+ ),
+ ),
+ ],
if (error != null) ...[
const SizedBox(height: 12),
Text(error!, style: DesktopChrome.metadata()),
@@ -298,10 +355,20 @@ class _SuperTabMachinesState extends State<SuperTabMachines> {
),
),
actions: [
- FilledButton(
- onPressed: busy || machineId == null ? null : save,
- child: Text(busy ? 'Preparing…' : 'Add machine'),
- ),
+ if (canAdd)
+ FilledButton(
+ onPressed: busy || machineId == null ? null : save,
+ child: Text(
+ busy
+ ? (isConfigure ? 'Saving…' : 'Preparing…')
+ : (isConfigure ? 'Save' : 'Add machine'),
+ ),
+ )
+ else
+ TextButton(
+ onPressed: () => Navigator.pop(context),
+ child: const Text('Close'),
+ ),
],
);
},
diff --git a/desktop/test/super_tab_machines_test.dart b/desktop/test/super_tab_machines_test.dart
index aba50ee30..1f6e6cd75 100644
--- a/desktop/test/super_tab_machines_test.dart
+++ b/desktop/test/super_tab_machines_test.dart
@@ -1,11 +1,38 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
+import 'package:harness/core/models.dart';
+import 'package:harness/state/app_state.dart';
import 'package:harness/super_tabs/machines.dart';
import 'package:harness/super_tabs/model.dart';
import 'package:harness/shared/widgets/app_select_field.dart';
import 'super_tab_launch_test.dart' show SuperTabLaunchFixture, tabId;
+Future<void> _openAddMachineDialog(
+ WidgetTester tester,
+ SuperTabLaunchFixture f,
+ dynamic c,
+) async {
+ await tester.pumpWidget(
+ MaterialApp(
+ home: Scaffold(
+ body: SizedBox(
+ width: 300,
+ height: 400,
+ child: SuperTabMachines(
+ controller: c,
+ app: f.app,
+ onAddAgent: (_) {},
+ ),
+ ),
+ ),
+ ),
+ );
+ await tester.pumpAndSettle();
+ await tester.tap(find.byTooltip('Add machine'));
+ await tester.pumpAndSettle();
+}
+
void main() {
test('shared repository metadata excludes embedded credentials', () {
expect(
@@ -56,7 +83,10 @@ void main() {
await tester.tap(find.byTooltip('Add machine'));
await tester.pumpAndSettle();
expect(find.byType(AppSelectField<String>), findsOneWidget);
- expect(find.text('This Mac'), findsOneWidget);
+ expect(
+ find.text('This Mac (${f.app.stateOf('m')!.machine.displayName})'),
+ findsOneWidget,
+ );
expect(find.byType(Checkbox), findsNothing);
expect(find.text('Choose project folder'), findsNothing);
await tester.tap(find.widgetWithText(FilledButton, 'Add machine'));
@@ -78,4 +108,161 @@ void main() {
await tester.pump();
},
);
+
+ testWidgets(
+ 'Add machine: only This Mac, already in the tab, offers no picker and no Add machine button',
+ (tester) async {
+ final f = SuperTabLaunchFixture();
+ f.app.bindSuperTab(f.app.activeSwarmId, tabId, 'Pilot');
+ f.connection.server.state['machines'] = [
+ {'machineId': 'm', 'contributorId': 'owner'},
+ ];
+ final c = await f.app.superTabs.open(tabId);
+ await c.refresh();
+ await _openAddMachineDialog(tester, f, c);
+
+ expect(find.byType(AppSelectField<String>), findsNothing);
+ expect(find.widgetWithText(FilledButton, 'Add machine'), findsNothing);
+ expect(
+ find.text(
+ 'This Mac (${f.app.stateOf('m')!.machine.displayName}) is already in this tab.',
+ ),
+ findsOneWidget,
+ );
+ expect(
+ find.textContaining('install Harness on it and sign in'),
+ findsOneWidget,
+ );
+ expect(find.widgetWithText(TextButton, 'Close'), findsOneWidget);
+ expect(find.widgetWithText(TextButton, 'Open Machines'), findsOneWidget);
+
+ await tester.pumpWidget(const SizedBox());
+ await c.flush();
+ f.app.superTabs.dispose();
+ await tester.pump();
+ },
+ );
+
+ testWidgets(
+ 'Add machine: with This Mac already in the tab, the picker offers only another online own '
+ 'machine, preselected, and keeps Add machine enabled',
+ (tester) async {
+ final f = SuperTabLaunchFixture();
+ f.app.bindSuperTab(f.app.activeSwarmId, tabId, 'Pilot');
+ f.connection.server.state['machines'] = [
+ {'machineId': 'm', 'contributorId': 'owner'},
+ ];
+ const other = Machine(
+ machineId: 'm2',
+ authMode: MachineAuthMode.remote,
+ name: 'Other Mac',
+ );
+ f.app.machines = [...f.app.machines, other];
+ f.app.machineStates['m2'] = MachineState(other)
+ ..nodeOnline = true
+ ..connectionStatus = ConnectionStatus.connected
+ ..agentLoadStatus = AgentLoadStatus.loaded;
+ final c = await f.app.superTabs.open(tabId);
+ await c.refresh();
+ await _openAddMachineDialog(tester, f, c);
+
+ expect(find.byType(AppSelectField<String>), findsOneWidget);
+ expect(find.text('Other Mac'), findsOneWidget);
+ expect(
+ find.text(
+ 'This Mac (${f.app.stateOf('m')!.machine.displayName})',
+ ),
+ findsNothing,
+ );
+ expect(
+ find.textContaining('Already in this tab:'),
+ findsOneWidget,
+ );
+ final button = tester.widget<FilledButton>(
+ find.widgetWithText(FilledButton, 'Add machine'),
+ );
+ expect(button.onPressed, isNotNull);
+
+ await tester.pumpWidget(const SizedBox());
+ await c.flush();
+ f.app.superTabs.dispose();
+ await tester.pump();
+ },
+ );
+
+ testWidgets(
+ 'Add machine: an offline own machine is not offered in the picker and is named as offline '
+ 'with a next step',
+ (tester) async {
+ final f = SuperTabLaunchFixture();
+ f.app.bindSuperTab(f.app.activeSwarmId, tabId, 'Pilot');
+ const offline = Machine(
+ machineId: 'm3',
+ authMode: MachineAuthMode.remote,
+ name: 'macbok test local',
+ );
+ f.app.machines = [...f.app.machines, offline];
+ f.app.machineStates['m3'] = MachineState(offline)
+ ..nodeOnline = false
+ ..connectionStatus = ConnectionStatus.disconnected
+ ..agentLoadStatus = AgentLoadStatus.loaded;
+ final c = await f.app.superTabs.open(tabId);
+ await c.refresh();
+ await _openAddMachineDialog(tester, f, c);
+
+ expect(find.byType(AppSelectField<String>), findsOneWidget);
+ expect(find.text('macbok test local'), findsNothing);
+ expect(
+ find.text('Offline: macbok test local. Start Harness on it to add it.'),
+ findsOneWidget,
+ );
+
+ await tester.pumpWidget(const SizedBox());
+ await c.flush();
+ f.app.superTabs.dispose();
+ await tester.pump();
+ },
+ );
+
+ testWidgets(
+ 'Configure on a machine card reads as editing: title "Configure machine", button "Save"',
+ (tester) async {
+ final f = SuperTabLaunchFixture();
+ f.app.bindSuperTab(f.app.activeSwarmId, tabId, 'Pilot');
+ f.connection.server.state['machines'] = [
+ {'machineId': 'm', 'contributorId': 'owner'},
+ ];
+ final c = await f.app.superTabs.open(tabId);
+ await c.refresh();
+ await tester.pumpWidget(
+ MaterialApp(
+ home: Scaffold(
+ body: SizedBox(
+ width: 300,
+ height: 400,
+ child: SuperTabMachines(
+ controller: c,
+ app: f.app,
+ onAddAgent: (_) {},
+ ),
+ ),
+ ),
+ ),
+ );
+ await tester.pumpAndSettle();
+ await tester.tap(find.byKey(const ValueKey('super-machine-m')));
+ await tester.pumpAndSettle();
+ await tester.tap(find.widgetWithText(TextButton, 'Configure'));
+ await tester.pumpAndSettle();
+
+ expect(find.text('Configure machine'), findsOneWidget);
+ expect(find.widgetWithText(FilledButton, 'Save'), findsOneWidget);
+ expect(find.widgetWithText(FilledButton, 'Add machine'), findsNothing);
+
+ await tester.pumpWidget(const SizedBox());
+ await c.flush();
+ f.app.superTabs.dispose();
+ await tester.pump();
+ },
+ );
}