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 a project chat's ⋮ opens its PM's, as the Buddy row's (Tony) (#2491)
harness-for-autonomous[bot]60a1a2257ddf
diff --git a/mobile/lib/swarm/swarm_project_page.dart b/mobile/lib/swarm/swarm_project_page.dartindex a23710a61..cd7ed666b 100644--- a/mobile/lib/swarm/swarm_project_page.dart+++ b/mobile/lib/swarm/swarm_project_page.dart@@ -33,6 +33,7 @@ import 'swarm_row.dart';import 'swarm_session.dart';import 'swarm_style.dart';import 'swarm_task_status.dart';+import 'swarm_terminal_row.dart';import 'swarm_unread.dart';import 'team_glance.dart';@@ -539,6 +540,8 @@ class _SwarmProjectPageState extends State<SwarmProjectPage> {),if (_homeC)_ProjectMenu(+ reader: reader,+ projectId: project.id,onLeaderboard: _openLeaderboardSheet,onTeam: _openTeamSheet,onNotifications:@@ -755,38 +758,97 @@ class _Frame extends StatelessWidget {}}+/// [projectId]'s Product Manager as [snapshot] has it now: the Lead of the+/// project's own chat, while that agent is the project's and no Buddy. Null+/// otherwise, never an agent of another project.+SuperTabAgent? swarmProjectPm(SuperTabSnapshot? snapshot, String projectId) {+ final project = snapshot?.projectById(projectId);+ if (project == null) return null;+ final chat = snapshot!.conversation(project.leadConversationId);+ if (chat == null || chat.projectId != projectId) return null;+ final pm = switch (chat.leadId) {+ final id? => snapshot.agent(id),+ null => null,+ };+ return pm == null || pm.projectId != projectId || pm.isBuddy ? null : pm;+}+/// ⋮ at the end of a Swarm Home C project's header: a small menu, on the-/// design system's menu surface (the theme's), of its Leaderboard, its Team-/// and its project chat's Notifications ([showSwarmNotifySheet]), while that-/// chat is read. It goes with the header: losing the project closes it.+/// design system's menu surface (the theme's), of Open terminal first for+/// someone who may write (Tony, 11-01: the PM's terminal on this phone, by+/// the Buddy row's rule and words, [swarmTerminalAction]), its Leaderboard,+/// its Team and its project chat's Notifications ([showSwarmNotifySheet]),+/// while that chat is read. It goes with the header: losing the project+/// closes it. Open terminal follows the Swarm and the phone's computers+/// while open, and at the tap reads the PM of [projectId] again.class _ProjectMenu extends StatelessWidget {const _ProjectMenu({+ required this.reader,+ required this.projectId,required this.onLeaderboard,required this.onTeam,this.onNotifications,});+ final SwarmReader reader;+ final String projectId;final VoidCallback onLeaderboard, onTeam;final VoidCallback? onNotifications;@overrideWidget build(BuildContext context) {AppTheme.watch(context);- Widget row(String key, String label, VoidCallback onTap) => MenuItemButton(+ final shell = PhoneShellScope.maybeOf(context);+ final computers = SwarmScope.computersOf(context);+ Widget row(+ String key,+ String label,+ VoidCallback? onTap, {+ String? value,+ }) => MenuItemButton(key: ValueKey(key),style: ButtonStyle(minimumSize: const WidgetStatePropertyAll(Size(AppSpace.xl * 6, minTouchTarget),),- foregroundColor: WidgetStatePropertyAll(AppPalette.textPrimary),+ foregroundColor: WidgetStateProperty.resolveWith(+ (states) => states.contains(WidgetState.disabled)+ ? AppPalette.textFaint+ : AppPalette.textPrimary,+ ),textStyle: WidgetStatePropertyAll(AppType.body()),),onPressed: onTap,+ // Dimmed with why it cannot open, as the Buddy row says it.+ trailingIcon: value == null+ ? null+ : Text(value, style: AppType.body(color: AppPalette.textFaint)),child: Text(label),);+ bool allowed() =>+ !reader.accessRevoked &&+ reader.snapshot?.projectById(projectId) != null &&+ swarmCanWrite(reader);+ // Built again as the Swarm moves (the header's) and as the phone's+ // computers do ([SwarmScope.computersOf] depends on its host).+ final terminal = allowed()+ ? swarmTerminalAction(+ agent: () => swarmProjectPm(reader.snapshot, projectId),+ allowed: allowed,+ shell: shell,+ computers: computers,+ )+ : null;return MenuAnchor(alignmentOffset: const Offset(0, AppSpace.xs),menuChildren: [+ if (terminal != null)+ row(+ 'swarm-project-menu-terminal',+ terminal.label,+ terminal.enabled ? terminal.onTap : null,+ value: terminal.value,+ ),row('swarm-project-menu-leaderboard', 'Leaderboard', onLeaderboard),row('swarm-project-menu-team', 'Team', onTeam),if (onNotifications case final onTap?)diff --git a/mobile/test/swarm/swarm_project_terminal_shots_test.dart b/mobile/test/swarm/swarm_project_terminal_shots_test.dartnew file mode 100644index 000000000..c468c5aef--- /dev/null+++ b/mobile/test/swarm/swarm_project_terminal_shots_test.dart@@ -0,0 +1,177 @@+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_project_page.dart';+import 'package:harness_mobile/swarm/swarm_project_tabs.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 project screen's ⋮ (Swarm+/// Home C), 390 points wide in both phone themes, from made-up data, to the+/// folder `SWARM_PROJECT_TERMINAL_SHOTS` names: each state of its row.+final shots = Platform.environment['SWARM_PROJECT_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 {+ // Real shadows, as the phone draws the menu's, not the test's outlines.+ debugDisableShadows = false;+ 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(+ agents: [+ {+ ...agent('agent-lead', name: 'Lead', displayName: 'River'),+ if (state == 'stopped') 'workDecision': 'stop',+ },+ agent('agent-builder', displayName: 'Nova'),+ ],+ ),+ '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/$leadChat/messages'] =+ (_) => {+ 'messages': [+ {+ 'id': 'msg-lead-1',+ 'conversationId': leadChat,+ 'text': 'CI on #2154 is green.',+ 'sequence': 1,+ 'author': {+ 'kind': 'agent',+ 'id': 'agent-lead',+ 'name': 'River',+ },+ 'createdAt': '2026-11-01T10:40:00.000Z',+ },+ ],+ '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 SwarmProjectPage(+ swarmId: tab,+ projectId: project,+ tabs: SwarmProjectTab.homeC,+ ),+ ),+ ),+ );+ await tester.pumpAndSettle();+ await tester.tap(find.byKey(const ValueKey('swarm-project-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-project-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));+ }+ }+ // Back before the test ends: the binding checks it is unset.+ debugDisableShadows = true;+ }, skip: shots == null);+}diff --git a/mobile/test/swarm/swarm_project_terminal_test.dart b/mobile/test/swarm/swarm_project_terminal_test.dartnew file mode 100644index 000000000..82aee0dcc--- /dev/null+++ b/mobile/test/swarm/swarm_project_terminal_test.dart@@ -0,0 +1,618 @@+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_project_page.dart';+import 'package:harness_mobile/swarm/swarm_project_tabs.dart';+import 'package:harness_mobile/swarm/swarm_request.dart';+import 'package:harness_mobile/swarm/swarm_session.dart';++import '../voice_fakes.dart';+import 'swarm_computers_fake.dart';+import 'swarm_fixture.dart';++/// Open terminal in a project chat's ⋮ (Tony, 11-01): first in Swarm Home+/// C's project menu, opening that project's PM's terminal on this phone by+/// the Buddy row's rule (its machine linked here and not reported offline),+/// otherwise dimmed with why: Stopped, Offline or Not linked. Never for a+/// viewer, never another project's PM, and the menu goes with access or the+/// project.+void main() {+ const changesPath = '/api/super-tabs/$tab/changes';+ const other = 'project-2';+ const otherChat = 'group-lead-2';++ Map<String, dynamic> projectData(String id, String name, String chat) => {+ 'id': id,+ 'name': name,+ 'ownerId': me,+ 'leadConversationId': chat,+ 'visibility': 'public',+ 'members': <Object>[],+ 'updateMinutes': 5,+ };++ final bothProjects = [+ projectData(project, 'Mobile', leadChat),+ projectData(other, 'Desktop', otherChat),+ ];++ /// Two projects of one Swarm: Mobile, whose PM is River on mac-1 unless+ /// [pm] says otherwise, and Desktop, whose PM is also called River, on+ /// mac-2. Mobile's chat names [leadOf] as its Lead.+ FakeSwarm backend({+ String role = 'owner',+ Map<String, dynamic>? pm,+ String leadOf = 'agent-lead',+ List<Map<String, dynamic>> extra = const [],+ }) {+ final fake = FakeSwarm();+ fake.routes['/api/super-tabs/list'] = (_) => {+ 'tabs': [+ {'id': tab, 'name': 'Phone Swarm', 'ownerId': me},+ ],+ 'next': null,+ };+ fake.routes['/api/super-tabs/$tab/parts'] = (_) {+ final read = firstLoad(+ head: headData(projects: bothProjects),+ groups: [+ {+ ...groupData(+ otherChat,+ title: 'Desktop',+ agentIds: ['agent-lead-2'],+ leadId: 'agent-lead-2',+ ),+ 'projectId': other,+ },+ ],+ agents: [+ pm ?? agent('agent-lead', name: 'Lead', displayName: 'River'),+ {+ ...agent(+ 'agent-lead-2',+ name: 'Lead',+ displayName: 'River',+ machineId: 'mac-2',+ ),+ 'projectId': other,+ },+ ...extra,+ ],+ );+ // Mobile's own chat, with the Lead it names.+ (read['groups'] as List)[0] = part(+ leadChat,+ 1,+ groupData(+ leadChat,+ title: 'Mobile',+ agentIds: [leadOf],+ leadId: leadOf,+ ),+ );+ return {+ ...read,+ 'members': [part(me, 1, person(me, role: role))],+ };+ };+ 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>[],+ };+ for (final chat in [leadChat, otherChat]) {+ 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', 'mac-2'};+ opened = [];+ computers = FakeComputers(const [])+ ..own = const [+ (id: 'mac-1', name: 'Tonys-MacBook-Pro', away: false),+ (id: 'mac-2', name: 'Tonys-Studio', away: false),+ ];+ });++ Future<SwarmHost> pump(+ WidgetTester tester,+ FakeSwarm fake, {+ String projectId = project,+ ValueNotifier<String?>? account,+ }) async {+ 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: SwarmProjectPage(+ swarmId: tab,+ projectId: projectId,+ tabs: SwarmProjectTab.homeC,+ ),+ ),+ );+ await tester.pumpAndSettle();+ return host;+ }++ Finder key(String value) => find.byKey(ValueKey(value));+ final row = key('swarm-project-menu-terminal');++ Future<void> openMenu(WidgetTester tester) async {+ await tester.tap(key('swarm-project-menu'));+ await tester.pumpAndSettle();+ }++ bool menuOpen() => find.text('Leaderboard').evaluate().isNotEmpty;++ /// 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+ .descendant(of: row, matching: find.text(w))+ .evaluate()+ .isNotEmpty) {+ return w;+ }+ }+ return null;+ }++ bool enabled(WidgetTester tester) =>+ tester.widget<MenuItemButton>(row).onPressed != null;++ /// Taps Open terminal, then: whether the menu stayed open.+ Future<bool> tapRow(WidgetTester tester) async {+ await tester.tap(find.text('Open terminal'), warnIfMissed: false);+ await tester.pumpAndSettle();+ return menuOpen();+ }++ Future<void> refreshWith(+ FakeSwarm fake,+ SwarmHost host, {+ List<Map<String, dynamic>> agents = const [],+ List<Map<String, dynamic>> members = const [],+ List<Map<String, dynamic>> groups = const [],+ Map<String, dynamic>? head,+ }) async {+ fake.routes[changesPath] = (_) => {+ ...changes(cursor: 'c3', lastChangedAt: 200, groups: groups),+ 'agents': agents,+ 'members': members,+ 'head': ?head,+ };+ await host.session!.inbox.reader(tab)!.refresh();+ }++ group('each state', () {+ testWidgets('PM running on a machine this phone opens: first in the '+ "menu, and opens that PM's terminal", (tester) async {+ await pump(tester, backend());+ await openMenu(tester);++ expect(+ tester.getTopLeft(row).dy,+ lessThan(tester.getTopLeft(key('swarm-project-menu-leaderboard')).dy),+ reason: 'above Leaderboard',+ );+ expect(word(tester), isNull);+ expect(enabled(tester), isTrue);++ expect(await tapRow(tester), isFalse, reason: 'the menu closes');+ expect(opened, [('mac-1', 'harness-agent-lead')]);+ });++ testWidgets('no PM in the project chat: dimmed, Stopped, and a tap does '+ 'nothing', (tester) async {+ await pump(tester, backend(leadOf: 'agent-gone'));+ await openMenu(tester);+ expect(word(tester), 'Stopped');+ expect(enabled(tester), isFalse);+ expect(await tapRow(tester), isTrue, reason: 'the menu stays');+ expect(opened, isEmpty);+ });++ testWidgets('a PM being stopped: Stopped', (tester) async {+ await pump(+ tester,+ backend(+ pm: {+ ...agent('agent-lead', name: 'Lead', displayName: 'River'),+ '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 = {'mac-2'};+ await pump(tester, backend());+ await openMenu(tester);+ expect(word(tester), 'Offline');+ expect(await tapRow(tester), isTrue);+ expect(opened, isEmpty);+ });++ testWidgets('the Swarm says the PM is down: Offline, even where the '+ 'phone could open the machine', (tester) async {+ await pump(+ tester,+ backend(+ pm: {+ ...agent('agent-lead', name: 'Lead', displayName: 'River'),+ '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 = {'mac-2'};+ computers.own = const [(id: 'mac-2', name: 'Tonys-Studio', away: false)];+ 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 [];+ await pump(+ tester,+ backend(+ pm: agent(+ 'agent-lead',+ name: 'Lead',+ displayName: 'River',+ machineId: 'team-mac',+ ),+ ),+ );+ await openMenu(tester);+ expect(word(tester), 'Not linked');+ expect(await tapRow(tester), isTrue);+ expect(opened, isEmpty);+ });+ });++ group('privacy', () {+ testWidgets('a viewer has the menu, but no Open terminal', (tester) async {+ await pump(tester, backend(role: 'viewer'));+ await openMenu(tester);+ expect(find.text('Leaderboard'), findsOneWidget);+ expect(row, findsNothing);+ expect(find.text('Open terminal'), findsNothing);+ });++ testWidgets("two projects, each PM named River: each project's menu "+ 'opens its own PM, never the other', (tester) async {+ await pump(tester, backend(), projectId: other);+ await openMenu(tester);+ expect(word(tester), isNull);+ expect(await tapRow(tester), isFalse);+ expect(opened, [('mac-2', 'harness-agent-lead-2')]);++ opened.clear();+ await pump(tester, backend());+ await openMenu(tester);+ expect(await tapRow(tester), isFalse);+ expect(opened, [('mac-1', 'harness-agent-lead')]);+ });++ testWidgets("a project chat naming another project's agent as its Lead "+ 'opens nothing: Stopped', (tester) async {+ await pump(tester, backend(leadOf: 'agent-lead-2'));+ await openMenu(tester);+ expect(word(tester), 'Stopped');+ expect(await tapRow(tester), isTrue);+ expect(opened, isEmpty);+ });++ testWidgets("a project chat naming a person's Buddy as its Lead opens "+ 'nothing: Stopped', (tester) async {+ await pump(+ tester,+ backend(+ leadOf: 'agent-wren',+ extra: [buddyData('agent-wren', displayName: 'Wren')],+ ),+ );+ await openMenu(tester);+ expect(word(tester), 'Stopped');+ expect(await tapRow(tester), isTrue);+ expect(opened, isEmpty);+ });++ test('swarmProjectPm refuses what is not the project\'s own PM', () {+ SuperTabSnapshot snapshot(String leadOf, Map<String, dynamic> lead) =>+ SuperTabSnapshot.fromJson({+ 'id': tab,+ 'name': 'Phone Swarm',+ 'ownerId': me,+ 'projects': bothProjects,+ 'people': [person(me)],+ 'invitations': <Object>[],+ 'version': 1,+ 'conversations': [+ groupData(leadChat, leadId: leadOf),+ {+ ...groupData(otherChat, leadId: 'agent-lead-2'),+ 'projectId': other,+ },+ ],+ 'agents': [+ lead,+ {...agent('agent-lead-2'), 'projectId': other},+ ],+ });+ expect(+ swarmProjectPm(+ snapshot('agent-lead', agent('agent-lead')),+ project,+ )?.id,+ 'agent-lead',+ );+ expect(+ swarmProjectPm(snapshot('agent-lead', agent('agent-lead')), other)?.id,+ 'agent-lead-2',+ );+ expect(+ swarmProjectPm(snapshot('agent-lead-2', agent('agent-lead')), project),+ isNull,+ );+ expect(+ swarmProjectPm(+ snapshot('agent-lead', buddyData('agent-lead')),+ project,+ ),+ isNull,+ );+ expect(+ swarmProjectPm(+ snapshot('agent-lead', agent('agent-lead')),+ 'project-gone',+ ),+ isNull,+ );+ expect(swarmProjectPm(null, project), isNull);+ });+ });++ group('lifecycle', () {+ testWidgets('access lost with the menu open closes it', (tester) async {+ final host = await pump(tester, backend());+ await openMenu(tester);+ expect(row, findsOneWidget);++ host.session!.inbox.reader(tab)!.revoke();+ await tester.pumpAndSettle();+ expect(menuOpen(), isFalse);+ expect(find.text('Open terminal'), findsNothing);+ expect(opened, isEmpty);+ });++ testWidgets(+ 'the project taken off the Swarm with the menu open closes it',+ (tester) async {+ final fake = backend();+ final host = await pump(tester, fake);+ await openMenu(tester);+ expect(row, findsOneWidget);++ await refreshWith(+ fake,+ host,+ head: part('head', 2, headData(projects: [bothProjects[1]])),+ );+ await tester.pumpAndSettle();+ expect(menuOpen(), isFalse);+ expect(find.text('Open terminal'), findsNothing);+ expect(opened, isEmpty);+ },+ );++ testWidgets('signing out with the menu open closes it', (tester) async {+ final account = ValueNotifier<String?>(me);+ await pump(tester, backend(), account: account);+ await openMenu(tester);+ expect(row, findsOneWidget);++ account.value = null;+ await tester.pumpAndSettle();+ expect(menuOpen(), isFalse);+ expect(find.text('Open terminal'), findsNothing);+ expect(opened, isEmpty);+ });++ testWidgets('losing write access with the menu open takes the row away', (+ tester,+ ) async {+ final fake = backend();+ final host = await pump(tester, fake);+ await openMenu(tester);+ expect(row, findsOneWidget);++ await refreshWith(+ fake,+ host,+ members: [part(me, 2, person(me, role: 'viewer'))],+ );+ await tester.pumpAndSettle();+ expect(row, findsNothing);+ expect(opened, isEmpty);+ });++ testWidgets('the PM stopped elsewhere with the menu open dims the row', (+ tester,+ ) async {+ final fake = backend();+ final host = await pump(tester, fake);+ await openMenu(tester);+ expect(word(tester), isNull);++ await refreshWith(+ fake,+ host,+ agents: [+ part('agent-lead', 9, {+ ...agent('agent-lead', name: 'Lead', displayName: 'River'),+ 'workDecision': 'stop',+ }),+ ],+ );+ await tester.pumpAndSettle();+ expect(word(tester), 'Stopped');+ expect(await tapRow(tester), isTrue);+ expect(opened, isEmpty);+ });++ testWidgets('a machine the phone lost between the menu 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 menu.+ opens.clear();+ expect(await tapRow(tester), isFalse);+ expect(opened, isEmpty);+ });++ testWidgets("the project's PM replaced while the menu is open: the tap "+ 'opens the one shown, and never the one it replaced', (tester) async {+ final fake = backend(+ extra: [agent('agent-nova', displayName: 'Nova', machineId: 'mac-2')],+ );+ final host = await pump(tester, fake);+ await openMenu(tester);++ await refreshWith(+ fake,+ host,+ groups: [+ part(+ leadChat,+ 5,+ groupData(+ leadChat,+ title: 'Mobile',+ agentIds: ['agent-nova'],+ leadId: 'agent-nova',+ ),+ ),+ ],+ );+ await tester.pumpAndSettle();+ expect(await tapRow(tester), isFalse);+ expect(opened, [('mac-2', 'harness-agent-nova')]);+ });++ testWidgets("the phone's computers answering late, with the menu 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-lead')]);+ });++ testWidgets('the machine going offline with the menu open dims the row', (+ tester,+ ) async {+ await pump(tester, backend());+ await openMenu(tester);+ expect(word(tester), isNull);++ opens.remove('mac-1');+ 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);+ });++ testWidgets('a first read that fails, then recovers on a pull, has the '+ 'row and opens the PM', (tester) async {+ final fake = backend();+ final parts = fake.routes['/api/super-tabs/$tab/parts']!;+ var fail = true;+ fake.routes['/api/super-tabs/$tab/parts'] = (body) => fail+ ? throw const SuperTabFailure('INTERNAL', 'Swarm is down.')+ : parts(body);+ await pump(tester, fake);+ expect(key('swarm-project-menu'), findsNothing);+ expect(find.text('Loading…'), findsNothing, reason: 'no stuck Loading');++ fail = false;+ await tester.fling(find.byType(ListView), const Offset(0, 400), 1000);+ await tester.pumpAndSettle();+ await openMenu(tester);+ expect(word(tester), isNull);+ expect(await tapRow(tester), isFalse);+ expect(opened, [('mac-1', 'harness-agent-lead')]);+ });+ });+}