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: decisions leave the chat; the status card and Activity hold them (Dee) (#2467)
0xken1510272b4c2c51
diff --git a/mobile/lib/phone/phone_shell.dart b/mobile/lib/phone/phone_shell.dartindex 8e1ef7a06..4be22528a 100644--- a/mobile/lib/phone/phone_shell.dart+++ b/mobile/lib/phone/phone_shell.dart@@ -8,10 +8,12 @@ import 'package:harness_mobile/state/app_state.dart';import '../notify/system_notices.dart';import '../p2p/phone_terminal_p2p.dart';+import '../swarm/swarm_activity_page.dart' show swarmActivityRoute;import '../swarm/swarm_attachment_store.dart';import '../swarm/swarm_computers.dart';import '../swarm/swarm_dictation.dart';import '../swarm/swarm_home_root.dart';+import '../swarm/swarm_inbox.dart' show SwarmDecisionNeed;import '../swarm/swarm_message_link.dart';import '../swarm/swarm_profile.dart';import '../swarm/swarm_project_page.dart' show swarmChatRoute;@@ -399,6 +401,20 @@ class _PhoneShellState extends State<PhoneShell> with WidgetsBindingObserver {if (navigator == null) return;navigator.popUntil((route) => route.isFirst);_home.showSwarm();+ // A decision opens in Activity, where it is answered, as Desktop opens+ // it in Notifications: no chat shows decisions. Activity says so when it+ // is no longer open, whoever's it was.+ if (target.decisionId case final decisionId?) {+ unawaited(+ navigator.push(+ swarmActivityRoute(+ focus: SwarmDecisionNeed.keyOf(decisionId),+ swarmId: target.swarmId,+ ),+ ),+ );+ return;+ }// A project's own chat opens as its project, on Swarm Home C's tabs.unawaited(navigator.push(@@ -406,7 +422,6 @@ class _PhoneShellState extends State<PhoneShell> with WidgetsBindingObserver {swarmId: target.swarmId,conversationId: target.conversationId,messageId: target.messageId,- decisionId: target.decisionId,),),);diff --git a/mobile/lib/swarm/swarm_activity.dart b/mobile/lib/swarm/swarm_activity.dartindex f849cc6f3..ac539fab2 100644--- a/mobile/lib/swarm/swarm_activity.dart+++ b/mobile/lib/swarm/swarm_activity.dart@@ -78,6 +78,28 @@ class SwarmActivityNeed extends SwarmActivityItem {};}+/// Whether [item] is of project [projectId], as [snapshot] — its Swarm's read+/// — has it: what it names and where it was asked must both be that project,+/// so a row whose chat moved, or that the read no longer has, shows in no+/// project's Activity.+bool swarmActivityItemIn(+ SwarmActivityItem item,+ SuperTabSnapshot snapshot,+ String projectId,+) {+ final named = switch (item) {+ SwarmActivityNeed(need: SwarmDecisionNeed(:final decision)) =>+ decision.projectId,+ SwarmActivityNeed(need: SwarmMentionNeed(:final mention)) =>+ mention.projectId,+ SwarmActivityNeed(need: SwarmWorkNeed(:final work)) => work.project.id,+ SwarmActivityThread(:final project) => project.id,+ SwarmActivityReaction(:final project) => project.id,+ };+ return named == projectId &&+ snapshot.conversation(item.conversationId)?.projectId == projectId;+}+/// A thread in a project chat that the person wrote in or was tagged in.class SwarmActivityThread extends SwarmActivityItem {const SwarmActivityThread(diff --git a/mobile/lib/swarm/swarm_activity_page.dart b/mobile/lib/swarm/swarm_activity_page.dartindex c7156587c..58dfd77ab 100644--- a/mobile/lib/swarm/swarm_activity_page.dart+++ b/mobile/lib/swarm/swarm_activity_page.dart@@ -11,11 +11,14 @@ import 'package:harness_mobile/shared/theme/app_theme.dart';import 'package:harness_mobile/shared/theme/app_type.dart';import 'identity.dart';+import 'model.dart';import 'swarm_activity.dart';+import 'swarm_asks.dart' show SwarmAsks;import 'swarm_home_rows.dart' show swarmNeedAsk;import 'swarm_inbox.dart';import 'swarm_need_rows.dart';import 'swarm_project_page.dart' show swarmChatRoute;+import 'swarm_project_status.dart' show swarmReadsProject;import 'swarm_reader.dart';import 'swarm_row.dart';import 'swarm_session.dart';@@ -23,26 +26,42 @@ import 'swarm_style.dart';/// Opens Activity over [context]'s page: [focus] — a row's key — open in/// full under its filter; only Swarm [swarmId]'s rows when Home shows that-/// Swarm alone.+/// Swarm alone, and only its project [projectId]'s when a project's status+/// card opens it.void openSwarmActivity(BuildContext context, {String? focus,String? swarmId,+ String? projectId,}) => unawaited(Navigator.of(context).push(- phoneRoute(- (_) => SwarmActivityPage(focus: focus, swarmId: swarmId),- listensForItself: true,- ),+ swarmActivityRoute(focus: focus, swarmId: swarmId, projectId: projectId),),);+/// The route [openSwarmActivity] pushes: a decision's notice or link pushes it+/// too, so the decision opens where it is answered, never in a chat.+Route<void> swarmActivityRoute({+ String? focus,+ String? swarmId,+ String? projectId,+}) => phoneRoute(+ (_) =>+ SwarmActivityPage(focus: focus, swarmId: swarmId, projectId: projectId),+ listensForItself: true,+);+/// Activity as a page of its own, with a way back: Home's "See all" and its/// rows open it until the tab bar does.class SwarmActivityPage extends StatelessWidget {- const SwarmActivityPage({super.key, this.focus, this.swarmId});+ const SwarmActivityPage({+ super.key,+ this.focus,+ this.swarmId,+ this.projectId,+ });- final String? focus, swarmId;+ final String? focus, swarmId, projectId;@overrideWidget build(BuildContext context) {@@ -52,6 +71,7 @@ class SwarmActivityPage extends StatelessWidget {body: SwarmActivityView(focus: focus,swarmId: swarmId,+ projectId: projectId,leading: SwarmBackButton(onPressed: () => Navigator.of(context).maybePop(),),@@ -70,7 +90,13 @@ class SwarmActivityPage extends StatelessWidget {/// Only while it is in sight ([OutOfSight]) does it read the project chats/// ([SwarmActivity.watch]) and keep the Swarm's notices quiet.class SwarmActivityView extends StatefulWidget {- const SwarmActivityView({super.key, this.focus, this.swarmId, this.leading});+ const SwarmActivityView({+ super.key,+ this.focus,+ this.swarmId,+ this.projectId,+ this.leading,+ });/// The row open first, by its key.final String? focus;@@ -78,6 +104,10 @@ class SwarmActivityView extends StatefulWidget {/// Only this Swarm's rows; null for every Swarm's.final String? swarmId;+ /// Only the rows of this project of [swarmId], while the person still reads+ /// it; none once they do not, and its name with them.+ final String? projectId;+/// Before the title: a page's back; none on the tab.final Widget? leading;@@ -91,6 +121,10 @@ class _SwarmActivityViewState extends State<SwarmActivityView> {late SwarmActivityFilter _filter = _filterOf(widget.focus);late String? _open = widget.focus;+ /// The focused row, brought into view once it is drawn.+ final _focusKey = GlobalKey();+ bool _focusShown = false;+static SwarmActivityFilter _filterOf(String? key) => switch (key) {final key? when key.startsWith('mention:') => SwarmActivityFilter.mentions,final key? when key.startsWith('thread:') => SwarmActivityFilter.threads,@@ -144,7 +178,25 @@ class _SwarmActivityViewState extends State<SwarmActivityView> {crossAxisAlignment: CrossAxisAlignment.stretch,children: [if (widget.leading case final leading?)- SwarmTopBar(leading: leading, title: 'Activity')+ // The project's name goes with the person's access to it.+ ListenableBuilder(+ listenable: Listenable.merge([+ session?.inbox,+ session?.activity,+ if (widget.swarmId case final id?) session?.inbox.reader(id),+ ]),+ builder: (context, _) => SwarmTopBar(+ leading: leading,+ title: 'Activity',+ subtitle: switch (session) {+ final session? => switch (_project(session)) {+ final project? => '#${project.name}',+ null => null,+ },+ null => null,+ },+ ),+ )elseconst SwarmTabHeader('Activity'),if (session != null)@@ -160,18 +212,43 @@ class _SwarmActivityViewState extends State<SwarmActivityView> {);}- /// [filter]'s rows, of [widget.swarmId] alone when it names one.+ /// [filter]'s rows, of [widget.swarmId] alone when it names one, and of+ /// [widget.projectId] alone when it names one.List<SwarmActivityItem> _items(- SwarmActivity activity,+ SwarmSession session,SwarmActivityFilter filter,- ) => [- for (final item in activity.items(filter))- if (widget.swarmId == null || item.swarmId == widget.swarmId) item,- ];+ ) {+ final projectId = widget.projectId;+ final reader = projectId == null || widget.swarmId == null+ ? null+ : session.inbox.reader(widget.swarmId!);+ final snapshot = _project(session) == null ? null : reader?.snapshot;+ return [+ for (final item in session.activity.items(filter))+ if ((widget.swarmId == null || item.swarmId == widget.swarmId) &&+ (projectId == null ||+ snapshot != null &&+ swarmActivityItemIn(item, snapshot, projectId)))+ item,+ ];+ }++ /// [widget.projectId] while the person reads it, as the status card holds+ /// to it ([swarmReadsProject]); null for none, or once they do not.+ SuperTabProject? _project(SwarmSession session) {+ final projectId = widget.projectId, swarmId = widget.swarmId;+ if (projectId == null || swarmId == null) return null;+ final reader = session.inbox.reader(swarmId);+ if (reader == null || reader.accessRevoked) return null;+ final project = reader.snapshot?.projectById(projectId);+ return project != null && swarmReadsProject(reader, project)+ ? project+ : null;+ }Widget _body(BuildContext context, SwarmSession session) {final activity = session.activity;- final items = _items(activity, _filter);+ final items = _items(session, _filter);return Column(crossAxisAlignment: CrossAxisAlignment.stretch,children: [@@ -191,7 +268,7 @@ class _SwarmActivityViewState extends State<SwarmActivityView> {key: ValueKey('swarm-activity-filter-${filter.name}'),filter: filter,count: _items(- activity,+ session,filter,).where((item) => activity.handled(item) == null).length,selected: filter == _filter,@@ -226,7 +303,34 @@ class _SwarmActivityViewState extends State<SwarmActivityView> {_filter == SwarmActivityFilter.threads ||_filter == SwarmActivityFilter.reactions;final note = AppType.caption(color: AppPalette.textSecondary, height: 1.35);+ final missing = _focusMissing(session, items);+ if (missing == null) _showFocus();return [+ if (missing case (:final asks?))+ _Note(+ key: const ValueKey('swarm-activity-focus-failed'),+ text: asks.error!,+ action: SwarmButton(+ key: const ValueKey('swarm-activity-focus-retry'),+ label: 'Try again',+ style: SwarmButtonStyle.link,+ onPressed: () => unawaited(asks.load()),+ ),+ )+ else if (missing != null)+ Padding(+ padding: const EdgeInsets.fromLTRB(+ AppSpace.xs,+ 0,+ AppSpace.xs,+ AppSpace.s,+ ),+ child: Text(+ 'This decision is no longer open.',+ key: const ValueKey('swarm-activity-focus-gone'),+ style: note,+ ),+ ),if (fromChats && activity.unreadChats)_Note(text: 'Some chats could not be read.',@@ -269,6 +373,48 @@ class _SwarmActivityViewState extends State<SwarmActivityView> {];}+ /// A decision this page was opened at (a notice, a link) that is not among+ /// its rows once what waits on the person is read: answered, withdrawn, or+ /// never theirs — said alike, naming nothing of it. When that read failed,+ /// [asks] is the Swarm's, to say so and read again: its next read that+ /// gets through brings the decision. Null while it is shown, or not read+ /// yet.+ ({SwarmAsks? asks})? _focusMissing(+ SwarmSession session,+ List<SwarmActivityItem> items,+ ) {+ final focus = widget.focus;+ if (focus == null || !focus.startsWith('decision:')) return null;+ if (_filter != SwarmActivityFilter.needsYou) return null;+ if (items.any((item) => item.key == focus)) return null;+ final inbox = session.inbox;+ if (!inbox.loaded) return null;+ final swarmId = widget.swarmId;+ final asks = swarmId == null ? null : inbox.asks(swarmId);+ if (asks != null && asks.loading) return null;+ return (+ asks: asks?.error != null && !asks!.reader.accessRevoked ? asks : null,+ );+ }++ /// Brings the focused row into view once, after the frame that draws it.+ void _showFocus() {+ if (_focusShown || widget.focus == null) return;+ WidgetsBinding.instance.addPostFrameCallback((_) {+ if (!mounted || _focusShown) return;+ final row = _focusKey.currentContext;+ if (row == null) return;+ _focusShown = true;+ unawaited(+ Scrollable.ensureVisible(+ row,+ alignment: 0.3,+ duration: const Duration(milliseconds: 250),+ ),+ );+ });+ }+static String _nothing(SwarmActivityFilter filter) => switch (filter) {SwarmActivityFilter.needsYou => 'Nothing needs you.',SwarmActivityFilter.mentions => 'No one tagged you.',@@ -283,6 +429,18 @@ class _SwarmActivityViewState extends State<SwarmActivityView> {) {final activity = session.activity;final handled = activity.handled(item);+ final row = _rowOf(context, session, item, handled);+ return item.key == widget.focus+ ? KeyedSubtree(key: _focusKey, child: row)+ : row;+ }++ Widget _rowOf(+ BuildContext context,+ SwarmSession session,+ SwarmActivityItem item,+ String? handled,+ ) {// A need tapped opens in full: every option, Done, Open chat.if (item case SwarmActivityNeed(:final need)when handled == null && item.key == _open) {@@ -307,7 +465,9 @@ class _SwarmActivityViewState extends State<SwarmActivityView> {);}- /// Opens where [item] was asked, at its message, and counts it handled.+ /// Opens where [item] was asked, at its message, and counts it handled. A+ /// decision opens its chat at the end: decisions are answered here, never+ /// shown in a chat.void _reply(BuildContext context,SwarmSession session,@@ -320,11 +480,6 @@ class _SwarmActivityViewState extends State<SwarmActivityView> {swarmId: item.swarmId,conversationId: item.conversationId,messageId: item.messageId,- decisionId: switch (item) {- SwarmActivityNeed(need: SwarmDecisionNeed(:final decision)) =>- decision.id,- _ => null,- },),),);@@ -344,8 +499,16 @@ class _SwarmActivityViewState extends State<SwarmActivityView> {return;}final need = item.need as SwarmDecisionNeed;- final yes = await confirmSwarmApprove(context, need, option);- if (yes && mounted) session.activity.approve(item);+ final activity = session.activity;+ final yes = await confirmSwarmApprove(+ context,+ need,+ option,+ // Answered elsewhere, or access lost, while it asks: it closes.+ until: activity,+ stillOpen: () => activity.canApprove(item),+ );+ if (yes && mounted) activity.approve(item);}}@@ -353,11 +516,17 @@ class _SwarmActivityViewState extends State<SwarmActivityView> {/// and the question, and that it can still be undone. True once the person/// confirms; the caller then holds the answer for Undo and sends it/// ([SwarmSession.hold]). Activity's Approve asks this.+///+/// With [until], the question closes, as Cancel, once [stillOpen] says the+/// decision can no longer be answered — answered elsewhere, or the person's+/// access to it lost — so nothing of it stays on screen.Future<bool> confirmSwarmApprove(BuildContext context,SwarmDecisionNeed need,- String option,-) async {+ String option, {+ Listenable? until,+ bool Function()? stillOpen,+}) async {final decision = need.decision;final where = decision.projectName.isEmpty? ''@@ -368,38 +537,95 @@ Future<bool> confirmSwarmApprove(// them, as access is lost, finds it there. The shell's pages are on a// navigator of their own, under the app's.useRootNavigator: false,- builder: (context) => AlertDialog(- title: Text(- 'Approve?',- style: AppType.heading(color: AppPalette.textPrimary),- ),- content: Text(- 'Sends “$option” to ${decision.askerName}$where: '- '${decision.question}\n\nYou can undo it for a few seconds.',- style: AppType.body(color: AppPalette.textSecondary),- ),- actions: [- SwarmButton(- key: const ValueKey('swarm-activity-approve-cancel'),- label: 'Cancel',- style: SwarmButtonStyle.link,- onPressed: () => Navigator.of(context).pop(false),+ builder: (context) => _ClosesWhenGone(+ until: until,+ stillOpen: stillOpen,+ child: AlertDialog(+ title: Text(+ 'Approve?',+ style: AppType.heading(color: AppPalette.textPrimary),),- SwarmButton(- key: const ValueKey('swarm-activity-approve-confirm'),- label: 'Approve',- style: SwarmButtonStyle.fill,- onPressed: () => Navigator.of(context).pop(true),+ content: Text(+ 'Sends “$option” to ${decision.askerName}$where: '+ '${decision.question}\n\nYou can undo it for a few seconds.',+ style: AppType.body(color: AppPalette.textSecondary),),- ],+ actions: [+ SwarmButton(+ key: const ValueKey('swarm-activity-approve-cancel'),+ label: 'Cancel',+ style: SwarmButtonStyle.link,+ onPressed: () => Navigator.of(context).pop(false),+ ),+ SwarmButton(+ key: const ValueKey('swarm-activity-approve-confirm'),+ label: 'Approve',+ style: SwarmButtonStyle.fill,+ onPressed: () => Navigator.of(context).pop(true),+ ),+ ],+ ),),);return yes ?? false;}+/// [child] — a question asked over Activity — closed as Cancel once+/// [stillOpen] no longer holds, checked whenever [until] changes.+class _ClosesWhenGone extends StatefulWidget {+ const _ClosesWhenGone({+ required this.until,+ required this.stillOpen,+ required this.child,+ });++ final Listenable? until;+ final bool Function()? stillOpen;+ final Widget child;++ @override+ State<_ClosesWhenGone> createState() => _ClosesWhenGoneState();+}++class _ClosesWhenGoneState extends State<_ClosesWhenGone> {+ bool _closing = false;++ @override+ void initState() {+ super.initState();+ widget.until?.addListener(_check);+ }++ @override+ void dispose() {+ widget.until?.removeListener(_check);+ super.dispose();+ }++ void _check() {+ if (_closing || (widget.stillOpen?.call() ?? true)) return;+ _closing = true;+ // Not while a listener's notice is being told: once this frame is done.+ WidgetsBinding.instance.addPostFrameCallback((_) {+ if (!mounted) return;+ final route = ModalRoute.of(context);+ if (route == null || !route.isActive) return;+ if (route.isCurrent) {+ Navigator.of(context).pop(false);+ } else {+ Navigator.of(context).removeRoute(route);+ }+ });+ WidgetsBinding.instance.ensureVisualUpdate();+ }++ @override+ Widget build(BuildContext context) => widget.child;+}+/// A line over the rows, with what can be done about it.class _Note extends StatelessWidget {- const _Note({required this.text, required this.action});+ const _Note({super.key, required this.text, required this.action});final String text;final Widget action;diff --git a/mobile/lib/swarm/swarm_conversation_page.dart b/mobile/lib/swarm/swarm_conversation_page.dartindex e7f571663..77cf558ab 100644--- a/mobile/lib/swarm/swarm_conversation_page.dart+++ b/mobile/lib/swarm/swarm_conversation_page.dart@@ -96,8 +96,10 @@ Future<void> attachSwarmFiles(/// One conversation: its messages, newest at the foot, older ones on demand —/// each with who wrote it, their role and when, follow-ups grouped, a reply's-/// quote leading to its original; the decisions asked of the person in it;-/// and, for a writer, a composer that posts text, as a reply or with+/// quote leading to its original; in the person's own Buddy chat, the+/// decisions asked of them in its project, as Desktop shows them there (no+/// other chat shows decisions: they are answered in Activity); and, for a+/// writer, a composer that posts text, as a reply or with/// @mentions of the conversation's agents picked as they are typed, and with/// files from the photo library, the camera or Files ([swarmSendsFiles]). A/// post shows at once and says when it is not confirmed.@@ -109,14 +111,13 @@ class SwarmConversationPage extends StatefulWidget {this.header = true,this.buddy,this.messageId,- this.decisionId,this.threadId,this.mention,this.homeC = false,});final String swarmId, conversationId;- final String? messageId, decisionId;+ final String? messageId;/// A thread to open over the chat as it opens, when [messageId] is its/// root: as Threads opens one on the desktop (`_openThreadFromList`), the@@ -174,7 +175,6 @@ class _SwarmConversationPageState extends State<SwarmConversationPage>/// the one lit for a moment on arrival, the search through earlier pages,/// and what to say when it cannot be found.String? _target, _lit;- String? _decisionTarget;bool _noticeHandled = false;final _targetKey = GlobalKey();Timer? _litTimer;@@ -613,17 +613,6 @@ class _SwarmConversationPageState extends State<SwarmConversationPage>}final view = _view.value = _ChatView.of(session, c, _view.value);_seeBuddy(c, view.buddyProject);- final decisionId = widget.decisionId;- if (!_noticeHandled &&- decisionId != null &&- _view.value!.decisions.any((need) => need.decision.id == decisionId)) {- _noticeHandled = true;- WidgetsBinding.instance.addPostFrameCallback((_) {- if (!mounted || _conversation != c) return;- setState(() => _decisionTarget = decisionId);- _reveal(c, decisionId, 0);- });- }}/// What the person does to their Buddy from its chat, while this is their@@ -967,7 +956,6 @@ class _SwarmConversationPageState extends State<SwarmConversationPage>_threadAt = null;final landing = _land();setState(() {- _decisionTarget = null;_finding = true;_note = null;});@@ -1035,9 +1023,7 @@ class _SwarmConversationPageState extends State<SwarmConversationPage>final jump = landing ?? _land();WidgetsBinding.instance.addPostFrameCallback((_) {if (!mounted) return;- if (_target != messageId && _decisionTarget != messageId) {- return _landed(jump);- }+ if (_target != messageId) return _landed(jump);if (_targetKey.currentContext case final row?) {unawaited(Scrollable.ensureVisible(@@ -1050,9 +1036,7 @@ class _SwarmConversationPageState extends State<SwarmConversationPage>}final shown = _shown;final index = shown.indexWhere(- (entry) => _decisionTarget == messageId- ? entry is _AskEntry && entry.need.decision.id == messageId- : entry is _MessageEntry && entry.message.id == messageId,+ (entry) => entry is _MessageEntry && entry.message.id == messageId,);if (!_scroll.hasClients || index < 0 || attempt > 20) {return _landed(jump);@@ -1726,19 +1710,15 @@ class _SwarmConversationPageState extends State<SwarmConversationPage>role,coordinator,swarmLookKey(_agentLook(asker)),- _decisionTarget == need.decision.id,),- () => KeyedSubtree(- key: _decisionTarget == need.decision.id ? _targetKey : null,- child: _Ask(- session: session,- need: need,- grouped: grouped,- askerId: asker?.id,- role: role,- pm: coordinator,- picture: asker?.avatar,- ),+ () => _Ask(+ session: session,+ need: need,+ grouped: grouped,+ askerId: asker?.id,+ role: role,+ pm: coordinator,+ picture: asker?.avatar,),);}@@ -2108,17 +2088,18 @@ class _ChatView {.where((p) => p.id == group?.projectId).firstOrNull?.name;- // A chat not open to the person shows none of its questions either, even- // while the decisions read has not caught up.+ // Only the person's own Buddy chat holds decisions, its project's, as+ // Desktop shows them above it; every other chat leaves them to Activity+ // (Dee, 11-01: they blocked the project chat). A chat not open to the+ // person shows none either, even while the decisions read has not caught+ // up.final decisions = [- for (final need in session.inbox.needs)- if (group != null &&- need is SwarmDecisionNeed &&- need.swarmId == reader.tabId &&- (need.conversationId == c.id ||- (buddyProject != null &&- need.decision.projectId == buddyProject)))- need,+ if (group != null && buddyProject != null)+ for (final need in session.inbox.needs)+ if (need is SwarmDecisionNeed &&+ need.swarmId == reader.tabId &&+ need.decision.projectId == buddyProject)+ need,];return _ChatView(known: group != null,diff --git a/mobile/lib/swarm/swarm_inbox.dart b/mobile/lib/swarm/swarm_inbox.dartindex d3420a003..473c4af08 100644--- a/mobile/lib/swarm/swarm_inbox.dart+++ b/mobile/lib/swarm/swarm_inbox.dart@@ -52,7 +52,10 @@ class SwarmDecisionNeed extends SwarmNeed {@overrideString get conversationId => decision.conversationId;@override- String get key => 'decision:${decision.id}';+ String get key => keyOf(decision.id);++ /// The key of decision [id]'s need: what Activity opens at for its notice.+ static String keyOf(String id) => 'decision:$id';}/// A Lead's tag of the person.diff --git a/mobile/lib/swarm/swarm_project_page.dart b/mobile/lib/swarm/swarm_project_page.dartindex 4c38bc4af..432b3676a 100644--- a/mobile/lib/swarm/swarm_project_page.dart+++ b/mobile/lib/swarm/swarm_project_page.dart@@ -101,22 +101,20 @@ void openSwarmProject(unawaited(replace ? navigator.pushReplacement(route) : navigator.push(route));}-/// A route to chat [conversationId] of Swarm [swarmId], at [messageId] with-/// [decisionId] asked, or with [threadId]'s thread open over it at its root,-/// as a notice, a link, Activity, Threads or a row opens it-/// ([SwarmOpenedChat]).+/// A route to chat [conversationId] of Swarm [swarmId], at [messageId], or+/// with [threadId]'s thread open over it at its root, as a notice, a link,+/// Activity, Threads or a row opens it ([SwarmOpenedChat]). A decision opens+/// in Activity instead, where it is answered.Route<void> swarmChatRoute({required String swarmId,required String conversationId,String? messageId,- String? decisionId,String? threadId,}) => phoneRoute((_) => SwarmOpenedChat(swarmId: swarmId,conversationId: conversationId,messageId: messageId,- decisionId: decisionId,threadId: threadId,),listensForItself: true,@@ -141,12 +139,11 @@ class SwarmOpenedChat extends StatefulWidget {required this.swarmId,required this.conversationId,this.messageId,- this.decisionId,this.threadId,});final String swarmId, conversationId;- final String? messageId, decisionId;+ final String? messageId;/// The thread opened over the chat ([SwarmConversationPage.threadId]).final String? threadId;@@ -264,7 +261,6 @@ class _SwarmOpenedChatState extends State<SwarmOpenedChat> {swarmId: widget.swarmId,projectId: projectId,messageId: widget.messageId,- decisionId: widget.decisionId,threadId: widget.threadId,),null => SwarmConversationPage(@@ -272,7 +268,6 @@ class _SwarmOpenedChatState extends State<SwarmOpenedChat> {swarmId: widget.swarmId,conversationId: widget.conversationId,messageId: widget.messageId,- decisionId: widget.decisionId,threadId: widget.threadId,),};@@ -297,7 +292,6 @@ class SwarmProjectPage extends StatefulWidget {this.tabs = SwarmProjectTab.current,this.mention,this.messageId,- this.decisionId,this.threadId,});@@ -313,11 +307,10 @@ class SwarmProjectPage extends StatefulWidget {/// ([SwarmConversationPage.mention]).final String? mention;- /// Where its chat opens, as a notice or a link names it: at that message,- /// with that decision asked ([SwarmConversationPage.messageId] and- /// [SwarmConversationPage.decisionId]), or with that thread open over it+ /// Where its chat opens, as a notice or a link names it: at that message+ /// ([SwarmConversationPage.messageId]), or with that thread open over it/// ([SwarmConversationPage.threadId]). Only the first time the chat shows.- final String? messageId, decisionId, threadId;+ final String? messageId, threadId;@overrideState<SwarmProjectPage> createState() => _SwarmProjectPageState();@@ -334,9 +327,7 @@ class _SwarmProjectPageState extends State<SwarmProjectPage> {/// Where the chat opens ([SwarmProjectPage.messageId]): forgotten once/// another tab is picked, so the chat shown again opens at its end.- late String? _messageId = widget.messageId,- _decisionId = widget.decisionId,- _threadId = widget.threadId;+ late String? _messageId = widget.messageId, _threadId = widget.threadId;/// What the page shows of the inbox ([_inboxChanged]): its Swarm's/// reader, whether there are several Swarms, why the list was not read.@@ -591,7 +582,6 @@ class _SwarmProjectPageState extends State<SwarmProjectPage> {header: false,mention: widget.mention,messageId: _messageId,- decisionId: _decisionId,threadId: _threadId,homeC: _homeC,),@@ -657,7 +647,7 @@ class _SwarmProjectPageState extends State<SwarmProjectPage> {: swarmChatNews(reader, asks, chat),onSelect: (tab) => setState(() {_tab = tab;- _messageId = _decisionId = _threadId = null;+ _messageId = _threadId = null;}),),),diff --git a/mobile/lib/swarm/swarm_project_status.dart b/mobile/lib/swarm/swarm_project_status.dartindex 39e29a818..17538b021 100644--- a/mobile/lib/swarm/swarm_project_status.dart+++ b/mobile/lib/swarm/swarm_project_status.dart@@ -13,6 +13,7 @@ import '../shared/theme/app_type.dart';import 'model.dart';import 'swarm_inbox.dart';import 'swarm_need_rows.dart';+import 'swarm_activity_page.dart' show openSwarmActivity;import 'swarm_needs_page.dart';import 'swarm_reader.dart';import 'swarm_session.dart';@@ -157,7 +158,7 @@ class SwarmProjectStatusCard extends StatelessWidget {child: Column(crossAxisAlignment: CrossAxisAlignment.stretch,children: [- _heading(status?.at, waiting.length, folded, chosen),+ _heading(context, status?.at, waiting.length, folded, chosen),if (!folded)// A long report, or many decisions, scroll inside the// card, so the chat keeps its room. Each part takes what@@ -192,10 +193,11 @@ class SwarmProjectStatusCard extends StatelessWidget {session: session,need: need,chevron: LucideIcons.chevronRight300,- onTap: () => openSwarmNeeds(+ onTap: () => openSwarmActivity(context,focus: need.key,swarmId: swarmId,+ projectId: projectId,),),],@@ -213,35 +215,44 @@ class SwarmProjectStatusCard extends StatelessWidget {);/// "Status · updated 09:52", with how many wait on the person while- /// folded, and the fold at its end. While the keyboard alone folds it,- /// there is no button, only its room: a tap then would save a fold, or an- /// unfold, the person never saw.- Widget _heading(DateTime? at, int waiting, bool folded, bool chosen) => Row(+ /// folded, and the fold at its end. "N need you" opens Activity on this+ /// project's rows, where they are answered: no chat shows decisions. While+ /// the keyboard alone folds it, there is no button, only its room: a tap+ /// then would save a fold, or an unfold, the person never saw.+ Widget _heading(+ BuildContext context,+ DateTime? at,+ int waiting,+ bool folded,+ bool chosen,+ ) => Row(children: [Expanded(- child: Text.rich(- TextSpan(- children: [- TextSpan(- text: 'Status',- style: AppType.label(color: AppPalette.textPrimary),- ),- if (at != null)- TextSpan(- text: ' · updated ${swarmStatusUpdatedAt(at, now())}',- style: AppType.caption(color: AppPalette.textSecondary),- ),- // Folded, the heading still says something waits.- if (folded && waiting > 0)+ child: Row(+ children: [+ Flexible(+ child: Text.rich(TextSpan(- text: ' · $waiting ${waiting == 1 ? 'needs' : 'need'} you',- style: AppType.caption(color: AppPalette.swarmAccent),+ children: [+ TextSpan(+ text: 'Status',+ style: AppType.label(color: AppPalette.textPrimary),+ ),+ if (at != null)+ TextSpan(+ text: ' · updated ${swarmStatusUpdatedAt(at, now())}',+ style: AppType.caption(color: AppPalette.textSecondary),+ ),+ ],),- ],- ),- key: ValueKey('swarm-project-status-heading-$projectId'),- maxLines: 1,- overflow: TextOverflow.ellipsis,+ key: ValueKey('swarm-project-status-heading-$projectId'),+ maxLines: 1,+ overflow: TextOverflow.ellipsis,+ ),+ ),+ // Folded, the heading still says something waits, and leads to it.+ if (folded && waiting > 0) _needYou(context, waiting),+ ],),),if (typing)@@ -256,6 +267,34 @@ class SwarmProjectStatusCard extends StatelessWidget {),],);++ /// " · 2 need you", a tap target as tall as the fold beside it: Activity,+ /// on what waits on the person in this project.+ Widget _needYou(BuildContext context, int waiting) {+ final text = '$waiting ${waiting == 1 ? 'needs' : 'need'} you';+ return Semantics(+ button: true,+ label: text,+ excludeSemantics: true,+ child: GestureDetector(+ key: ValueKey('swarm-project-status-needs-you-$projectId'),+ behavior: HitTestBehavior.opaque,+ onTap: () =>+ openSwarmActivity(context, swarmId: swarmId, projectId: projectId),+ child: ConstrainedBox(+ constraints: const BoxConstraints(minHeight: 44),+ child: Align(+ widthFactor: 1,+ child: Text(+ ' · $text',+ maxLines: 1,+ style: AppType.caption(color: AppPalette.swarmAccent),+ ),+ ),+ ),+ ),+ );+ }}/// The report as the coordinator wrote it, line for line, with its web linksdiff --git a/mobile/test/phone/phone_shell_swarm_notice_test.dart b/mobile/test/phone/phone_shell_swarm_notice_test.dartindex b5b7d97f1..fafe05495 100644--- a/mobile/test/phone/phone_shell_swarm_notice_test.dart+++ b/mobile/test/phone/phone_shell_swarm_notice_test.dart@@ -5,6 +5,7 @@ import 'package:harness_mobile/notify/system_notices.dart';import 'package:harness_mobile/phone/phone_shell.dart';import 'package:harness_mobile/phone/agent_home.dart';import 'package:harness_mobile/settings/experimental_features.dart';+import 'package:harness_mobile/swarm/swarm_activity_page.dart';import 'package:harness_mobile/swarm/swarm_conversation_page.dart';import 'package:harness_mobile/swarm/swarm_page.dart';@@ -82,13 +83,20 @@ void main() {}await tester.pump();await tester.pump(const Duration(milliseconds: 400));- if (on) {+ if (on && kind == 'decision') {+ // A decision opens in Activity, at it: no chat shows decisions.+ final page = tester.widget<SwarmActivityPage>(+ find.byType(SwarmActivityPage),+ );+ expect((page.focus, page.swarmId), ('decision:d1', 'tab-b'));+ expect(find.byType(SwarmConversationPage), findsNothing);+ expect(find.byType(SwarmPage, skipOffstage: false), findsOneWidget);+ } else if (on) {final page = tester.widget<SwarmConversationPage>(find.byType(SwarmConversationPage),);expect(page.conversationId, target.conversationId);expect(page.messageId, target.messageId);- expect(page.decisionId, target.decisionId);} else {expect(find.byType(SwarmConversationPage), findsNothing);expect(find.byType(AgentHome), findsOneWidget);@@ -122,9 +130,7 @@ void main() {});testWidgets("a tap on a project chat's notice opens the project on Home "- "C's screen, its chat at the message, its decision asked", (- tester,- ) async {+ "C's screen, its chat at the message", (tester) async {final fake = FakeSwarm();fake.routes['/api/super-tabs/list'] = (_) => {'tabs': [@@ -151,7 +157,7 @@ void main() {swarmId: tab,conversationId: leadChat,messageId: 'm7',- decisionId: 'd1',+ decisionId: null,);for (var i = 0; i < 20; i++) {await tester.pump(const Duration(milliseconds: 100));@@ -161,10 +167,7 @@ void main() {final chat = tester.widget<SwarmConversationPage>(find.byType(SwarmConversationPage),);- expect(- (chat.conversationId, chat.messageId, chat.decisionId),- (leadChat, 'm7', 'd1'),- );+ expect((chat.conversationId, chat.messageId), (leadChat, 'm7'));});testWidgets('a tap that launched the app opens it too', (tester) async {diff --git a/mobile/test/swarm/swarm_activity_page_test.dart b/mobile/test/swarm/swarm_activity_page_test.dartindex 5f1c99bb5..b9be2361f 100644--- a/mobile/test/swarm/swarm_activity_page_test.dart+++ b/mobile/test/swarm/swarm_activity_page_test.dart@@ -1,3 +1,5 @@+import 'dart:async';+import 'package:flutter/material.dart';import 'package:flutter_test/flutter_test.dart';import 'package:harness_mobile/notify/system_notices.dart';@@ -376,4 +378,136 @@ void main() {await tester.pumpAndSettle();expect(chatReads(fake), 1);});++ group('opened at a decision (a notice or link)', () {+ Future<SwarmHost> at(+ WidgetTester tester,+ FakeSwarm fake, {+ String focus = 'decision:d1',+ String swarmId = tab,+ }) => pump(+ tester,+ fake,+ home: SwarmActivityPage(focus: focus, swarmId: swarmId),+ );++ testWidgets('it opens in full, every option and Done there', (+ tester,+ ) async {+ await at(tester, activityBackend());++ expect(key('swarm-activity-open-decision:d1'), findsOneWidget);+ expect(key('swarm-option-d1-0'), findsOneWidget);+ expect(key('swarm-option-d1-1'), findsOneWidget);+ expect(key('swarm-activity-focus-gone'), findsNothing);+ });++ testWidgets('one no longer open, another Swarm\'s, or never the '+ 'person\'s says so alike, naming nothing of it', (tester) async {+ for (final (focus, swarmId) in [+ ('decision:gone', tab),+ ('decision:d1', 'tab-other'),+ ('decision:theirs', 'tab-other'),+ ]) {+ await tester.pumpWidget(const SizedBox());+ await at(tester, activityBackend(), focus: focus, swarmId: swarmId);++ expect(+ find.text('This decision is no longer open.'),+ findsOneWidget,+ reason: '$focus in $swarmId',+ );+ expect(key('swarm-activity-open-decision:d1'), findsNothing);+ expect(key('swarm-activity-loading'), findsNothing);+ if (swarmId != tab) {+ expect(find.textContaining('Approve merge'), findsNothing);+ expect(find.textContaining('Mobile'), findsNothing);+ }+ }+ });++ testWidgets('until the decisions are read it says nothing of it; a read '+ 'that fails says so, and Try again brings the decision', (+ tester,+ ) async {+ final fake = activityBackend();+ final held = Completer<Object?>();+ fake.routes['/api/super-tabs/$tab/decisions?state=open'] = (_) =>+ held.future;+ await pump(+ tester,+ fake,+ home: const SwarmActivityPage(focus: 'decision:d1', swarmId: tab),+ );+ expect(key('swarm-activity-focus-gone'), findsNothing);+ expect(key('swarm-activity-focus-failed'), findsNothing);++ held.completeError(const SuperTabFailure('UNAVAILABLE', 'Down.'));+ await tester.pumpAndSettle();+ expect(key('swarm-activity-focus-failed'), findsOneWidget);+ expect(key('swarm-activity-focus-gone'), findsNothing);++ final first = activityBackend();+ fake.routes['/api/super-tabs/$tab/decisions?state=open'] =+ first.routes['/api/super-tabs/$tab/decisions?state=open']!;+ await tester.tap(key('swarm-activity-focus-retry'));+ await tester.pumpAndSettle();+ expect(key('swarm-activity-focus-failed'), findsNothing);+ expect(key('swarm-activity-open-decision:d1'), findsOneWidget);+ });++ testWidgets('a read that answers after access was lost shows nothing of '+ 'it', (tester) async {+ final fake = activityBackend();+ final held = Completer<Object?>();+ fake.routes['/api/super-tabs/$tab/decisions?state=open'] = (_) =>+ held.future;+ final host = await at(tester, fake);+ host.session!.inbox.reader(tab)!.revoke();+ await tester.pump();+ held.complete(+ activityBackend().routes['/api/super-tabs/$tab/decisions?state=open']!(+ null,+ ),+ );+ await tester.pumpAndSettle();++ expect(key('swarm-activity-open-decision:d1'), findsNothing);+ expect(find.textContaining('Approve merge'), findsNothing);+ expect(find.text('This decision is no longer open.'), findsOneWidget);+ });++ testWidgets('access lost while it is answered: the row goes and the '+ 'answer held for Undo is never sent', (tester) async {+ final fake = activityBackend();+ final host = await at(tester, fake);+ await tester.tap(key('swarm-option-d1-1'));+ await tester.pump();+ expect(find.text('Sending “Merge”'), findsOneWidget);++ host.session!.inbox.reader(tab)!.revoke();+ await tester.pump(const Duration(seconds: 10));+ await tester.pumpAndSettle();++ expect(fake.commands, isEmpty);+ expect(key('swarm-activity-open-decision:d1'), findsNothing);+ expect(find.textContaining('Approve merge'), findsNothing);+ expect(find.textContaining('Sending'), findsNothing);+ });++ testWidgets('access lost while Approve asks: the question closes and '+ 'nothing is sent', (tester) async {+ final fake = activityBackend();+ final host = await pump(tester, fake);+ await tester.tap(key('swarm-activity-approve-decision:d1'));+ await tester.pumpAndSettle();+ expect(find.text('Approve?'), findsOneWidget);++ host.session!.inbox.reader(tab)!.revoke();+ await tester.pumpAndSettle();+ expect(find.text('Approve?'), findsNothing);+ expect(find.textContaining('Approve merge'), findsNothing);+ expect(fake.commands, isEmpty);+ });+ });}diff --git a/mobile/test/swarm/swarm_chat_test.dart b/mobile/test/swarm/swarm_chat_test.dartindex ceb39b480..6c031395b 100644--- a/mobile/test/swarm/swarm_chat_test.dart+++ b/mobile/test/swarm/swarm_chat_test.dart@@ -178,7 +178,6 @@ void main() {String swarmId = tab,String conversation = 'g1',String? messageId,- String? decisionId,bool settle = true,bool homeC = false,bool systemMenu = false,@@ -203,7 +202,6 @@ void main() {swarmId: swarmId,conversationId: conversation,messageId: messageId,- decisionId: decisionId,homeC: homeC,),),@@ -221,7 +219,6 @@ void main() {String swarmId = tab,String conversation = 'g1',String? messageId,- String? decisionId,bool settle = true,bool homeC = false,SwarmUpload upload = refuseSwarmUpload,@@ -247,7 +244,6 @@ void main() {conversation: conversation,settle: settle,messageId: messageId,- decisionId: decisionId,homeC: homeC,systemMenu: systemMenu,);@@ -517,41 +513,33 @@ void main() {expect(marksSent().last, 40);});- testWidgets(- 'following a quote after a decision notification changes the target',- (tester) async {- await pump(- tester,- backend(- [- message('m1', 1, text: 'Original plan'),- message('m2', 2, text: 'Follow up', replyTo: 'm1', minute: 1),- ],- decisions: [decision('d1')],- ),- decisionId: 'd1',- );- await tester.tap(key('swarm-quote-m2'));- await tester.pumpAndSettle();- expect(key('swarm-lit-m1'), findsOneWidget);- },- );-- testWidgets('a notification brings its decision card into view', (- tester,- ) async {+ testWidgets('a chat with open decisions shows none of them: they are '+ 'answered in Activity (Dee, 11-01)', (tester) async {await pump(tester,backend([- for (var i = 1; i <= 40; i++)- message('m$i', i, text: 'Message $i\nMore text', minute: i),+ message('m1', 1, text: 'The build is green'),+ message('m2', 2, author: me, text: 'Flag it', minute: 2),],- decisions: [decision('d1')],+ decisions: [decision('d1', minute: 1), decision('d2', minute: 3)],),- decisionId: 'd1',);- expect(inView(tester, find.text('Ship it behind a flag?')), isTrue);++ expect(key('swarm-message-m1'), findsOneWidget);+ expect(key('swarm-message-m2'), findsOneWidget);+ expect(key('swarm-ask-d1'), findsNothing);+ expect(key('swarm-ask-d2'), findsNothing);+ expect(find.text('Ship it behind a flag?'), findsNothing);+ expect(key('swarm-option-d1-0'), findsNothing);+ });++ testWidgets('a chat with no messages and an open decision says it has no '+ 'messages, with no decision under it', (tester) async {+ await pump(tester, backend(const [], decisions: [decision('d1')]));++ expect(key('swarm-chat-empty'), findsOneWidget);+ expect(key('swarm-ask-d1'), findsNothing);});testWidgets('a reply quotes its original; tapping the quote brings the '@@ -1467,8 +1455,13 @@ void main() {expect(today, lessThan(tester.getTopLeft(find.text('From today')).dy));});- testWidgets('a decision sits among the messages where it was asked: a card '- 'with its question, the options side by side', (tester) async {+ /// g1 as the person's own Buddy chat: the one chat that still holds the+ /// decisions asked of them in its project, as Desktop shows them there.+ const ownBuddy = {'kind': 'buddy', 'buddyOwnerId': me};++ testWidgets('in the person\'s own Buddy chat, a decision sits among the '+ 'messages where it was asked: a card with its question, the options '+ 'side by side', (tester) async {await pump(tester,backend(@@ -1476,6 +1469,7 @@ void main() {message('m1', 1, text: 'The build is green'),message('m2', 2, author: me, text: 'Flag it', minute: 2),],+ g1: ownBuddy,decisions: [decision('d1', minute: 1)],),);@@ -1506,8 +1500,10 @@ void main() {await tester.pumpAndSettle();});- testWidgets('an open decision from before the messages read so far waits at '- 'the foot, not behind Earlier messages', (tester) async {+ testWidgets('in the Buddy chat, an open decision from before the messages '+ 'read so far waits at the foot, not behind Earlier messages', (+ tester,+ ) async {await pump(tester,backend(@@ -1516,6 +1512,7 @@ void main() {message('m$i', i, text: 'Line $i\nof the log', minute: i),],next: {'sequence': 10, 'id': 'm10'},+ g1: ownBuddy,decisions: [decision('d1')],),);@@ -1576,8 +1573,10 @@ void main() {expect(tester.getSize(field).height, greaterThan(oneLine * 2));});- testWidgets('a decision asked just after its asker\'s own message is drawn '- 'as part of it, under one name and time', (tester) async {+ testWidgets('in the Buddy chat, a decision asked just after its asker\'s '+ 'own message is drawn as part of it, under one name and time', (+ tester,+ ) async {await pump(tester,backend(@@ -1589,11 +1588,19 @@ void main() {text: 'One question before the release:',),],+ g1: ownBuddy,decisions: [decision('d1', minute: 1)],),);- expect(find.text('River'), findsOneWidget);+ // Under the message's own name and time: the card carries none.+ expect(+ find.descendant(+ of: key('swarm-ask-d1'),+ matching: find.textContaining('River'),+ ),+ findsNothing,+ );expect(find.text(time(1)), findsNothing);expect(tester.getRect(key('swarm-ask-d1')).top,diff --git a/mobile/test/swarm/swarm_project_status_shots_test.dart b/mobile/test/swarm/swarm_project_status_shots_test.dartindex d3fc36d29..e385e3c8e 100644--- a/mobile/test/swarm/swarm_project_status_shots_test.dart+++ b/mobile/test/swarm/swarm_project_status_shots_test.dart@@ -19,8 +19,9 @@ import '../voice_fakes.dart';import 'swarm_fixture.dart';/// Review screenshots of the project status card at the top of a project's-/// chat (Tony 11-01, task 1): open, with the report and a decision waiting,-/// then folded. On a 390-point phone in both phone themes, from made-up data+/// chat (Tony 11-01, task 1): open, with the report and a decision waiting+/// (none among the messages, Dee 11-01), then folded, then the Activity its+/// "1 needs you" opens. On a 390-point phone in both phone themes, from made-up data/// only, to the folder `SWARM_PROJECT_STATUS_SHOTS` names.final shots = Platform.environment['SWARM_PROJECT_STATUS_SHOTS'];void main() {@@ -193,12 +194,20 @@ void main() {find.byKey(const ValueKey('swarm-project-status-$project')),findsOneWidget,);+ // The decision is on the card, never among the messages.+ expect(find.byKey(const ValueKey('swarm-ask-d1')), findsNothing);await capture('open');await tester.tap(find.byKey(const ValueKey('swarm-project-status-fold-$project')),);await tester.pumpAndSettle();await capture('folded');+ // "1 needs you" opens Activity on this project, where it is answered.+ await tester.tap(+ find.byKey(ValueKey('swarm-project-status-needs-you-$project')),+ );+ await tester.pumpAndSettle();+ await capture('activity');await tester.pumpWidget(const SizedBox());host.dispose();}diff --git a/mobile/test/swarm/swarm_project_status_test.dart b/mobile/test/swarm/swarm_project_status_test.dartindex 32788b2f3..4e00f7442 100644--- a/mobile/test/swarm/swarm_project_status_test.dart+++ b/mobile/test/swarm/swarm_project_status_test.dart@@ -15,6 +15,7 @@ import 'package:harness_mobile/swarm/swarm_request.dart';import 'package:harness_mobile/swarm/swarm_session.dart';import '../voice_fakes.dart';+import 'swarm_activity_fixture.dart' show activityMessage;import 'swarm_fixture.dart';/// The project status card at the top of a project's chat (Tony 11-01, task@@ -154,8 +155,18 @@ void main() {final card = key('swarm-project-status-$project');final heading = key('swarm-project-status-heading-$project');final fold = key('swarm-project-status-fold-$project');- String headingText(WidgetTester tester) =>- tester.widget<Text>(heading).textSpan!.toPlainText();+ final needsYou = key('swarm-project-status-needs-you-$project');++ /// The heading as read: Status, when, and how many wait while folded.+ String headingText(WidgetTester tester) => [+ tester.widget<Text>(heading).textSpan!.toPlainText(),+ if (tester.any(needsYou))+ tester+ .widget<Text>(+ find.descendant(of: needsYou, matching: find.byType(Text)),+ )+ .data!,+ ].join();group('states', () {testWidgets('empty: no report and nothing waiting draws no card', (@@ -275,10 +286,16 @@ void main() {tester,) async {final long = List.generate(30, (i) => 'Line $i of the report').join('\n');- await pump(- tester,- backend(status: {'text': long, 'at': today}, decisions: [decision('d1')]),+ final fake = backend(+ status: {'text': long, 'at': today},+ decisions: [decision('d1')],);+ // A message, so the chat has its list: decisions are not in it.+ fake.routes['/api/super-tabs/$tab/conversations/'] = (_) => {+ 'messages': [activityMessage('m1', 1)],+ 'next': null,+ };+ await pump(tester, fake);final chat = key('swarm-messages');final composer = find.byType(EditableText);final openCard = tester.getSize(card).height;@@ -735,6 +752,188 @@ void main() {prefs.dispose();});});++ group('Activity from the card', () {+ /// River asks the same question in both projects: one decision in+ /// Mobile's chat, one in Backend's.+ List<Map<String, dynamic>> both() => [+ decision('d1'),+ decision('other', projectId: other, chat: otherChat),+ ];++ /// Activity shows [project]'s decision alone, under its name, counted+ /// once.+ void expectMobileOnly(WidgetTester tester) {+ final page = tester.widget<SwarmActivityPage>(+ find.byType(SwarmActivityPage),+ );+ expect((page.swarmId, page.projectId), (tab, project));+ expect(find.text('#Mobile'), findsOneWidget);+ expect(+ key('swarm-activity-row-decision:d1').evaluate().length ++ key('swarm-activity-open-decision:d1').evaluate().length,+ 1,+ );+ expect(key('swarm-activity-row-decision:other'), findsNothing);+ expect(key('swarm-activity-open-decision:other'), findsNothing);+ expect(find.textContaining('Backend'), findsNothing);+ expect(+ find.descendant(+ of: key('swarm-activity-filter-needsYou'),+ matching: find.text('1'),+ ),+ findsOneWidget,+ );+ }++ testWidgets('the project chat with open decisions shows none among its '+ 'messages; the card holds them', (tester) async {+ await pump(+ tester,+ backend(+ status: {'text': 'Building', 'at': today},+ decisions: [decision('d1')],+ ),+ );+ expect(key('swarm-project-status-need-decision:d1'), findsOneWidget);+ expect(key('swarm-ask-d1'), findsNothing);+ expect(key('swarm-option-d1-0'), findsNothing);+ });++ testWidgets('folded, "N need you" is a tap target that opens Activity on '+ 'this project alone', (tester) async {+ await pump(+ tester,+ backend(status: {'text': 'Building', 'at': today}, decisions: both()),+ );+ await tester.tap(fold);+ await tester.pumpAndSettle();+ expect(needsYou, findsOneWidget);+ expect(tester.getSize(needsYou).height, greaterThanOrEqualTo(44));++ await tester.tap(needsYou);+ await tester.pumpAndSettle();+ expect(+ tester.widget<SwarmActivityPage>(find.byType(SwarmActivityPage)).focus,+ isNull,+ );+ expectMobileOnly(tester);+ });++ testWidgets('a waiting line opens Activity at it, on this project alone', (+ tester,+ ) async {+ await pump(tester, backend(decisions: both()));+ await tester.tap(key('swarm-project-status-need-decision:d1'));+ await tester.pumpAndSettle();++ expect(key('swarm-activity-open-decision:d1'), findsOneWidget);+ expectMobileOnly(tester);+ });++ testWidgets("answering in Activity takes it off the card's count", (+ tester,+ ) async {+ final fake = backend(+ status: {'text': 'Building', 'at': today},+ decisions: both(),+ );+ fake.routes['/api/super-tabs/$tab/commands'] = (_) => {+ 'result': <String, dynamic>{},+ };+ await pump(tester, fake);+ final session = host(tester);+ await tester.tap(fold);+ await tester.pumpAndSettle();+ expect(headingText(tester), endsWith(' · 1 needs you'));++ await tester.tap(needsYou);+ await tester.pumpAndSettle();+ await tester.tap(key('swarm-activity-row-decision:d1'));+ await tester.pumpAndSettle();+ await tester.tap(key('swarm-option-d1-0'));+ await tester.pump(const Duration(seconds: 10));+ await tester.pumpAndSettle();+ expect(fake.commands.single, {+ 'type': 'decision.answer',+ 'decisionId': 'd1',+ 'choice': 0,+ });+ // The server: d1 answered, one decision left in the Swarm.+ fake.routes['/api/super-tabs/$tab/decisions?state=open'] = (_) => {+ 'decisions': [decision('other', projectId: other, chat: otherChat)],+ };+ fake.routes['/api/super-tabs/$tab/changes'] = (_) => changes(+ cursor: 'c3',+ lastChangedAt: 103,+ derived: {'decisionsWaiting': 1},+ );+ await session.inbox.reader(tab)!.refresh();+ await session.inbox.refresh();+ await tester.pumpAndSettle();++ await tester.tap(find.byKey(const ValueKey('tty-back')).first);+ await tester.pumpAndSettle();+ expect(find.byType(SwarmActivityPage), findsNothing);+ expect(card, findsOneWidget);+ expect(needsYou, findsNothing);+ expect(headingText(tester), isNot(contains('need')));+ });++ testWidgets('access lost while its Activity is open: the rows and the '+ "project's name go, nothing stuck loading", (tester) async {+ await pump(tester, backend(decisions: both()));+ final session = host(tester);+ await tester.tap(key('swarm-project-status-need-decision:d1'));+ await tester.pumpAndSettle();+ expect(find.text('Fold the card by default?'), findsWidgets);++ session.inbox.reader(tab)!.revoke();+ await tester.pumpAndSettle();+ expect(find.text('#Mobile'), findsNothing);+ expect(find.text('Fold the card by default?'), findsNothing);+ expect(find.textContaining('River'), findsNothing);+ expect(key('swarm-activity-loading'), findsNothing);+ });++ testWidgets('the project made private to others while its Activity is '+ 'open: its rows and name go', (tester) async {+ final fake = backend(decisions: both());+ await pump(tester, fake);+ final session = host(tester);+ await tester.tap(key('swarm-project-status-need-decision:d1'));+ await tester.pumpAndSettle();+ expect(find.text('#Mobile'), findsOneWidget);++ fake.routes['/api/super-tabs/$tab/changes'] = (_) => {+ ...changes(+ cursor: 'c2',+ lastChangedAt: 102,+ derived: {'decisionsWaiting': 2},+ ),+ 'head': part(+ 'head',+ 2,+ headData(+ projects: [+ {+ ...projectData(project, leadChat),+ 'ownerId': 'diego',+ 'visibility': 'private',+ },+ projectData(other, otherChat),+ ],+ ),+ ),+ };+ await session.inbox.reader(tab)!.refresh();+ await tester.pumpAndSettle();+ expect(find.text('#Mobile'), findsNothing);+ expect(key('swarm-activity-open-decision:d1'), findsNothing);+ expect(key('swarm-activity-row-decision:other'), findsNothing);+ expect(find.text('Fold the card by default?'), findsNothing);+ });+ });}/// The session of the host the page was pumped under.diff --git a/mobile/test/swarm/swarm_screens_test.dart b/mobile/test/swarm/swarm_screens_test.dartindex 69ce58b91..7a718c83f 100644--- a/mobile/test/swarm/swarm_screens_test.dart+++ b/mobile/test/swarm/swarm_screens_test.dart@@ -961,7 +961,8 @@ void main() {expect(find.text('This conversation is read only.'), findsOneWidget);});- testWidgets('the decision asked in it is answered in it', (tester) async {+ testWidgets('the decision asked in it is not shown in it: it is answered '+ 'in Activity (Dee, 11-01)', (tester) async {await pump(tester,backend(),@@ -969,8 +970,9 @@ void main() {);await tester.pumpAndSettle();- expect(find.text('Ship it behind a flag?'), findsOneWidget);- expect(key('swarm-option-d1-0'), findsOneWidget);+ expect(find.text('Which name should the flag have?'), findsOneWidget);+ expect(find.text('Ship it behind a flag?'), findsNothing);+ expect(key('swarm-option-d1-0'), findsNothing);});testWidgets('a viewer reads it and cannot post', (tester) async {@@ -990,8 +992,9 @@ void main() {);});- testWidgets('one the person can no longer read shows nothing of it, '- 'its decision included', (tester) async {+ testWidgets('one the person can no longer read shows nothing of it', (+ tester,+ ) async {final fake = backend();final host = await pump(tester,@@ -1001,7 +1004,6 @@ void main() {await tester.pumpAndSettle();await tester.enterText(find.byType(TextField), 'my reply');expect(find.text('Which name should the flag have?'), findsOneWidget);- expect(find.text('Ship it behind a flag?'), findsOneWidget);// Taken out of g1: the Swarm is read again in full without it, and// the decision list has not caught up yet.