mirror of
https://github.com/block/buzz.git
synced 2026-11-15 22:02:04 +00:00
Long-pressing the Buzz icon on iOS now offers three quick actions: - **New chat** opens a new solo chat (the same draft as New › New chat). - **New DM** opens the New DM picker. - **Message <Bestie>** opens the DM with the current community's Bestie, using the agent's display name (for example "Message astra"). It's hidden when the community has no Bestie, and it updates when the Bestie, its name or the community changes. | Before | After | | --- | --- | | <img alt="before" src="https://github.com/user-attachments/assets/393c3fb6-fe64-4505-a7a4-12714d8bf1df" width="300"> | <img alt="after" src="https://github.com/user-attachments/assets/1c57df92-6fed-4fee-9ce8-e9ea0ec70294" width="300"> | ### How it works Home publishes the items through a small native bridge (`buzz/home_screen_shortcuts`), which sets `UIApplication.shortcutItems`. A tap goes through the scene delegate. The bridge keeps the latest one until Dart has handled it, the same pattern push-notification taps use, so cold launches work too. Home runs it only once the app is active and the destination is ready. When a tap arrives, Home pops back to the first route once, so a shortcut never opens beneath a Flutter sheet or a conversation that was already open. A screen that refuses to close (for example a New chat whose first message is still sending) stays, and the tap is dropped. The one exception is the native iOS New channel form, which isn't a Flutter route: a shortcut tapped with it open runs underneath it. If a screen is opened while a tap is still waiting for its destination, the tap is dropped. A New DM tap while the New DM picker is open replaces the picker. Opening the Bestie DM now goes through one shared function, so the Home launcher button and the shortcut run identical code. A second open while the DM is still being looked up does nothing. Signing out clears the items. The shortcut wiring lives in its own leaf widget, so Home doesn't rebuild for it. Behavior change for the existing Home Bestie launcher: if you open another screen while it's still looking up the DM, the DM no longer opens over that screen. Behavior change for the native member picker (New DM, and Add members in channels): a picker reopened while the previous one is still closing now opens once the dismissal finishes, instead of failing with "Cannot open the member picker". ### Validation - Added tests: a Home journey covers the published titles (including the Bestie's name), a cold tap that waits for the app to resume and for New chat to be available, a Bestie tap made with another route open, a New chat tap while a draft is open, a New DM tap replacing an open picker, a waiting tap dropped once another screen opens, no Home rebuilds on lifecycle changes, and clearing the items when Home goes away. A launcher test covers a slow Bestie lookup, and a New chat test covers a shortcut tapped while the first message is still sending. I also broke the code that runs the shortcut and confirmed the journey fails. - Full mobile suite and `flutter analyze` pass. CI doesn't compile Swift on drafts, so `NativeAddMembersSheet.swift` was compiled with a local `flutter build ios --simulator` build. - iPhone 17 Pro simulator (iOS 27), signed in to a Builderlab community: from a cold launch, New chat opened the new-chat draft. Then, with the app warm, New DM opened the picker and Message <Bestie> replaced it with the Bestie DM. The recording stays in Buzz because it shows real account data. buzz-review-completed 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Tom Brow <tomb@squareup.com> Co-authored-by: Tom Brow <tomb@squareup.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
306 lines
12 KiB
Dart
306 lines
12 KiB
Dart
import 'package:flutter/services.dart';
|
||
import 'package:buzz/shared/widgets/app_list_card.dart';
|
||
import 'package:buzz/shared/agents/remote_agents.dart';
|
||
import 'package:buzz/shared/me/me_sync.dart';
|
||
import 'package:buzz/shared/me/default_agent.dart';
|
||
import 'package:buzz/shared/theme/theme_provider.dart';
|
||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||
import 'package:buzz/features/channels/default_agent_launcher.dart';
|
||
import 'package:buzz/features/agents/agents_page.dart';
|
||
import 'package:buzz/features/agents/agent_card.dart';
|
||
import 'package:buzz/features/profile/user_profile_sheet.dart';
|
||
import 'package:flutter/material.dart';
|
||
import 'package:buzz/features/home/home_page.dart';
|
||
import 'package:flutter_test/flutter_test.dart';
|
||
import 'package:shared_preferences/shared_preferences.dart';
|
||
|
||
import 'agents_harness.dart';
|
||
import '../../helpers/remote_agents_fixture.dart';
|
||
|
||
void main() {
|
||
final existing = existingDesktopKeys.public;
|
||
|
||
testWidgets('agent profile sheet closes back to the full-page directory', (
|
||
tester,
|
||
) async {
|
||
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
||
const MethodChannel('dev.fluttercommunity.plus/connectivity_status'),
|
||
(_) async => null,
|
||
);
|
||
addTearDown(
|
||
() => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
||
const MethodChannel('dev.fluttercommunity.plus/connectivity_status'),
|
||
null,
|
||
),
|
||
);
|
||
tester.view.physicalSize = const Size(390, 844);
|
||
tester.view.devicePixelRatio = 1;
|
||
addTearDown(tester.view.resetPhysicalSize);
|
||
addTearDown(tester.view.resetDevicePixelRatio);
|
||
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
|
||
final h = await AgentsHarness.create();
|
||
final prefs = await SharedPreferences.getInstance();
|
||
await h.open(
|
||
tester,
|
||
directory: [existing, otherAgentKeys.public],
|
||
overrides: [savedPrefsProvider.overrideWithValue(prefs)],
|
||
);
|
||
expect(find.byKey(ValueKey(otherAgentKeys.public)), findsNothing);
|
||
expect(find.byKey(ValueKey(oldAppAgentKeys.public)), findsNothing);
|
||
if (!supportsRemoteAgents(h.community)) {
|
||
expect(find.text('Sign in to create an agent'), findsNothing);
|
||
for (final button in tester.widgetList<IconButton>(
|
||
find.byWidgetPredicate(
|
||
(widget) => widget is IconButton && widget.tooltip == 'Add agent',
|
||
),
|
||
)) {
|
||
expect(button.onPressed, isNull);
|
||
}
|
||
}
|
||
await h.controller.run(() async {
|
||
throw StateError('Resume unfinished setup');
|
||
});
|
||
await tester.pumpAndSettle();
|
||
expect(find.textContaining('Resume unfinished setup'), findsNothing);
|
||
expect(find.byType(LinearProgressIndicator), findsNothing);
|
||
final list = tester.element(find.byType(AgentsPage));
|
||
final container = ProviderScope.containerOf(list);
|
||
expect(find.text('Set as default'), findsNothing);
|
||
expect(find.text('Model not shared'), findsNothing);
|
||
expect(find.byIcon(Icons.star), findsNothing);
|
||
expect(find.text('Manage on desktop'), findsOneWidget);
|
||
expect(find.byIcon(Icons.keyboard_arrow_down), findsNothing);
|
||
|
||
await tester.tap(find.byKey(ValueKey(existing)));
|
||
await tester.pump();
|
||
await tester.pumpAndSettle();
|
||
expect(find.byType(BottomSheet), findsOneWidget);
|
||
expect(find.byType(UserProfileSheet), findsOneWidget);
|
||
expect(find.text('Model not shared'), findsNothing);
|
||
expect(list.mounted, isTrue);
|
||
expect(find.text('Identity'), findsNothing);
|
||
expect(find.text('Settings'), findsNothing);
|
||
expect(
|
||
find.descendant(
|
||
of: find.byType(UserProfileSheet),
|
||
matching: find.text('Manage on desktop'),
|
||
),
|
||
findsNothing,
|
||
);
|
||
expect(
|
||
find.descendant(
|
||
of: find.byType(UserProfileSheet),
|
||
matching: find.text('Unknown'),
|
||
),
|
||
findsNothing,
|
||
);
|
||
expect(find.text('Instructions'), findsOneWidget);
|
||
expect(find.text('Management'), findsOneWidget);
|
||
expect(
|
||
find.textContaining('Keep Buzz open and your desktop online'),
|
||
findsOneWidget,
|
||
);
|
||
expect(
|
||
find.textContaining('Instructions aren’t available'),
|
||
findsOneWidget,
|
||
);
|
||
await tester.pumpAndSettle();
|
||
expect(find.byTooltip('Copy public key'), findsOneWidget);
|
||
final semantics = tester.ensureSemantics();
|
||
final platformCalls = <MethodCall>[];
|
||
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
||
SystemChannels.platform,
|
||
(call) async {
|
||
platformCalls.add(call);
|
||
return null;
|
||
},
|
||
);
|
||
addTearDown(
|
||
() => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
||
SystemChannels.platform,
|
||
null,
|
||
),
|
||
);
|
||
final keyRow = find.byTooltip('Copy public key');
|
||
await tester.ensureVisible(keyRow);
|
||
await tester.tapAt(tester.getTopLeft(keyRow) + const Offset(8, 8));
|
||
await tester.pumpAndSettle();
|
||
expect(
|
||
platformCalls.where((call) => call.method == 'Clipboard.setData'),
|
||
hasLength(1),
|
||
);
|
||
expect(
|
||
platformCalls.where((call) => call.method == 'HapticFeedback.vibrate'),
|
||
hasLength(1),
|
||
);
|
||
expect(find.bySemanticsLabel('Copied public key'), findsOneWidget);
|
||
semantics.dispose();
|
||
|
||
await tester.pumpAndSettle();
|
||
expect(find.byTooltip('Delete agent'), findsNothing);
|
||
// Reopen through the real reader, recover a failed network query, then
|
||
// verify the registered instruction text appears rather than profile bio.
|
||
await tester.tap(find.byTooltip('Close sheet'));
|
||
await tester.pumpAndSettle();
|
||
h.onQuery = (_) async => throw StateError('Offline');
|
||
await tester.tap(find.byKey(ValueKey(existing)));
|
||
await tester.pumpAndSettle();
|
||
expect(find.text('Could not load instructions.'), findsOneWidget);
|
||
h.onQuery = (_) async => [];
|
||
h.authorityDown = true;
|
||
await tester.ensureVisible(find.text('Retry'));
|
||
await tester.tap(find.text('Retry'));
|
||
await tester.pumpAndSettle();
|
||
expect(find.text('Could not load instructions.'), findsOneWidget);
|
||
h.authorityDown = false;
|
||
await tester.ensureVisible(find.text('Retry'));
|
||
await tester.tap(find.text('Retry'));
|
||
await tester.pumpAndSettle();
|
||
expect(
|
||
find.textContaining('Instructions aren’t available'),
|
||
findsOneWidget,
|
||
);
|
||
tester.platformDispatcher.textScaleFactorTestValue = 2;
|
||
await tester.pumpAndSettle();
|
||
await tester.pumpAndSettle();
|
||
await tester.ensureVisible(find.byTooltip('Copy public key'));
|
||
expect(tester.takeException(), isNull);
|
||
tester.platformDispatcher.clearTextScaleFactorTestValue();
|
||
await tester.pumpAndSettle();
|
||
await tester.pumpAndSettle();
|
||
h.relay.loseAcknowledgment = true;
|
||
await tester.ensureVisible(find.text('Make Bestie'));
|
||
await tester.tap(find.text('Make Bestie'));
|
||
await tester.pumpAndSettle();
|
||
expect(find.textContaining('Could not save Bestie.'), findsOneWidget);
|
||
h.relay.loseAcknowledgment = false;
|
||
h.relay.events = []; // The unacknowledged write was not retained.
|
||
await tester.ensureVisible(find.text('Make Bestie'));
|
||
await tester.tap(find.text('Make Bestie'));
|
||
await tester.pumpAndSettle();
|
||
expect(find.text('Your Bestie'), findsOneWidget);
|
||
final savedSync = container.read(meSyncProvider);
|
||
expect(decodeDefaultAgent(h.relay.events.single, savedSync), existing);
|
||
expect(
|
||
savedSync.prefs!.containsKey(
|
||
'main-agent:${savedSync.community}:${savedSync.pubkey}',
|
||
),
|
||
isTrue,
|
||
);
|
||
|
||
await tester.tap(find.byTooltip('Close sheet'));
|
||
await tester.pumpAndSettle();
|
||
expect(find.byType(UserProfileSheet), findsNothing);
|
||
expect(find.byKey(ValueKey(existing)), findsOneWidget);
|
||
expect(tester.element(find.byType(AgentsPage)), same(list));
|
||
expect(
|
||
tester.widget<AgentCard>(find.byKey(ValueKey(existing))).isBestie,
|
||
isTrue,
|
||
);
|
||
expect(
|
||
find.descendant(
|
||
of: find.byKey(ValueKey(existing)),
|
||
matching: find.byIcon(Icons.star),
|
||
),
|
||
findsOneWidget,
|
||
);
|
||
if (supportsRemoteAgents(h.community)) {
|
||
h.registry.listed = [
|
||
{
|
||
'agent_pubkey': fakeAgent,
|
||
'agent_id': 'remote-id',
|
||
'agent_name': 'Scout',
|
||
'agent_instructions': 'Review carefully.',
|
||
},
|
||
];
|
||
await h.controller.run(h.controller.refresh);
|
||
await tester.pumpAndSettle();
|
||
await tester.tap(find.byKey(ValueKey(fakeAgent)));
|
||
await tester.pumpAndSettle();
|
||
expect(
|
||
find.textContaining('This agent runs on Builderbot.'),
|
||
findsOneWidget,
|
||
);
|
||
// Remote instructions come from the registry row, not published config.
|
||
expect(h.registry.bodies['/v3/beekeeper/list-agents'], {
|
||
'include_instructions': true,
|
||
});
|
||
expect(find.text('Review carefully.'), findsOneWidget);
|
||
expect(
|
||
find.textContaining('Instructions aren’t available'),
|
||
findsNothing,
|
||
);
|
||
await tester.pumpAndSettle();
|
||
await tester.ensureVisible(find.text('Delete agent'));
|
||
expect(
|
||
tester.getTopLeft(find.text('Delete agent')).dy,
|
||
greaterThan(tester.getTopLeft(find.text('Public key')).dy),
|
||
);
|
||
final deleteCard = find.ancestor(
|
||
of: find.text('Delete agent'),
|
||
matching: find.byType(AppListCard),
|
||
);
|
||
expect(deleteCard, findsOneWidget);
|
||
expect(
|
||
find.descendant(of: deleteCard, matching: find.text('Public key')),
|
||
findsNothing,
|
||
);
|
||
await tester.tap(find.text('Delete agent'));
|
||
await tester.pumpAndSettle();
|
||
await tester.tap(find.text('Cancel'));
|
||
await tester.pumpAndSettle();
|
||
await tester.pumpAndSettle();
|
||
h.relay.events = [];
|
||
await tester.ensureVisible(find.text('Make Bestie'));
|
||
await tester.tap(find.text('Make Bestie'));
|
||
await tester.pumpAndSettle();
|
||
expect(find.text('Your Bestie'), findsOneWidget);
|
||
expect(decodeDefaultAgent(h.relay.events.single, savedSync), fakeAgent);
|
||
await tester.tap(find.byTooltip('Close sheet'));
|
||
await tester.pumpAndSettle();
|
||
expect(
|
||
tester.widget<AgentCard>(find.byKey(ValueKey(existing))).isBestie,
|
||
isFalse,
|
||
);
|
||
expect(
|
||
tester.widget<AgentCard>(find.byKey(ValueKey(fakeAgent))).isBestie,
|
||
isTrue,
|
||
);
|
||
}
|
||
ScaffoldMessenger.of(list).clearSnackBars();
|
||
await tester.tap(find.byTooltip('Close agents'));
|
||
await tester.pumpAndSettle();
|
||
expect(find.byType(BottomSheet), findsNothing);
|
||
h.relay.events = [];
|
||
final sync = container.read(meSyncProvider);
|
||
await sync.prefs!.remove('main-agent:${sync.community}:${sync.pubkey}');
|
||
await h.open(
|
||
tester,
|
||
directory: [existing],
|
||
overrides: [savedPrefsProvider.overrideWithValue(prefs)],
|
||
home: HomePage(
|
||
onAgents: showAgents,
|
||
openBestieConversation: (_, _, _) async {},
|
||
defaultAgentBuilder: (context) => DefaultAgentLauncher(
|
||
onChooseAgent: () => showAgents(context, createOnOpen: true),
|
||
),
|
||
settingsPageBuilder: (_) => const SizedBox.shrink(),
|
||
mePageBuilder: (_, _, _) =>
|
||
const SliverToBoxAdapter(child: Text('Solo workspace')),
|
||
),
|
||
);
|
||
await tester.tap(find.byTooltip('Bestie'));
|
||
await tester.pumpAndSettle();
|
||
await tester.tap(find.byKey(ValueKey(existing)));
|
||
await tester.pumpAndSettle();
|
||
expect(find.byType(UserProfileSheet), findsOneWidget);
|
||
expect(find.text('Model not shared'), findsNothing);
|
||
await tester.binding.handlePopRoute();
|
||
await tester.pumpAndSettle();
|
||
expect(find.byType(UserProfileSheet), findsNothing);
|
||
await tester.tap(find.byTooltip('Close agents'));
|
||
await tester.pumpAndSettle();
|
||
expect(find.byTooltip('Search'), findsOneWidget);
|
||
});
|
||
}
|