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
fix(desktop): a Buddy starts in the project whose chat started it (#2370)
0xken15f8320df806ba
diff --git a/desktop/lib/super_tabs/buddies.dart b/desktop/lib/super_tabs/buddies.dartindex 1690b2a29..03c7a2a2e 100644--- a/desktop/lib/super_tabs/buddies.dart+++ b/desktop/lib/super_tabs/buddies.dart@@ -520,6 +520,10 @@ class SuperTabBuddyBar extends StatelessWidget {final error = start?['error'];if (start == null || (error is! String && start['harnessId'] != null)) {return _BuddyStart(+ // One bar per chat: another project's Buddy chat gets a bar of its+ // own, and leaving this one stops its start (Diego, 10-30: a Buddy+ // was created in whichever chat was open when setup ended).+ key: ValueKey(('super-buddy-start', chat.id)),controller: c,projectId: chat.projectId,padding: _padding,@@ -623,6 +627,7 @@ class SuperTabBuddyBar extends StatelessWidget {/// A viewer, who adds nothing, sees no bar.class _BuddyStart extends StatefulWidget {const _BuddyStart({+ super.key,required this.controller,required this.projectId,required this.padding,@@ -646,28 +651,30 @@ class _BuddyStartState extends State<_BuddyStart> {/// Starts the Buddy on [machine], first preparing it when it is one of the/// reader's machines outside the Swarm. A failed setup says why and starts- /// nothing.+ /// nothing. The Buddy is for the project whose chat was clicked: once the+ /// bar shows another chat, the start stops and sends nothing.Future<void> _start(BuddyMachine machine) async {if (_adding) return;+ final projectId = widget.projectId;+ bool here() => mounted && widget.projectId == projectId;setState(() {_adding = true;_error = null;});- final (:id, :setup, :error) = await _adder.resolve(- machine,- alive: () => mounted,- );+ final (:id, :setup, :error) = await _adder.resolve(machine, alive: here);if (!mounted) return;+ final stillHere = here();setState(() {_adding = false;- _error = error;+ // Another chat's bar never shows this start's error.+ _error = stillHere ? error : null;});- if (id == null) return;+ if (id == null || !stillHere) return;final app = widget.app;unawaited(c.addBuddy(- projectId: widget.projectId,+ projectId: projectId,machineId: id,engine: _engine,setup: setup,diff --git a/desktop/test/super_tab_buddy_own_machines_test.dart b/desktop/test/super_tab_buddy_own_machines_test.dartindex 21757c1bd..bab79587f 100644--- a/desktop/test/super_tab_buddy_own_machines_test.dart+++ b/desktop/test/super_tab_buddy_own_machines_test.dart@@ -15,6 +15,8 @@ import 'package:harness/super_tabs/view.dart';import 'super_tab_launch_test.dart' show SuperTabLaunchFixture, tabId;import 'support/capture.dart';+import 'support/super_tab_fixture.dart'+ show conversationFixture, projectFixture;/// The Buddy pickers list every machine of the reader's own (Dee, 10-29: "I/// just wanted to create my buddy. I don't want to add my machine to the@@ -459,6 +461,143 @@ void main() {});});+ // Diego, 10-30: a Buddy started in one project's chat was created in+ // whichever Buddy chat was open when this Mac's setup ended.+ group('the Start bar when the chat changes mid-setup', () {+ /// A second project, Beta, beside the Swarm's own.+ void twoProjects(SuperTabLaunchFixture f) {+ final state = f.connection.server.state;+ state['projects'] = [+ projectFixture('lead', 'Pilot', 'lead'),+ projectFixture('beta', 'Beta', 'beta-lead'),+ ];+ (state['conversations'] as List).add({+ ...conversationFixture('beta-lead', 'Lead'),+ 'projectId': 'beta',+ });+ }++ /// The projects each Buddy start was sent for.+ List<Object?> createdIn(SuperTabLaunchFixture f) => [+ for (final post in f.connection.server.posts)+ if ((post['command'] as Map)['type'] == 'buddy.create')+ (post['command'] as Map)['projectId'],+ ];+ final error = find.byKey(const ValueKey('super-buddy-start-error'));++ testWidgets(+ 'a setup that ends after Beta\'s chat opened starts nothing in Beta, '+ 'and Beta\'s bar is neither busy nor showing the first chat\'s error',+ (tester) async {+ final (:f, :c, :mac) = await open(+ tester,+ machines: [rig()],+ prepare: twoProjects,+ );+ expect(c.buddyChat('lead')?.id, c.selectedId);+ f.connection.keepPreparing = true;+ await tester.tap(start);+ await tester.pump();+ await tester.pump(const Duration(seconds: 2));+ expect(prepares(f), isNotEmpty);+ expect(tester.widget<FilledButton>(start).onPressed, isNull);++ expect(await c.openBuddyChat('beta'), isTrue);+ await tester.pump();+ expect(c.selectedId, c.buddyChat('beta')?.id);+ // Beta's own Start bar, free to use.+ expect(tester.widget<FilledButton>(start).onPressed, isNotNull);++ f.connection.keepPreparing = false;+ await settle(tester);++ expect(createdIn(f), isNot(contains('beta')));+ expect(c.buddy('beta'), isNull);+ // Nothing pulled the person back to the first chat either.+ expect(c.selectedId, c.buddyChat('beta')?.id);+ expect(tester.widget<FilledButton>(start).onPressed, isNotNull);+ expect(error, findsNothing);+ await close(tester, f, c);+ },+ );++ testWidgets('a setup that fails after Beta\'s chat opened shows nothing '+ 'in Beta', (tester) async {+ final (:f, :c, :mac) = await open(+ tester,+ machines: [rig()],+ prepare: twoProjects,+ );+ f.connection.keepPreparing = true;+ await tester.tap(start);+ await tester.pump();+ expect(await c.openBuddyChat('beta'), isTrue);+ await tester.pump();+ // Alpha's setup would now run out of time and say so.+ for (var i = 0; i < 6; i++) {+ await tester.pump(const Duration(seconds: 60));+ }+ await tester.pumpAndSettle();++ expect(find.textContaining('still running'), findsNothing);+ expect(error, findsNothing);+ expect(createdIn(f), isEmpty);+ await close(tester, f, c);+ });++ testWidgets('back in the first chat, Start starts its Buddy there', (+ tester,+ ) async {+ final (:f, :c, :mac) = await open(+ tester,+ machines: [rig()],+ prepare: twoProjects,+ );+ f.connection.keepPreparing = true;+ await tester.tap(start);+ await tester.pump();+ expect(await c.openBuddyChat('beta'), isTrue);+ await tester.pump();+ f.connection.keepPreparing = false;+ await settle(tester);++ expect(await c.openBuddyChat('lead'), isTrue);+ await tester.pump();+ await tester.tap(start);+ await settle(tester);++ expect(createdIn(f), ['lead']);+ expect(c.buddy('lead'), isNotNull);+ expect(c.buddy('beta'), isNull);+ await close(tester, f, c);+ });++ testWidgets('the same chat keeps the picked machine when it redraws', (+ tester,+ ) async {+ final (:f, :c, :mac) = await open(+ tester,+ prepare: (f) {+ twoProjects(f);+ accountMachines(f);+ },+ );+ await tester.tap(barMachine);+ await tester.pumpAndSettle();+ await tester.tap(find.text('Studio').last);+ await tester.pumpAndSettle();++ await c.refresh();+ await tester.pumpAndSettle();++ expect(+ find.descendant(of: barMachine, matching: find.text('Studio')),+ findsOneWidget,+ );+ await close(tester, f, c);+ });+ });+group('Add a Buddy', () {testWidgets('lists this Mac first and picked, under its heading alone', (tester,