Skip to content

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.

Merge batch 11-05 i2240: #3191 (#3195)

0xken15448112033002
diff --git a/desktop/lib/super_tabs/controller.dart b/desktop/lib/super_tabs/controller.dart
index c60ab3663..16ccd3611 100644
--- a/desktop/lib/super_tabs/controller.dart
+++ b/desktop/lib/super_tabs/controller.dart
@@ -5526,6 +5526,20 @@ class SuperTabController extends ChangeNotifier {
return result;
}
+ /// Sends [message], which names a box's files already [uploaded], as
+ /// [send] sends its own: they leave their box only once the server takes
+ /// the message, so a refused or unanswered one keeps them there, and a
+ /// refusal of the files themselves sends them up again next time.
+ Future<Map<String, dynamic>?> sendWithUploads(
+ Map<String, dynamic> message,
+ Map<HarnessAttachment, String> uploaded,
+ ) async {
+ _uploaded.addAll(uploaded);
+ final result = await command(message);
+ _forgetRefusedUploads(result);
+ return result;
+ }
+
/// A refusal of the files themselves sends them up once more; one of the
/// message (a mention, a recipient) leaves them uploaded.
void _forgetRefusedUploads(Map<String, dynamic>? result) {
diff --git a/desktop/lib/super_tabs/voice_send.dart b/desktop/lib/super_tabs/voice_send.dart
index b92b5668b..e4e39fd37 100644
--- a/desktop/lib/super_tabs/voice_send.dart
+++ b/desktop/lib/super_tabs/voice_send.dart
@@ -5,6 +5,7 @@ import 'package:flutter/foundation.dart';
import '../state/harness_attachments.dart';
import 'controller.dart';
import 'model.dart';
+import 'attachment_upload.dart' show kSuperTabAttachmentMaxFiles;
import 'voice_take.dart';
/// The name a voice message's clip is uploaded under: what an older app shows
@@ -45,16 +46,28 @@ extension SuperTabVoiceSend on SuperTabController {
required String lang,
}) async {
if (!canWrite) return (sent: false, notice: null);
- if (saving || hasPendingAction) {
+ if (saving || uploading || hasPendingAction) {
return (sent: false, notice: superTabVoiceBusy);
}
- final String id;
+ final owner = root == null
+ ? attachments(conversationId)
+ : threadAttachments(conversationId, root);
+ final attached = owner.files;
+ if (attached.length >= kSuperTabAttachmentMaxFiles) {
+ return (
+ sent: false,
+ notice: 'Attach at most 9 files with a voice message.',
+ );
+ }
+ final ids = <String>[];
try {
- final answer = await uploadFile(
- conversationId,
+ for (final file in [
+ ...attached,
HarnessAttachment(superTabVoiceFileName, wav),
- );
- id = superTabMap(answer['attachment'])['id'] as String;
+ ]) {
+ final answer = await uploadFile(conversationId, file);
+ ids.add(superTabMap(answer['attachment'])['id'] as String);
+ }
} on SuperTabFailure catch (failure) {
return (sent: false, notice: failure.message);
} on TimeoutException {
@@ -62,23 +75,28 @@ extension SuperTabVoiceSend on SuperTabController {
} on Object {
return (sent: false, notice: superTabVoiceNoAnswer);
}
- final read = await _readVoice(id, lang);
+ final read = await _readVoice(ids.last, lang);
final voice = read.voice;
if (voice == null) return (sent: false, notice: read.refused);
- if (saving || hasPendingAction) {
+ if (saving || uploading || hasPendingAction) {
return (sent: false, notice: superTabVoiceBusy);
}
// Answered or not, the message is now the chat's: a lost answer or a
- // refusal shows it there with Retry, under the same receipt.
- await command({
- 'type': 'message.send',
- 'conversationId': conversationId,
- 'text': '',
- 'replyTo': root,
- 'recipientIds': const <String>[],
- 'attachmentIds': [id],
- if (oneBuddy) 'oneBuddy': true,
- });
+ // refusal shows it there with Retry, under the same receipt. The attached
+ // files stay in the composer until the server takes it, as a typed
+ // message's do.
+ await sendWithUploads(
+ {
+ 'type': 'message.send',
+ 'conversationId': conversationId,
+ 'text': '',
+ 'replyTo': root,
+ 'recipientIds': const <String>[],
+ 'attachmentIds': ids,
+ if (oneBuddy) 'oneBuddy': true,
+ },
+ {for (final (i, file) in attached.indexed) file: ids[i]},
+ );
// Nothing to say once sent: a voice message plays only, and never has
// words to go without (anh Dee, 2026-11-04).
return (sent: true, notice: null);
diff --git a/desktop/test/super_tab_voice_send_test.dart b/desktop/test/super_tab_voice_send_test.dart
index 5645789cf..137a2a57d 100644
--- a/desktop/test/super_tab_voice_send_test.dart
+++ b/desktop/test/super_tab_voice_send_test.dart
@@ -6,6 +6,7 @@ import 'dart:typed_data';
import 'package:flutter_test/flutter_test.dart';
import 'package:harness/super_tabs/controller.dart';
+import 'package:harness/state/harness_attachments.dart';
import 'package:harness/super_tabs/voice_send.dart';
import 'support/voice_server.dart';
@@ -54,6 +55,166 @@ void main() {
},
);
+ for (final root in <String?>[null, 'message-1']) {
+ final where = root == null ? 'chat' : 'thread';
+ HarnessAttachments files() => root == null
+ ? c.attachments('lead')
+ : c.threadAttachments('lead', root);
+
+ test('$where sends image, document and clip in one ordered post', () async {
+ files().add([
+ HarnessAttachment('picture.png', Uint8List.fromList([1])),
+ HarnessAttachment('notes.txt', Uint8List.fromList([2])),
+ ]);
+ final other = root == null
+ ? c.threadAttachments('lead', 'other')
+ : c.attachments('lead');
+ other.add([
+ HarnessAttachment('other.txt', Uint8List.fromList([3])),
+ ]);
+ final posted = await c.sendVoice(
+ conversationId: 'lead',
+ root: root,
+ wav: _wav,
+ lang: 'en',
+ );
+ expect(posted.sent, isTrue);
+ expect(server.uploads.map((u) => u['name']), [
+ 'picture.png',
+ 'notes.txt',
+ 'Voice message.wav',
+ ]);
+ expect(sent()!['attachmentIds'], [
+ 'attachment-1',
+ 'attachment-2',
+ 'attachment-3',
+ ]);
+ expect(sent()!['replyTo'], root);
+ expect(
+ server.posts.where(
+ (p) => (p['command'] as Map)['type'] == 'message.send',
+ ),
+ hasLength(1),
+ );
+ expect(files().files, isEmpty);
+ expect(other.files.single.name, 'other.txt');
+ });
+
+ test('$where keeps image when its upload fails', () async {
+ final image = HarnessAttachment('picture.png', Uint8List.fromList([1]));
+ files().add([image]);
+ server.failUpload = 'picture.png';
+ final posted = await c.sendVoice(
+ conversationId: 'lead',
+ root: root,
+ wav: _wav,
+ lang: 'en',
+ );
+ expect(posted.sent, isFalse);
+ expect(posted.notice, 'The file is too large.');
+ expect(files().files, [image]);
+ expect(sent(), isNull);
+ });
+
+ test('$where keeps image when voice reading fails', () async {
+ final image = HarnessAttachment('picture.png', Uint8List.fromList([1]));
+ files().add([image]);
+ server.voiceAnswers = [
+ const SuperTabFailure('NOT_FOUND', 'Not found.', statusCode: 404),
+ ];
+ final posted = await c.sendVoice(
+ conversationId: 'lead',
+ root: root,
+ wav: _wav,
+ lang: 'en',
+ );
+ expect(posted.sent, isFalse);
+ expect(files().files, [image]);
+ expect(sent(), isNull);
+ });
+
+ test(
+ '$where leaves files added during voice reading for next time',
+ () async {
+ files().add([
+ HarnessAttachment('picture.png', Uint8List.fromList([1])),
+ ]);
+ final later = HarnessAttachment('later.txt', Uint8List.fromList([2]));
+ server.onVoiceRead = () => files().add([later]);
+ final posted = await c.sendVoice(
+ conversationId: 'lead',
+ root: root,
+ wav: _wav,
+ lang: 'en',
+ );
+ expect(posted.sent, isTrue);
+ expect(sent()!['attachmentIds'], ['attachment-1', 'attachment-2']);
+ expect(files().files, [later]);
+ },
+ );
+
+ test('$where keeps image when the post is refused, and Retry sends it '
+ 'once', () async {
+ final image = HarnessAttachment('picture.png', Uint8List.fromList([1]));
+ files().add([image]);
+ server
+ ..refuse = {'code': 'INVALID_RECIPIENT', 'message': 'Refused.'}
+ ..refuseStatus = 400;
+ await c.sendVoice(
+ conversationId: 'lead',
+ root: root,
+ wav: _wav,
+ lang: 'en',
+ );
+ expect(files().files, [image]);
+ server.refuse = null;
+ final row = c.outgoing('lead').single;
+ expect(row.state, SuperTabOutgoingState.refused);
+ expect(await c.retryOutgoing(row), isNotNull);
+ expect(sent()!['attachmentIds'], ['attachment-1', 'attachment-2']);
+ expect(server.uploads, hasLength(2));
+ expect(files().files, isEmpty);
+ });
+
+ test('$where keeps image until a lost answer is retried, posting '
+ 'once', () async {
+ final image = HarnessAttachment('picture.png', Uint8List.fromList([1]));
+ files().add([image]);
+ server.loseReply = true;
+ await c.sendVoice(
+ conversationId: 'lead',
+ root: root,
+ wav: _wav,
+ lang: 'en',
+ );
+ expect(files().files, [image]);
+ expect(await c.retry(), isNotNull);
+ final sends = server.posts.where(
+ (p) => (p['command'] as Map)['type'] == 'message.send',
+ );
+ expect(sends.map((p) => p['operationId']).toSet(), hasLength(1));
+ expect(files().files, isEmpty);
+ });
+
+ test('$where counts clip toward ten-file limit before uploading', () async {
+ files().add([
+ for (var i = 0; i < 10; i++)
+ HarnessAttachment('$i.txt', Uint8List.fromList([1])),
+ ]);
+ final posted = await c.sendVoice(
+ conversationId: 'lead',
+ root: root,
+ wav: _wav,
+ lang: 'en',
+ );
+ expect(posted.sent, isFalse);
+ expect(posted.notice, isNotEmpty);
+ expect(server.uploads, isEmpty);
+ expect(sent(), isNull);
+ expect(files().files, hasLength(10));
+ });
+ }
+
test("a thread's take is a reply to its root", () async {
await c.sendVoice(
conversationId: 'lead',
diff --git a/desktop/test/support/voice_server.dart b/desktop/test/support/voice_server.dart
index 8ff4f125a..6e1244bb7 100644
--- a/desktop/test/support/voice_server.dart
+++ b/desktop/test/support/voice_server.dart
@@ -6,6 +6,8 @@ import 'super_tab_fixture.dart';
/// [voiceAnswers] are given in turn, the last one again; a [SuperTabFailure]
/// in it is thrown.
class VoiceServer extends ConversationServer {
+ void Function()? onVoiceRead;
+
final voiceReads = <String>[];
List<Object> voiceAnswers = [
{
@@ -36,6 +38,7 @@ class VoiceServer extends ConversationServer {
}) async {
if (method == 'POST' && path.contains('/voice')) {
voiceReads.add(path);
+ onVoiceRead?.call();
final answer =
voiceAnswers[(voiceReads.length - 1).clamp(
0,
diff --git a/docs/plans/2026-11-05-voice-with-attachments-plan.md b/docs/plans/2026-11-05-voice-with-attachments-plan.md
new file mode 100644
index 000000000..3b529caf0
--- /dev/null
+++ b/docs/plans/2026-11-05-voice-with-attachments-plan.md
@@ -0,0 +1,68 @@
+# Voice with attachments implementation plan
+
+> Implement task by task in this Engineer session, test first, with one independent review of the pull request.
+
+**Goal:** Send the composer's attached images/files and recorded clip as one message.
+**Architecture:** Snapshot each composer's existing files, append the clip, upload all, then send one ordered attachment list. Keep typed text in the composer and retain existing outbox retry behavior.
+**Tech Stack:** Flutter/Dart; existing Swarm upload and message APIs.
+**Spec:** Swarm task #3354, conversation f2f09555de1e552303361d78.
+
+## Global Constraints
+
+- Voice messages play only; no transcript controls. No backend/protocol changes.
+- Phone and Desktop chat and thread composers behave alike. Simulator only for phone acceptance.
+- Preserve attachments on upload/read failure; consume only the snapshot when a send enters the outbox.
+- Respect the existing ten-file message limit, counting the clip.
+
+## Design
+
+- Growth: existing attachment storage/lifetime and outbox cleanup; no new stored data.
+- Concurrency: existing upload/send lane; snapshot files before awaiting and leave files added later alone.
+- Read cost/scale: at most ten uploads per message; no new polling or reads. Existing upload error/progress is the first warning.
+- Compatibility: existing ordered attachmentIds contract, understood by old clients.
+- Migration/rollback: no migration; revert client changes.
+- Audience/identity: existing authenticated upload/send endpoints enforce both.
+- Failure: no send after failed upload or voice read; existing outbox handles uncertain delivery.
+- Platforms: iOS/Android and Desktop/web, shared Dart send code.
+
+## Review Focus
+
+- Chat and thread files must stay isolated.
+- A failed upload or voice read must keep composer files.
+- A file added during upload belongs to the next message.
+- Ten attachments plus a clip must be refused before upload.
+- Pending combined messages must retain their voice bubble.
+
+### Task 1: Phone send paths
+
+**Files:** mobile/lib/swarm/swarm_conversation.dart, swarm_thread.dart, swarm_new_message_sheet.dart; mobile/test/swarm/swarm_voice_send_test.dart and new-message widget tests.
+**Interfaces:** Existing sendVoice(VoiceTake, String) and SwarmOutgoingFiles; no signature changes.
+
+- [x] Add chat/thread tests asserting one command contains image, document, clip in that order; typed text remains, sent files leave the composer. Cover failed upload/read, concurrent additions, and file limit. Existing clip-alone test remains.
+- [x] Run the focused tests and commit failing tests.
+- [x] Snapshot composer files plus clip; read voice using the clip's final ID; remove only submitted files. Copy new-message sheet files into its chat before sending voice.
+- [x] Run focused phone tests and commit the fix.
+
+### Task 2: Desktop send paths
+
+**Files:** desktop/lib/super_tabs/voice_send.dart; desktop/test/super_tab_voice_send_test.dart.
+**Interfaces:** Existing SuperTabController.sendVoice and attachments/threadAttachments.
+
+- [x] Add tests for ordered image/document/clip in one send, thread isolation, failed upload/read preservation, concurrent additions, and max count; retain clip-alone coverage.
+- [x] Run focused tests and commit failing tests.
+- [x] Upload a snapshot of the appropriate composer's files with the clip; consume only that snapshot once command owns the send.
+- [x] Run focused Desktop tests and commit the fix.
+
+### Task 3: Pending phone presentation and acceptance
+
+**Files:** mobile/lib/swarm/swarm_conversation_page.dart; mobile/test/swarm/swarm_chat_voice_test.dart.
+**Interfaces:** Existing SwarmPost.files and voice; the appended final file is the recorded clip.
+
+- [x] Add a widget regression proving a pending combined post retains a voice bubble and file chip; run red and commit.
+- [x] Render each file in order, rendering the final recorded clip as voice; run green and commit.
+- [x] Run affected caller/widget tests and static analysis; record red/green evidence and exact revisions in the PR.
+- [ ] Hand ready PR to independent review and simulator acceptance through Swarm steps; do not merge.
+
+## Integration note
+
+River authorized building on PR #3185 until it lands. Its play-only UI and no-notice sends are merged here; review and merge after that dependency. Refused phone posts also restore their original composer files before any later files; the recorded take remains owned by the recorder.
diff --git a/mobile/lib/swarm/swarm_conversation.dart b/mobile/lib/swarm/swarm_conversation.dart
index 1e33e0450..e97c7be78 100644
--- a/mobile/lib/swarm/swarm_conversation.dart
+++ b/mobile/lib/swarm/swarm_conversation.dart
@@ -993,7 +993,7 @@ class SwarmConversation extends ChangeNotifier
String? _startedRoot;
- /// Sends [take] as a voice message, alone, as a reply to [replyingTo] when
+ /// Sends [take] as a voice message with attached files, as a reply to [replyingTo] when
/// there is one: its clip goes up, the backend reads it once in [lang], and
/// the post names that file. What is typed stays in the box. Not sent, the
/// take is the voice row's to keep; a post whose answer was lost is the
@@ -1003,14 +1003,22 @@ class SwarmConversation extends ChangeNotifier
if (uploading || _disposed || !canPost || group == null) {
return (sent: false, notice: null);
}
+ final attached = files.files;
+ if (attached.length >= swarmAttachmentMaxFiles) {
+ return (
+ sent: false,
+ notice: 'Attach at most 9 files with a voice message.',
+ );
+ }
final clip = SwarmOutgoingFile(swarmVoiceFileName, take.wav);
+ final outgoing = [...attached, clip];
// A failure says itself in the chat, as a file's does.
- final ids = await _uploadAll([clip]);
+ final ids = await _uploadAll(outgoing);
if (ids == null || _disposed) return (sent: false, notice: null);
final read = await swarmReadVoice(
reader.request,
tabId: reader.tabId,
- attachmentId: ids.single,
+ attachmentId: ids.last,
lang: lang,
);
final voice = read.voice;
@@ -1034,11 +1042,15 @@ class SwarmConversation extends ChangeNotifier
accountId: reader.accountId,
operationId: operationId,
),
- files: [clip],
+ files: outgoing,
voice: voice,
+ held: (voiceFiles: attached),
);
_replyingTo = null;
error = null;
+ for (final file in attached) {
+ files.remove(file);
+ }
final outcome = await _outbox.add(post);
_answered(post, outcome);
final sent =
@@ -1629,6 +1641,13 @@ class SwarmConversation extends ChangeNotifier
/// A refused post's text back in the draft, before anything typed since.
void _restore(SwarmPost post) {
+ if (post.held case (voiceFiles: final List<SwarmOutgoingFile> attached)) {
+ final since = files.files;
+ files
+ ..clear()
+ ..add([...attached, ...since]);
+ return;
+ }
final sent = post.held;
if (sent
is! ({
diff --git a/mobile/lib/swarm/swarm_conversation_page.dart b/mobile/lib/swarm/swarm_conversation_page.dart
index 2a8f98caf..777c1c19d 100644
--- a/mobile/lib/swarm/swarm_conversation_page.dart
+++ b/mobile/lib/swarm/swarm_conversation_page.dart
@@ -3461,7 +3461,7 @@ class _Pending extends StatelessWidget {
/// nothing until the post is read back with their links.
final List<SwarmOutgoingFile> files;
- /// What makes it a voice message, its one file the clip: drawn as its
+ /// What makes it a voice message, its final file the clip: drawn as its
/// bubble, which plays once the post is read back.
final SuperTabVoice? voice;
@@ -3509,19 +3509,19 @@ class _Pending extends StatelessWidget {
),
),
),
- if (voice case final voice? when files.length == 1)
- SwarmVoiceBubble(
- file: SuperTabAttachment.fromJson({
- 'id': '',
- 'name': files.single.name,
- 'mime': swarmMimeForName(files.single.name),
- 'size': files.single.size,
- 'url': '',
- }),
- voice: voice,
- )
- else
- for (final file in files)
+ for (final (index, file) in files.indexed)
+ if (voice case final voice? when index == files.length - 1)
+ SwarmVoiceBubble(
+ file: SuperTabAttachment.fromJson({
+ 'id': '',
+ 'name': file.name,
+ 'mime': swarmMimeForName(file.name),
+ 'size': file.size,
+ 'url': '',
+ }),
+ voice: voice,
+ )
+ else
SwarmFileChip(
file: SuperTabAttachment.fromJson({
'id': '',
diff --git a/mobile/lib/swarm/swarm_new_message_sheet.dart b/mobile/lib/swarm/swarm_new_message_sheet.dart
index 7802b3b56..6363048ff 100644
--- a/mobile/lib/swarm/swarm_new_message_sheet.dart
+++ b/mobile/lib/swarm/swarm_new_message_sheet.dart
@@ -511,6 +511,11 @@ class _SwarmNewMessageSheetState extends State<SwarmNewMessageSheet>
}
final chat = _chat ??= SwarmConversation(reader, pick.chatId, shown: false)
..composer.addListener(_redraw);
+ if (!listEquals(chat.files.files, files.files)) {
+ chat.files
+ ..clear()
+ ..add(files.files);
+ }
setState(() => _error = _note = null);
final posted = await chat.sendVoice(take, voiceLanguageStore.value);
if (!mounted || _closing || _chat != chat) return posted;
diff --git a/mobile/lib/swarm/swarm_thread.dart b/mobile/lib/swarm/swarm_thread.dart
index 5aa14cada..a659f6126 100644
--- a/mobile/lib/swarm/swarm_thread.dart
+++ b/mobile/lib/swarm/swarm_thread.dart
@@ -688,7 +688,7 @@ class SwarmThread extends ChangeNotifier
}
}
- /// Sends [take] as a voice message in the thread, alone, as the chat's
+ /// Sends [take] as a voice message with attached files in the thread, as the chat's
/// [SwarmConversation.sendVoice] does: what is typed stays in the box.
Future<SwarmVoicePosted> sendVoice(VoiceTake take, String lang) async {
if (uploading || _disposed || !canPost || chat.conversation == null) {
@@ -696,13 +696,21 @@ class SwarmThread extends ChangeNotifier
}
final epoch = _epoch;
bool current() => !_disposed && epoch == _epoch;
+ final attached = files.files;
+ if (attached.length >= swarmAttachmentMaxFiles) {
+ return (
+ sent: false,
+ notice: 'Attach at most 9 files with a voice message.',
+ );
+ }
final clip = SwarmOutgoingFile(swarmVoiceFileName, take.wav);
+ final outgoing = [...attached, clip];
error = null;
- final up = await _uploads.upload([clip]);
+ final up = await _uploads.upload(outgoing);
if (!current()) return (sent: false, notice: null);
if (up.failure case final failure?) {
if (failure is! SuperTabFailure || !_refusedChat(failure)) {
- error = swarmUploadError(failure, 1);
+ error = swarmUploadError(failure, outgoing.length);
_tell();
}
return (sent: false, notice: null);
@@ -712,7 +720,7 @@ class SwarmThread extends ChangeNotifier
final read = await swarmReadVoice(
reader.request,
tabId: reader.tabId,
- attachmentId: ids.single,
+ attachmentId: ids.last,
lang: lang,
);
final voice = read.voice;
@@ -736,9 +744,13 @@ class SwarmThread extends ChangeNotifier
accountId: reader.accountId,
operationId: operationId,
),
- files: [clip],
+ files: outgoing,
voice: voice,
+ held: (voiceFiles: attached),
);
+ for (final file in attached) {
+ files.remove(file);
+ }
final outcome = await _outbox.add(post);
_answered(post, outcome, current);
final sent =
@@ -904,6 +916,13 @@ class SwarmThread extends ChangeNotifier
/// A refused reply's text and files back in the box, before anything
/// typed or added since.
void _restore(SwarmPost post) {
+ if (post.held case (voiceFiles: final List<SwarmOutgoingFile> attached)) {
+ final since = files.files;
+ files
+ ..clear()
+ ..add([...attached, ...since]);
+ return;
+ }
final sent = post.held;
if (sent
is! ({
diff --git a/mobile/test/swarm/swarm_chat_voice_test.dart b/mobile/test/swarm/swarm_chat_voice_test.dart
index b3452da7e..45f76556d 100644
--- a/mobile/test/swarm/swarm_chat_voice_test.dart
+++ b/mobile/test/swarm/swarm_chat_voice_test.dart
@@ -1,8 +1,9 @@
-import 'dart:async';
-
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
+import 'package:image_picker/image_picker.dart' show XFile;
+import 'package:harness_mobile/swarm/swarm_file_picker.dart';
+import 'package:harness_mobile/swarm/swarm_voice_bubble.dart';
import 'package:harness_mobile/notify/system_notices.dart';
import 'package:harness_mobile/phone/voice_recorder.dart';
import 'package:harness_mobile/settings/experimental_features.dart';
@@ -165,6 +166,54 @@ void main() {
expect(field(tester).controller!.text, 'typed first');
});
+ testWidgets('a pending image and clip retain the voice bubble', (
+ tester,
+ ) async {
+ final originalPicker = pickSwarmFiles;
+ final originalFolders = swarmPickerCopyFolders;
+ swarmPickerCopyFolders = () async => const [];
+ addTearDown(() {
+ pickSwarmFiles = originalPicker;
+ swarmPickerCopyFolders = originalFolders;
+ });
+ pickSwarmFiles = () async => [
+ XFile.fromData(
+ Uint8List.fromList([1, 2, 3]),
+ name: 'picture.png',
+ path: '/copies/picture.png',
+ ),
+ ];
+ await pump(tester);
+ await tester.tap(key('swarm-attach'));
+ await tester.pumpAndSettle();
+ await tester.tap(key('swarm-attach-files'));
+ await tester.pumpAndSettle();
+ expect(key('swarm-outgoing-picture.png'), findsOneWidget);
+ await tapMic(tester);
+ await tester.tap(key('swarm-voice-send'));
+ await frames(tester);
+ await tester.pump(const Duration(milliseconds: 100));
+ await frames(tester);
+ expect(fake.commands.single['attachmentIds'], [
+ 'id-picture.png',
+ 'id-Voice message.wav',
+ ]);
+ expect(
+ find.descendant(
+ of: key('swarm-pending'),
+ matching: find.byType(SwarmVoiceBubble),
+ ),
+ findsOneWidget,
+ );
+ expect(
+ find.descendant(
+ of: key('swarm-pending'),
+ matching: find.text('picture.png'),
+ ),
+ findsOneWidget,
+ );
+ });
+
testWidgets('X throws the take away and sends nothing', (tester) async {
await pump(tester);
await tapMic(tester);
diff --git a/mobile/test/swarm/swarm_new_message_test.dart b/mobile/test/swarm/swarm_new_message_test.dart
index 53693463b..53859efa4 100644
--- a/mobile/test/swarm/swarm_new_message_test.dart
+++ b/mobile/test/swarm/swarm_new_message_test.dart
@@ -915,6 +915,32 @@ void main() {
expect(find.byType(SwarmNewMessageSheet), findsNothing);
});
+ testWidgets('a picked file and recording leave the sheet in one message', (
+ tester,
+ ) async {
+ final fake = await talking(tester);
+ pickSwarmFiles = () async => [
+ XFile.fromData(
+ Uint8List.fromList([1, 2, 3]),
+ name: 'picture.png',
+ path: '/copies/picture.png',
+ ),
+ ];
+ await tester.tap(key('swarm-new-message-attach'));
+ await tester.pumpAndSettle();
+ await tester.tap(key('swarm-attach-files'));
+ await tester.pumpAndSettle();
+ expect(key('swarm-outgoing-picture.png'), findsOneWidget);
+ await tapIn(tester, 'swarm-mic');
+ await tapIn(tester, 'swarm-voice-send');
+ await tester.pumpAndSettle();
+ expect(sends(fake).single['command']['attachmentIds'], [
+ 'id-picture.png',
+ 'id-Voice message.wav',
+ ]);
+ expect(find.byType(SwarmNewMessageSheet), findsNothing);
+ });
+
testWidgets("with no chat picked the row's Send is off", (tester) async {
final fake = await talking(tester, pick: false);
await tapIn(tester, 'swarm-mic');
diff --git a/mobile/test/swarm/swarm_voice_send_test.dart b/mobile/test/swarm/swarm_voice_send_test.dart
index fed77a373..3024159e9 100644
--- a/mobile/test/swarm/swarm_voice_send_test.dart
+++ b/mobile/test/swarm/swarm_voice_send_test.dart
@@ -5,6 +5,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:harness_mobile/phone/voice_recorder.dart';
import 'package:harness_mobile/swarm/swarm_conversation.dart';
import 'package:harness_mobile/swarm/swarm_reader.dart';
+import 'package:harness_mobile/swarm/swarm_outgoing_files.dart';
import 'package:harness_mobile/swarm/swarm_request.dart';
import 'package:harness_mobile/swarm/swarm_thread.dart';
import 'package:harness_mobile/swarm/swarm_voice_send.dart';
@@ -97,6 +98,148 @@ void main() {
expect(c.draft, 'typed before');
});
+ for (final inThread in [false, true]) {
+ final where = inThread ? 'thread' : 'chat';
+ test(
+ '$where sends attached image and file with the clip in one post',
+ () async {
+ final r = rig();
+ final c = await open(r.reader);
+ final thread = SwarmThread(c, 'root-1');
+ addTearDown(thread.dispose);
+ final files = inThread ? thread.files : c.files;
+ files.add([
+ SwarmOutgoingFile('picture.png', Uint8List.fromList([1, 2])),
+ SwarmOutgoingFile('notes.txt', Uint8List.fromList([3])),
+ ]);
+ c.draft = 'keep typing';
+ thread.draft = 'keep replying';
+ final sent = inThread
+ ? await thread.sendVoice(take, 'en')
+ : await c.sendVoice(take, 'en');
+ expect(sent.sent, isTrue);
+ expect(r.swarm.commands.single['attachmentIds'], [
+ 'id-picture.png',
+ 'id-notes.txt',
+ 'id-Voice message.wav',
+ ]);
+ expect(r.swarm.commands.single['replyTo'], inThread ? 'root-1' : null);
+ expect(files.files, isEmpty);
+ expect(c.draft, 'keep typing');
+ expect(thread.draft, 'keep replying');
+ },
+ );
+
+ test('$where keeps attachments when their upload fails', () async {
+ final r = rig();
+ final c = await open(r.reader);
+ final thread = SwarmThread(c, 'root-1');
+ addTearDown(thread.dispose);
+ final files = inThread ? thread.files : c.files;
+ final image = SwarmOutgoingFile('picture.png', Uint8List.fromList([1]));
+ files.add([image]);
+ r.uploads.refuse['picture.png'] = const SuperTabFailure(
+ 'UPLOAD_FAILED',
+ 'Try again',
+ );
+ final sent = inThread
+ ? await thread.sendVoice(take, 'en')
+ : await c.sendVoice(take, 'en');
+ expect(sent.sent, isFalse);
+ expect(r.swarm.commands, isEmpty);
+ expect(files.files, [image]);
+ });
+
+ test(
+ '$where restores attached files after a refused combined post',
+ () async {
+ final r = rig();
+ final c = await open(r.reader);
+ final thread = SwarmThread(c, 'root-1');
+ addTearDown(thread.dispose);
+ final files = inThread ? thread.files : c.files;
+ final image = SwarmOutgoingFile('picture.png', Uint8List.fromList([1]));
+ final later = SwarmOutgoingFile('later.txt', Uint8List.fromList([2]));
+ files.add([image]);
+ r.swarm.routes[commands] = (_) {
+ files.add([later]);
+ throw const SuperTabFailure('INVALID', 'Try again', statusCode: 400);
+ };
+ final sent = inThread
+ ? await thread.sendVoice(take, 'en')
+ : await c.sendVoice(take, 'en');
+ expect(sent.sent, isFalse);
+ expect(files.files, [image, later]);
+ },
+ );
+
+ test('$where keeps attachments when voice reading fails', () async {
+ final r = rig();
+ final c = await open(r.reader);
+ final thread = SwarmThread(c, 'root-1');
+ addTearDown(thread.dispose);
+ final files = inThread ? thread.files : c.files;
+ final image = SwarmOutgoingFile('picture.png', Uint8List.fromList([1]));
+ files.add([image]);
+ r.swarm.routes['/api/super-tabs/$tab/attachments/'] = (_) =>
+ throw TimeoutException('offline');
+ final sent = inThread
+ ? await thread.sendVoice(take, 'en')
+ : await c.sendVoice(take, 'en');
+ expect(sent.sent, isFalse);
+ expect(r.swarm.commands, isEmpty);
+ expect(files.files, [image]);
+ });
+
+ test(
+ '$where leaves files added while the clip is read for next time',
+ () async {
+ final r = rig();
+ final c = await open(r.reader);
+ final thread = SwarmThread(c, 'root-1');
+ addTearDown(thread.dispose);
+ final files = inThread ? thread.files : c.files;
+ files.add([
+ SwarmOutgoingFile('picture.png', Uint8List.fromList([1])),
+ ]);
+ final later = SwarmOutgoingFile('later.txt', Uint8List.fromList([2]));
+ r.swarm.routes['/api/super-tabs/$tab/attachments/'] = (_) {
+ files.add([later]);
+ return facts();
+ };
+ final sent = inThread
+ ? await thread.sendVoice(take, 'en')
+ : await c.sendVoice(take, 'en');
+ expect(sent.sent, isTrue);
+ expect(files.files, [later]);
+ expect(r.swarm.commands.single['attachmentIds'], [
+ 'id-picture.png',
+ 'id-Voice message.wav',
+ ]);
+ },
+ );
+
+ test('$where counts the clip toward the ten-file limit', () async {
+ final r = rig();
+ final c = await open(r.reader);
+ final thread = SwarmThread(c, 'root-1');
+ addTearDown(thread.dispose);
+ final files = inThread ? thread.files : c.files;
+ files.add([
+ for (var i = 0; i < 10; i++)
+ SwarmOutgoingFile('$i.txt', Uint8List.fromList([1])),
+ ]);
+ final sent = inThread
+ ? await thread.sendVoice(take, 'en')
+ : await c.sendVoice(take, 'en');
+ expect(sent.sent, isFalse);
+ expect(sent.notice, isNotEmpty);
+ expect(r.uploads.asked, isEmpty);
+ expect(r.swarm.commands, isEmpty);
+ expect(files.files, hasLength(10));
+ });
+ }
+
test('waits while the backend still transcribes it', () async {
final r = rig();
var asks = 0;