mirror of
https://github.com/block/buzz.git
synced 2026-11-09 19:02:00 +00:00
## Summary Builderlab's model catalog can now recommend a model and thinking effort for new agents (`recommended_selection` on `/v3/beekeeper/get-model-catalog`). The mobile create-agent screen now starts on that recommendation, so the default can change on the server without an app release. New agents start on the first of these that applies: 1. The model an agent link suggests, when the catalog offers it (unchanged). 2. The server's recommended model and effort. 3. The first Sonnet model at medium effort, as added in #9034. Used while a deployment sends no recommendation. 4. Blank. A setup resumed after a failure still keeps its saved choice. A recommendation that isn't in the returned catalog, or that is malformed, is ignored. Existing agents' saved models are never changed. The server only sends a recommendation when the deployment's catalog config sets `recommended_selection`. Until then, the app keeps falling back to Sonnet. ## Testing - Unit tests cover the recommendation beating the Sonnet fallback, a draft model beating the recommendation, and recommendations that should be ignored (unsupported effort, unknown model, missing effort, malformed, absent). - A new widget test checks that the form opens on the recommended model and effort instead of Sonnet. - `just mobile-check` and the full mobile suite (`flutter test --dart-define=BUZZ_PUSH_GATEWAY_URL=https://push.example`) pass locally. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: Wes <wesbillman@users.noreply.github.com> Co-authored-by: Carl <32a2e2c9d428ee08902cab75d956da2c1d235a22d4766b0dd4138bf6e2e5db1d@buzz.block.builderlab.xyz> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
325 lines
11 KiB
Dart
325 lines
11 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:buzz/shared/widgets/frosted_app_bar.dart';
|
|
import 'package:buzz/shared/widgets/preset_agent_avatar.dart';
|
|
import 'package:buzz/shared/agents/agent_avatar_catalog.dart';
|
|
import 'package:buzz/features/agents/agent_avatar_editor_page.dart';
|
|
|
|
import 'dart:async';
|
|
|
|
import 'package:buzz/shared/agents/remote_agents.dart';
|
|
|
|
import 'package:buzz/features/agents/agents_page.dart';
|
|
import 'package:buzz/features/agents/create_agent_page.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:nostr/nostr.dart' as nostr;
|
|
|
|
import 'agents_harness.dart';
|
|
|
|
void main() {
|
|
final existing = existingDesktopKeys.public;
|
|
|
|
testWidgets(
|
|
'creation overlays the retained list, then failure and resume both land',
|
|
(tester) async {
|
|
final h = await AgentsHarness.create();
|
|
final controller = h.controller;
|
|
final added = nostr.Keys('0' * 63 + '2').public;
|
|
await h.open(tester, directory: [existing]);
|
|
final list = tester.element(find.byType(AgentsPage));
|
|
if (!supportsRemoteAgents(h.community)) {
|
|
expect(find.byTooltip('Add agent'), findsNothing);
|
|
expect(find.text('Sign in to create an agent'), findsNothing);
|
|
expect(find.byKey(ValueKey(existing)), findsOneWidget);
|
|
return;
|
|
}
|
|
await tester.tap(find.byTooltip('Add agent'));
|
|
await tester.pumpAndSettle();
|
|
expect(find.byType(CreateAgentPage), findsOneWidget);
|
|
final createContext = tester.element(find.byType(CreateAgentPage));
|
|
expect(Navigator.of(list), same(Navigator.of(createContext)));
|
|
|
|
expect(find.text('Thinking'), findsOneWidget);
|
|
expect(find.byIcon(Icons.unfold_more), findsNWidgets(2));
|
|
expect(
|
|
tester.getTopLeft(find.text('Name')).dy,
|
|
lessThan(tester.getTopLeft(find.text('Model')).dy),
|
|
);
|
|
expect(
|
|
tester.getTopLeft(find.text('Model')).dy,
|
|
lessThan(tester.getTopLeft(find.text('Instructions')).dy),
|
|
);
|
|
|
|
await tester.ensureVisible(find.text('Model'));
|
|
await tester.tap(find.text('Model'));
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.text('Test model').last);
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.text('Thinking'));
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.text('high').last);
|
|
await tester.pumpAndSettle();
|
|
// Switching models must clear an effort unsupported by the new choice.
|
|
await tester.tap(find.text('Test model'));
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.text('Other model').last);
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
tester
|
|
.widget<IconButton>(find.widgetWithIcon(IconButton, Icons.check))
|
|
.onPressed,
|
|
isNull,
|
|
);
|
|
await tester.tap(find.text('Other model'));
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.text('Test model').last);
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.text('Thinking'));
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.text('high').last);
|
|
await tester.pumpAndSettle();
|
|
controller.gate = Completer<void>();
|
|
await tester.enterText(
|
|
find.descendant(
|
|
of: find.byWidgetPredicate(
|
|
(widget) =>
|
|
widget is Semantics && widget.properties.label == 'Name',
|
|
),
|
|
matching: find.byType(TextField),
|
|
),
|
|
'Scout',
|
|
);
|
|
await tester.enterText(
|
|
find.descendant(
|
|
of: find.byWidgetPredicate(
|
|
(widget) =>
|
|
widget is Semantics &&
|
|
widget.properties.label == 'Instructions',
|
|
),
|
|
matching: find.byType(TextField),
|
|
),
|
|
'Reply concisely.',
|
|
);
|
|
await tester.pump();
|
|
final originalAvatar = tester
|
|
.widget<PresetAgentAvatar>(find.byType(PresetAgentAvatar))
|
|
.imageUrl;
|
|
final originalPack = AgentAvatarPack.values.firstWhere(
|
|
(pack) => pack.indices.any(
|
|
(i) => agentAvatarCatalog[i].url == originalAvatar,
|
|
),
|
|
);
|
|
final targetIndex = originalPack.indices.firstWhere(
|
|
(i) => agentAvatarCatalog[i].url != originalAvatar,
|
|
);
|
|
await tester.ensureVisible(find.text('Choose avatar'));
|
|
// Repeated callbacks before the next rebuild must still open one editor.
|
|
final openAvatar = tester
|
|
.widget<FilledButton>(
|
|
find.widgetWithText(FilledButton, 'Choose avatar'),
|
|
)
|
|
.onPressed!;
|
|
// A stalled CDN must not prevent entry to the editor.
|
|
final stalledClient = _StalledPosterClient();
|
|
debugNetworkImageHttpClientProvider = () => stalledClient;
|
|
addTearDown(() => debugNetworkImageHttpClientProvider = null);
|
|
await NetworkImage(originalAvatar).evict();
|
|
openAvatar();
|
|
openAvatar();
|
|
await tester.pump();
|
|
await tester.pump(const Duration(milliseconds: 301));
|
|
await tester.pumpAndSettle();
|
|
expect(stalledClient.requests, greaterThan(0));
|
|
debugNetworkImageHttpClientProvider = null;
|
|
expect(find.byType(AgentAvatarEditorPage), findsOneWidget);
|
|
expect(find.text('Instructions'), findsNothing);
|
|
await tester.tap(find.byKey(ValueKey('agent-avatar-$targetIndex')));
|
|
await tester.pumpAndSettle();
|
|
// This harness disables motion, so the return transition completes
|
|
// immediately. Check suppression while editing, then restoration on exit.
|
|
final chooseButton = find.widgetWithText(
|
|
FilledButton,
|
|
'Choose avatar',
|
|
skipOffstage: false,
|
|
);
|
|
expect(tester.widget<FilledButton>(chooseButton).onPressed, isNull);
|
|
final playback = find.byKey(
|
|
const ValueKey('create-agent-avatar-playback'),
|
|
skipOffstage: false,
|
|
);
|
|
expect(tester.widget<TickerMode>(playback).enabled, isFalse);
|
|
final sourceBar = find.descendant(
|
|
of: find.byType(CreateAgentPage, skipOffstage: false),
|
|
matching: find.byType(FrostedAppBar, skipOffstage: false),
|
|
skipOffstage: false,
|
|
);
|
|
expect(
|
|
tester.widget<FrostedAppBar>(sourceBar).nativeViewSuppressed?.value,
|
|
isTrue,
|
|
);
|
|
await tester.tap(find.byTooltip('Cancel'));
|
|
await tester.pumpAndSettle();
|
|
expect(tester.widget<FilledButton>(chooseButton).onPressed, isNotNull);
|
|
expect(tester.widget<TickerMode>(playback).enabled, isTrue);
|
|
expect(
|
|
tester.widget<FrostedAppBar>(sourceBar).nativeViewSuppressed?.value,
|
|
isFalse,
|
|
);
|
|
expect(
|
|
tester
|
|
.widget<PresetAgentAvatar>(find.byType(PresetAgentAvatar))
|
|
.imageUrl,
|
|
originalAvatar,
|
|
);
|
|
await tester.tap(find.text('Choose avatar'));
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.byKey(ValueKey('agent-avatar-$targetIndex')));
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.byTooltip('Done'));
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
tester
|
|
.widget<PresetAgentAvatar>(find.byType(PresetAgentAvatar))
|
|
.imageUrl,
|
|
isNot(originalAvatar),
|
|
);
|
|
expect(find.text('Scout'), findsOneWidget);
|
|
expect(find.text('Reply concisely.'), findsOneWidget);
|
|
await tester.tap(find.byTooltip('Create'));
|
|
await tester.pump(const Duration(milliseconds: 100));
|
|
expect(controller.busy, isTrue);
|
|
expect(
|
|
find.descendant(
|
|
of: find.byType(CreateAgentPage),
|
|
matching: find.byType(LinearProgressIndicator),
|
|
),
|
|
findsOneWidget,
|
|
);
|
|
expect(
|
|
tester
|
|
.widget<IconButton>(
|
|
find.ancestor(
|
|
of: find.byTooltip('Create'),
|
|
matching: find.byType(IconButton),
|
|
),
|
|
)
|
|
.onPressed,
|
|
isNull,
|
|
);
|
|
int catalogLoads() =>
|
|
h.registry.calls.where((call) => call == 'get-model-catalog').length;
|
|
final loadsBeforeFailure = catalogLoads();
|
|
controller.gate!.complete();
|
|
await tester.pumpAndSettle();
|
|
expect(find.byType(CreateAgentPage), findsOneWidget);
|
|
// A rejected choice may be stale, so the catalog reloads.
|
|
expect(catalogLoads(), loadsBeforeFailure + 1);
|
|
expect(find.byType(CreateAgentPage), findsOneWidget);
|
|
expect(find.text('Creation failed. Retry.'), findsOneWidget);
|
|
expect(controller.submittedName, 'Scout');
|
|
expect(controller.submittedInstructions, 'Reply concisely.');
|
|
|
|
// The real registry flow then succeeds and returns to the same list.
|
|
controller.gate = null;
|
|
await tester.tap(find.byTooltip('Create'));
|
|
await tester.pumpAndSettle();
|
|
expect(find.byType(BottomSheet), findsNothing);
|
|
expect(tester.element(find.byType(AgentsPage)), same(list));
|
|
expect(find.byKey(ValueKey(added)), findsOneWidget);
|
|
expect(h.registry.calls, contains('publish-policy'));
|
|
},
|
|
);
|
|
|
|
testWidgets('a new agent starts on the affordable default model', (
|
|
tester,
|
|
) async {
|
|
final h = await AgentsHarness.create();
|
|
h.registry.models = [
|
|
{
|
|
'id': 'premium-model',
|
|
'display_name': 'Premium model',
|
|
'supported_reasoning_efforts': ['low', 'medium', 'high'],
|
|
},
|
|
{
|
|
'id': 'kgoose-claude-sonnet-4-6',
|
|
'display_name': 'Sonnet',
|
|
'supported_reasoning_efforts': ['low', 'medium', 'high'],
|
|
},
|
|
];
|
|
await h.open(tester, directory: [existing]);
|
|
if (!supportsRemoteAgents(h.community)) return;
|
|
await tester.tap(find.byTooltip('Add agent'));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.text('Sonnet'), findsOneWidget);
|
|
expect(find.text('Premium model'), findsNothing);
|
|
expect(find.text('medium'), findsOneWidget);
|
|
|
|
// Naming it is all that's left before Create.
|
|
await tester.enterText(
|
|
find.descendant(
|
|
of: find.byWidgetPredicate(
|
|
(widget) => widget is Semantics && widget.properties.label == 'Name',
|
|
),
|
|
matching: find.byType(TextField),
|
|
),
|
|
'Scout',
|
|
);
|
|
await tester.pump();
|
|
expect(
|
|
tester
|
|
.widget<IconButton>(
|
|
find.ancestor(
|
|
of: find.byTooltip('Create'),
|
|
matching: find.byType(IconButton),
|
|
),
|
|
)
|
|
.onPressed,
|
|
isNotNull,
|
|
);
|
|
});
|
|
|
|
testWidgets('a new agent starts on the service-recommended model', (
|
|
tester,
|
|
) async {
|
|
final h = await AgentsHarness.create();
|
|
h.registry.models = [
|
|
{
|
|
'id': 'premium-model',
|
|
'display_name': 'Premium model',
|
|
'supported_reasoning_efforts': ['low', 'medium', 'high'],
|
|
},
|
|
{
|
|
'id': 'kgoose-claude-sonnet-4-6',
|
|
'display_name': 'Sonnet',
|
|
'supported_reasoning_efforts': ['low', 'medium', 'high'],
|
|
},
|
|
];
|
|
h.registry.recommendedSelection = {
|
|
'model_id': 'premium-model',
|
|
'reasoning_effort': 'high',
|
|
};
|
|
await h.open(tester, directory: [existing]);
|
|
if (!supportsRemoteAgents(h.community)) return;
|
|
await tester.tap(find.byTooltip('Add agent'));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.text('Premium model'), findsOneWidget);
|
|
expect(find.text('Sonnet'), findsNothing);
|
|
expect(find.text('high'), findsOneWidget);
|
|
});
|
|
}
|
|
|
|
class _StalledPosterClient implements HttpClient {
|
|
int requests = 0;
|
|
@override
|
|
Future<HttpClientRequest> getUrl(Uri url) {
|
|
requests++;
|
|
return Completer<HttpClientRequest>().future;
|
|
}
|
|
|
|
@override
|
|
dynamic noSuchMethod(Invocation invocation) => null;
|
|
}
|