The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
A new member's first join adds this computer and asks the account choice (#3367)
harness-for-autonomous[bot]062077589b2c
diff --git a/desktop/lib/state/app_state.dart b/desktop/lib/state/app_state.dartindex ae22d2069..39b18f53d 100644--- a/desktop/lib/state/app_state.dart+++ b/desktop/lib/state/app_state.dart@@ -1609,6 +1609,7 @@ class AppNotifier extends ChangeNotifier {deviceHosts.clear();_deviceReads.clear();// Names and membership belong to the account that discovered them.+ _openedInRun.clear();_superTabNames = {};}_currentUser = profile;@@ -1973,7 +1974,10 @@ class AppNotifier extends ChangeNotifier {// new here (task #3160)._addMachineWhereNew([for (final tab in tabs) tab.id],- {for (final swarm in swarms) ?swarm.superTabId, ...hidden},+ {+ for (final swarm in swarms) ?swarm.superTabId,+ ...hidden,+ }.difference(_openedInRun),);var changed = false;// Membership and names for the closed list: a tab hidden before a@@ -1992,6 +1996,7 @@ class AppNotifier extends ChangeNotifier {changed = true;}} else if (!hidden.contains(tab.id)) {+ _openedInRun.add(tab.id);swarms.add(Swarm(id: newDeskId(),@@ -2787,6 +2792,16 @@ class AppNotifier extends ChangeNotifier {/// (review of #3115).final _joinPassed = <String>{};+ /// The Swarms that became open on this computer during this run: joined in+ /// the dialog, opened by the person, or added by discovery. The update's+ /// baseline ([SwarmJoinSeen.fresh]) takes the Swarms a long-time member had+ /// open or hidden here as seen, never these: a new member's Swarm is open+ /// by the time the first pass that can add runs (this computer's own row,+ /// or Swarm mode, was not ready at sign-in), and counting it with the ones+ /// they had skipped the add and the account choice (task #3791). A Swarm the+ /// person had hidden and reopens stays known.+ final _openedInRun = <String>{};+/// The pass discovery started last, for tests to wait on.@visibleForTestingFuture<void> get joinAddPassForTest => _joinPass ?? Future.value();@@ -3007,6 +3022,7 @@ class AppNotifier extends ChangeNotifier {/// Reopen later cannot add a second view.void openSuperTab(String tabId, String name, {String? intoSwarmId}) {enterSuperTabs();+ _noteOpenedInRun(tabId);_rememberSuperTabVisibility(tabId, true);_closedHistory.removeWhere((entry) => entry is ClosedSwarm && entry.superTabId == tabId,@@ -3033,12 +3049,24 @@ class AppNotifier extends ChangeNotifier {bindSuperTab(activeSwarmId, tabId, name);}+ /// Notes that Swarm [tabId] is about to open on this computer for the first+ /// time in this run ([_openedInRun]). Read before the visibility is saved:+ /// showing a Swarm clears its hidden state at once, and one the person had+ /// hidden and reopens is still one they had.+ void _noteOpenedInRun(String tabId) {+ if (!swarms.any((s) => s.superTabId == tabId) &&+ !superTabs.hiddenIds.contains(tabId)) {+ _openedInRun.add(tabId);+ }+ }+/// Shows Swarm [tabId] in the Swarm tab [swarmId] in place of the Swarm it/// shows, from the Swarm dropdown: the tab keeps its place and its name/// follows. A Swarm already open in another tab is selected there instead,/// so no tab is added or closed. The Swarm the tab showed is hidden here as/// a closed one is, and let go, which keeps its draft for its return.void showSuperTabIn(String swarmId, String tabId, String name) {+ _noteOpenedInRun(tabId);final tab = swarms.where((s) => s.id == swarmId).firstOrNull;final previous = tab?.superTabId;if (tab == null || previous == null || previous == tabId) return;diff --git a/desktop/test/super_tab_launch_test.dart b/desktop/test/super_tab_launch_test.dartindex 9949fd26c..b84a9a6fd 100644--- a/desktop/test/super_tab_launch_test.dart+++ b/desktop/test/super_tab_launch_test.dart@@ -453,6 +453,8 @@ class SuperTabLaunchFixture {LocalCliDiscovery? discovery,SystemNotifications? systemNotifications,Future<String> Function(ProjectFolderRequest request)? prepareFolder,+ // False: a fresh sign-in, before any Swarm view (or draft) has put the app in Swarm mode.+ bool swarmMode = true,}) {connection =connectionFactory?.call(store) ??@@ -479,7 +481,7 @@ class SuperTabLaunchFixture {id: 'owner',email: '[email protected]',);- app.markSuperTabDraft(app.activeSwarmId);+ if (swarmMode) app.markSuperTabDraft(app.activeSwarmId);addTearDown(dispose);}final store = MemoryStore();diff --git a/desktop/test/swarm_first_join_paths_test.dart b/desktop/test/swarm_first_join_paths_test.dartnew file mode 100644index 000000000..33ddf0652--- /dev/null+++ b/desktop/test/swarm_first_join_paths_test.dart@@ -0,0 +1,136 @@+import 'package:flutter_test/flutter_test.dart';+import 'package:harness/state/app_state.dart';+import 'package:harness/state/swarm.dart';++import 'super_tab_launch_test.dart' show SuperTabLaunchFixture, tabId;++// Task #3791 (Scholes, 11-06): a new member on Desktop 1.3.82 still had to click Add machine and never saw the Harness+// Team account / My account choice. The join's add (#3115) and its choice (#3178) must run on every first join, however+// it happened, once for each Swarm on this computer and account, and never for a computer the person removed (#3138).++/// A fresh install's app: signed in, this Mac's own row not known yet, so nothing can be added until it is, and the+/// Swarm's server state naming the person a collaborator.+SuperTabLaunchFixture _freshComputer({bool chooseTeam = true}) {+ final f = SuperTabLaunchFixture();+ f.app.status = AppStatus.authenticated;+ f.app.teamAccountHereForTest = false;+ f.connection.teamCheck = {'state': 'wanted'};+ f.connection.server.state+ ..['ownerId'] = 'boss'+ ..['people'] = <dynamic>[+ {'id': 'boss', 'email': '[email protected]', 'role': 'owner'},+ {'id': 'owner', 'email': '[email protected]', 'role': 'collaborator'},+ ];+ if (chooseTeam) {+ f.app.addListener(() => f.app.joinAccountRequest?.complete(false));+ }+ return f;+}++/// What the Join Swarm dialog does once the server took the join+/// (`SwarmJoinDialog._join`): opens the Swarm, then asks for the add.+Future<void> _joinInTheDialog(SuperTabLaunchFixture f) async {+ f.app.openSuperTab(tabId, 'Swarm');+ await f.app.addMachineOnJoin(tabId, role: 'collaborator');+}++/// One discovery, and the add it started run to its end.+Future<void> _discover(SuperTabLaunchFixture f) async {+ await f.app.superTabs.refreshTabs();+ await f.app.joinAddPassForTest;+ await pumpEventQueue();+}++List<Map> _contributions(SuperTabLaunchFixture f) => [+ for (final post in f.connection.server.posts)+ if ((post['command'] as Map)['type'] == 'machine.contribute')+ post['command'] as Map,+];++void main() {+ test('an invite joined before this Mac\'s own row is known adds it once the row is, with no click', () async {+ final f = _freshComputer();+ await _joinInTheDialog(f);+ // Nothing could be added yet: this Mac's own row was not known.+ expect(_contributions(f), isEmpty);++ // The row arrives; the person never opens Machines. The first discovery+ // for this account must not take the Swarm they just joined as one they+ // already had (the update's baseline).+ f.app.teamAccountHereForTest = true;+ await _discover(f);+ expect(_contributions(f), [containsPair('teamAccountOnly', true)]);+ });++ test('the account choice appears for an invite joined before this Mac\'s own row is known', () async {+ final f = _freshComputer(chooseTeam: false);+ await _joinInTheDialog(f);+ f.app.teamAccountHereForTest = true;+ // The add waits for the person's answer, so the pass is not awaited here.+ await f.app.superTabs.refreshTabs();+ await pumpEventQueue();+ expect(f.app.joinAccountRequest, isNotNull);+ expect(f.app.joinAccountRequest!.swarmName, isNotEmpty);+ f.app.joinAccountRequest!.complete(false);+ await f.app.joinAddPassForTest;+ expect(_contributions(f), [containsPair('teamAccountOnly', true)]);+ });++ test('a domain auto-join listed at sign-in, then opened here, is added with the choice when this Mac\'s row is known', () async {+ // River, 11-06: the Swarm arrives at sign-in, before the add and the choice can run, and was then taken as one+ // the person already had. No dialog: the server joined them as someone at the owner's email domain.+ final f = _freshComputer(chooseTeam: false);+ (f.connection.server.state['people'] as List)[1]['joinedVia'] = 'domain';+ // Sign-in's discovery lists the Swarm; no Swarm view is open, so nothing runs.+ await f.app.superTabs.refreshTabs();+ await f.app.joinAddPassForTest;+ expect(_contributions(f), isEmpty);++ // The Swarm is shown (it is the person's only one), and this Mac's row arrives.+ f.app.openSuperTab(tabId, 'Swarm');+ f.app.teamAccountHereForTest = true;+ await f.app.superTabs.refreshTabs();+ await pumpEventQueue();+ expect(f.app.joinAccountRequest, isNotNull);+ f.app.joinAccountRequest!.complete(false);+ await f.app.joinAddPassForTest;+ expect(_contributions(f), [containsPair('teamAccountOnly', true)]);+ });++ test('a computer the person removed stays out of an invite joined before its row is known', () async {+ final f = _freshComputer();+ f.connection.server.state['removedMachines'] = ['m'];+ await _joinInTheDialog(f);+ f.app.teamAccountHereForTest = true;+ await _discover(f);+ expect(_contributions(f), isEmpty);+ expect(f.app.joinAccountRequest, isNull);+ });++ test('a Swarm the person hid before the update and reopens is still never added or asked about', () async {+ // Review of #3367: reopening clears the hidden state at once, so the reopened Swarm must still read as one they had.+ final f = _freshComputer(chooseTeam: false);+ await f.app.superTabs.setTabVisible(tabId, false);+ expect(f.app.superTabs.hiddenIds, contains(tabId));+ f.app.openSuperTab(tabId, 'Swarm');+ f.app.teamAccountHereForTest = true;+ // Not _discover: an add would wait for the person's answer.+ await f.app.superTabs.refreshTabs();+ await pumpEventQueue();+ expect(f.app.joinAccountRequest, isNull);+ expect(_contributions(f), isEmpty);+ });++ test('a Swarm the person already had open before the update is still never added', () async {+ // The baseline's own job (#3115): a long-time member's Swarms stay as they chose.+ final f = _freshComputer();+ // Restored from the saved layout at launch: not opened in this run.+ f.app.swarms.add(+ Swarm(id: 'restored', name: 'Swarm', nameIsCustom: true, kind: 'superTab')+ ..superTabId = tabId,+ );+ f.app.teamAccountHereForTest = true;+ await _discover(f);+ expect(_contributions(f), isEmpty);+ });+}diff --git a/desktop/test/swarm_first_join_widget_test.dart b/desktop/test/swarm_first_join_widget_test.dartnew file mode 100644index 000000000..8c0b567e3--- /dev/null+++ b/desktop/test/swarm_first_join_widget_test.dart@@ -0,0 +1,164 @@+import 'dart:async';++import 'package:flutter/material.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:harness/shared/theme/app_theme.dart' as grid;+import 'package:harness/state/app_state.dart';+import 'package:harness/super_tabs/join_dialog.dart';++import 'super_tab_launch_test.dart' show SuperTabLaunchFixture, tabId;++// Task #3791 (Scholes, 11-06; Rowtest's review): the first-join paths as a person sees them. Each mounts the join host+// the workspace mounts (`SwarmJoinHost`), so the account choice is the real dialog, and ends with this Mac added or+// not, with no click on Add machine. The state-level cases are in swarm_first_join_paths_test.dart.++/// A new member's app: signed in as a collaborator the server joined by their email domain, this Mac's own row known.+/// [swarmMode] false is a fresh sign-in, before any Swarm view has put the app in Swarm mode.+SuperTabLaunchFixture _newMember({bool swarmMode = true}) {+ final f = SuperTabLaunchFixture(swarmMode: swarmMode);+ f.app.status = AppStatus.authenticated;+ f.app.teamAccountHereForTest = true;+ f.connection.teamCheck = {'state': 'wanted'};+ f.connection.server.state+ ..['ownerId'] = 'boss'+ ..['people'] = <dynamic>[+ {'id': 'boss', 'email': '[email protected]', 'role': 'owner'},+ {+ 'id': 'owner',+ 'email': '[email protected]',+ 'role': 'collaborator',+ 'joinedVia': 'domain',+ },+ ];+ return f;+}++Future<void> _mount(WidgetTester tester, SuperTabLaunchFixture f) async {+ await tester.pumpWidget(+ MaterialApp(+ theme: grid.buildAppTheme(brightness: Brightness.light),+ home: SwarmJoinHost(app: f.app, child: const Scaffold()),+ ),+ );+ addTearDown(() => tester.binding.setSurfaceSize(null));+ await tester.binding.setSurfaceSize(const Size(900, 700));+}++/// One discovery, with the real timers of the fake server running.+Future<void> _discover(WidgetTester tester, SuperTabLaunchFixture f) async {+ await tester.runAsync(() async {+ await f.app.superTabs.refreshTabs();+ await pumpEventQueue();+ });+ await tester.pump();+ await tester.pump(const Duration(milliseconds: 50));+}++List<Map> _contributions(SuperTabLaunchFixture f) => [+ for (final post in f.connection.server.posts)+ if ((post['command'] as Map)['type'] == 'machine.contribute')+ post['command'] as Map,+];++/// The person answers the choice with its default, a separate Harness Team account, and waits for the add.+Future<void> _continueWithTeamAccount(+ WidgetTester tester,+ SuperTabLaunchFixture f,+) async {+ expect(find.text('Separate Harness Team account'), findsOneWidget);+ expect(find.text('My account'), findsOneWidget);+ await tester.tap(find.byKey(const Key('swarm-join-account-continue')));+ await tester.pump();+ await tester.runAsync(() async {+ await f.app.joinAddPassForTest;+ await pumpEventQueue();+ });+ await tester.pump(const Duration(milliseconds: 50));+}++void main() {+ testWidgets(+ 'a domain auto-join listed at sign-in, then opened from the picker, shows the choice and adds this Mac',+ (tester) async {+ // Sign-in's discovery lists the Swarm before the app is in Swarm mode: the result is dropped. The person then+ // opens that Swarm, so it is open here by the time the first pass that can add runs; it must still be new.+ final f = _newMember(swarmMode: false);+ await _mount(tester, f);+ await _discover(tester, f);+ expect(find.text('Separate Harness Team account'), findsNothing);+ expect(_contributions(f), isEmpty);++ f.app.openSuperTab(tabId, 'Swarm');+ await _discover(tester, f);+ await _continueWithTeamAccount(tester, f);+ expect(_contributions(f), [containsPair('teamAccountOnly', true)]);+ expect(_contributions(f).single['machineId'], 'm');+ },+ );++ testWidgets(+ 'a Swarm joined on the phone or in a Workspace, listed when Swarm mode is on, shows the choice and adds this Mac',+ (tester) async {+ final f = _newMember();+ await _mount(tester, f);+ await _discover(tester, f);+ await _continueWithTeamAccount(tester, f);+ expect(_contributions(f), [containsPair('teamAccountOnly', true)]);+ },+ );++ testWidgets(+ 'an invite joined in the dialog before this Mac\'s row is known shows the choice once it is, and adds this Mac',+ (tester) async {+ final f = _newMember();+ f.app.teamAccountHereForTest = false;+ await _mount(tester, f);+ // What the dialog does once the server took the join: opens the Swarm, then asks for the add.+ f.app.openSuperTab(tabId, 'Swarm');+ await tester.runAsync(+ () => f.app.addMachineOnJoin(tabId, role: 'collaborator'),+ );+ await tester.pump();+ expect(find.text('Separate Harness Team account'), findsNothing);++ f.app.teamAccountHereForTest = true;+ await _discover(tester, f);+ await _continueWithTeamAccount(tester, f);+ expect(_contributions(f), [containsPair('teamAccountOnly', true)]);+ },+ );++ testWidgets(+ 'a Swarm the person hid and reopens shows no choice and adds nothing',+ (tester) async {+ final f = _newMember();+ await _mount(tester, f);+ // The hidden id is set at once; its saved write is not what this checks.+ unawaited(f.app.superTabs.setTabVisible(tabId, false));+ expect(f.app.superTabs.hiddenIds, contains(tabId));+ f.app.openSuperTab(tabId, 'Swarm');+ await _discover(tester, f);+ // Nothing waits for an answer, so the pass ends by itself.+ await tester.runAsync(() => f.app.joinAddPassForTest);+ await tester.pump();+ expect(find.text('Separate Harness Team account'), findsNothing);+ expect(f.app.joinAccountRequest, isNull);+ expect(_contributions(f), isEmpty);+ },+ );++ testWidgets(+ 'a computer the person removed from the Swarm shows no choice and stays out',+ (tester) async {+ final f = _newMember();+ f.connection.server.state['removedMachines'] = ['m'];+ await _mount(tester, f);+ await _discover(tester, f);+ await tester.runAsync(() => f.app.joinAddPassForTest);+ await tester.pump();+ expect(find.text('Separate Harness Team account'), findsNothing);+ expect(f.app.joinAccountRequest, isNull);+ expect(_contributions(f), isEmpty);+ },+ );+}diff --git a/desktop/test/swarm_join_any_test.dart b/desktop/test/swarm_join_any_test.dartindex a5c5dd0dc..8eec34ec8 100644--- a/desktop/test/swarm_join_any_test.dart+++ b/desktop/test/swarm_join_any_test.dart@@ -1,6 +1,7 @@import 'package:fake_async/fake_async.dart';import 'package:flutter_test/flutter_test.dart';import 'package:harness/state/app_state.dart';+import 'package:harness/state/swarm.dart';import 'package:harness/super_tabs/join_machine.dart';import 'package:harness/ws/ws_conn.dart';@@ -233,7 +234,16 @@ void main() {'a Swarm already shown on this computer before the update is left as it is',() async {final f = _computer();- f.app.bindSuperTab(f.app.activeSwarmId, tabId, 'Pilot');+ // Restored from the saved layout at launch, as a long-time member's Swarm+ // is; a Swarm opened in this run is new here (task #3791).+ f.app.swarms.add(+ Swarm(+ id: 'restored',+ name: 'Pilot',+ nameIsCustom: true,+ kind: 'superTab',+ )..superTabId = tabId,+ );await _discover(f);expect(_contributions(f), isEmpty);expect(_teamOffers(f), isEmpty);