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.

Phone chat like Slack: code blocks, pictures at their shape, Not sent · Retry (#2219)

harness-for-autonomous[bot]8306d33f7a6f
diff --git a/mobile/lib/swarm/swarm_attachment.dart b/mobile/lib/swarm/swarm_attachment.dart
index c0a27068f..fb501f409 100644
--- a/mobile/lib/swarm/swarm_attachment.dart
+++ b/mobile/lib/swarm/swarm_attachment.dart
@@ -50,13 +50,14 @@ class SwarmAttachment extends StatelessWidget {
}
}
-/// The widest a picture shows in a message.
-const _previewWidth = 240.0;
-
-/// A picture in its message: a skeleton in a fixed 4:3 box while it loads,
-/// then the picture filling the same box, so the chat never moves under the
-/// reader. The backend sends no picture's size, so the box cannot take its
-/// shape; the whole picture is a tap away ([SwarmAttachmentViewer]).
+/// The most a picture shows in a message, each way (Dee, 10-29: Slack's 360).
+const _maxSide = 360.0;
+
+/// A picture in its message, as Slack shows one: a skeleton in a 4:3 box
+/// while it loads (the backend sends no picture's size), then the picture at
+/// its own shape, up to [_maxSide] each way and never wider than the message.
+/// The chat is held at its foot, so the newest messages stay put as it takes
+/// that shape; the whole picture is a tap away ([SwarmAttachmentViewer]).
class _Preview extends StatefulWidget {
const _Preview({
required this.file,
@@ -129,8 +130,9 @@ class _PreviewState extends State<_Preview> {
if (_failed) return widget.chip;
return LayoutBuilder(
builder: (context, constraints) {
- final width = math.min(constraints.maxWidth, _previewWidth);
+ final width = math.min(constraints.maxWidth, _maxSide);
final height = width * 3 / 4;
+ final ratio = MediaQuery.devicePixelRatioOf(context);
final skeleton = Skeleton(
width: width,
height: height,
@@ -159,9 +161,11 @@ class _PreviewState extends State<_Preview> {
child: GestureDetector(
key: ValueKey('swarm-attachment-preview-${widget.file.id}'),
onTap: file == null ? null : () => _open(context, file),
- child: SizedBox(
- width: width,
- height: height,
+ child: ConstrainedBox(
+ constraints: BoxConstraints(
+ maxWidth: width,
+ maxHeight: _maxSide,
+ ),
child: file == null
? skeleton
: ClipRRect(
@@ -169,17 +173,14 @@ class _PreviewState extends State<_Preview> {
AppControl.rowRadius,
),
child: Image(
- // Decoded at the box's size, not the picture's.
+ // Decoded no larger than it shows, its shape kept.
image: ResizeImage(
FileImage(file),
- width:
- (width *
- MediaQuery.devicePixelRatioOf(
- context,
- ))
- .round(),
+ width: (width * ratio).round(),
+ height: (_maxSide * ratio).round(),
+ policy: ResizeImagePolicy.fit,
),
- fit: BoxFit.cover,
+ fit: BoxFit.contain,
gaplessPlayback: true,
frameBuilder: (_, image, frame, synchronous) =>
frame == null && !synchronous
diff --git a/mobile/lib/swarm/swarm_attachment_store.dart b/mobile/lib/swarm/swarm_attachment_store.dart
index b94311989..777d1da4e 100644
--- a/mobile/lib/swarm/swarm_attachment_store.dart
+++ b/mobile/lib/swarm/swarm_attachment_store.dart
@@ -4,6 +4,7 @@ import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
+import 'package:http/http.dart' as http;
import 'package:harness_mobile/logging/app_log.dart';
@@ -179,7 +180,7 @@ class SwarmAttachmentStore {
File('${folder.path}/index.json'),
),
fileSystem: _files?.call(folder) ?? IOFileSystem(key),
- fileService: _fileService ?? HttpFileService(),
+ fileService: _fileService ?? SwarmFileFetch(),
),
);
}
@@ -201,8 +202,9 @@ class SwarmAttachmentStore {
}
}
-/// The app's one store of Swarm's files.
-final swarmAttachments = SwarmAttachmentStore();
+/// The app's one store of Swarm's files; review screenshots put in one
+/// that serves made-up pictures.
+SwarmAttachmentStore swarmAttachments = SwarmAttachmentStore();
/// Keeps [store] to the account whose Swarm [host] reads: the files go on
/// sign-out, Swarm turned off and another account ([SwarmAttachmentStore.keepOnly]),
@@ -295,3 +297,23 @@ class SwarmAttachmentKeeper {
_session?.inbox.removeListener(_listChanged);
}
}
+
+/// The cache's fetch of a chat file: `HttpFileService`'s, with a redirect
+/// refused, so a picture comes only from the host its message names and
+/// nothing from another host is kept or drawn.
+class SwarmFileFetch extends FileService {
+ SwarmFileFetch({http.Client? client}) : _client = client ?? http.Client();
+
+ final http.Client _client;
+
+ @override
+ Future<FileServiceResponse> get(
+ String url, {
+ Map<String, String>? headers,
+ }) async {
+ final request = http.Request('GET', Uri.parse(url))
+ ..followRedirects = false;
+ if (headers != null) request.headers.addAll(headers);
+ return HttpGetResponse(await _client.send(request));
+ }
+}
diff --git a/mobile/lib/swarm/swarm_code_block.dart b/mobile/lib/swarm/swarm_code_block.dart
new file mode 100644
index 000000000..b0d2c0087
--- /dev/null
+++ b/mobile/lib/swarm/swarm_code_block.dart
@@ -0,0 +1,176 @@
+import 'dart:async';
+
+import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
+import 'package:lucide_icons_flutter/lucide_icons.dart';
+
+import 'package:harness_mobile/phone/tty.dart';
+import 'package:harness_mobile/shared/theme/app_space.dart';
+import 'package:harness_mobile/shared/theme/app_theme.dart';
+
+import 'swarm_message_row.dart'
+ show swarmChatCard, swarmChatHair, swarmChatText;
+
+/// A piece of a message's text: prose, or a fenced code block with the
+/// fence's [name] (`dart`, `main.dart`), null without one.
+typedef SwarmTextPart = ({String text, bool code, String? name});
+
+/// A fence on lines of its own: ```name, the code, then ```.
+final _fence = RegExp(
+ r'^```([^\n`]*)\n([\s\S]*?)\n?```[ \t]*$',
+ multiLine: true,
+);
+
+/// [text] as prose and fenced code blocks, in order. Prose loses only the
+/// line breaks that held a fence; an unclosed fence stays prose.
+List<SwarmTextPart> swarmTextParts(String text) {
+ final parts = <SwarmTextPart>[];
+ void prose(String value) {
+ final trimmed = value.replaceAll(RegExp(r'^\n+|\n+$'), '');
+ if (trimmed.isNotEmpty) parts.add((text: trimmed, code: false, name: null));
+ }
+
+ var from = 0;
+ for (final fence in _fence.allMatches(text)) {
+ prose(text.substring(from, fence.start));
+ final name = fence[1]!.trim();
+ parts.add((text: fence[2]!, code: true, name: name.isEmpty ? null : name));
+ from = fence.end;
+ }
+ prose(text.substring(from));
+ return parts;
+}
+
+/// A fenced code block in a message, as Slack shows one: monospace, the
+/// fence's name over it, Copy beside that, and a long one folded to its first
+/// [foldedLines] lines behind Show more (the desktop's `SuperTabCodeBlock`).
+class SwarmCodeBlock extends StatefulWidget {
+ const SwarmCodeBlock({super.key, required this.code, this.name, this.onTap});
+
+ static const foldedLines = 12;
+
+ final String code;
+ final String? name;
+
+ /// The message's own tap (it shows Reply), anywhere in the block but Copy
+ /// and Show more, which keep theirs; null where the message has none.
+ final VoidCallback? onTap;
+
+ @override
+ State<SwarmCodeBlock> createState() => _SwarmCodeBlockState();
+}
+
+class _SwarmCodeBlockState extends State<SwarmCodeBlock> {
+ bool _unfolded = false;
+
+ Future<void> _copy() async {
+ await Clipboard.setData(ClipboardData(text: widget.code));
+ if (!mounted) return;
+ ScaffoldMessenger.maybeOf(context)?.showSnackBar(
+ const SnackBar(content: Text('Code copied'), duration: Durations.long4),
+ );
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final tty = Tty.of(context);
+ final lines = widget.code.split('\n');
+ final long = lines.length > SwarmCodeBlock.foldedLines;
+ final shown = long && !_unfolded
+ ? lines.take(SwarmCodeBlock.foldedLines).join('\n')
+ : widget.code;
+ final block = Container(
+ width: double.infinity,
+ margin: const EdgeInsets.only(top: AppSpace.s),
+ padding: const EdgeInsets.only(left: AppSpace.m, bottom: AppSpace.m),
+ decoration: BoxDecoration(
+ color: swarmChatCard(tty),
+ border: Border.all(color: swarmChatHair(tty)),
+ borderRadius: BorderRadius.circular(AppControl.radius),
+ ),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Row(
+ children: [
+ Expanded(
+ child: Text(
+ widget.name ?? '',
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: tty.style(color: AppPalette.textFaint, size: 12.5),
+ ),
+ ),
+ _Action(icon: LucideIcons.copy, label: 'Copy', onTap: _copy),
+ ],
+ ),
+ Padding(
+ padding: const EdgeInsets.only(right: AppSpace.m),
+ child: Text(shown, softWrap: true, style: tty.style(size: 14)),
+ ),
+ if (long)
+ _Action(
+ label: _unfolded ? 'Show less' : 'Show more',
+ onTap: () => setState(() => _unfolded = !_unfolded),
+ ),
+ ],
+ ),
+ );
+ final tap = widget.onTap;
+ if (tap == null) return block;
+ return Semantics(
+ hint: 'Reply to this message',
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: tap,
+ child: block,
+ ),
+ );
+ }
+}
+
+/// A phone control's least height and width (design system, Phone: 44-point
+/// targets).
+const _finger = 44.0;
+
+/// A quiet action in the block: its words in the link colour, a finger tall.
+class _Action extends StatelessWidget {
+ const _Action({required this.label, required this.onTap, this.icon});
+
+ final String label;
+ final VoidCallback onTap;
+ final IconData? icon;
+
+ @override
+ Widget build(BuildContext context) {
+ final tty = Tty.of(context);
+ return Semantics(
+ button: true,
+ label: label,
+ excludeSemantics: true,
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: () => unawaited(Future.sync(onTap)),
+ child: ConstrainedBox(
+ constraints: const BoxConstraints(
+ minHeight: _finger,
+ minWidth: _finger,
+ ),
+ child: Padding(
+ padding: const EdgeInsets.symmetric(horizontal: AppSpace.m),
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ if (icon case final icon?) ...[
+ Icon(icon, size: 16, color: tty.blue),
+ const SizedBox(width: AppSpace.xs),
+ ],
+ Text(label, style: swarmChatText(14, color: tty.blue)),
+ ],
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+}
diff --git a/mobile/lib/swarm/swarm_conversation.dart b/mobile/lib/swarm/swarm_conversation.dart
index 088689b90..22842171a 100644
--- a/mobile/lib/swarm/swarm_conversation.dart
+++ b/mobile/lib/swarm/swarm_conversation.dart
@@ -671,7 +671,7 @@ class SwarmConversation extends ChangeNotifier implements SwarmFilesBox {
error = failure.message;
return false;
} catch (_) {
- error = 'Your message is not confirmed. Send again to check it.';
+ error = 'Your message was not sent. Retry to check it.';
return false;
} finally {
sending = false;
diff --git a/mobile/lib/swarm/swarm_conversation_page.dart b/mobile/lib/swarm/swarm_conversation_page.dart
index 832691765..e972050b0 100644
--- a/mobile/lib/swarm/swarm_conversation_page.dart
+++ b/mobile/lib/swarm/swarm_conversation_page.dart
@@ -19,6 +19,8 @@ import 'package:harness_mobile/shared/widgets/skeleton.dart';
import 'identity.dart';
import 'model.dart';
import 'prompt_alerts.dart';
+import 'swarm_code_block.dart';
+import 'swarm_post_line.dart';
import 'swarm_attach.dart';
import 'swarm_buddy.dart';
import 'swarm_buddy_chat.dart';
@@ -2131,8 +2133,8 @@ class _NewPill extends StatelessWidget {
);
}
-/// The person's post on its way: "Sending…", then — its answer lost — "Not
-/// confirmed" with Send again, until it is read back.
+/// The person's post on its way, with [SwarmPostLine] under it: "Sending…",
+/// then — its answer lost — "Not sent · Retry", until it is read back.
class _Pending extends StatelessWidget {
const _Pending({
super.key,
@@ -2161,7 +2163,6 @@ class _Pending extends StatelessWidget {
@override
Widget build(BuildContext context) {
- final tty = Tty.of(context);
return Padding(
key: const ValueKey('swarm-pending'),
padding: SwarmMessageFrame.padding(),
@@ -2174,35 +2175,28 @@ class _Pending extends StatelessWidget {
picture: look.picture,
status: look.status,
),
- header: SwarmMessageHeader(
- name: name,
- agent: false,
- trailing: Text(
- sending ? 'Sending…' : 'Not confirmed',
- style: tty.style(
- color: sending ? AppPalette.textFaint : tty.yellow,
- size: 12.5,
- ),
- ),
- ),
+ header: SwarmMessageHeader(name: name, agent: false),
body: [
?quote,
- if (text.isNotEmpty)
- Padding(
- padding: const EdgeInsets.only(top: SwarmMessageFrame.bodyGap),
- child: Text.rich(
- mentions.span(
- text,
- swarmChatText(
- 16,
- height: 1.42,
- color: sending
- ? AppPalette.textSecondary
- : AppPalette.textPrimary,
+ for (final part in swarmTextParts(text))
+ if (part.code)
+ SwarmCodeBlock(code: part.text, name: part.name)
+ else
+ Padding(
+ padding: const EdgeInsets.only(top: SwarmMessageFrame.bodyGap),
+ child: Text.rich(
+ mentions.span(
+ part.text,
+ swarmChatText(
+ 16,
+ height: 1.42,
+ color: sending
+ ? AppPalette.textSecondary
+ : AppPalette.textPrimary,
+ ),
),
),
),
- ),
for (final file in files)
SwarmFileChip(
file: SuperTabAttachment.fromJson({
@@ -2214,16 +2208,10 @@ class _Pending extends StatelessWidget {
}),
link: null,
),
- if (!sending)
- Padding(
- padding: const EdgeInsets.only(top: AppSpace.s),
- child: SwarmSmallButton(
- key: const ValueKey('swarm-resend-post'),
- icon: LucideIcons.rotateCw,
- label: 'Send again',
- onTap: onSendAgain,
- ),
- ),
+ Padding(
+ padding: const EdgeInsets.only(top: AppSpace.xs),
+ child: SwarmPostLine(sending: sending, onRetry: onSendAgain),
+ ),
],
),
);
diff --git a/mobile/lib/swarm/swarm_message_row.dart b/mobile/lib/swarm/swarm_message_row.dart
index 6ac2c447d..27ee17bc8 100644
--- a/mobile/lib/swarm/swarm_message_row.dart
+++ b/mobile/lib/swarm/swarm_message_row.dart
@@ -13,6 +13,7 @@ import 'package:harness_mobile/shared/theme/app_theme.dart';
import 'model.dart';
import 'swarm_attachment.dart';
+import 'swarm_code_block.dart';
import 'swarm_face.dart';
import 'swarm_ship_row.dart';
@@ -295,27 +296,29 @@ class SwarmMessageRow extends StatelessWidget {
body: [
if (lit) SizedBox(key: ValueKey('swarm-lit-${message.id}')),
?quote,
- if (message.text.isNotEmpty)
- Semantics(
- button: true,
- hint: 'Reply to this message',
- child: GestureDetector(
- behavior: HitTestBehavior.opaque,
- onTap: onTap,
- child: Padding(
- padding: const EdgeInsets.only(top: SwarmMessageFrame.bodyGap),
- child: SizedBox(
- width: double.infinity,
- child: Text.rich(
- mentions.span(
- message.text,
- swarmChatText(16, height: 1.42),
+ for (final part in swarmTextParts(message.text))
+ if (part.code)
+ SwarmCodeBlock(code: part.text, name: part.name, onTap: onTap)
+ else
+ Semantics(
+ button: true,
+ hint: 'Reply to this message',
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: onTap,
+ child: Padding(
+ padding: const EdgeInsets.only(
+ top: SwarmMessageFrame.bodyGap,
+ ),
+ child: SizedBox(
+ width: double.infinity,
+ child: Text.rich(
+ mentions.span(part.text, swarmChatText(16, height: 1.42)),
),
),
),
),
),
- ),
for (final file in message.attachments)
SwarmAttachment(
file: file,
@@ -685,7 +688,12 @@ class SwarmFileChip extends StatelessWidget {
style: swarmChatText(14, color: color),
),
),
- const SizedBox(width: 8),
+ const SizedBox(width: AppSpace.xs),
+ Text(
+ '·',
+ style: swarmChatText(13, color: AppPalette.textFaint),
+ ),
+ const SizedBox(width: AppSpace.xs),
Text(
size,
style: swarmChatText(13, color: AppPalette.textFaint),
diff --git a/mobile/lib/swarm/swarm_post_line.dart b/mobile/lib/swarm/swarm_post_line.dart
new file mode 100644
index 000000000..a806e2b3a
--- /dev/null
+++ b/mobile/lib/swarm/swarm_post_line.dart
@@ -0,0 +1,72 @@
+import 'package:flutter/material.dart';
+import 'package:lucide_icons_flutter/lucide_icons.dart';
+
+import 'package:harness_mobile/phone/tty.dart';
+import 'package:harness_mobile/shared/theme/app_space.dart';
+import 'package:harness_mobile/shared/theme/app_theme.dart';
+
+import 'swarm_message_row.dart' show swarmChatText;
+
+/// A phone control's least height (design system, Phone: 44-point targets).
+const _finger = 44.0;
+
+/// The line under the person's post on its way, as Slack shows it (Dee,
+/// 10-29): "Sending…", then — its answer lost — "Not sent · Retry". A post
+/// that arrived carries no line.
+class SwarmPostLine extends StatelessWidget {
+ const SwarmPostLine({
+ super.key,
+ required this.sending,
+ required this.onRetry,
+ });
+
+ final bool sending;
+ final VoidCallback onRetry;
+
+ @override
+ Widget build(BuildContext context) {
+ final tty = Tty.of(context);
+ final color = sending ? AppPalette.textFaint : tty.yellow;
+ final style = swarmChatText(14, color: color);
+ return Semantics(
+ liveRegion: true,
+ child: Row(
+ children: [
+ Icon(
+ sending ? LucideIcons.loaderCircle : LucideIcons.triangleAlert,
+ size: 16,
+ color: color,
+ ),
+ const SizedBox(width: AppSpace.xs),
+ Text(sending ? 'Sending…' : 'Not sent', style: style),
+ if (!sending) ...[
+ Text(' · ', style: style),
+ Semantics(
+ button: true,
+ label: 'Retry',
+ excludeSemantics: true,
+ child: GestureDetector(
+ key: const ValueKey('swarm-resend-post'),
+ behavior: HitTestBehavior.opaque,
+ onTap: onRetry,
+ child: ConstrainedBox(
+ constraints: const BoxConstraints(
+ minHeight: _finger,
+ minWidth: _finger,
+ ),
+ child: Center(
+ widthFactor: 1,
+ child: Text(
+ 'Retry',
+ style: swarmChatText(14, color: tty.blue),
+ ),
+ ),
+ ),
+ ),
+ ),
+ ],
+ ],
+ ),
+ );
+ }
+}
diff --git a/mobile/lib/swarm/swarm_thread.dart b/mobile/lib/swarm/swarm_thread.dart
index 0a1084bd6..6ae805399 100644
--- a/mobile/lib/swarm/swarm_thread.dart
+++ b/mobile/lib/swarm/swarm_thread.dart
@@ -540,7 +540,7 @@ class SwarmThread extends ChangeNotifier implements SwarmFilesBox {
return false;
} catch (_) {
if (!current()) return false;
- error = 'Your reply is not confirmed. Send again to check it.';
+ error = 'Your reply was not sent. Retry to check it.';
return false;
} finally {
sending = false;
diff --git a/mobile/lib/swarm/swarm_thread_page.dart b/mobile/lib/swarm/swarm_thread_page.dart
index 4076a4167..7b94ae8dd 100644
--- a/mobile/lib/swarm/swarm_thread_page.dart
+++ b/mobile/lib/swarm/swarm_thread_page.dart
@@ -29,8 +29,7 @@ typedef SwarmThreadRow = Widget Function(
required VoidCallback onTap,
});
-/// Draws the person's reply on its way: "Sending…", then "Not confirmed"
-/// with Send again.
+/// Draws the person's reply on its way: "Sending…", then "Not sent · Retry"
typedef SwarmThreadPending = Widget Function(SwarmThread thread, String text);
/// One thread of a chat, full screen as Slack Mobile opens one: its root at
diff --git a/mobile/pubspec.lock b/mobile/pubspec.lock
index de0683c76..5d3725cac 100644
--- a/mobile/pubspec.lock
+++ b/mobile/pubspec.lock
@@ -419,7 +419,7 @@ packages:
source: hosted
version: "0.15.7"
http:
- dependency: transitive
+ dependency: "direct main"
description:
name: http
sha256: "87721a4a50b19c7f1d49001e51409bddc46303966ce89a65af4f4e6004896412"
diff --git a/mobile/pubspec.yaml b/mobile/pubspec.yaml
index 15865789c..8b3de4682 100644
--- a/mobile/pubspec.yaml
+++ b/mobile/pubspec.yaml
@@ -72,6 +72,9 @@ dependencies:
# files, and emptied on sign-out, Swarm off, account change and a Swarm's removal. Pinned
# exactly: it decides where the account's files lie on the phone.
flutter_cache_manager: 3.4.5
+ # The cache's fetch of a chat picture, sent with redirects refused (`SwarmFileFetch`), so
+ # nothing from another host is kept or drawn. Already in the app through flutter_cache_manager.
+ http: ^1.6.0
# Sending any other file to an agent — a PDF, a log, a zip — from the same key: the system's own
# document picker (Files on iOS, the Storage Access Framework on Android), which hands over one
# file the person chose and asks for no storage permission. The bytes go out as the CLI's
diff --git a/mobile/test/swarm/swarm_attachment_fakes.dart b/mobile/test/swarm/swarm_attachment_fakes.dart
index 14bf42065..3e8a610fc 100644
--- a/mobile/test/swarm/swarm_attachment_fakes.dart
+++ b/mobile/test/swarm/swarm_attachment_fakes.dart
@@ -81,7 +81,7 @@ class _Folder implements FileSystem {
/// A store over [root] and [storage], as the app's is over its temporary
/// folder and the network.
-SwarmAttachmentStore storeIn(io.Directory root, FakeFileStorage storage) =>
+SwarmAttachmentStore storeIn(io.Directory root, FileService storage) =>
SwarmAttachmentStore(
root: () async => root,
fileService: storage,
diff --git a/mobile/test/swarm/swarm_attachment_fetch_test.dart b/mobile/test/swarm/swarm_attachment_fetch_test.dart
new file mode 100644
index 000000000..9596feec5
--- /dev/null
+++ b/mobile/test/swarm/swarm_attachment_fetch_test.dart
@@ -0,0 +1,83 @@
+// The chat's picture fetch over an in-memory transport that answers as a
+// real one does: it keeps the picture the attachments host serves, and
+// refuses a redirect, so nothing from another host is fetched, kept or drawn.
+import 'dart:io';
+
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness_mobile/swarm/swarm_attachment_store.dart';
+import 'package:http/http.dart' as http;
+
+import 'swarm_attachment_fakes.dart';
+
+/// The attachments host and another one. A redirect is followed only when the
+/// request allows it, as `IOClient` does.
+class _Hosts extends http.BaseClient {
+ _Hosts(this.status);
+
+ /// What the attachments host answers: 200 with the picture, or a redirect
+ /// to the other host.
+ final int status;
+ int elsewhereHits = 0;
+ final sent = <http.BaseRequest>[];
+
+ @override
+ Future<http.StreamedResponse> send(http.BaseRequest request) async {
+ sent.add(request);
+ if (status == HttpStatus.ok) return _picture();
+ if (!request.followRedirects) {
+ return http.StreamedResponse(
+ const Stream.empty(),
+ status,
+ headers: {'location': 'https://elsewhere.example/b.png'},
+ );
+ }
+ elsewhereHits++;
+ return _picture();
+ }
+
+ http.StreamedResponse _picture() => http.StreamedResponse(
+ Stream.value(pixelPng),
+ HttpStatus.ok,
+ headers: {'content-type': 'image/png'},
+ );
+}
+
+void main() {
+ late Directory root;
+ final link = Uri.parse('https://cdn.harness.autonomous.ai/a1/a.png');
+
+ setUp(() => root = Directory.systemTemp.createTempSync('swarm-fetch-'));
+ tearDown(() {
+ if (root.existsSync()) root.deleteSync(recursive: true);
+ });
+
+ Future<SwarmAttachmentStore> storeOver(_Hosts hosts) async {
+ final store = storeIn(root, SwarmFileFetch(client: hosts));
+ await store.keepOnly('person-me');
+ return store;
+ }
+
+ test('keeps the picture the attachments host serves', () async {
+ final hosts = _Hosts(HttpStatus.ok);
+ final store = await storeOver(hosts);
+
+ final file = await store.file(link);
+ expect(await file.readAsBytes(), pixelPng);
+ expect(hosts.sent.single.url, link);
+ });
+
+ for (final status in [
+ HttpStatus.movedPermanently,
+ HttpStatus.found,
+ HttpStatus.temporaryRedirect,
+ ]) {
+ test('refuses a $status redirect: nothing from the other host', () async {
+ final hosts = _Hosts(status);
+ final store = await storeOver(hosts);
+
+ await expectLater(store.file(link), throwsA(anything));
+ expect(hosts.elsewhereHits, 0);
+ expect(hosts.sent.single.followRedirects, isFalse);
+ });
+ }
+}
diff --git a/mobile/test/swarm/swarm_attachment_test.dart b/mobile/test/swarm/swarm_attachment_test.dart
index 834097be7..8cbbb881e 100644
--- a/mobile/test/swarm/swarm_attachment_test.dart
+++ b/mobile/test/swarm/swarm_attachment_test.dart
@@ -1,5 +1,6 @@
import 'dart:async';
import 'dart:io';
+import 'dart:ui' as ui;
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -10,10 +11,11 @@ import 'package:harness_mobile/swarm/swarm_attachment_store.dart';
import 'swarm_attachment_fakes.dart';
-/// A picture in a chat shows in place: a skeleton in a fixed 4:3 box while it
-/// loads, then the picture in the same box, decoded at the box's size, and a
-/// tap opens it full screen. Every other file, and a picture that cannot be
-/// shown, keeps the chip.
+/// A picture in a chat shows in place, as Slack shows one (Dee, 10-29): a
+/// skeleton in a 4:3 box while it loads, then the picture at its own shape, up
+/// to 360 points each way and never wider than its message, decoded at the
+/// size it shows; a tap opens it full screen. Every other file, and a picture
+/// that cannot be shown, keeps the chip.
void main() {
late Directory root;
late FakeFileStorage storage;
@@ -100,19 +102,33 @@ void main() {
await tester.pump(const Duration(minutes: 1));
}
+ /// A real [width]×[height] PNG for the storage to serve.
+ Future<List<int>> png(WidgetTester tester, int width, int height) async =>
+ (await tester.runAsync(() async {
+ final recorder = ui.PictureRecorder();
+ Canvas(recorder).drawRect(
+ Rect.fromLTWH(0, 0, width.toDouble(), height.toDouble()),
+ Paint()..color = const Color(0xFF3060A0),
+ );
+ final image = await recorder.endRecording().toImage(width, height);
+ final data = await image.toByteData(format: ui.ImageByteFormat.png);
+ return data!.buffer.asUint8List();
+ }))!;
+
bool drawn(WidgetTester tester) => find
.descendant(of: preview, matching: find.byType(RawImage))
.evaluate()
.any((e) => (e.widget as RawImage).image != null);
testWidgets('a picture shows a skeleton in a 4:3 box while it loads, then '
- 'the picture in the same box', (tester) async {
+ 'the picture at its own shape', (tester) async {
+ storage.bytes = await png(tester, 720, 360);
storage.hold = Completer();
await pump(tester);
await tester.pump();
expect(preview, findsOneWidget);
- expect(tester.getSize(preview), const Size(240, 180));
+ expect(tester.getSize(preview), const Size(320, 240));
expect(
find.descendant(of: preview, matching: find.byType(Skeleton)),
findsOneWidget,
@@ -123,7 +139,7 @@ void main() {
storage.hold!.complete();
await until(tester, () => drawn(tester));
- expect(tester.getSize(preview), const Size(240, 180), reason: 'no jump');
+ expect(tester.getSize(preview), const Size(320, 160));
expect(
find.descendant(of: preview, matching: find.byType(Skeleton)),
findsNothing,
@@ -131,12 +147,32 @@ void main() {
final image = tester.widget<Image>(
find.descendant(of: preview, matching: find.byType(Image)),
);
- expect(image.image, isA<ResizeImage>());
- expect((image.image as ResizeImage).width, 480, reason: '240 at 2x');
+ final resized = image.image as ResizeImage;
+ expect(resized.policy, ResizeImagePolicy.fit);
+ expect((resized.width, resized.height), (640, 720), reason: 'at 2x');
await closed(tester);
});
+ for (final (width, height, message, shown) in [
+ (720, 360, 480.0, const Size(360, 180)),
+ (200, 800, 320.0, const Size(90, 360)),
+ (120, 80, 320.0, const Size(120, 80)),
+ ]) {
+ testWidgets(
+ 'a ${width}x$height picture in a ${message.round()} wide message '
+ 'shows at $shown',
+ (tester) async {
+ storage.bytes = await png(tester, width, height);
+ await pump(tester, width: message);
+ await until(tester, () => drawn(tester));
+
+ expect(tester.getSize(preview), shown);
+ await closed(tester);
+ },
+ );
+ }
+
testWidgets('a narrow message makes the box narrower, still 4:3', (
tester,
) async {
diff --git a/mobile/test/swarm/swarm_chat_pictures_test.dart b/mobile/test/swarm/swarm_chat_pictures_test.dart
index d3362f983..5656a8508 100644
--- a/mobile/test/swarm/swarm_chat_pictures_test.dart
+++ b/mobile/test/swarm/swarm_chat_pictures_test.dart
@@ -7,6 +7,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:harness_mobile/notify/system_notices.dart';
import 'package:harness_mobile/settings/experimental_features.dart';
import 'package:harness_mobile/shared/widgets/skeleton.dart';
+import 'package:harness_mobile/swarm/model.dart';
import 'package:harness_mobile/swarm/swarm_attachment_store.dart';
import 'package:harness_mobile/swarm/swarm_conversation_page.dart';
import 'package:harness_mobile/swarm/swarm_message_row.dart';
@@ -93,6 +94,25 @@ void main() {
return fake;
}
+ testWidgets('a file chip reads name · size, as Slack shows it', (
+ tester,
+ ) async {
+ final pdf = SuperTabAttachment.fromJson(
+ file('f2', 'plan.pdf', 'application/pdf'),
+ );
+ await tester.pumpWidget(
+ MaterialApp(
+ home: Scaffold(
+ body: SwarmFileChip(file: pdf, link: swarmAttachmentLink(pdf.url)),
+ ),
+ ),
+ );
+
+ for (final part in ['plan.pdf', '·', '2 KB']) {
+ expect(find.text(part), findsOneWidget);
+ }
+ });
+
testWidgets('a picture shows in place; a PDF keeps its chip', (tester) async {
// The app's store keeps this account's files, as the shell's keeper has
// it do. Real folders: outside the test's fake clock.
diff --git a/mobile/test/swarm/swarm_chat_test.dart b/mobile/test/swarm/swarm_chat_test.dart
index a6a9e9c5c..bb4395fcf 100644
--- a/mobile/test/swarm/swarm_chat_test.dart
+++ b/mobile/test/swarm/swarm_chat_test.dart
@@ -675,6 +675,11 @@ void main() {
expect(key('swarm-pending'), findsOneWidget);
expect(find.text('Sending…'), findsOneWidget);
expect(find.text('On it'), findsOneWidget);
+ // Under the message, as Slack shows it, not beside the name.
+ expect(
+ tester.getTopLeft(find.text('Sending…')).dy,
+ greaterThan(tester.getBottomLeft(find.text('On it')).dy),
+ );
fake.routes['$messages?after=1'] = (_) => {
'messages': [message('m2', 2, author: me, text: 'On it', minute: 5)],
@@ -688,8 +693,26 @@ void main() {
expect(find.text('On it'), findsOneWidget);
});
- testWidgets('a post whose answer was lost says it is not confirmed, and '
- 'Send again sends the same post', (tester) async {
+ testWidgets('a post lost to an unknown failure says to Retry, the word '
+ 'under it', (tester) async {
+ final fake = backend([message('m1', 1)]);
+ fake.routes[commands] = (_) => throw StateError('socket closed');
+ await pump(tester, fake);
+
+ await tester.enterText(find.byType(TextField), 'On it');
+ await tester.pump();
+ await tester.tap(key('swarm-send'));
+ await tester.pumpAndSettle();
+
+ expect(find.text('Not sent'), findsOneWidget);
+ expect(
+ find.text('Your message was not sent. Retry to check it.'),
+ findsOneWidget,
+ );
+ });
+
+ testWidgets('a post whose answer was lost reads Not sent under it, and '
+ 'Retry sends the same post', (tester) async {
final fake = backend([message('m1', 1)]);
var lost = true;
fake.routes[commands] = (_) => lost
@@ -702,8 +725,23 @@ void main() {
await tester.tap(key('swarm-send'));
await tester.pumpAndSettle();
- expect(find.text('Not confirmed'), findsOneWidget);
- expect(key('swarm-resend-post'), findsOneWidget);
+ expect(find.text('Not sent'), findsOneWidget);
+ expect(find.text('Not confirmed'), findsNothing);
+ expect(
+ tester.getTopLeft(find.text('Not sent')).dy,
+ greaterThan(tester.getBottomLeft(find.text('On it')).dy),
+ );
+ expect(
+ find.descendant(
+ of: key('swarm-resend-post'),
+ matching: find.text('Retry'),
+ ),
+ findsOneWidget,
+ );
+ expect(
+ tester.getSize(key('swarm-resend-post')).height,
+ greaterThanOrEqualTo(44),
+ );
lost = false;
await tester.tap(key('swarm-resend-post'));
@@ -716,7 +754,7 @@ void main() {
call.body!['operationId'],
};
expect(receipts, hasLength(1));
- expect(find.text('Not confirmed'), findsNothing);
+ expect(find.text('Not sent'), findsNothing);
});
testWidgets('a refused post says why and puts its text back in the field', (
@@ -804,14 +842,14 @@ void main() {
await tester.tap(key('swarm-send'));
await tester.pumpAndSettle();
- expect(find.text('Not confirmed'), findsOneWidget);
+ expect(find.text('Not sent'), findsOneWidget);
expect(composer(tester), up);
lost = false;
await tester.tap(key('swarm-resend-post'));
await tester.pumpAndSettle();
- expect(find.text('Not confirmed'), findsNothing);
+ expect(find.text('Not sent'), findsNothing);
expect(composer(tester), down);
});
@@ -1551,6 +1589,45 @@ void main() {
expect(key('swarm-reply-bar'), findsNothing);
});
+ testWidgets('a message that is only a code block still opens its thread: '
+ 'a tap on the code shows Reply, Copy only copies', (tester) async {
+ const code = '```\nflutter test\n```';
+ final page = [message('m5', 5, text: code, thread: 'm5')];
+ final fake = backend(page);
+ fake.routes['$messages?thread=m5'] = (_) => {
+ 'messages': page,
+ 'next': null,
+ 'threads': <Object>[],
+ };
+ await pump(tester, fake);
+ TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
+ .setMockMethodCallHandler(SystemChannels.platform, (_) async => null);
+ addTearDown(
+ () => TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
+ .setMockMethodCallHandler(SystemChannels.platform, null),
+ );
+
+ // Copy does its own thing: no Reply.
+ await tester.tap(find.text('Copy'));
+ await tester.pumpAndSettle();
+ expect(key('swarm-reply-m5'), findsNothing);
+
+ await tester.tap(find.text('flutter test'));
+ await tester.pumpAndSettle();
+ expect(
+ find.descendant(
+ of: key('swarm-reply-m5'),
+ matching: find.text('Reply in thread'),
+ ),
+ findsOneWidget,
+ );
+ await tester.tap(key('swarm-reply-m5'));
+ await tester.pumpAndSettle();
+
+ expect(fake.paths, contains('$messages?thread=m5'));
+ expect(inThread('flutter test'), findsOneWidget);
+ });
+
testWidgets('Replied in thread opens the thread it was written in', (
tester,
) async {
diff --git a/mobile/test/swarm/swarm_code_block_test.dart b/mobile/test/swarm/swarm_code_block_test.dart
new file mode 100644
index 000000000..f6a19cfb5
--- /dev/null
+++ b/mobile/test/swarm/swarm_code_block_test.dart
@@ -0,0 +1,152 @@
+import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness_mobile/phone/tty.dart';
+import 'package:harness_mobile/swarm/model.dart';
+import 'package:harness_mobile/swarm/swarm_code_block.dart';
+import 'package:harness_mobile/swarm/swarm_message_row.dart';
+
+/// A fenced block in a message, as Slack shows one on a phone (Dee, 10-29):
+/// monospace, its name, Copy, and a long one folded behind Show more.
+void main() {
+ group('swarmTextParts', () {
+ test('splits prose from fenced blocks, with each fence name', () {
+ expect(
+ swarmTextParts('Try:\n```main.dart\nfinal x = 1;\n```\nthen run it'),
+ [
+ (text: 'Try:', code: false, name: null),
+ (text: 'final x = 1;', code: true, name: 'main.dart'),
+ (text: 'then run it', code: false, name: null),
+ ],
+ );
+ });
+
+ test('a fence with no name, and text with no fence', () {
+ expect(swarmTextParts('```\nls -la\n```'), [
+ (text: 'ls -la', code: true, name: null),
+ ]);
+ expect(swarmTextParts('plain words'), [
+ (text: 'plain words', code: false, name: null),
+ ]);
+ });
+
+ test('an unclosed fence stays prose', () {
+ expect(swarmTextParts('see ```dart\nx'), [
+ (text: 'see ```dart\nx', code: false, name: null),
+ ]);
+ });
+ });
+
+ late List<String> copied;
+ setUp(() {
+ copied = [];
+ TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
+ .setMockMethodCallHandler(SystemChannels.platform, (call) async {
+ if (call.method == 'Clipboard.setData') {
+ copied.add((call.arguments as Map)['text'] as String);
+ }
+ return null;
+ });
+ });
+ tearDown(
+ () => TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
+ .setMockMethodCallHandler(SystemChannels.platform, null),
+ );
+
+ Future<void> show(WidgetTester tester, String text) async {
+ final message = SuperTabMessage.fromJson({
+ 'id': 'm1',
+ 'conversationId': 'g1',
+ 'text': text,
+ 'sequence': 1,
+ 'author': {'kind': 'agent', 'id': 'agent-lead', 'name': 'Lead'},
+ 'createdAt': DateTime.now().toUtc().toIso8601String(),
+ });
+ await tester.pumpWidget(
+ MaterialApp(
+ home: Scaffold(
+ body: ListView(
+ children: [
+ SwarmMessageRow(
+ message: message,
+ name: 'River',
+ look: (picture: null, status: null),
+ role: 'PM',
+ mentions: SwarmMentions(const []),
+ grouped: false,
+ lit: false,
+ quote: null,
+ actions: false,
+ onTap: () {},
+ onReply: null,
+ ),
+ ],
+ ),
+ ),
+ ),
+ );
+ await tester.pumpAndSettle();
+ }
+
+ testWidgets('a code block is monospace, named, and Copy copies it', (
+ tester,
+ ) async {
+ await show(tester, 'Try:\n```main.dart\nfinal x = 1;\nprint(x);\n```');
+
+ expect(find.text('Try:'), findsOneWidget);
+ final code = find.text('final x = 1;\nprint(x);');
+ expect(code, findsOneWidget);
+ expect(
+ tester.widget<Text>(code).style?.fontFamily,
+ Tty.of(tester.element(code)).fontFamily,
+ );
+ expect(find.text('main.dart'), findsOneWidget);
+ expect(find.textContaining('```'), findsNothing);
+ await tester.tap(find.text('Copy'));
+ await tester.pump();
+ expect(copied, ['final x = 1;\nprint(x);']);
+ });
+
+ testWidgets('a long block folds with Show more, and Copy takes it all', (
+ tester,
+ ) async {
+ final lines = [for (var i = 1; i <= 30; i++) 'line $i'];
+ await show(tester, '```\n${lines.join('\n')}\n```');
+
+ expect(find.text(lines.take(12).join('\n')), findsOneWidget);
+ expect(find.textContaining('line 13'), findsNothing);
+ await tester.tap(find.text('Show more'));
+ await tester.pump();
+ expect(find.text(lines.join('\n')), findsOneWidget);
+ await tester.ensureVisible(find.text('Show less'));
+ await tester.pump();
+ await tester.tap(find.text('Show less'));
+ await tester.pump();
+ expect(find.textContaining('line 13'), findsNothing);
+ await tester.tap(find.text('Copy'));
+ await tester.pump();
+ expect(copied, [lines.join('\n')]);
+ });
+
+ testWidgets('a short block has no Show more', (tester) async {
+ await show(
+ tester,
+ '```\n${[for (var i = 1; i <= 12; i++) 'l$i'].join('\n')}\n```',
+ );
+
+ expect(find.text('Show more'), findsNothing);
+ });
+
+ testWidgets('every Copy and Show more is a finger tall', (tester) async {
+ final lines = [for (var i = 1; i <= 30; i++) 'line $i'];
+ await show(tester, '```\n${lines.join('\n')}\n```');
+
+ for (final label in ['Copy', 'Show more']) {
+ final control = find.ancestor(
+ of: find.text(label),
+ matching: find.byType(GestureDetector),
+ );
+ expect(tester.getSize(control.first).height, greaterThanOrEqualTo(44));
+ }
+ });
+}
diff --git a/mobile/test/swarm/swarm_rows_shots_test.dart b/mobile/test/swarm/swarm_rows_shots_test.dart
new file mode 100644
index 000000000..5f0514360
--- /dev/null
+++ b/mobile/test/swarm/swarm_rows_shots_test.dart
@@ -0,0 +1,237 @@
+import 'dart:convert';
+import 'dart:io';
+import 'dart:ui' as ui;
+
+import 'package:flutter/material.dart';
+import 'package:flutter/rendering.dart';
+import 'package:flutter/services.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness_mobile/notify/system_notices.dart';
+import 'package:harness_mobile/settings/experimental_features.dart';
+import 'package:harness_mobile/shared/theme/app_theme.dart';
+import 'package:harness_mobile/shared/theme/color_palette.dart';
+import 'package:harness_mobile/swarm/swarm_attachment_store.dart';
+import 'package:harness_mobile/swarm/swarm_conversation_page.dart';
+import 'package:harness_mobile/swarm/swarm_message_row.dart';
+import 'package:harness_mobile/swarm/swarm_request.dart';
+import 'package:harness_mobile/swarm/swarm_session.dart';
+
+import '../voice_fakes.dart';
+import 'swarm_attachment_fakes.dart';
+import 'swarm_fixture.dart';
+
+/// Review screenshots of the phone chat's rows as Slack shows them (Dee,
+/// 10-29): a picture at its own shape, a code block with Copy, a file chip,
+/// and a post that was not sent, in both phone themes, from made-up data.
+final shots = Platform.environment['SWARM_ROW_SHOTS'];
+
+/// A 1440×900 stand-in for a pasted screenshot: a window with a sidebar.
+Future<List<int>> _screenshot() async {
+ final recorder = ui.PictureRecorder();
+ final canvas = Canvas(recorder)
+ ..drawRect(
+ const Rect.fromLTWH(0, 0, 1440, 900),
+ Paint()..color = const Color(0xFFF2F4F8),
+ )
+ ..drawRect(
+ const Rect.fromLTWH(0, 0, 320, 900),
+ Paint()..color = const Color(0xFF2B3442),
+ );
+ for (var i = 0; i < 6; i++) {
+ canvas.drawRRect(
+ RRect.fromLTRBR(
+ 400,
+ 80.0 + i * 120,
+ 1360,
+ 160.0 + i * 120,
+ const Radius.circular(16),
+ ),
+ Paint()..color = const Color(0xFFDCE3EE),
+ );
+ }
+ final image = await recorder.endRecording().toImage(1440, 900);
+ final data = await image.toByteData(format: ui.ImageByteFormat.png);
+ return data!.buffer.asUint8List();
+}
+
+void main() {
+ setUpAll(() async {
+ if (shots == null || !Platform.isMacOS) return;
+ final sf = ByteData.sublistView(
+ await File('/System/Library/Fonts/SFNS.ttf').readAsBytes(),
+ );
+ for (final family in ['.AppleSystemUIFont', 'Roboto']) {
+ await (FontLoader(family)..addFont(Future.value(sf))).load();
+ }
+ final mono = ByteData.sublistView(
+ await File('/System/Library/Fonts/SFNSMono.ttf').readAsBytes(),
+ );
+ for (final family in ['.AppleSystemUIFontMonospaced', 'monospace']) {
+ await (FontLoader(family)..addFont(Future.value(mono))).load();
+ }
+ final manifest =
+ jsonDecode(await rootBundle.loadString('FontManifest.json')) as List;
+ for (final entry in manifest.cast<Map<String, dynamic>>()) {
+ final loader = FontLoader(entry['family'] as String);
+ for (final font in (entry['fonts'] as List).cast<Map>()) {
+ loader.addFont(rootBundle.load(font['asset'] as String));
+ }
+ await loader.load();
+ }
+ });
+
+ testWidgets('the chat rows, in both phone themes', (tester) async {
+ const messages = '/api/super-tabs/$tab/conversations/g1/messages';
+ const commands = '/api/super-tabs/$tab/commands';
+ await tester.binding.setSurfaceSize(const Size(375, 812));
+ addTearDown(() => tester.binding.setSurfaceSize(null));
+ final root = Directory.systemTemp.createTempSync('swarm-row-shots-');
+ addTearDown(() => root.deleteSync(recursive: true));
+ final storage = FakeFileStorage()
+ ..bytes = (await tester.runAsync(_screenshot))!;
+ final original = swarmAttachments;
+ swarmAttachments = storeIn(root, storage);
+ addTearDown(() => swarmAttachments = original);
+ await tester.runAsync(() => swarmAttachments.keepOnly(me));
+
+ for (final palette in [HarnessPalette.graphite, HarnessPalette.paper]) {
+ final brightness = palette.brightness;
+ AppTheme.palette.value = palette;
+ AppTheme.brightness.value = brightness;
+ final fake = FakeSwarm();
+ fake.routes['/api/super-tabs/list'] = (_) => {
+ 'tabs': [
+ {'id': tab, 'name': 'OpenHarness', 'ownerId': me},
+ ],
+ 'next': null,
+ };
+ fake.routes['/api/super-tabs/$tab/parts'] = (_) => {
+ ...firstLoad(
+ groups: [
+ groupData(
+ 'g1',
+ title: 'Pilot',
+ agentIds: ['agent-lead'],
+ lastMessageSequence: 2,
+ ),
+ ],
+ ),
+ 'members': [part(me, 1, person(me))],
+ };
+ fake.routes['/api/super-tabs/$tab/changes'] = (_) =>
+ changes(cursor: 'c2');
+ fake.routes['/api/super-tabs/$tab/decisions?state=open'] = (_) => {
+ 'decisions': <Object>[],
+ };
+ fake.routes['/api/super-tabs/$tab/mentions?state=waiting'] = (_) => {
+ 'mentions': <Object>[],
+ };
+ fake.routes[messages] = (_) => {
+ 'messages': [
+ {
+ 'id': 'm1',
+ 'conversationId': 'g1',
+ 'text': 'this is so confusing. how do i create a new project now?',
+ 'sequence': 1,
+ 'author': {'kind': 'person', 'id': me, 'name': 'dee'},
+ 'attachments': [
+ {
+ 'id': 'f1',
+ 'name': 'projects.png',
+ 'mime': 'image/png',
+ 'size': 182 * 1024,
+ 'url': 'https://$swarmAttachmentHost/f1/projects.png',
+ },
+ ],
+ 'createdAt': DateTime.utc(2026, 10, 29, 11, 57).toIso8601String(),
+ },
+ {
+ 'id': 'm2',
+ 'conversationId': 'g1',
+ 'text':
+ 'New Project is in the sidebar now. The setting it reads:\n'
+ '```main.dart\nfinal project = Project.create(name: name);\n'
+ 'await sidebar.select(project);\n```',
+ 'sequence': 2,
+ 'author': {'kind': 'agent', 'id': 'agent-lead', 'name': 'River'},
+ 'attachments': [
+ {
+ 'id': 'f2',
+ 'name': 'report.pdf',
+ 'mime': 'application/pdf',
+ 'size': 120 * 1024,
+ 'url': 'https://$swarmAttachmentHost/f2/report.pdf',
+ },
+ ],
+ 'createdAt': DateTime.utc(2026, 10, 29, 11, 58).toIso8601String(),
+ },
+ ],
+ 'next': null,
+ };
+ fake.routes[commands] = (_) =>
+ throw const SuperTabFailure('MACHINE_UNAVAILABLE', 'No computer.');
+ final host = SwarmHost(
+ accountId: () => me,
+ account: ValueNotifier<String?>(me),
+ request: fake.request,
+ notices: SilentSystemNotices(),
+ features: ExperimentalFeaturesStore(storage: MemoryKeyValueStore())
+ ..value = {PhoneExperiment.swarm},
+ readMarks: MemoryKeyValueStore(),
+ )..foreground = false;
+ final boundary = GlobalKey();
+ await tester.pumpWidget(
+ RepaintBoundary(
+ key: boundary,
+ child: MaterialApp(
+ debugShowCheckedModeBanner: false,
+ theme: buildAppTheme(brightness: brightness),
+ builder: (_, child) => SwarmScope(notifier: host, child: child!),
+ home: const SwarmConversationPage(
+ swarmId: tab,
+ conversationId: 'g1',
+ ),
+ ),
+ ),
+ );
+ final picture = find.byKey(const ValueKey('swarm-attachment-preview-f1'));
+ for (var i = 0; i < 100; i++) {
+ await tester.runAsync(
+ () => Future<void>.delayed(const Duration(milliseconds: 20)),
+ );
+ await tester.pump();
+ if (picture.evaluate().isNotEmpty &&
+ find
+ .descendant(of: picture, matching: find.byType(RawImage))
+ .evaluate()
+ .any((e) => (e.widget as RawImage).image != null)) {
+ break;
+ }
+ }
+ await tester.enterText(find.byType(TextField), 'Can it be the default?');
+ await tester.pump();
+ await tester.tap(find.byKey(const ValueKey('swarm-send')));
+ for (var i = 0; i < 20; i++) {
+ await tester.pump(const Duration(milliseconds: 50));
+ }
+ expect(find.text('Not sent'), findsOneWidget);
+ FocusManager.instance.primaryFocus?.unfocus();
+ await tester.pump(const Duration(milliseconds: 300));
+
+ await tester.runAsync(() async {
+ final image =
+ await (boundary.currentContext!.findRenderObject()!
+ as RenderRepaintBoundary)
+ .toImage(pixelRatio: 3);
+ final png = await image.toByteData(format: ui.ImageByteFormat.png);
+ await Directory(shots!).create(recursive: true);
+ await File('$shots/phone-rows-${brightness.name}.png')
+ .writeAsBytes(png!.buffer.asUint8List());
+ image.dispose();
+ });
+ await tester.pumpWidget(const SizedBox());
+ host.dispose();
+ await tester.pump(const Duration(minutes: 1));
+ }
+ }, skip: shots == null);
+}
diff --git a/mobile/test/swarm/swarm_thread_test.dart b/mobile/test/swarm/swarm_thread_test.dart
index f08047762..3bd4c49c6 100644
--- a/mobile/test/swarm/swarm_thread_test.dart
+++ b/mobile/test/swarm/swarm_thread_test.dart
@@ -425,7 +425,7 @@ void main() {
expect(await t.send(), isFalse);
expect(t.unconfirmed, isTrue);
expect(t.pending, 'Once only');
- expect(t.error, contains('not confirmed'));
+ expect(t.error, contains('not sent'));
lost = false;
expect(await t.send(), isTrue);