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: Send in the voice row ends the take and posts it, last words included (Tony) (#2488)
harness-for-autonomous[bot]2d1da8d4d7ec
diff --git a/mobile/lib/swarm/swarm_conversation_page.dart b/mobile/lib/swarm/swarm_conversation_page.dartindex f77f2df9b..b9bca943b 100644--- a/mobile/lib/swarm/swarm_conversation_page.dart+++ b/mobile/lib/swarm/swarm_conversation_page.dart@@ -300,6 +300,7 @@ class _SwarmConversationPageState extends State<SwarmConversationPage>dictation: SwarmScope.dictationOf(context),draft: () => _conversation?.draft ?? '',write: (text) => _conversation?.draft = text,+ post: _voiceSend,);}}@@ -790,6 +791,13 @@ class _SwarmConversationPageState extends State<SwarmConversationPage>});}+ /// The voice row's Send, once its take has ended into the draft: the+ /// composer's own Send, in the chat shown now.+ void _voiceSend() {+ final c = _conversation;+ if (mounted && c != null && c.canSend) _send(c);+ }+/// Sends the draft, back at the foot of the chat where the post shows.void _send(SwarmConversation c) {_target = null;@@ -1884,7 +1892,8 @@ class _SwarmConversationPageState extends State<SwarmConversationPage>/// not hear, then the card ([SwarmComposerCard]): the files going with the/// post, a field that grows with what is typed and its X, and the toolbar —/// +, @ Tag, the mic and a round Send. While a take is under way the toolbar- /// is the voice row ([SwarmVoiceRow]) and the picker and X are hidden. An @+ /// is the voice row ([SwarmVoiceRow]), with its own Send, and the picker+ /// and X are hidden. An @/// is typed in the field or put there by Tag: both open the same picker.Widget _composer(SwarmConversation c, Tty tty, {required String hint}) {final snapshot = c.reader.snapshot;diff --git a/mobile/lib/swarm/swarm_new_message_sheet.dart b/mobile/lib/swarm/swarm_new_message_sheet.dartindex 5ff702b53..ab9e1fa8e 100644--- a/mobile/lib/swarm/swarm_new_message_sheet.dart+++ b/mobile/lib/swarm/swarm_new_message_sheet.dart@@ -297,6 +297,9 @@ class _SwarmNewMessageSheetState extends State<SwarmNewMessageSheet>selection: TextSelection.collapsed(offset: text.length),);},+ post: () {+ if (mounted && _canSend) unawaited(_send());+ },)..addListener(_redraw);}}@@ -703,8 +706,8 @@ class _SwarmNewMessageSheetState extends State<SwarmNewMessageSheet>/// Why the last Send did not go, what the last pick left out, what the mic/// could not hear, then the card ([SwarmComposerCard]): the files going,/// the field and its X, then +, the mic and Send — or, while a take is- /// under way, the voice row ([SwarmVoiceRow]). No Tag: New message has no- /// @ picker.+ /// under way, the voice row ([SwarmVoiceRow]) and its Send, for the chat+ /// picked. No Tag: New message has no @ picker.Widget _composer(Tty tty, SwarmNewMessageChat? picked) {final canSend = _canSend;final locked = _locked;@@ -767,7 +770,10 @@ class _SwarmNewMessageSheetState extends State<SwarmNewMessageSheet>),),toolbar: talking- ? SwarmVoiceRow(voice: voice!)+ ? SwarmVoiceRow(+ voice: voice!,+ canPost: _picked != null && !_closing && !locked,+ ): Row(children: [if (swarmSendsFiles)diff --git a/mobile/lib/swarm/swarm_thread_page.dart b/mobile/lib/swarm/swarm_thread_page.dartindex 008769566..104ec197c 100644--- a/mobile/lib/swarm/swarm_thread_page.dart+++ b/mobile/lib/swarm/swarm_thread_page.dart@@ -163,6 +163,9 @@ class _SwarmThreadPageState extends State<SwarmThreadPage> {write: (text) {if (_mayReply) _thread.draft = text;},+ post: () {+ if (mounted && _mayReply && _thread.canSend) unawaited(_send());+ },);}}@@ -542,8 +545,8 @@ class _SwarmThreadPageState extends State<SwarmThreadPage> {/// then +, Also send, the mic and a round Send (the desktop's thread/// composer, with the main chat's mic). While a take is under way the/// toolbar is the voice row ([SwarmVoiceRow]): Also send is hidden, and- /// keeps its tick for the Send after the take. No Tag: a thread has no @- /// picker.+ /// keeps its tick for the row's Send or the one after the take. No Tag: a+ /// thread has no @ picker.Widget _box(SwarmThread t, Tty tty) {// A reply on its way never holds the box: the next is typed meanwhile.final canSend = t.canSend;diff --git a/mobile/lib/swarm/swarm_voice.dart b/mobile/lib/swarm/swarm_voice.dartindex 1cc66463a..67a0bb8ac 100644--- a/mobile/lib/swarm/swarm_voice.dart+++ b/mobile/lib/swarm/swarm_voice.dart@@ -8,21 +8,26 @@ import 'package:flutter/services.dart';import 'package:lucide_icons_flutter/lucide_icons.dart';import 'package:harness_mobile/phone/tty.dart';+import 'package:harness_mobile/phone/tty_controls.dart';import 'package:harness_mobile/phone/voice_input_controller.dart';import 'package:harness_mobile/phone/voice_language_store.dart';import 'package:harness_mobile/phone/voice_mic_face.dart';import 'package:harness_mobile/phone/voice_notice.dart';+import 'package:harness_mobile/shared/theme/app_icon_size.dart';+import 'package:harness_mobile/shared/theme/app_ink.dart';import 'package:harness_mobile/shared/theme/app_space.dart';import 'package:harness_mobile/shared/theme/app_theme.dart';import 'package:harness_mobile/shared/theme/swarm_tokens_set_b.dart';+import 'swarm_conversation_page.dart' show SwarmRoundButton;import 'swarm_dictation.dart';/// Talking instead of typing in a chat, into the message box (Tony, 10-28:/// "like the Claude app"). Tap the mic to talk. While talking the composer/// shows [SwarmVoiceRow]: [stop] ends the take with its words left in the box,-/// [cancel] throws away what the take added. Voice never sends by itself-/// (Tony, 11-01): sending is a tap on Send. No pause ends a take (10-29:+/// [cancel] throws away what the take added, and [send] ends it and posts+/// the box. Voice never sends by itself (Tony, 11-01): sending is a tap on+/// Send, the composer's or the row's. No pause ends a take (10-29:/// "until I tap") — save [idle] without a new word, which stops listening/// with the words left in the box. A long press on the mic picks the language/// ([voiceLanguageStore]).@@ -51,6 +56,7 @@ class SwarmVoice extends ChangeNotifier {this.dictation,required this.draft,required this.write,+ required this.post,});/// How long the recognizer listens without hearing a new word before it@@ -65,6 +71,9 @@ class SwarmVoice extends ChangeNotifier {static const stoppedListening = 'Stopped listening';static const stoppedLinger = Duration(seconds: 3);+ /// What the chat says as a [send] ends with nothing to post (Tony, 11-01).+ static const nothingSent = "Couldn't hear anything, nothing sent";+/// How long the recognizer has to say it has stopped, after [stop] asked it/// to, before its take is given up with what the box holds left there.static const _endWait = Duration(seconds: 2);@@ -79,6 +88,10 @@ class SwarmVoice extends ChangeNotifier {final String Function() draft;final void Function(String text) write;+ /// Posts the draft through the composer's own Send, once [send]'s take+ /// has ended into it.+ final VoidCallback post;+/// The recognizer's take: asking for it, listening, or waiting for it to/// say it has stopped — as only [stop] asks._Live _live = _Live.off;@@ -104,6 +117,11 @@ class SwarmVoice extends ChangeNotifier {final ValueNotifier<double> _liveLevel = ValueNotifier(0);String? _liveNotice;+ /// The row's Send under way ([send]): the take ends, then the draft is+ /// posted once. Replaced by everything that ends a take otherwise, so a+ /// take cancelled or gone meanwhile posts nothing.+ Object? _sending;+VoiceInputController? _voice;bool _disposed = false;@@ -150,6 +168,24 @@ class SwarmVoice extends ChangeNotifier {},};+ /// The row's Send is under way: the take is ending, then the draft posts.+ /// The row takes no tap meanwhile.+ bool get sending => _sending != null;++ /// The row's Send can be tapped: listening, and with the phone's+ /// recognizer only once the box has words — the words a recording heard+ /// reach it only as it ends.+ bool get canSend {+ if (_disposed || _sending != null) return false;+ if (_live != _Live.off) {+ return _live == _Live.listening && draft().trim().isNotEmpty;+ }+ final voice = _voice;+ return voice != null &&+ !voice.isSending &&+ voice.status == VoiceInputStatus.listening;+ }+/// The microphone was refused: the mic is off.bool get off =>_live == _Live.off && _voice?.status == VoiceInputStatus.unavailable;@@ -218,11 +254,44 @@ class SwarmVoice extends ChangeNotifier {}}+ /// Ends the take and posts the draft with its words, once ([post]): the+ /// recognizer's last words, waited for no longer than it is at [stop]; or+ /// the recording, once transcribed. A take that ends with nothing to post+ /// posts nothing and says [nothingSent]; what was typed stays.+ void send() {+ if (!canSend) return;+ final sending = _sending = Object();+ if (_live == _Live.listening) {+ _endLive();+ return;+ }+ notifyListeners();+ unawaited(_sendRecorded(_voice!, sending));+ }++ /// [send] on a recording: what was typed, then the words transcribed.+ Future<void> _sendRecorded(VoiceInputController voice, Object sending) async {+ var posted = false;+ await voice.submit((words) async {+ // Gone meanwhile: its words land nowhere.+ if (_sending != sending) return true;+ write(_joined(draft(), words));+ posted = true;+ post();+ return true;+ });+ if (_disposed || _sending != sending) return;+ _sending = null;+ if (!posted) _setLiveNotice(nothingSent);+ notifyListeners();+ }+/// Throws the take away: what it added leaves the box, the person's edits/// stay. A recorded take is dropped with its words, even while they are/// being transcribed ([VoiceInputController.clear]).void cancel() {if (_disposed) return;+ _sending = null;if (_live != _Live.off) {if (_live != _Live.asking && draft() == _liveShown) write(_liveFrom);_offLive();@@ -240,6 +309,7 @@ class SwarmVoice extends ChangeNotifier {/// ⚠️ `clear`, never `stopListening` or a [_finish]: those transcribe the/// take, and a take nobody can see must not leave the phone.void hide() {+ _sending = null;_offLive();_release(false);final voice = _voice;@@ -372,17 +442,22 @@ class SwarmVoice extends ChangeNotifier {unawaited(dictation.stop());}- /// The recognizer has stopped, as [stop] asked or because it cannot go on:- /// its words stay in the box and nothing is sent. No notice after a stop- /// with words in the box, however the recognizer's last session ended.+ /// The recognizer has stopped, as [stop] or [send] asked or because it+ /// cannot go on: its words stay in the box, and only [send]'s are posted.+ /// No notice after a stop with words in the box, however the recognizer's+ /// last session ended.void _liveEnded(int take, SwarmDictationEnd end) {if (take != _liveTake || _live == _Live.off) return;final stopped = _live == _Live.ending && draft().trim().isNotEmpty;+ final send = _sending != null && _live == _Live.ending;+ _sending = null;_liveTake++;_live = _Live.off;_stopLiveTimers();_liveLevel.value = 0;+ if (send && stopped) post();_setLiveNotice(switch (end) {+ _ when send && !stopped => nothingSent,_ when stopped => null,SwarmDictationEnd.failed => VoiceNotice.notTranscribed,_ when _liveHeard.isEmpty => VoiceNotice.nothingHeard,@@ -395,6 +470,7 @@ class SwarmVoice extends ChangeNotifier {/// shown stay in the draft, and nothing is sent.void _offLive() {if (_live == _Live.off) return;+ _sending = null;final listened = _live != _Live.asking;_liveTake++;_live = _Live.off;@@ -574,37 +650,47 @@ class SwarmVoiceMic extends StatelessWidget {}/// The card's toolbar while a take is under way (Tony, 11-01): cancel, the-/// wave, stop — no +, Tag, mic or Send, so nothing is sent from here.+/// wave, stop and Send — no +, Tag or mic.///-/// - Opening ([VoiceMicFace.starting]): cancel and a flat wave.-/// - Listening: cancel, the wave following [SwarmVoice.level], and stop.-/// - Busy (the recognizer stopping, or the recording being transcribed):-/// cancel and the terminal's busy face where stop was.+/// - Opening ([VoiceMicFace.starting]): cancel, a flat wave and Send off.+/// - Listening: cancel, the wave following [SwarmVoice.level], stop, and+/// Send ([SwarmVoice.send]) — with the phone's recognizer only once the box+/// has words; a recording's reach it only as it ends.+/// - Busy after stop (the recognizer stopping, or the recording being+/// transcribed): cancel, the terminal's busy face where stop was, Send off.+/// - Sending ([SwarmVoice.sending]): Send's spinner, and nothing else takes+/// a tap until the post has gone.///-/// Cancel and Stop are one word each: VoiceOver reads a label aloud, and a-/// sentence read into an open microphone lands in the take.+/// Every label is one word: VoiceOver reads a label aloud, and a sentence+/// read into an open microphone lands in the take.class SwarmVoiceRow extends StatelessWidget {- const SwarmVoiceRow({super.key, required this.voice});+ const SwarmVoiceRow({super.key, required this.voice, this.canPost = true});final SwarmVoice voice;+ /// The composer could post now, words aside: New message has a chat+ /// picked and no post on its way.+ final bool canPost;+@overrideWidget build(BuildContext context) {final tty = Tty.of(context);final face = voice.face;final fill = tty.text.withValues(alpha: 0.08);+ final sending = voice.sending;+ final canSend = canPost && voice.canSend;return Row(children: [_VoiceButton(key: const ValueKey('swarm-voice-cancel'),label: 'Cancel',- onTap: voice.cancel,+ onTap: sending ? null : voice.cancel,child: _VoiceRound(fill: fill,child: Icon(LucideIcons.x,size: 20,- color: AppPalette.textSecondary,+ color: sending ? AppPalette.textFaint : AppPalette.textSecondary,),),),@@ -618,6 +704,7 @@ class SwarmVoiceRow extends StatelessWidget {),const SizedBox(width: AppSpace.xs),switch (face) {+ _ when sending => const SizedBox(width: 44),VoiceMicFace.listening => _VoiceButton(key: const ValueKey('swarm-voice-stop'),label: 'Stop',@@ -652,6 +739,32 @@ class SwarmVoiceRow extends StatelessWidget {),),},+ SwarmRoundButton(+ key: const ValueKey('swarm-voice-send'),+ label: 'Send',+ face: 36,+ fill: canSend || sending ? AppPalette.accent : ttyRaised(tty),+ onTap: canSend+ ? () {+ HapticFeedback.lightImpact();+ voice.send();+ }+ : null,+ child: sending+ ? SizedBox.square(+ dimension: AppIconSize.besideText,+ child: CircularProgressIndicator(+ key: const ValueKey('swarm-voice-sending'),+ strokeWidth: 2,+ color: AppInk.onFill,+ ),+ )+ : Icon(+ LucideIcons.arrowUp,+ size: 20,+ color: canSend ? AppInk.onFill : AppPalette.textFaint,+ ),+ ),],);}@@ -679,7 +792,7 @@ class _VoiceRound extends StatelessWidget {);}-/// One of [SwarmVoiceRow]'s buttons, with a light tap felt.+/// One of [SwarmVoiceRow]'s round buttons, with a light tap felt.class _VoiceButton extends StatelessWidget {const _VoiceButton({super.key,@@ -689,25 +802,28 @@ class _VoiceButton extends StatelessWidget {});final String label;- final VoidCallback onTap;++ /// Null while the row's Send is under way: no tap.+ final VoidCallback? onTap;final Widget child;@overrideWidget build(BuildContext context) {+ final onTap = this.onTap;void tap() {HapticFeedback.lightImpact();- onTap();+ onTap?.call();}return Semantics(button: true,- enabled: true,+ enabled: onTap != null,label: label,- onTap: tap,+ onTap: onTap == null ? null : tap,excludeSemantics: true,child: GestureDetector(behavior: HitTestBehavior.opaque,- onTap: tap,+ onTap: onTap == null ? null : tap,child: child,),);diff --git a/mobile/test/render/swarm_composer_render_test.dart b/mobile/test/render/swarm_composer_render_test.dartindex 87a138fac..bdb4e35a5 100644--- a/mobile/test/render/swarm_composer_render_test.dart+++ b/mobile/test/render/swarm_composer_render_test.dart@@ -20,11 +20,13 @@ import 'package:harness_mobile/swarm/swarm_session.dart';import 'package:image_picker/image_picker.dart' show XFile;import '../voice_fakes.dart';+import '../swarm/swarm_chat_dictation_test.dart' show FakeDictation;import '../swarm/swarm_fixture.dart';/// Renders a phone Swarm chat's composer in the states Tony's composer brief/// (11-01) names — empty, text, five lines, the @ picker open, a reply, files-/// and listening — in light and dark, on a 393 x 852 iPhone with the keyboard+/// and listening, the voice row's Send live, off and sending — in light and+/// dark, on a 393 x 852 iPhone with the keyboard/// up (336 tall), in the system fonts, to PNGs a reviewer can compare.////// Only keys the composer has had since before the card are used, so the same@@ -163,6 +165,8 @@ void main() {Future<GlobalKey> chat(WidgetTester tester, {_MeteredRecorder? recorder,+ FakeTranscriber? stt,+ FakeDictation? dictation,}) async {await tester.runAsync(_loadFonts);final photos = (await tester.runAsync(@@ -210,10 +214,11 @@ void main() {notices: SilentSystemNotices(),features: features,voice: () => VoiceInputController(- transcriber: FakeTranscriber().call,+ transcriber: (stt ?? FakeTranscriber()).call,recorder: recorder ?? _MeteredRecorder(),language: ValueNotifier('en'),),+ dictation: dictation,)..foreground = false;addTearDown(host.dispose);final key = GlobalKey();@@ -319,6 +324,48 @@ void main() {}await shoot(tester, key, 'composer-listening-$look');});++ // Tony, 11-01: the voice row's Send, right of stop: off on an empty box+ // with the phone's recognizer, live once it has words.+ for (final words in ['', 'Check whether PR #2466 has merged']) {+ final name = words.isEmpty ? 'off' : 'live';+ testWidgets('voice row Send $name, dictation ($look)', skip: skip, (+ tester,+ ) async {+ final dictation = FakeDictation();+ final key = await chat(tester, dictation: dictation);+ await tester.showKeyboard(find.byType(TextField));+ await tester.tap(find.byKey(const ValueKey('swarm-mic')));+ for (var i = 0; i < 5; i++) {+ await tester.pump();+ }+ if (words.isNotEmpty) dictation.say(words);+ for (var i = 0; i < 24; i++) {+ dictation.loud(const [0.3, 0.7, 0.5, 0.9][i % 4]);+ await tester.pump(const Duration(milliseconds: 120));+ }+ await shoot(tester, key, 'composer-voice-send-$name-$look');+ });+ }++ testWidgets('voice row Send while sending ($look)', skip: skip, (+ tester,+ ) async {+ final recorder = _MeteredRecorder();+ final stt = FakeTranscriber()..pending = Completer<String>();+ final key = await chat(tester, recorder: recorder, stt: stt);+ await type(tester, 'Check whether PR #2466');+ await tester.tap(find.byKey(const ValueKey('swarm-mic')));+ for (var i = 0; i < 24; i++) {+ recorder.meter.value = const [0.3, 0.7, 0.5, 0.9][i % 4];+ await tester.pump(const Duration(milliseconds: 120));+ }+ await tester.tap(find.byKey(const ValueKey('swarm-voice-send')));+ for (var i = 0; i < 5; i++) {+ await tester.pump(const Duration(milliseconds: 120));+ }+ await shoot(tester, key, 'composer-voice-sending-$look');+ });}}diff --git a/mobile/test/swarm/swarm_chat_dictation_test.dart b/mobile/test/swarm/swarm_chat_dictation_test.dartindex 95e8bd2a6..14e8dbe6a 100644--- a/mobile/test/swarm/swarm_chat_dictation_test.dart+++ b/mobile/test/swarm/swarm_chat_dictation_test.dart@@ -38,6 +38,9 @@ void main() {late List<String> uploads;late String language;+ /// Who is signed in, in the last [pump].+ late ValueNotifier<String?> account;+setUp(() {dictation = FakeDictation();recorder = FakeVoiceRecorder();@@ -77,7 +80,7 @@ void main() {Future<void> pump(WidgetTester tester, {bool reduceMotion = false}) async {final features = ExperimentalFeaturesStore(storage: MemoryKeyValueStore())..value = {PhoneExperiment.swarm};- final account = ValueNotifier<String?>(me);+ account = ValueNotifier<String?>(me);final host = SwarmHost(accountId: () => account.value,account: account,@@ -306,8 +309,8 @@ void main() {atRest();});- testWidgets('no Send, +, Tag or X during a take; they come back after '- 'Stop', (tester) async {+ testWidgets("only the row's Send during a take: no composer Send, +, Tag "+ 'or X; they come back after Stop', (tester) async {await pump(tester);await tester.enterText(find.byType(TextField), 'Draft');await tester.pump();@@ -322,11 +325,13 @@ void main() {expect(key('swarm-voice-cancel'), findsOneWidget);expect(key('swarm-voice-wave'), findsOneWidget);expect(key('swarm-voice-stop'), findsOneWidget);+ expect(key('swarm-voice-send'), findsOneWidget);await say(tester, 'ship it');await stop(tester);await tester.pumpAndSettle();atRest();+ expect(key('swarm-voice-send'), findsNothing);expect(key('swarm-attach'), findsOneWidget);expect(key('swarm-tag'), findsOneWidget);expect(key('swarm-field-clear'), findsOneWidget);@@ -337,6 +342,168 @@ void main() {);});+ // Tony, 11-01: Send right of stop ends the take and posts the box, the last+ // words included. With the recognizer the words are in the box as they are+ // said: Send is off while it is empty.+ group("the voice row's Send", () {+ Future<void> rowSend(WidgetTester tester) async {+ await tester.tap(key('swarm-voice-send'));+ await frames(tester);+ }++ SwarmRoundButton sendButton(WidgetTester tester) =>+ tester.widget<SwarmRoundButton>(key('swarm-voice-send'));++ testWidgets('off while the box is empty, on once it has words', (+ tester,+ ) async {+ await pump(tester);+ await tapMic(tester);+ expect(sendButton(tester).onTap, isNull, reason: 'empty box');+ await rowSend(tester);+ expect(dictation.stops, 0, reason: 'an off Send ends nothing');+ expect(dictation.listening, isTrue);++ await say(tester, 'ship');+ expect(sendButton(tester).onTap, isNotNull);++ await tester.enterText(find.byType(TextField), ' ');+ await tester.pump();+ expect(sendButton(tester).onTap, isNull, reason: 'only a space');+ expect(fake.commands, isEmpty);+ });++ testWidgets('one tap ends the take and posts the box with its last '+ 'words, once', (tester) async {+ await pump(tester);+ await tester.enterText(find.byType(TextField), 'Nova:');+ await tester.pump();+ await tapMic(tester);+ await say(tester, 'ship the');++ dictation.lastWords = 'ship the fix today';+ await rowSend(tester);+ await tester.pumpAndSettle();++ expect(dictation.stops, 1);+ expect(fake.commands.single['text'], 'Nova: ship the fix today');+ expect(box(tester), isEmpty);+ expect(key('swarm-voice-note'), findsNothing);+ atRest();+ });++ testWidgets('waits for the last words no longer than about two seconds, '+ 'then posts what the box holds', (tester) async {+ await pump(tester);+ await tapMic(tester);+ await say(tester, 'ship it');++ dictation.stopsSilently = true;+ await rowSend(tester);+ expect(key('swarm-voice-sending'), findsOneWidget);+ await tester.pump(const Duration(milliseconds: 1900));+ expect(fake.commands, isEmpty, reason: 'still waiting for its words');++ await tester.pump(const Duration(milliseconds: 200));+ await tester.pumpAndSettle();+ expect(fake.commands.single['text'], 'ship it');+ expect(dictation.cancels, 1, reason: 'the microphone released');+ atRest();+ });++ testWidgets('a double tap posts once', (tester) async {+ await pump(tester);+ await tapMic(tester);+ await say(tester, 'just once');++ dictation.stopsSilently = true;+ final at = tester.getCenter(key('swarm-voice-send'));+ for (var i = 0; i < 2; i++) {+ await tester.tapAt(at);+ await tester.pump(const Duration(milliseconds: 40));+ }+ expect(dictation.stops, 1);+ dictation.end(SwarmDictationEnd.done);+ await tester.pump();+ await tester.tapAt(at);+ await tester.pumpAndSettle();++ expect(fake.commands, hasLength(1));+ expect(fake.commands.single['text'], 'just once');+ });++ testWidgets('while it ends the row takes no tap: cancel does not take '+ 'the words back', (tester) async {+ await pump(tester);+ await tapMic(tester);+ await say(tester, 'keep these');++ dictation.stopsSilently = true;+ await rowSend(tester);+ expect(sendButton(tester).onTap, isNull);+ await cancel(tester);+ expect(box(tester), 'keep these');++ dictation.end(SwarmDictationEnd.done);+ await tester.pumpAndSettle();+ expect(fake.commands.single['text'], 'keep these');+ });++ testWidgets('a box emptied before the take ended posts nothing and says '+ 'one line', (tester) async {+ await pump(tester);+ await tapMic(tester);+ await say(tester, 'oops');++ dictation.stopsSilently = true;+ await rowSend(tester);+ await tester.enterText(find.byType(TextField), '');+ await tester.pump();+ dictation.end(SwarmDictationEnd.done);+ await tester.pumpAndSettle();++ expect(fake.commands, isEmpty);+ expect(find.text(SwarmVoice.nothingSent), findsOneWidget);+ });++ testWidgets('the app leaving while the take ends posts nothing; the words '+ 'stay in the box', (tester) async {+ await pump(tester);+ await tapMic(tester);+ await say(tester, 'not yet');++ dictation.stopsSilently = true;+ await rowSend(tester);+ await lifecycle(tester, [AppLifecycleState.inactive]);+ await lifecycle(tester, [AppLifecycleState.resumed]);+ dictation.end(SwarmDictationEnd.done);+ await tester.pump(const Duration(seconds: 3));+ await tester.pumpAndSettle();++ expect(fake.commands, isEmpty);+ expect(box(tester), 'not yet');+ expect(find.text(SwarmVoice.nothingSent), findsNothing);+ });++ testWidgets('signed out while the take ends: nothing is posted', (+ tester,+ ) async {+ await pump(tester);+ await tapMic(tester);+ await say(tester, 'after sign out');++ dictation.stopsSilently = true;+ await rowSend(tester);+ account.value = null;+ await frames(tester);+ dictation.end(SwarmDictationEnd.done);+ await tester.pump(const Duration(seconds: 3));+ await tester.pumpAndSettle();++ expect(fake.commands, isEmpty);+ });+ });+testWidgets('the @ picker hides during a take and comes back after Cancel', (tester,) async {diff --git a/mobile/test/swarm/swarm_chat_voice_test.dart b/mobile/test/swarm/swarm_chat_voice_test.dartindex 83bb9b231..788abf5a4 100644--- a/mobile/test/swarm/swarm_chat_voice_test.dart+++ b/mobile/test/swarm/swarm_chat_voice_test.dart@@ -20,10 +20,10 @@ import 'swarm_fixture.dart';/// Talking instead of typing in a Swarm chat (Tony, 10-28), where the phone/// has no speech recognizer of its own to use: the terminal's mic in the/// composer records, and what the backend hears lands in the message box as-/// the take ends. While a take runs the toolbar is cancel, wave and stop:-/// stop leaves the words in the box and sends nothing — sending is a tap on-/// Send (Tony, 11-01) — and nothing but stop, cancel or its 5-minute limit-/// ends a take (Tony, 10-29). A long press on the mic picks the language.+/// the take ends. While a take runs the toolbar is cancel, wave, stop and+/// Send: stop leaves the words in the box and sends nothing — sending is a+/// tap on Send, the row's or the composer's (Tony, 11-01) — and nothing but+/// stop, Send, cancel or its 5-minute limit ends a take (Tony, 10-29). A long press on the mic picks the language./// With the phone's recognizer: `swarm_chat_dictation_test`.void main() {const messages = '/api/super-tabs/$tab/conversations/g1/messages';@@ -739,8 +739,10 @@ void main() {expect(fake.commands, isEmpty);});- testWidgets('during a take the toolbar is cancel, wave and stop: no Send, '- '+, Tag, mic, X or @ picker; all come back after stop', (tester) async {+ testWidgets('during a take the toolbar is cancel, wave, stop and the '+ "row's Send: no +, Tag, mic, X or @ picker; all come back after stop", (+ tester,+ ) async {await pump(tester);await tester.enterText(find.byType(TextField), '@');await tester.pump();@@ -763,13 +765,20 @@ void main() {'swarm-voice-cancel','swarm-voice-wave','swarm-voice-stop',+ 'swarm-voice-send',]) {expect(key(shown), findsOneWidget, reason: '$shown during a take');}+ // Right of stop, as the composer's Send is right of the mic.+ expect(+ tester.getCenter(key('swarm-voice-send')).dx,+ greaterThan(tester.getCenter(key('swarm-voice-stop')).dx),+ );await stop(tester);await tester.pumpAndSettle();expect(box(tester), '@ Nova');+ expect(key('swarm-voice-send'), findsNothing);for (final back in ['swarm-send','swarm-attach',@@ -820,6 +829,11 @@ void main() {expect(key('swarm-voice-busy'), findsOneWidget);expect(key('swarm-voice-stop'), findsNothing);expect(key('swarm-send'), findsNothing);+ expect(+ tester.widget<SwarmRoundButton>(key('swarm-voice-send')).onTap,+ isNull,+ reason: 'after stop the words go to the box, not out',+ );await cancel(tester);stt.pending!.complete('late words');@@ -839,6 +853,209 @@ void main() {expect(key('swarm-send'), findsOneWidget);});+ // Tony, 11-01: Send right of stop ends the take and posts it, last words+ // and all. A recording's words reach the box only once transcribed, so the+ // row's Send is live from the first moment of the take.+ group("the voice row's Send", () {+ Future<void> rowSend(WidgetTester tester) async {+ await tester.tap(key('swarm-voice-send'));+ await frames(tester);+ }++ SwarmRoundButton sendButton(WidgetTester tester) =>+ tester.widget<SwarmRoundButton>(key('swarm-voice-send'));++ testWidgets('live while recording with an empty box; one tap stops, '+ 'transcribes and posts the words once', (tester) async {+ await pump(tester);+ stt.pending = Completer<String>();++ await tapMic(tester);+ expect(box(tester), isEmpty);+ expect(sendButton(tester).onTap, isNotNull, reason: 'empty box, live');++ await rowSend(tester);+ expect(recorder.recording, isFalse, reason: 'the take ended');+ expect(stt.calls, hasLength(1));+ expect(key('swarm-voice-sending'), findsOneWidget);+ expect(fake.commands, isEmpty, reason: 'not before the words are back');++ stt.pending!.complete('ship the fix today');+ await tester.pumpAndSettle();+ expect(fake.commands.single['text'], 'ship the fix today');+ expect(box(tester), isEmpty);+ expect(key('swarm-voice-wave'), findsNothing);+ expect(key('swarm-mic'), findsOneWidget);+ expect(key('swarm-voice-note'), findsNothing);+ });++ testWidgets('posts what was typed, then what was said', (tester) async {+ await pump(tester);+ await tester.enterText(find.byType(TextField), 'Nova:');+ await tester.pump();+ stt.replies.add('ship the fix');++ await tapMic(tester);+ await rowSend(tester);+ await tester.pumpAndSettle();++ expect(fake.commands.single['text'], 'Nova: ship the fix');+ expect(box(tester), isEmpty);+ });++ testWidgets('while it sends the row takes no tap: a second Send, stop or '+ 'cancel changes nothing, and the post goes once', (tester) async {+ await pump(tester);+ stt.pending = Completer<String>();++ await tapMic(tester);+ await rowSend(tester);+ expect(sendButton(tester).onTap, isNull);+ expect(key('swarm-voice-stop'), findsNothing);+ await rowSend(tester);+ await cancel(tester);+ expect(stt.calls, hasLength(1));+ expect(+ key('swarm-voice-sending'),+ findsOneWidget,+ reason: 'not called off',+ );++ stt.pending!.complete('once');+ await tester.pumpAndSettle();+ expect(fake.commands, hasLength(1));+ expect(fake.commands.single['text'], 'once');+ });++ testWidgets('a double tap posts once', (tester) async {+ await pump(tester);+ stt.pending = Completer<String>();++ await tapMic(tester);+ // Where Send is, whatever is there by then: the row's Send, or the+ // composer's once the row has gone.+ final at = tester.getCenter(key('swarm-voice-send'));+ for (var i = 0; i < 2; i++) {+ await tester.tapAt(at);+ await tester.pump(const Duration(milliseconds: 40));+ }+ stt.pending!.complete('just once');+ await tester.pump();+ await tester.tapAt(at);+ await tester.pumpAndSettle();++ expect(fake.commands, hasLength(1));+ expect(fake.commands.single['text'], 'just once');+ });++ testWidgets('nothing heard posts nothing, keeps what was typed, and says '+ 'one line', (tester) async {+ await pump(tester);+ await tester.enterText(find.byType(TextField), 'Draft');+ await tester.pump();+ stt.replies.add('');++ await tapMic(tester);+ await rowSend(tester);+ await tester.pumpAndSettle();++ expect(fake.commands, isEmpty);+ expect(box(tester), 'Draft');+ expect(key('swarm-voice-note'), findsOneWidget);+ expect(find.text(SwarmVoice.nothingSent), findsOneWidget);+ expect(find.text("Didn't catch that · tap the mic again"), findsNothing);+ expect(key('swarm-mic'), findsOneWidget);+ });++ testWidgets('a transcription that fails posts nothing and says the same '+ 'line', (tester) async {+ await pump(tester);+ await tester.enterText(find.byType(TextField), 'Draft');+ await tester.pump();+ stt.fails = true;++ await tapMic(tester);+ await rowSend(tester);+ await tester.pumpAndSettle();++ expect(fake.commands, isEmpty);+ expect(box(tester), 'Draft');+ expect(find.text(SwarmVoice.nothingSent), findsOneWidget);+ });++ testWidgets('a silent take posts nothing and says the same line', (+ tester,+ ) async {+ await pump(tester);+ recorder.captured = (+ wav: Uint8List.fromList([0, 0]),+ length: const Duration(seconds: 2),+ peak: 0,+ );++ await tapMic(tester);+ await rowSend(tester);+ await tester.pumpAndSettle();++ expect(stt.calls, isEmpty, reason: 'silence is not uploaded');+ expect(fake.commands, isEmpty);+ expect(find.text(SwarmVoice.nothingSent), findsOneWidget);+ });++ testWidgets('off while the microphone opens', (tester) async {+ await pump(tester);+ recorder.pendingPermission = Completer<bool>();++ await tapMic(tester);+ expect(sendButton(tester).onTap, isNull);+ recorder.pendingPermission!.complete(true);+ await frames(tester);+ expect(sendButton(tester).onTap, isNotNull);+ });++ testWidgets('a chat covered while its Send transcribes posts nothing, and '+ 'says nothing', (tester) async {+ await pump(tester);+ stt.pending = Completer<String>();+ await tapMic(tester);+ await rowSend(tester);++ final navigator = tester.state<NavigatorState>(find.byType(Navigator));+ unawaited(+ navigator.push(+ MaterialPageRoute<void>(builder: (_) => const SizedBox()),+ ),+ );+ await tester.pumpAndSettle();+ stt.pending!.complete('behind your back');+ await tester.pumpAndSettle();+ navigator.pop();+ await tester.pumpAndSettle();++ expect(fake.commands, isEmpty);+ expect(box(tester), isEmpty);+ expect(find.text(SwarmVoice.nothingSent), findsNothing);+ expect(key('swarm-mic'), findsOneWidget);+ });++ testWidgets('signed out while its Send transcribes: nothing is posted', (+ tester,+ ) async {+ await pump(tester);+ stt.pending = Completer<String>();+ await tapMic(tester);+ await rowSend(tester);++ account.value = null;+ await frames(tester);+ stt.pending!.complete('after sign out');+ await tester.pumpAndSettle();++ expect(fake.commands, isEmpty);+ expect(find.text('after sign out'), findsNothing);+ });+ });+// The composer goes with the right to post, and its mic with it: a take// must not go on recording, or land its words, once the person can no// longer post here (as a thread's reply box already guards).diff --git a/mobile/test/swarm/swarm_new_message_test.dart b/mobile/test/swarm/swarm_new_message_test.dartindex e330a36ae..56bac6408 100644--- a/mobile/test/swarm/swarm_new_message_test.dart+++ b/mobile/test/swarm/swarm_new_message_test.dart@@ -21,6 +21,7 @@ import 'package:harness_mobile/swarm/swarm_page.dart';import 'package:harness_mobile/swarm/swarm_project_page.dart';import 'package:harness_mobile/swarm/swarm_request.dart';import 'package:harness_mobile/swarm/swarm_session.dart';+import 'package:harness_mobile/swarm/swarm_voice.dart';import '../voice_fakes.dart';import 'swarm_fixture.dart';@@ -894,21 +895,29 @@ void main() {expect(sends(fake).single['command']['text'], 'Ship it tonight');});- /// The sheet open on the Lead's chat, its mic heard by [dictation].- Future<FakeSwarm> talking(WidgetTester tester, _Dictation dictation) async {+ /// The sheet open on the Lead's chat — or on none, unless [pick] — its+ /// mic heard by [dictation], or recorded and transcribed by [stt].+ Future<FakeSwarm> talking(+ WidgetTester tester,+ _Dictation? dictation, {+ FakeTranscriber? stt,+ bool pick = true,+ void Function(SwarmHost host)? host,+ }) async {final fake = backend();- await pump(+ final pumped = await pump(tester,fake,voice: () => VoiceInputController(- transcriber: FakeTranscriber().call,+ transcriber: (stt ?? FakeTranscriber()).call,recorder: FakeVoiceRecorder(),language: ValueNotifier('vi'),),dictation: dictation,);+ host?.call(pumped);await open(tester);- await tester.tap(row(leadChat));+ if (pick) await tester.tap(row(leadChat));await tester.pump();return fake;}@@ -952,6 +961,101 @@ void main() {expect(sheetOpen(), isFalse);});+ // Tony, 11-01: Send right of stop ends the take and posts it.+ testWidgets("the row's Send ends the take and posts its last words to the "+ 'chat picked, once, and the sheet closes', (tester) async {+ final dictation = _Dictation();+ final fake = await talking(tester, dictation);++ await tapIn(tester, 'swarm-mic');+ expect(+ tester.widget<SwarmRoundButton>(inSheet('swarm-voice-send')).onTap,+ isNull,+ reason: 'an empty box',+ );+ dictation.say('Mai họp');+ await tester.pump();+ dictation.lastWords = 'Mai họp lúc 9 giờ';+ final at = tester.getCenter(inSheet('swarm-voice-send'));+ await tester.tapAt(at);+ await tester.pump();+ await tester.tapAt(at);+ await tester.pumpAndSettle();++ expect(sends(fake), hasLength(1));+ expect(sends(fake).single['command']['text'], 'Mai họp lúc 9 giờ');+ expect(sends(fake).single['command']['conversationId'], leadChat);+ expect(sheetOpen(), isFalse);+ });++ testWidgets("with no chat picked the row's Send is off", (tester) async {+ final dictation = _Dictation();+ final fake = await talking(tester, dictation, pick: false);++ await tapIn(tester, 'swarm-mic');+ dictation.say('cho ai đây');+ await tester.pump();+ expect(field(tester), 'cho ai đây');+ expect(+ tester.widget<SwarmRoundButton>(inSheet('swarm-voice-send')).onTap,+ isNull,+ );+ await tapIn(tester, 'swarm-voice-send');+ expect(sends(fake), isEmpty);+ expect(inSheet('swarm-voice-stop'), findsOneWidget, reason: 'listening');+ });++ testWidgets("a recording: the row's Send posts what was typed and what "+ 'was said; nothing heard posts nothing and keeps the sheet', (+ tester,+ ) async {+ final stt = FakeTranscriber()..replies.addAll(['', 'lúc 9 giờ']);+ final fake = await talking(tester, null, stt: stt);+ await write(tester, 'Mai họp');++ await tapIn(tester, 'swarm-mic');+ expect(+ tester.widget<SwarmRoundButton>(inSheet('swarm-voice-send')).onTap,+ isNotNull,+ reason: 'live while recording',+ );+ await tapIn(tester, 'swarm-voice-send');+ await tester.pumpAndSettle();+ expect(sends(fake), isEmpty);+ expect(field(tester), 'Mai họp');+ expect(sheetOpen(), isTrue);+ expect(find.text(SwarmVoice.nothingSent), findsOneWidget);++ await tapIn(tester, 'swarm-mic');+ await tapIn(tester, 'swarm-voice-send');+ await tester.pumpAndSettle();+ expect(sends(fake).single['command']['text'], 'Mai họp lúc 9 giờ');+ expect(sheetOpen(), isFalse);+ });++ testWidgets("the Swarm's read taken away while the row's Send transcribes "+ 'closes the sheet and posts nothing', (tester) async {+ final stt = FakeTranscriber()..pending = Completer<String>();+ late SwarmHost host;+ final fake = await talking(tester, null, stt: stt, host: (h) => host = h);+ await tapIn(tester, 'swarm-mic');+ await tapIn(tester, 'swarm-voice-send');+ expect(inSheet('swarm-voice-sending'), findsOneWidget);++ for (final route in ['parts', 'changes']) {+ fake.routes['/api/super-tabs/$tab/$route'] = (_) =>+ throw SuperTabFailure('FORBIDDEN', 'No access.', statusCode: 403);+ }+ unawaited(host.session!.inbox.reader(tab)!.refresh());+ await tester.pumpAndSettle();+ expect(sheetOpen(), isFalse);+ stt.pending!.complete('bí mật');+ await tester.pumpAndSettle();++ expect(sends(fake), isEmpty);+ expect(find.text('bí mật'), findsNothing);+ });+testWidgets('cancel takes back what the take added and keeps what was ''typed before it', (tester) async {final dictation = _Dictation();@@ -1354,6 +1458,9 @@ class _Dictation implements SwarmDictation {void Function(String)? _words;void Function(SwarmDictationEnd)? _end;+ /// What [stop] hears last, before it ends.+ String? lastWords;+void say(String words) => _words?.call(words);@override@@ -1373,6 +1480,7 @@ class _Dictation implements SwarmDictation {@overrideFuture<void> stop() async {+ if (lastWords case final words?) say(words);final end = _end;_words = _end = null;end?.call(SwarmDictationEnd.done);diff --git a/mobile/test/swarm/swarm_thread_voice_test.dart b/mobile/test/swarm/swarm_thread_voice_test.dartindex b88af50d2..2e5752235 100644--- a/mobile/test/swarm/swarm_thread_voice_test.dart+++ b/mobile/test/swarm/swarm_thread_voice_test.dart@@ -9,6 +9,7 @@ import 'package:harness_mobile/shared/theme/app_theme.dart' as grid;import 'package:harness_mobile/swarm/swarm_conversation_page.dart';import 'package:harness_mobile/swarm/swarm_session.dart';import 'package:harness_mobile/swarm/swarm_thread_page.dart';+import 'package:harness_mobile/swarm/swarm_voice.dart';import '../voice_fakes.dart';import 'swarm_chat_dictation_test.dart' show FakeDictation;@@ -16,9 +17,10 @@ import 'swarm_fixture.dart';/// Talking instead of typing in a thread (Dee, 11-01: "how do I voice in a/// thread?"): the main chat's mic, in the thread's reply box beside Send. Tap-/// to talk; while talking the toolbar is cancel, the wave and stop. Voice never-/// sends by itself (Tony, 11-01): stop leaves the words in the box, and Send-/// posts them as a reply — to the chat too with Also send. A take goes,+/// to talk; while talking the toolbar is cancel, the wave, stop and Send.+/// Voice never sends by itself (Tony, 11-01): stop leaves the words in the+/// box, and Send — the row's, or the box's after stop — posts them as a reply,+/// to the chat too with Also send. A take goes,/// nothing of it written or sent, once the person can no longer reply there./// The mic itself: `swarm_chat_voice_test` and `swarm_chat_dictation_test`.void main() {@@ -308,6 +310,66 @@ void main() {expect(fake.commands.single['alsoSend'], isTrue);});+ // Tony, 11-01: the row's Send, as in the main chat.+ testWidgets("the row's Send ends the take and posts it as one reply, to the "+ 'chat too with Also send ticked', (tester) async {+ await pump(tester);+ await tester.tap(key('swarm-thread-also-send'));+ await tester.pump();+ await tester.enterText(key('swarm-thread-field'), 'Nova:');+ await tester.pump();+ stt.pending = Completer<String>();++ await tapMic(tester);+ final at = tester.getCenter(inBox(key('swarm-voice-send')));+ await tester.tapAt(at);+ await tester.pump(const Duration(milliseconds: 40));+ await tester.tapAt(at);+ await frames(tester);+ expect(inBox(key('swarm-voice-sending')), findsOneWidget);+ stt.pending!.complete('ship it');+ await tester.pumpAndSettle();++ expect(fake.commands, hasLength(1));+ expect(fake.commands.single['text'], 'Nova: ship it');+ expect(fake.commands.single['replyTo'], 'm1');+ expect(fake.commands.single['alsoSend'], isTrue);+ expect(box(tester), isEmpty);+ });++ testWidgets("the row's Send with nothing heard posts nothing and keeps "+ 'what was typed', (tester) async {+ await pump(tester);+ await tester.enterText(key('swarm-thread-field'), 'Draft');+ await tester.pump();++ await tapMic(tester);+ await tester.tap(inBox(key('swarm-voice-send')));+ await tester.pumpAndSettle();++ expect(fake.commands, isEmpty);+ expect(box(tester), 'Draft');+ expect(find.text(SwarmVoice.nothingSent), findsOneWidget);+ });++ testWidgets("access lost while the row's Send transcribes: nothing posted, "+ 'nothing kept', (tester) async {+ final host = await pump(tester);+ stt.pending = Completer<String>();+ await tapMic(tester);+ await tester.tap(inBox(key('swarm-voice-send')));+ await frames(tester);++ await reread(tester, host, listed: false);+ stt.pending!.complete('too late');+ await tester.pumpAndSettle();++ expect(fake.commands, isEmpty);+ expect(find.text('too late'), findsNothing);+ expect(kept(tester), isEmpty);+ expect(find.text(SwarmVoice.nothingSent), findsNothing);+ });+// After #2471 a reply on its way no longer holds the box: a take stopped// meanwhile leaves its words for the next reply, which Send posts after the// first, and the first keeps its own text.@@ -355,8 +417,9 @@ void main() {expect(inBox(key('swarm-thread-voice-note')), findsOneWidget);});- testWidgets('during a take the toolbar is cancel, the wave and stop: no '- 'Send, Also send, + or X, which come back after stop', (tester) async {+ testWidgets("during a take the toolbar is cancel, the wave, stop and the "+ "row's Send: no box Send, Also send, + or X, which come back after "+ 'stop', (tester) async {await pump(tester);await tester.enterText(key('swarm-thread-field'), 'Nova:');await tester.pump();@@ -378,6 +441,7 @@ void main() {'swarm-voice-cancel','swarm-voice-wave','swarm-voice-stop',+ 'swarm-voice-send',]) {expect(inBox(key(shown)), findsOneWidget, reason: shown);}@@ -590,6 +654,28 @@ void main() {expect(box(tester), isEmpty);});+ testWidgets("the row's Send ends the take and posts its last words as a "+ 'reply', (tester) async {+ await pump(tester, dictation: dictation);++ await tapMic(tester);+ expect(+ tester.widget<SwarmRoundButton>(inBox(key('swarm-voice-send'))).onTap,+ isNull,+ reason: 'an empty box',+ );+ dictation.say('looks good');+ await frames(tester);+ dictation.lastWords = 'looks good to me';+ await tester.tap(inBox(key('swarm-voice-send')));+ await tester.pumpAndSettle();++ expect(dictation.stops, 1);+ expect(fake.commands.single['text'], 'looks good to me');+ expect(fake.commands.single['replyTo'], 'm1');+ expect(box(tester), isEmpty);+ });+testWidgets('cancel takes back what the take added and keeps what was ''typed before it', (tester) async {await pump(tester, dictation: dictation);