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
Phone: Open terminal in your Buddy chat's ⋮, as Team's (Tony) (#2486)
harness-for-autonomous[bot]aea6e81c1537
diff --git a/mobile/lib/swarm/swarm_buddy_chat.dart b/mobile/lib/swarm/swarm_buddy_chat.dartindex d47537b75..03bbdee84 100644--- a/mobile/lib/swarm/swarm_buddy_chat.dart+++ b/mobile/lib/swarm/swarm_buddy_chat.dart@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';import 'package:flutter/services.dart';import 'package:lucide_icons_flutter/lucide_icons.dart';+import 'package:harness_mobile/phone/phone_shell_scope.dart';import 'package:harness_mobile/phone/phone_sheet.dart';import 'package:harness_mobile/shared/theme/app_icon_size.dart';import 'package:harness_mobile/shared/theme/app_space.dart';@@ -21,6 +22,7 @@ import 'swarm_request.dart';import 'swarm_row.dart';import 'swarm_session.dart' show SwarmScope;import 'swarm_start.dart' show SwarmOwnComputer;+import 'swarm_terminal_row.dart';import 'swarm_style.dart';/// Opens the person's Buddy chat in [projectId] over [context]'s page, on the@@ -437,10 +439,12 @@ class _Field extends StatelessWidget {}/// At the end of the person's own Buddy chat's header, while they may-/// write: ⋮, with Rename Buddy, and Remove Buddy while one runs, which asks-/// first, then stops it; the chat stays (the desktop's Buddy options); and-/// the chat's Notifications, as its menu on the desktop has. Nothing in-/// anyone else's Buddy chat.+/// write: ⋮, with Open terminal first (Tony, 11-01: the Buddy's terminal on+/// this phone, as Team's agent rows open theirs; dimmed with why while it+/// cannot be, [swarmTerminalAction]), Rename Buddy, and Remove Buddy+/// while one runs, which asks first, then stops it; the chat stays (the+/// desktop's Buddy options); and the chat's Notifications, as its menu on+/// the desktop has. Nothing in anyone else's Buddy chat.class SwarmBuddyMenuButton extends StatelessWidget {const SwarmBuddyMenuButton({super.key,@@ -456,14 +460,31 @@ class SwarmBuddyMenuButton extends StatelessWidget {/// The sheet, with the chat's Notifications under the Buddy's own rows/// ([swarmNotifySection]). It goes once the chat is no longer the- /// person's own Buddy chat to read: access lost, or signed out.+ /// person's own Buddy chat to read (access lost, or signed out), they may+ /// no longer write there (a viewer now), or the Buddy it opened on is no+ /// longer theirs there (removed or being stopped). Its Open+ /// terminal row follows the Swarm and the phone's computers while open.Future<void> _open(BuildContext context, String chatId) async {final reader = actions.reader;+ final computers = SwarmScope.computersOf(context);+ final shell = PhoneShellScope.maybeOf(context);+ // The running Buddy the sheet has shown: one that starts while it is+ // open is taken up; one removed or being stopped closes it.+ String? running() => switch (swarmBuddy(reader, actions.projectId)) {+ final b? when b.workDecision != 'stop' => b.id,+ _ => null,+ };+ var buddyId = running();Route<void>? sheet;void moved() {final route = sheet;+ final now = running();+ buddyId ??= now;if (route == null ||- (!reader.accessRevoked && swarmIsOwnBuddyChat(reader, chatId))) {+ (!reader.accessRevoked &&+ swarmIsOwnBuddyChat(reader, chatId) &&+ swarmCanWrite(reader) &&+ now == buddyId)) {return;}sheet = null;@@ -478,24 +499,36 @@ class SwarmBuddyMenuButton extends StatelessWidget {context,title: swarmBuddyName(reader, actions.projectId),onShown: (route) => sheet = route,- rebuildOn: reader,- rows: () => (- actions: [- PhoneSheetAction(- icon: LucideIcons.pencil,- label: 'Rename Buddy',- onTap: () => unawaited(_rename(context, chatId)),- ),- if (swarmBuddy(reader, actions.projectId) != null)+ rebuildOn: Listenable.merge([reader, ?computers]),+ rows: () {+ final buddy = swarmBuddy(reader, actions.projectId);+ return (+ actions: [+ swarmTerminalAction(+ agent: () => swarmBuddy(reader, actions.projectId),+ allowed: () =>+ !reader.accessRevoked &&+ swarmIsOwnBuddyChat(reader, chatId) &&+ swarmCanWrite(reader),+ shell: shell,+ computers: computers,+ ),PhoneSheetAction(- icon: LucideIcons.userMinus,- label: 'Remove Buddy',- destructive: true,- onTap: () => unawaited(_confirmRemove(context)),+ icon: LucideIcons.pencil,+ label: 'Rename Buddy',+ onTap: () => unawaited(_rename(context, chatId)),),- ],- sections: [swarmNotifySection(context, reader, chatId)],- ),+ if (buddy != null)+ PhoneSheetAction(+ icon: LucideIcons.userMinus,+ label: 'Remove Buddy',+ destructive: true,+ onTap: () => unawaited(_confirmRemove(context)),+ ),+ ],+ sections: [swarmNotifySection(context, reader, chatId)],+ );+ },);} finally {reader.removeListener(moved);diff --git a/mobile/lib/swarm/swarm_terminal_row.dart b/mobile/lib/swarm/swarm_terminal_row.dartnew file mode 100644index 000000000..7e2c0b3fc--- /dev/null+++ b/mobile/lib/swarm/swarm_terminal_row.dart@@ -0,0 +1,69 @@+import 'package:lucide_icons_flutter/lucide_icons.dart';++import 'package:harness_mobile/phone/phone_shell_scope.dart';+import 'package:harness_mobile/phone/phone_sheet.dart';++import 'model.dart';+import 'swarm_start.dart' show SwarmComputers, SwarmOwnComputer;++/// Why this phone cannot open [agent]'s terminal now, in the word its Open+/// terminal row says; null when it can (Tony, 11-01). Team's rule: the+/// agent's machine linked to this phone and not reported offline+/// ([canOpen], `PhoneShellScope.canOpenMachine`). "Stopped" with no agent+/// running or one being stopped; "Not linked" for a machine this phone does+/// not have among the person's own [own] and cannot open (not linked here,+/// or a Harness Team account's); "Offline" for one it has but that is+/// reported offline, or an agent the Swarm says is down.+String? swarmTerminalBlock(+ SuperTabAgent? agent, {+ required bool Function(String machineId)? canOpen,+ required List<SwarmOwnComputer> own,+}) {+ if (agent == null ||+ agent.workDecision == 'stop' ||+ agent.harnessId.isEmpty ||+ agent.machineId.isEmpty) {+ return 'Stopped';+ }+ final opens = canOpen?.call(agent.machineId) == true;+ if (!opens && !own.any((m) => m.id == agent.machineId)) return 'Not linked';+ if (!opens || agent.downSince != null) return 'Offline';+ return null;+}++/// A sheet's Open terminal row for the agent [agent] reads now: it opens that+/// agent's terminal on this phone ([PhoneShellScope.onOpenAgent]), or is+/// dimmed with [swarmTerminalBlock]'s word. Checked again at the tap: still+/// [allowed], still the same agent, its machine still one the phone opens.+/// The caller rebuilds it as the Swarm and [computers] change.+PhoneSheetAction swarmTerminalAction({+ required SuperTabAgent? Function() agent,+ required bool Function() allowed,+ required PhoneShellScope? shell,+ required SwarmComputers? computers,+}) {+ String? block(SuperTabAgent? a) => swarmTerminalBlock(+ a,+ canOpen: shell?.canOpenMachine,+ own: computers?.own ?? const [],+ );+ final shown = agent();+ final why = block(shown);+ return PhoneSheetAction(+ icon: LucideIcons.squareTerminal,+ label: 'Open terminal',+ value: why,+ enabled: why == null,+ onTap: () {+ final now = agent();+ if (shell == null ||+ now == null ||+ now.id != shown?.id ||+ !allowed() ||+ block(now) != null) {+ return;+ }+ shell.onOpenAgent(now.machineId, now.harnessId);+ },+ );+}diff --git a/mobile/test/swarm/swarm_buddy_terminal_shots_test.dart b/mobile/test/swarm/swarm_buddy_terminal_shots_test.dartnew file mode 100644index 000000000..6c04f7629--- /dev/null+++ b/mobile/test/swarm/swarm_buddy_terminal_shots_test.dart@@ -0,0 +1,163 @@+import 'dart:convert';+import 'dart:io';+import 'dart:ui' as ui;++import 'package:flutter/material.dart';+import 'package:flutter/rendering.dart';+import 'package:flutter/services.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:harness_mobile/notify/system_notices.dart';+import 'package:harness_mobile/phone/phone_shell_scope.dart';+import 'package:harness_mobile/settings/experimental_features.dart';+import 'package:harness_mobile/shared/theme/app_theme.dart';+import 'package:harness_mobile/shared/theme/color_palette.dart';+import 'package:harness_mobile/swarm/swarm_conversation_page.dart';+import 'package:harness_mobile/swarm/swarm_session.dart';++import '../voice_fakes.dart';+import 'swarm_computers_fake.dart';+import 'swarm_fixture.dart';++/// Review screenshots of Open terminal in the real Buddy chat's ⋮, 390 points+/// wide in both phone themes, from made-up data, to the folder+/// `SWARM_BUDDY_TERMINAL_SHOTS` names: each state of its row.+final shots = Platform.environment['SWARM_BUDDY_TERMINAL_SHOTS'];++void main() {+ setUpAll(() async {+ if (shots == null || !Platform.isMacOS) return;+ final sf = ByteData.sublistView(+ await File('/System/Library/Fonts/SFNS.ttf').readAsBytes(),+ );+ for (final family in ['.AppleSystemUIFont', 'Roboto']) {+ await (FontLoader(family)..addFont(Future.value(sf))).load();+ }+ final mono = ByteData.sublistView(+ await File('/System/Library/Fonts/SFNSMono.ttf').readAsBytes(),+ );+ for (final family in ['.AppleSystemUIFontMonospaced', 'monospace']) {+ await (FontLoader(family)..addFont(Future.value(mono))).load();+ }+ final manifest =+ jsonDecode(await rootBundle.loadString('FontManifest.json')) as List;+ for (final entry in manifest.cast<Map<String, dynamic>>()) {+ final loader = FontLoader(entry['family'] as String);+ for (final font in (entry['fonts'] as List).cast<Map>()) {+ loader.addFont(rootBundle.load(font['asset'] as String));+ }+ await loader.load();+ }+ });++ testWidgets('Open terminal, in both phone themes', (tester) async {+ const chat = 'buddy-me';+ addTearDown(() => tester.binding.setSurfaceSize(null));+ for (final palette in [HarnessPalette.graphite, HarnessPalette.paper]) {+ final brightness = palette.brightness;+ AppTheme.palette.value = palette;+ AppTheme.brightness.value = brightness;+ await tester.binding.setSurfaceSize(const Size(390, 640));+ for (final state in ['open', 'stopped', 'offline', 'not-linked']) {+ final fake = FakeSwarm();+ fake.routes['/api/super-tabs/list'] = (_) => {+ 'tabs': [+ {'id': tab, 'name': 'OpenHarness', 'ownerId': me},+ ],+ 'next': null,+ };+ fake.routes['/api/super-tabs/$tab/parts'] = (_) => {+ ...firstLoad(+ groups: [+ {+ ...buddyChatData(chat, agentIds: ['agent-wren']),+ 'buddyName': 'Wren',+ },+ ],+ agents: [+ agent('agent-lead', name: 'Lead', displayName: 'River'),+ {+ ...buddyData('agent-wren', displayName: 'Wren'),+ if (state == 'stopped') 'workDecision': 'stop',+ },+ ],+ ),+ 'members': [+ part(me, 1, {...person(me), 'email': '[email protected]'}),+ ],+ };+ fake.routes['/api/super-tabs/$tab/changes'] = (_) =>+ changes(cursor: 'c2');+ fake.routes['/api/super-tabs/$tab/decisions?state=open'] = (_) => {+ 'decisions': <Object>[],+ };+ fake.routes['/api/super-tabs/$tab/mentions?state=waiting'] = (_) => {+ 'mentions': <Object>[],+ };+ fake.routes['/api/super-tabs/$tab/conversations/$chat/messages'] = (+ _,+ ) => {'messages': <Object>[], 'next': null};+ final computers = FakeComputers(const [])+ ..own = [+ if (state != 'not-linked')+ (+ id: 'mac-1',+ name: 'Tonys-MacBook-Pro',+ away: state == 'offline',+ ),+ ];+ final host = SwarmHost(+ accountId: () => me,+ account: ValueNotifier<String?>(me),+ request: fake.request,+ notices: SilentSystemNotices(),+ computers: computers,+ features: ExperimentalFeaturesStore(storage: MemoryKeyValueStore())+ ..value = {PhoneExperiment.swarm},+ readMarks: MemoryKeyValueStore(),+ )..foreground = false;+ final boundary = GlobalKey();+ await tester.pumpWidget(+ RepaintBoundary(+ key: boundary,+ child: MaterialApp(+ debugShowCheckedModeBanner: false,+ theme: buildAppTheme(brightness: brightness),+ builder: (_, child) => PhoneShellScope(+ onMachineLinked: (_) {},+ onOpenAgent: (_, _) {},+ canOpenMachine: (id) =>+ id == 'mac-1' && (state == 'open' || state == 'stopped'),+ child: SwarmScope(notifier: host, child: child!),+ ),+ home: const SwarmConversationPage(+ swarmId: tab,+ conversationId: chat,+ ),+ ),+ ),+ );+ await tester.pumpAndSettle();+ await tester.tap(find.byKey(const ValueKey('swarm-buddy-menu')));+ await tester.pumpAndSettle();+ expect(find.text('Open terminal'), findsOneWidget);+ expect(tester.takeException(), isNull);+ await tester.runAsync(() async {+ final image =+ await (boundary.currentContext!.findRenderObject()!+ as RenderRepaintBoundary)+ .toImage(pixelRatio: 3);+ final png = await image.toByteData(format: ui.ImageByteFormat.png);+ await Directory(shots!).create(recursive: true);+ await File(+ '$shots/phone-buddy-terminal-$state-${brightness.name}-390.png',+ ).writeAsBytes(png!.buffer.asUint8List());+ image.dispose();+ });+ await tester.pumpWidget(const SizedBox());+ host.dispose();+ computers.dispose();+ await tester.pump(const Duration(minutes: 1));+ }+ }+ }, skip: shots == null);+}diff --git a/mobile/test/swarm/swarm_buddy_terminal_test.dart b/mobile/test/swarm/swarm_buddy_terminal_test.dartnew file mode 100644index 000000000..19b2ec7a7--- /dev/null+++ b/mobile/test/swarm/swarm_buddy_terminal_test.dart@@ -0,0 +1,448 @@+import 'dart:async';++import 'package:flutter/material.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:harness_mobile/notify/system_notices.dart';+import 'package:harness_mobile/phone/phone_shell_scope.dart';+import 'package:harness_mobile/settings/experimental_features.dart';+import 'package:harness_mobile/shared/theme/app_theme.dart' as grid;+import 'package:harness_mobile/swarm/model.dart';+import 'package:harness_mobile/swarm/swarm_conversation_page.dart';+import 'package:harness_mobile/swarm/swarm_request.dart';+import 'package:harness_mobile/swarm/swarm_session.dart';+import 'package:harness_mobile/swarm/swarm_terminal_row.dart';++import '../voice_fakes.dart';+import 'swarm_computers_fake.dart';+import 'swarm_fixture.dart';++/// Open terminal in your Buddy chat's ⋮ (Tony, 11-01): first in the sheet,+/// opening the Buddy's terminal on this phone by Team's rule (its machine+/// linked here and not reported offline), otherwise dimmed with why:+/// Stopped, Offline or Not linked. Never in anyone else's Buddy chat nor for+/// a viewer, and the sheet goes with access or the Buddy.+void main() {+ const chat = 'buddy-me';+ const changesPath = '/api/super-tabs/$tab/changes';++ /// One Swarm where the person has their Buddy chat in Mobile, owned by+ /// [owner], with [buddies] in the Swarm's agents (Wren, the person's own on+ /// mac-1, unless told otherwise).+ FakeSwarm backend({+ String owner = me,+ String role = 'owner',+ List<Map<String, dynamic>>? buddies,+ }) {+ final fake = FakeSwarm();+ fake.routes['/api/super-tabs/list'] = (_) => {+ 'tabs': [+ {'id': tab, 'name': 'Phone Swarm', 'ownerId': me},+ ],+ 'next': null,+ };+ final agents =+ buddies ?? [buddyData('agent-wren', owner: owner, displayName: 'Wren')];+ fake.routes['/api/super-tabs/$tab/parts'] = (_) => {+ ...firstLoad(+ groups: [+ buddyChatData(+ chat,+ owner: owner,+ agentIds: [for (final a in agents) a['id'] as String],+ ),+ ],+ agents: [+ agent('agent-lead', name: 'Lead', displayName: 'River'),+ ...agents,+ ],+ ),+ 'members': [+ part(me, 1, person(me, role: role)),+ part('person-dee', 1, person('person-dee', role: 'member')),+ ],+ };+ fake.routes[changesPath] = (_) => changes(cursor: 'c2');+ fake.routes['/api/super-tabs/$tab/decisions?state=open'] = (_) => {+ 'decisions': <Object>[],+ };+ fake.routes['/api/super-tabs/$tab/mentions?state=waiting'] = (_) => {+ 'mentions': <Object>[],+ };+ fake.routes['/api/super-tabs/$tab/conversations/$chat/messages'] = (_) => {+ 'messages': <Object>[],+ 'next': null,+ };+ return fake;+ }++ /// The phone's machines as the shell sees them: [opens] those it can open+ /// now; every terminal it was asked to open lands in [opened].+ late Set<String> opens;+ late List<(String, String)> opened;+ late FakeComputers computers;++ setUp(() {+ opens = {'mac-1'};+ opened = [];+ computers = FakeComputers(const [])+ ..own = const [(id: 'mac-1', name: 'Tonys-MacBook-Pro', away: false)];+ });++ Future<SwarmHost> pump(WidgetTester tester, FakeSwarm fake) async {+ final account = ValueNotifier<String?>(me);+ final host = SwarmHost(+ accountId: () => account.value,+ account: account,+ request: fake.request,+ upload: refuseSwarmUpload,+ notices: SilentSystemNotices(),+ computers: computers,+ features: ExperimentalFeaturesStore(storage: MemoryKeyValueStore())+ ..value = {PhoneExperiment.swarm},+ )..foreground = false;+ addTearDown(host.dispose);+ await tester.pumpWidget(+ MaterialApp(+ theme: grid.buildAppTheme(brightness: Brightness.dark),+ builder: (context, child) => PhoneShellScope(+ onMachineLinked: (_) {},+ onOpenAgent: (machine, agent) => opened.add((machine, agent)),+ canOpenMachine: opens.contains,+ child: SwarmScope(notifier: host, child: child!),+ ),+ home: const SwarmConversationPage(swarmId: tab, conversationId: chat),+ ),+ );+ await tester.pumpAndSettle();+ return host;+ }++ Finder key(String value) => find.byKey(ValueKey(value));++ Future<void> openMenu(WidgetTester tester) async {+ await tester.tap(key('swarm-buddy-menu'));+ await tester.pumpAndSettle();+ }++ /// The word at the end of the Open terminal row, or null with none.+ String? word(WidgetTester tester) {+ for (final w in const ['Stopped', 'Offline', 'Not linked']) {+ if (find.text(w).evaluate().isNotEmpty) return w;+ }+ return null;+ }++ /// Taps Open terminal, then: whether the sheet stayed open.+ Future<bool> tapRow(WidgetTester tester) async {+ await tester.tap(find.text('Open terminal'));+ await tester.pumpAndSettle();+ return find.text('Rename Buddy').evaluate().isNotEmpty;+ }++ void refreshWith(+ FakeSwarm fake,+ SwarmHost host, {+ List<Map<String, dynamic>> agents = const [],+ List<Map<String, dynamic>> members = const [],+ }) {+ fake.routes[changesPath] = (_) => {+ ...changes(cursor: 'c3', lastChangedAt: 200),+ 'agents': agents,+ 'members': members,+ };+ unawaited(host.session!.inbox.reader(tab)!.refresh());+ }++ Map<String, dynamic> gone(String id) => {+ 'key': id,+ 'version': 9,+ 'changedAt': 200,+ 'deleted': true,+ };++ group('each state', () {+ testWidgets('running on a machine this phone opens: first in the sheet, '+ "and opens that Buddy's terminal", (tester) async {+ await pump(tester, backend());+ await openMenu(tester);++ final terminal = tester.getTopLeft(find.text('Open terminal')).dy;+ expect(+ terminal,+ lessThan(tester.getTopLeft(find.text('Rename Buddy')).dy),+ reason: 'above Rename Buddy',+ );+ expect(word(tester), isNull);++ expect(await tapRow(tester), isFalse, reason: 'the sheet closes');+ expect(opened, [('mac-1', 'harness-agent-wren')]);+ });++ testWidgets('no Buddy running: dimmed, Stopped, and a tap does nothing', (+ tester,+ ) async {+ await pump(tester, backend(buddies: const []));+ await openMenu(tester);+ expect(word(tester), 'Stopped');+ expect(await tapRow(tester), isTrue, reason: 'the sheet stays');+ expect(opened, isEmpty);+ });++ testWidgets('a Buddy being stopped: Stopped', (tester) async {+ await pump(+ tester,+ backend(+ buddies: [+ {...buddyData('agent-wren'), 'workDecision': 'stop'},+ ],+ ),+ );+ await openMenu(tester);+ expect(word(tester), 'Stopped');+ expect(await tapRow(tester), isTrue);+ expect(opened, isEmpty);+ });++ testWidgets('its machine linked here but reported offline: Offline', (+ tester,+ ) async {+ opens = {};+ await pump(tester, backend());+ await openMenu(tester);+ expect(word(tester), 'Offline');+ expect(await tapRow(tester), isTrue);+ expect(opened, isEmpty);+ });++ testWidgets('the Swarm says the Buddy is down: Offline, even where the '+ 'phone could open the machine', (tester) async {+ await pump(+ tester,+ backend(+ buddies: [+ {...buddyData('agent-wren'), 'downSince': '2026-11-01T07:00:00Z'},+ ],+ ),+ );+ await openMenu(tester);+ expect(word(tester), 'Offline');+ expect(await tapRow(tester), isTrue);+ expect(opened, isEmpty);+ });++ testWidgets('its machine not linked to this phone: Not linked', (+ tester,+ ) async {+ opens = {};+ computers.own = const [];+ await pump(tester, backend());+ await openMenu(tester);+ expect(word(tester), 'Not linked');+ expect(await tapRow(tester), isTrue);+ expect(opened, isEmpty);+ });++ testWidgets('a Team-account machine the phone cannot open: Not linked', (+ tester,+ ) async {+ // A Harness Team account's machine is never among the person's own.+ opens = {};+ computers.own = const [(id: 'mac-2', name: 'Studio', away: false)];+ await pump(tester, backend());+ await openMenu(tester);+ expect(word(tester), 'Not linked');+ expect(opened, isEmpty);+ });++ test('outside the shell nothing opens: Not linked', () {+ expect(+ swarmTerminalBlock(+ SuperTabAgent.fromJson(buddyData('agent-wren')),+ canOpen: null,+ own: const [],+ ),+ 'Not linked',+ );+ });+ });++ group('privacy', () {+ testWidgets("someone else's Buddy chat has no ⋮, so no Open terminal", (+ tester,+ ) async {+ await pump(tester, backend(owner: 'person-dee'));+ expect(key('swarm-buddy-menu'), findsNothing);+ expect(find.text('Open terminal'), findsNothing);+ });++ testWidgets('a viewer has no Open terminal', (tester) async {+ await pump(tester, backend(role: 'viewer'));+ expect(key('swarm-buddy-menu'), findsNothing);+ expect(find.text('Open terminal'), findsNothing);+ });++ testWidgets("another person's Buddy in the same chat's project is never "+ 'opened from mine', (tester) async {+ await pump(+ tester,+ backend(+ buddies: [+ buddyData('agent-dee', owner: 'person-dee', displayName: 'Juno'),+ ],+ ),+ );+ await openMenu(tester);+ expect(word(tester), 'Stopped');+ expect(await tapRow(tester), isTrue);+ expect(opened, isEmpty);+ });++ testWidgets("my Buddy of another project is not this chat's", (+ tester,+ ) async {+ await pump(+ tester,+ backend(+ buddies: [+ {...buddyData('agent-wren'), 'projectId': 'project-other'},+ ],+ ),+ );+ await openMenu(tester);+ expect(word(tester), 'Stopped');+ expect(await tapRow(tester), isTrue);+ expect(opened, isEmpty);+ });+ });++ group('lifecycle', () {+ testWidgets('access lost with the sheet open closes it', (tester) async {+ final host = await pump(tester, backend());+ await openMenu(tester);+ expect(find.text('Open terminal'), findsOneWidget);++ host.session!.inbox.reader(tab)!.revoke();+ await tester.pumpAndSettle();+ expect(find.text('Open terminal'), findsNothing);+ expect(opened, isEmpty);+ });++ testWidgets('the Buddy removed with the sheet open closes it', (+ tester,+ ) async {+ final fake = backend();+ final host = await pump(tester, fake);+ await openMenu(tester);+ expect(word(tester), isNull);++ refreshWith(fake, host, agents: [gone('agent-wren')]);+ await tester.pumpAndSettle();+ expect(find.text('Open terminal'), findsNothing);+ expect(find.text('Rename Buddy'), findsNothing);+ expect(opened, isEmpty);+ });++ testWidgets('the Buddy stopped elsewhere with the sheet open closes it', (+ tester,+ ) async {+ final fake = backend();+ final host = await pump(tester, fake);+ await openMenu(tester);++ refreshWith(+ fake,+ host,+ agents: [+ part('agent-wren', 9, {+ ...buddyData('agent-wren'),+ 'workDecision': 'stop',+ }),+ ],+ );+ await tester.pumpAndSettle();+ expect(find.text('Open terminal'), findsNothing);+ });++ testWidgets('losing write access with the sheet open closes it', (+ tester,+ ) async {+ final fake = backend();+ final host = await pump(tester, fake);+ await openMenu(tester);++ refreshWith(+ fake,+ host,+ members: [part(me, 2, person(me, role: 'viewer'))],+ );+ await tester.pumpAndSettle();+ expect(find.text('Open terminal'), findsNothing);+ });++ testWidgets('a machine the phone lost between the sheet and the tap is '+ 'not opened', (tester) async {+ await pump(tester, backend());+ await openMenu(tester);+ expect(word(tester), isNull);++ // The shell's own word changes without telling the sheet.+ opens.clear();+ expect(await tapRow(tester), isFalse);+ expect(opened, isEmpty);+ });++ testWidgets("a Buddy started while the sheet is open: the row follows, "+ 'and opens the new one', (tester) async {+ final fake = backend(buddies: const []);+ final host = await pump(tester, fake);+ await openMenu(tester);+ expect(word(tester), 'Stopped');++ refreshWith(+ fake,+ host,+ agents: [part('agent-wren', 2, buddyData('agent-wren'))],+ );+ await tester.pumpAndSettle();+ expect(word(tester), isNull);+ expect(await tapRow(tester), isFalse);+ expect(opened, [('mac-1', 'harness-agent-wren')]);+ });++ testWidgets("the phone's computers answering late, with the sheet open, "+ 'enables the row', (tester) async {+ // A first read of the machines that had not answered: nothing linked.+ opens = {};+ computers.own = const [];+ await pump(tester, backend());+ await openMenu(tester);+ expect(word(tester), 'Not linked');++ opens.add('mac-1');+ computers+ ..own = const [(id: 'mac-1', name: 'Tonys-MacBook-Pro', away: false)]+ ..notifyListeners();+ await tester.pumpAndSettle();+ expect(word(tester), isNull);+ expect(await tapRow(tester), isFalse);+ expect(opened, [('mac-1', 'harness-agent-wren')]);+ });++ testWidgets('the machine going offline with the sheet open dims the row', (+ tester,+ ) async {+ await pump(tester, backend());+ await openMenu(tester);+ expect(word(tester), isNull);++ opens.clear();+ computers+ ..own = const [(id: 'mac-1', name: 'Tonys-MacBook-Pro', away: true)]+ ..notifyListeners();+ await tester.pumpAndSettle();+ expect(word(tester), 'Offline');+ expect(await tapRow(tester), isTrue);+ expect(opened, isEmpty);+ });+ });+}