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: rename your Buddy from its chat, as on Desktop (Tony, task 7) (#2466)
harness-for-autonomous[bot]e98aea2303ce
diff --git a/mobile/lib/swarm/swarm_buddy.dart b/mobile/lib/swarm/swarm_buddy.dartindex 0f4feb804..1b195b098 100644--- a/mobile/lib/swarm/swarm_buddy.dart+++ b/mobile/lib/swarm/swarm_buddy.dart@@ -485,8 +485,41 @@ Future<void> removeSwarmBuddy(SwarmReader reader, String projectId) async {await reader.refresh();}+/// What the person's Buddy is called until they name it, as the backend+/// names it (`defaultBuddyName`): "tony's Buddy".+String swarmBuddyDefaultName(SwarmReader reader) {+ final email = reader.snapshot?.people+ .where((p) => p.id == reader.accountId)+ .firstOrNull+ ?.email;+ return "${(email ?? '').split('@').first}'s Buddy";+}++/// The name the person chose for the Buddy of their chat [chatId]; null for+/// the default.+String? swarmBuddyChosenName(SwarmReader reader, String chatId) =>+ reader.snapshot?.conversation(chatId)?.buddyName;++/// Names the person's Buddy from its chat [chatId] (backend buddy.rename, the+/// desktop's `renameBuddy`), or back to the default when [name] is empty:+/// everyone in the Swarm sees it. By the chat, never the project, so it holds+/// for one Buddy per Swarm too. Reads the Swarm again; a refusal throws.+Future<void> renameSwarmBuddy(+ SwarmReader reader,+ String chatId,+ String name,+) async {+ final trimmed = name.trim();+ await _command(reader, {+ 'type': 'buddy.rename',+ 'conversationId': chatId,+ 'name': trimmed.isEmpty ? null : trimmed,+ });+ await reader.refresh();+}+/// What the person does to their Buddy in one project from its chat: start-/// it, start it again, remove it. One at a time — a second tap while one is+/// it, start it again, rename it, remove it. One at a time — a second tap while one is/// under way does nothing — and what went wrong with the last, as a sentence/// to show; it lasts until the next.class SwarmBuddyActions extends ChangeNotifier {@@ -551,6 +584,38 @@ class SwarmBuddyActions extends ChangeNotifier {"Couldn't remove your Buddy. Try again.",);+ /// Names the Buddy of chat [chatId] ([renameSwarmBuddy]): whether it was+ /// renamed, and the refusal for the rename's own dialog to say, never kept+ /// in [error]. While another action is under way it does nothing; a+ /// refusal that comes once the Swarm was let go says nothing.+ Future<({bool renamed, String? error})> rename(+ String chatId,+ String name,+ ) async {+ if (_busy || _disposed) return (renamed: false, error: null);+ final generation = reader.generation;+ _busy = true;+ notifyListeners();+ String? error;+ try {+ await renameSwarmBuddy(reader, chatId, name);+ } on SuperTabFailure catch (failure) {+ error = failure.message;+ } catch (_) {+ error = "Couldn't rename your Buddy. Try again.";+ }+ if (_disposed) return (renamed: false, error: null);+ _busy = false;+ notifyListeners();+ // Access lost, or the Swarm read anew from nothing: the refusal is for a+ // chat no longer shown.+ if (error != null &&+ (reader.accessRevoked || generation != reader.generation)) {+ return (renamed: false, error: null);+ }+ return (renamed: error == null, error: error);+ }+Future<void> _run(Future<Object?> Function() act, String fallback) async {if (_busy || _disposed) return;_busy = true;diff --git a/mobile/lib/swarm/swarm_buddy_chat.dart b/mobile/lib/swarm/swarm_buddy_chat.dartindex a57145dbb..e666b966c 100644--- a/mobile/lib/swarm/swarm_buddy_chat.dart+++ b/mobile/lib/swarm/swarm_buddy_chat.dart@@ -435,28 +435,50 @@ class _Field extends StatelessWidget {static const _labelWidth = AppSpace.xl * 3;}-/// At the end of the person's Buddy chat's header, while their Buddy runs-/// and they may write: ⋮, whose one row, Remove Buddy, asks first, then-/// stops it; the chat stays (the desktop's Buddy options). Nothing-/// otherwise.+/// At the end of the person's own Buddy chat's header, while they may+/// write: ⋮, with Rename Buddy, and Remove Buddy while one runs, which asks+/// first, then stops it; the chat stays (the desktop's Buddy options).+/// Nothing in anyone else's Buddy chat.class SwarmBuddyMenuButton extends StatelessWidget {- const SwarmBuddyMenuButton({super.key, required this.actions});+ const SwarmBuddyMenuButton({+ super.key,+ required this.actions,+ required this.chatId,+ });final SwarmBuddyActions actions;- Future<void> _open(BuildContext context) => showPhoneSheet(+ /// The Buddy chat it is on: what Rename names the Buddy of, by its id+ /// rather than its project. Null while that chat is not known yet.+ final String? chatId;++ Future<void> _open(BuildContext context, String chatId) => showPhoneSheet(context,title: swarmBuddyName(actions.reader, actions.projectId),actions: [PhoneSheetAction(- icon: LucideIcons.userMinus,- label: 'Remove Buddy',- destructive: true,- onTap: () => unawaited(_confirmRemove(context)),+ icon: LucideIcons.pencil,+ label: 'Rename Buddy',+ onTap: () => unawaited(_rename(context, chatId)),),+ if (swarmBuddy(actions.reader, actions.projectId) != null)+ PhoneSheetAction(+ icon: LucideIcons.userMinus,+ label: 'Remove Buddy',+ destructive: true,+ onTap: () => unawaited(_confirmRemove(context)),+ ),],);+ Future<void> _rename(BuildContext context, String chatId) async {+ if (!context.mounted) return;+ await showDialog<void>(+ context: context,+ builder: (_) => SwarmRenameBuddyDialog(actions: actions, chatId: chatId),+ );+ }+Future<void> _confirmRemove(BuildContext context) async {if (!context.mounted) return;final remove = await showDialog<bool>(@@ -497,7 +519,9 @@ class SwarmBuddyMenuButton extends StatelessWidget {listenable: Listenable.merge([actions.reader, actions]),builder: (context, _) {final reader = actions.reader;- if (swarmBuddy(reader, actions.projectId) == null ||+ final chat = chatId;+ if (chat == null ||+ !swarmIsOwnBuddyChat(reader, chat) ||!swarmCanWrite(reader)) {return const SizedBox.shrink();}@@ -515,7 +539,7 @@ class SwarmBuddyMenuButton extends StatelessWidget {? null: () {HapticFeedback.selectionClick();- unawaited(_open(context));+ unawaited(_open(context, chat));},child: SizedBox.square(dimension: minTouchTarget,@@ -543,3 +567,155 @@ class SwarmBuddyMenuButton extends StatelessWidget {);}}++/// Rename your Buddy (the desktop's, mockup confirmed by Diego, 10-29;+/// without its explanatory lines, Tony's design language): the name everyone+/// in the Swarm sees, empty for the default the field's hint shows. The+/// backend checks it and its words show here. It closes once the chat is no+/// longer the person's to rename in: access lost, signed out, or no longer+/// allowed to write.+class SwarmRenameBuddyDialog extends StatefulWidget {+ const SwarmRenameBuddyDialog({+ super.key,+ required this.actions,+ required this.chatId,+ });++ final SwarmBuddyActions actions;+ final String chatId;++ @override+ State<SwarmRenameBuddyDialog> createState() => _SwarmRenameBuddyDialogState();+}++class _SwarmRenameBuddyDialogState extends State<SwarmRenameBuddyDialog> {+ /// The backend's limit: a longer name is refused there anyway.+ static const _maxLength = 32;++ late final _name = TextEditingController(+ text: swarmBuddyChosenName(widget.actions.reader, widget.chatId) ?? '',+ );+ late final Listenable _source = Listenable.merge([+ widget.actions.reader,+ widget.actions,+ ]);+ bool _saving = false, _closed = false;+ String? _error;++ @override+ void initState() {+ super.initState();+ _source.addListener(_changed);+ }++ @override+ void dispose() {+ _source.removeListener(_changed);+ _name.dispose();+ super.dispose();+ }++ bool get _allowed {+ final reader = widget.actions.reader;+ return !reader.accessRevoked &&+ swarmCanWrite(reader) &&+ swarmIsOwnBuddyChat(reader, widget.chatId);+ }++ void _changed() {+ if (!mounted) return;+ if (!_allowed) {+ _close();+ } else {+ setState(() {});+ }+ }++ void _close() {+ if (_closed || !mounted) return;+ _closed = true;+ Navigator.of(context).pop();+ }++ Future<void> _save() async {+ if (_saving || widget.actions.busy || !_allowed) return;+ setState(() {+ _saving = true;+ _error = null;+ });+ final answer = await widget.actions.rename(widget.chatId, _name.text);+ if (!mounted || _closed) return;+ if (answer.renamed) {+ _close();+ return;+ }+ setState(() {+ _saving = false;+ _error = answer.error;+ });+ }++ @override+ Widget build(BuildContext context) {+ AppTheme.watch(context);+ final busy = _saving || widget.actions.busy;+ return AlertDialog(+ title: Text(+ 'Rename your Buddy',+ style: AppType.heading(color: AppPalette.textPrimary),+ ),+ content: Column(+ mainAxisSize: MainAxisSize.min,+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ TextField(+ key: const ValueKey('swarm-buddy-name'),+ controller: _name,+ autofocus: true,+ enabled: !busy,+ maxLength: _maxLength,+ textInputAction: TextInputAction.done,+ style: AppType.body(color: AppPalette.textPrimary),+ decoration: InputDecoration(+ hintText: swarmBuddyDefaultName(widget.actions.reader),+ hintStyle: TextStyle(color: AppPalette.textFaint),+ counterText: '',+ filled: true,+ fillColor: AppPalette.swarmField,+ border: OutlineInputBorder(+ borderRadius: BorderRadius.circular(AppControl.radius),+ borderSide: BorderSide.none,+ ),+ ),+ onSubmitted: (_) => unawaited(_save()),+ ),+ if (_error case final error?)+ Padding(+ padding: const EdgeInsets.only(top: AppSpace.s),+ child: Text(+ error,+ key: const ValueKey('swarm-buddy-name-error'),+ style: AppType.caption(color: AppColors.danger),+ ),+ ),+ ],+ ),+ actions: [+ SwarmButton(+ key: const ValueKey('swarm-buddy-name-cancel'),+ label: 'Cancel',+ style: SwarmButtonStyle.link,+ onPressed: busy ? null : _close,+ ),+ SwarmButton(+ key: const ValueKey('swarm-buddy-name-save'),+ label: 'Save',+ style: SwarmButtonStyle.fill,+ busy: busy,+ busyLabel: 'Saving…',+ onPressed: busy ? null : () => unawaited(_save()),+ ),+ ],+ );+ }+}diff --git a/mobile/lib/swarm/swarm_conversation_page.dart b/mobile/lib/swarm/swarm_conversation_page.dartindex 916aa9ad9..104e4ab92 100644--- a/mobile/lib/swarm/swarm_conversation_page.dart+++ b/mobile/lib/swarm/swarm_conversation_page.dart@@ -1213,9 +1213,12 @@ class _SwarmConversationPageState extends State<SwarmConversationPage>? view.title: null,project: view.project,- // The person's own Buddy chat: Remove Buddy.+ // The person's own Buddy chat: Rename Buddy, Remove Buddy.action: switch (_buddy) {- final buddy? => SwarmBuddyMenuButton(actions: buddy),+ final buddy? => SwarmBuddyMenuButton(+ actions: buddy,+ chatId: widget.conversationId,+ ),null => null,},),diff --git a/mobile/lib/swarm/swarm_project_page.dart b/mobile/lib/swarm/swarm_project_page.dartindex 4119b6ecb..4c38bc4af 100644--- a/mobile/lib/swarm/swarm_project_page.dart+++ b/mobile/lib/swarm/swarm_project_page.dart@@ -534,7 +534,10 @@ class _SwarmProjectPageState extends State<SwarmProjectPage> {mainAxisSize: MainAxisSize.min,children: [if (_tab == SwarmProjectTab.buddy && _buddy != null)- SwarmBuddyMenuButton(actions: _buddy!),+ SwarmBuddyMenuButton(+ actions: _buddy!,+ chatId: swarmBuddyChat(_buddy!.reader, widget.projectId)?.id,+ ),if (_homeC)_ProjectMenu(onLeaderboard: _openLeaderboardSheet,diff --git a/mobile/test/swarm/swarm_buddy_chat_test.dart b/mobile/test/swarm/swarm_buddy_chat_test.dartindex 72f6271e2..4beda4bea 100644--- a/mobile/test/swarm/swarm_buddy_chat_test.dart+++ b/mobile/test/swarm/swarm_buddy_chat_test.dart@@ -577,7 +577,13 @@ void main() {),findsOneWidget,);- expect(key('swarm-buddy-menu'), findsNothing, reason: 'none to remove');+ // Renamed before it runs, as on Desktop; nothing to remove yet.+ await tester.tap(key('swarm-buddy-menu'));+ await tester.pumpAndSettle();+ expect(find.text('Rename Buddy'), findsOneWidget);+ expect(find.text('Remove Buddy'), findsNothing, reason: 'none to remove');+ await tester.tapAt(const Offset(10, 10));+ await tester.pumpAndSettle();startsNext(fake, [buddyStartData('s1', chatId: chat, machineId: 'mac-1'),diff --git a/mobile/test/swarm/swarm_buddy_rename_shots_test.dart b/mobile/test/swarm/swarm_buddy_rename_shots_test.dartnew file mode 100644index 000000000..bcb6ca0cc--- /dev/null+++ b/mobile/test/swarm/swarm_buddy_rename_shots_test.dart@@ -0,0 +1,191 @@+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_conversation_page.dart';+import 'package:harness_mobile/swarm/swarm_request.dart';+import 'package:harness_mobile/swarm/swarm_session.dart';++import '../voice_fakes.dart';+import 'swarm_fixture.dart';++/// Review screenshots of Rename your Buddy in the real Buddy chat, 390 points+/// wide in both phone themes, from made-up data, to the folder+/// `SWARM_BUDDY_RENAME_SHOTS` names: the ⋮ sheet, the dialog, and a name the+/// server refused.+final shots = Platform.environment['SWARM_BUDDY_RENAME_SHOTS'];++void main() {+ setUpAll(() async {+ if (shots == null || !Platform.isMacOS) return;+ final sf = ByteData.sublistView(+ await File('/System/Library/Fonts/SFNS.ttf').readAsBytes(),+ );+ for (final family in ['.AppleSystemUIFont', 'Roboto']) {+ await (FontLoader(family)..addFont(Future.value(sf))).load();+ }+ final mono = ByteData.sublistView(+ await File('/System/Library/Fonts/SFNSMono.ttf').readAsBytes(),+ );+ for (final family in ['.AppleSystemUIFontMonospaced', 'monospace']) {+ await (FontLoader(family)..addFont(Future.value(mono))).load();+ }+ final manifest =+ jsonDecode(await rootBundle.loadString('FontManifest.json')) as List;+ for (final entry in manifest.cast<Map<String, dynamic>>()) {+ final loader = FontLoader(entry['family'] as String);+ for (final font in (entry['fonts'] as List).cast<Map>()) {+ loader.addFont(rootBundle.load(font['asset'] as String));+ }+ await loader.load();+ }+ });++ testWidgets('Rename your Buddy, in both phone themes', (tester) async {+ const chat = 'buddy-me';+ addTearDown(() => tester.binding.setSurfaceSize(null));+ for (final palette in [HarnessPalette.graphite, HarnessPalette.paper]) {+ final brightness = palette.brightness;+ AppTheme.palette.value = palette;+ AppTheme.brightness.value = brightness;+ await tester.binding.setSurfaceSize(const Size(390, 640));+ for (final state in ['menu', 'dialog', 'refused']) {+ 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: [+ {+ ...buddyChatData(chat, agentIds: ['agent-wren']),+ 'buddyName': 'Wren',+ },+ ],+ agents: [+ agent('agent-lead', name: 'Lead', displayName: 'River'),+ buddyData('agent-wren', displayName: 'Wren'),+ ],+ ),+ 'members': [+ part(me, 1, {...person(me), 'email': '[email protected]'}),+ ],+ };+ fake.routes['/api/super-tabs/$tab/changes'] = (_) =>+ changes(cursor: 'c2');+ fake.routes['/api/super-tabs/$tab/decisions?state=open'] = (_) => {+ 'decisions': <Object>[],+ };+ fake.routes['/api/super-tabs/$tab/mentions?state=waiting'] = (_) => {+ 'mentions': <Object>[],+ };+ fake.routes['/api/super-tabs/$tab/conversations/$chat/messages'] =+ (_) => {+ 'messages': [+ {+ 'id': 'm1',+ 'conversationId': chat,+ 'text': 'Want me to sketch the release notes?',+ 'sequence': 1,+ 'author': {+ 'kind': 'agent',+ 'id': 'agent-wren',+ 'name': 'Wren',+ },+ 'createdAt': DateTime.now()+ .subtract(const Duration(minutes: 4))+ .toUtc()+ .toIso8601String(),+ },+ ],+ 'next': null,+ };+ fake.routes['/api/super-tabs/$tab/commands'] = (_) =>+ throw const SuperTabFailure(+ 'BUDDY_NAME_TAKEN',+ 'River is taken in this Swarm. Choose another.',+ statusCode: 409,+ );+ 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: chat,+ ),+ ),+ ),+ );+ await tester.pumpAndSettle();+ await tester.tap(find.byKey(const ValueKey('swarm-buddy-menu')));+ await tester.pumpAndSettle();+ if (state != 'menu') {+ await tester.tap(find.text('Rename Buddy'));+ await tester.pumpAndSettle();+ if (state == 'refused') {+ await tester.enterText(+ find.byKey(const ValueKey('swarm-buddy-name')),+ 'River',+ );+ await tester.tap(+ find.byKey(const ValueKey('swarm-buddy-name-save')),+ );+ await tester.pumpAndSettle();+ expect(+ find.text('River is taken in this Swarm. Choose another.'),+ findsOneWidget,+ );+ } else {+ expect(find.text('Rename your Buddy'), findsOneWidget);+ }+ // The caret's blink is not in the picture.+ FocusManager.instance.primaryFocus?.unfocus();+ await tester.pumpAndSettle();+ } else {+ expect(find.text('Rename Buddy'), findsOneWidget);+ }+ expect(tester.takeException(), isNull);+ await tester.runAsync(() async {+ final image =+ await (boundary.currentContext!.findRenderObject()!+ as RenderRepaintBoundary)+ .toImage(pixelRatio: 3);+ final png = await image.toByteData(format: ui.ImageByteFormat.png);+ await Directory(shots!).create(recursive: true);+ await File(+ '$shots/phone-buddy-rename-$state-${brightness.name}-390.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_buddy_rename_test.dart b/mobile/test/swarm/swarm_buddy_rename_test.dartnew file mode 100644index 000000000..e0d2dc2a1--- /dev/null+++ b/mobile/test/swarm/swarm_buddy_rename_test.dart@@ -0,0 +1,372 @@+import 'dart:async';++import 'package:flutter/material.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' as grid;+import 'package:harness_mobile/swarm/swarm_conversation_page.dart';+import 'package:harness_mobile/swarm/swarm_request.dart';+import 'package:harness_mobile/swarm/swarm_session.dart';++import '../voice_fakes.dart';+import 'swarm_fixture.dart';++/// Rename your Buddy from its chat's ⋮ (the desktop's Rename Buddy…,+/// `buddy.rename`): by the chat's id, a name or empty for the default, the+/// server's refusal said in the dialog, and nothing for anyone else's Buddy.+void main() {+ const chat = 'buddy-me';+ const commands = '/api/super-tabs/$tab/commands';++ /// One Swarm where the person has their Buddy chat [chatId] in Mobile,+ /// owned by [owner], named [named] (null for the default), with Wren+ /// running in it unless [running] is false; each command answers [command].+ FakeSwarm backend({+ String chatId = chat,+ String owner = me,+ String? named,+ bool running = true,+ String role = 'owner',+ FutureOr<Object?> Function(Map<String, dynamic>? body)? command,+ }) {+ final fake = FakeSwarm();+ fake.routes['/api/super-tabs/list'] = (_) => {+ 'tabs': [+ {'id': tab, 'name': 'Phone Swarm', 'ownerId': me},+ ],+ 'next': null,+ };+ fake.routes['/api/super-tabs/$tab/parts'] = (_) => {+ ...firstLoad(+ groups: [+ {+ ...buddyChatData(+ chatId,+ owner: owner,+ agentIds: [if (running) 'agent-wren'],+ ),+ 'buddyName': ?named,+ },+ ],+ agents: [+ agent('agent-lead', name: 'Lead', displayName: 'River'),+ if (running)+ buddyData('agent-wren', owner: owner, displayName: named ?? 'Wren'),+ ],+ ),+ 'members': [+ part(me, 1, person(me, role: role)),+ part('person-dee', 1, person('person-dee', role: 'member')),+ ],+ };+ fake.routes['/api/super-tabs/$tab/changes'] = (_) => changes(cursor: 'c2');+ fake.routes['/api/super-tabs/$tab/decisions?state=open'] = (_) => {+ 'decisions': <Object>[],+ };+ fake.routes['/api/super-tabs/$tab/mentions?state=waiting'] = (_) => {+ 'mentions': <Object>[],+ };+ fake.routes['/api/super-tabs/$tab/conversations/$chatId/messages'] = (_) =>+ {'messages': <Object>[], 'next': null};+ fake.routes[commands] = command ?? (_) => {'result': <String, dynamic>{}};+ return fake;+ }++ Future<SwarmHost> pump(+ WidgetTester tester,+ FakeSwarm fake, {+ String chatId = chat,+ }) async {+ final account = ValueNotifier<String?>(me);+ final host = SwarmHost(+ accountId: () => account.value,+ account: account,+ request: fake.request,+ upload: refuseSwarmUpload,+ notices: SilentSystemNotices(),+ features: ExperimentalFeaturesStore(storage: MemoryKeyValueStore())+ ..value = {PhoneExperiment.swarm},+ )..foreground = false;+ addTearDown(host.dispose);+ await tester.pumpWidget(+ MaterialApp(+ theme: grid.buildAppTheme(brightness: Brightness.dark),+ builder: (context, child) => SwarmScope(notifier: host, child: child!),+ home: SwarmConversationPage(swarmId: tab, conversationId: chatId),+ ),+ );+ await tester.pumpAndSettle();+ return host;+ }++ Finder key(String value) => find.byKey(ValueKey(value));++ List<Map<String, dynamic>> renames(FakeSwarm fake) => [+ for (final c in fake.commands)+ if (c['type'] == 'buddy.rename') c,+ ];++ /// ⋮, then Rename Buddy: the dialog.+ Future<void> openRename(WidgetTester tester) async {+ await tester.tap(key('swarm-buddy-menu'));+ await tester.pumpAndSettle();+ await tester.tap(find.text('Rename Buddy'));+ await tester.pumpAndSettle();+ }++ String field(WidgetTester tester) =>+ tester.widget<TextField>(key('swarm-buddy-name')).controller!.text;++ group('the dialog', () {+ testWidgets('shows the name chosen, and the default as the empty '+ "field's hint", (tester) async {+ await pump(tester, backend(named: 'Juniper'));+ await openRename(tester);++ expect(find.text('Rename your Buddy'), findsOneWidget);+ expect(field(tester), 'Juniper');+ expect(+ tester.widget<TextField>(key('swarm-buddy-name')).decoration!.hintText,+ "person-me's Buddy",+ );+ expect(+ tester.widget<TextField>(key('swarm-buddy-name')).maxLength,+ 32,+ reason: "the server's limit",+ );+ });++ testWidgets('Rename is offered before a Buddy runs; Remove is not', (+ tester,+ ) async {+ await pump(tester, backend(running: false));+ await tester.tap(key('swarm-buddy-menu'));+ await tester.pumpAndSettle();+ expect(find.text('Rename Buddy'), findsOneWidget);+ expect(find.text('Remove Buddy'), findsNothing);+ });+ });++ group('each case', () {+ testWidgets('Save sends the name by the chat, then the dialog closes', (+ tester,+ ) async {+ final fake = backend();+ await pump(tester, fake);+ await openRename(tester);+ await tester.enterText(key('swarm-buddy-name'), ' Juniper ');+ await tester.tap(key('swarm-buddy-name-save'));+ await tester.pumpAndSettle();++ expect(renames(fake), [+ {'type': 'buddy.rename', 'conversationId': chat, 'name': 'Juniper'},+ ]);+ expect(find.text('Rename your Buddy'), findsNothing);+ expect(+ fake.paths.last,+ startsWith('/api/super-tabs/$tab/changes'),+ reason: 'the Swarm read again, so the new name shows',+ );+ });++ testWidgets('empty goes back to the default', (tester) async {+ final fake = backend(named: 'Juniper');+ await pump(tester, fake);+ await openRename(tester);+ await tester.enterText(key('swarm-buddy-name'), ' ');+ await tester.tap(key('swarm-buddy-name-save'));+ await tester.pumpAndSettle();++ expect(renames(fake), [+ {'type': 'buddy.rename', 'conversationId': chat, 'name': null},+ ]);+ expect(find.text('Rename your Buddy'), findsNothing);+ });++ testWidgets('a name past 32 characters goes cut at 32', (tester) async {+ final fake = backend();+ await pump(tester, fake);+ await openRename(tester);+ await tester.enterText(key('swarm-buddy-name'), 'a' * 40);+ await tester.tap(key('swarm-buddy-name-save'));+ await tester.pumpAndSettle();+ expect(renames(fake).single['name'], 'a' * 32);+ });++ testWidgets('a name the server refuses: its words show, the dialog '+ 'stays, and Save works again', (tester) async {+ var refuse = true;+ final fake = backend(+ command: (_) {+ if (refuse) {+ throw const SuperTabFailure(+ 'BUDDY_NAME_TAKEN',+ 'Wren is taken in this Swarm. Choose another.',+ statusCode: 409,+ );+ }+ return {'result': <String, dynamic>{}};+ },+ );+ await pump(tester, fake);+ await openRename(tester);+ await tester.enterText(key('swarm-buddy-name'), 'Wren');+ await tester.tap(key('swarm-buddy-name-save'));+ await tester.pumpAndSettle();++ expect(+ tester.widget<Text>(key('swarm-buddy-name-error')).data,+ 'Wren is taken in this Swarm. Choose another.',+ );+ expect(find.text('Rename your Buddy'), findsOneWidget);+ expect(field(tester), 'Wren', reason: 'kept to correct');+ expect(key('swarm-buddy-error'), findsNothing, reason: 'said once');++ refuse = false;+ await tester.enterText(key('swarm-buddy-name'), 'Juniper');+ await tester.tap(key('swarm-buddy-name-save'));+ await tester.pumpAndSettle();+ expect(renames(fake), hasLength(2));+ expect(find.text('Rename your Buddy'), findsNothing);+ });++ testWidgets('an older server without the command: its refusal shows and '+ 'the dialog stays', (tester) async {+ final fake = backend(+ command: (_) => throw const SuperTabFailure(+ 'VALIDATION_ERROR',+ 'Invalid discriminator value.',+ statusCode: 400,+ ),+ );+ await pump(tester, fake);+ await openRename(tester);+ await tester.enterText(key('swarm-buddy-name'), 'Juniper');+ await tester.tap(key('swarm-buddy-name-save'));+ await tester.pumpAndSettle();+ expect(+ tester.widget<Text>(key('swarm-buddy-name-error')).data,+ 'Invalid discriminator value.',+ );+ expect(find.text('Rename your Buddy'), findsOneWidget);+ });++ testWidgets('no answer at all says to try again', (tester) async {+ final fake = backend(command: (_) => throw Exception('reset'));+ await pump(tester, fake);+ await openRename(tester);+ await tester.tap(key('swarm-buddy-name-save'));+ await tester.pumpAndSettle();+ expect(+ tester.widget<Text>(key('swarm-buddy-name-error')).data,+ "Couldn't rename your Buddy. Try again.",+ );+ });++ testWidgets('while it saves, a second Save sends nothing more', (+ tester,+ ) async {+ final answer = Completer<Object?>();+ final fake = backend(command: (_) => answer.future);+ await pump(tester, fake);+ await openRename(tester);+ await tester.enterText(key('swarm-buddy-name'), 'Juniper');+ await tester.tap(key('swarm-buddy-name-save'));+ await tester.pump();+ await tester.tap(key('swarm-buddy-name-save'));+ await tester.testTextInput.receiveAction(TextInputAction.done);+ await tester.pump();+ expect(renames(fake), hasLength(1));++ answer.complete({'result': <String, dynamic>{}});+ await tester.pumpAndSettle();+ expect(find.text('Rename your Buddy'), findsNothing);+ });+ });++ group('privacy', () {+ testWidgets("someone else's Buddy chat shows no ⋮", (tester) async {+ final fake = backend(chatId: 'buddy-dee', owner: 'person-dee');+ await pump(tester, fake, chatId: 'buddy-dee');+ expect(key('swarm-buddy-menu'), findsNothing);+ expect(find.text('Rename Buddy'), findsNothing);+ expect(renames(fake), isEmpty);+ });++ testWidgets('a viewer has no ⋮', (tester) async {+ await pump(tester, backend(role: 'viewer'));+ expect(key('swarm-buddy-menu'), findsNothing);+ });+ });++ group('lifecycle', () {+ testWidgets('access lost while the dialog is open closes it, and the '+ 'late refusal says nothing', (tester) async {+ final answer = Completer<Object?>();+ final fake = backend(command: (_) => answer.future);+ final host = await pump(tester, fake);+ await openRename(tester);+ await tester.enterText(key('swarm-buddy-name'), 'Juniper');+ await tester.tap(key('swarm-buddy-name-save'));+ await tester.pump();++ host.session!.inbox.reader(tab)!.revoke();+ await tester.pumpAndSettle();+ expect(find.text('Rename your Buddy'), findsNothing);++ answer.completeError(+ const SuperTabFailure('NOT_FOUND', 'This conversation is unavailable.'),+ );+ await tester.pumpAndSettle();+ expect(find.text('This conversation is unavailable.'), findsNothing);+ expect(key('swarm-buddy-error'), findsNothing);+ });++ testWidgets('losing write access while it is open closes it', (+ tester,+ ) async {+ var role = 'owner';+ final fake = backend();+ final parts = fake.routes['/api/super-tabs/$tab/parts']!;+ fake.routes['/api/super-tabs/$tab/parts'] = (body) => {+ ...parts(body)! as Map<String, dynamic>,+ 'members': [part(me, 1, person(me, role: role))],+ };+ final host = await pump(tester, fake);+ await openRename(tester);+ expect(find.text('Rename your Buddy'), findsOneWidget);++ role = 'viewer';+ fake.routes['/api/super-tabs/$tab/changes'] = (_) => {+ ...changes(cursor: 'c3'),+ 'members': [part(me, 2, person(me, role: 'viewer'))],+ };+ unawaited(host.session!.inbox.reader(tab)!.refresh());+ await tester.pumpAndSettle();+ expect(find.text('Rename your Buddy'), findsNothing);+ expect(renames(fake), isEmpty);+ });++ testWidgets('a refusal after the Swarm was read anew from nothing says '+ 'nothing', (tester) async {+ final answer = Completer<Object?>();+ final fake = backend(command: (_) => answer.future);+ final host = await pump(tester, fake);+ await openRename(tester);+ await tester.tap(key('swarm-buddy-name-save'));+ await tester.pump();++ host.session!.inbox.reader(tab)!.generation++;+ answer.completeError(+ const SuperTabFailure(+ 'BUDDY_NAME_TAKEN',+ 'Wren is taken in this Swarm. Choose another.',+ statusCode: 409,+ ),+ );+ await tester.pumpAndSettle();+ expect(key('swarm-buddy-name-error'), findsNothing);+ });+ });+}diff --git a/mobile/test/swarm/swarm_home_test.dart b/mobile/test/swarm/swarm_home_test.dartindex b7ff83731..98e0da84e 100644--- a/mobile/test/swarm/swarm_home_test.dart+++ b/mobile/test/swarm/swarm_home_test.dart@@ -1941,6 +1941,32 @@ void main() {expect(key('swarm-title-button'), findsOneWidget, reason: 'back on Home');});+ testWidgets('the Buddy tab\'s ⋮ renames the Buddy by its chat', (+ tester,+ ) async {+ final fake = backend(buddy: true);+ await pump(tester, fake);+ await openProject(tester, project);+ await openTab(tester, 'buddy');++ await tester.tap(key('swarm-buddy-menu'));+ await tester.pumpAndSettle();+ await tester.tap(find.text('Rename Buddy'));+ await tester.pumpAndSettle();+ await tester.enterText(key('swarm-buddy-name'), 'Juniper');+ await tester.tap(key('swarm-buddy-name-save'));+ await tester.pumpAndSettle();++ expect(fake.commands.where((c) => c['type'] == 'buddy.rename').toList(), [+ {+ 'type': 'buddy.rename',+ 'conversationId': 'buddy-me',+ 'name': 'Juniper',+ },+ ]);+ expect(find.text('Rename your Buddy'), findsNothing);+ });+testWidgets('a viewer with no Buddy chat in the project starts none from ''the Buddy tab', (tester) async {final fake = backend();