mirror of
https://github.com/block/buzz.git
synced 2026-11-24 10:12:19 +00:00
Show the Huddle action in owned Codex agent DMs and invite the agent before connecting audio. Revalidate eligibility on starts/recovery, ask before inviting into an existing call, and distinguish pending invitations from connected audio peers with actionable timeout feedback. DM hangup leaves shared room cleanup to the relay so another owner device stays connected. Pairs with https://github.com/block/buzz-app/pull/3048. Desktop and the Codex agent must remain running. Validated: 4,559 mobile tests, analysis, formatting, push hooks, and independent source review. Live phone-to-desktop audio and human trial remain pending. --------- Signed-off-by: kenny lopez <klopez4212@gmail.com> Signed-off-by: Tom Brow <tomb@squareup.com> Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz> Co-authored-by: Tom Brow <tomb@block.xyz> Co-authored-by: Tom Brow <tomb@squareup.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
228 lines
7.6 KiB
Dart
228 lines
7.6 KiB
Dart
import 'package:buzz/shared/agents/owned_agent_directory.dart';
|
|
import 'package:buzz/shared/relay/relay.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
import 'package:nostr/nostr.dart' as nostr;
|
|
|
|
import '../../helpers/remote_agents_fixture.dart';
|
|
|
|
NostrEvent registration(
|
|
String agent, {
|
|
String content = '{"name":"Agent"}',
|
|
String? runtime = 'block.builderlab/builderlab',
|
|
int createdAt = 1,
|
|
}) => NostrEvent.fromJson(
|
|
nostr.Event.from(
|
|
kind: 30177,
|
|
content: content,
|
|
secretKey: fakeOwner.secret,
|
|
createdAt: createdAt,
|
|
tags: [
|
|
['d', agent],
|
|
if (runtime != null) ['runtime', runtime],
|
|
],
|
|
).toMap(),
|
|
);
|
|
|
|
class _Session extends RelaySessionNotifier {
|
|
_Session(this.registrations, this.profiles);
|
|
final List<NostrEvent> registrations;
|
|
final List<NostrEvent> profiles;
|
|
|
|
@override
|
|
SessionState build() =>
|
|
const SessionState(status: SessionStatus.disconnected);
|
|
|
|
void connect() => state = const SessionState(status: SessionStatus.connected);
|
|
|
|
@override
|
|
Future<List<NostrEvent>> queryRelay(
|
|
List<NostrFilter> filters, {
|
|
Duration timeout = const Duration(seconds: 8),
|
|
}) async {
|
|
final filter = filters.single;
|
|
if (filter.kinds.contains(30177)) {
|
|
return filter.extensions['page'] == 1 ? registrations : const [];
|
|
}
|
|
return profiles
|
|
.where((profile) => filter.authors!.contains(profile.pubkey))
|
|
.toList();
|
|
}
|
|
}
|
|
|
|
class _RelayConfig extends RelayConfigNotifier {
|
|
@override
|
|
RelayConfig build() =>
|
|
const RelayConfig(baseUrl: 'https://relay.example', nsec: null);
|
|
}
|
|
|
|
void main() {
|
|
test('stays unknown, not empty, until the session connects', () async {
|
|
final session = _Session(
|
|
[registration(fakeAgent)],
|
|
[signedAgentProfile(fakeAgentKeys, fakeOwner)],
|
|
);
|
|
final container = ProviderContainer(
|
|
overrides: [
|
|
relayConfigProvider.overrideWith(_RelayConfig.new),
|
|
myPubkeyProvider.overrideWithValue(fakeOwner.public),
|
|
relaySessionProvider.overrideWith(() => session),
|
|
],
|
|
);
|
|
addTearDown(container.dispose);
|
|
final subscription = container.listen(
|
|
ownedAgentDirectoryProvider,
|
|
(_, _) {},
|
|
);
|
|
addTearDown(subscription.close);
|
|
|
|
await Future<void>.delayed(Duration.zero);
|
|
expect(container.read(ownedAgentDirectoryProvider).isLoading, isTrue);
|
|
expect(container.read(ownedAgentDirectoryProvider).asData, isNull);
|
|
|
|
session.connect();
|
|
final found = await container.read(ownedAgentDirectoryProvider.future);
|
|
expect(found.map((entry) => entry.pubkey), [fakeAgent]);
|
|
});
|
|
|
|
test('lists owned agents as desktop does, without runtime directory '
|
|
'entries or account sign-in', () async {
|
|
final desktop = nostr.Keys('0' * 63 + '3');
|
|
final outsider = nostr.Keys('0' * 63 + '4');
|
|
final oldApp = nostr.Keys('0' * 63 + '5');
|
|
final reverted = nostr.Keys('0' * 63 + '6');
|
|
final imported = nostr.Keys('0' * 63 + '7');
|
|
final registrations = [
|
|
registration(
|
|
fakeAgent,
|
|
content: '{"name":"Remote","model":"Claude Sonnet"}',
|
|
),
|
|
registration(desktop.public, runtime: 'block.claude-code/claude-code'),
|
|
registration(outsider.public),
|
|
// An earlier Buzz wrote no runtime; desktop lists it once imported.
|
|
registration(oldApp.public, runtime: null),
|
|
registration(imported.public, runtime: null),
|
|
registration(imported.public, createdAt: 2),
|
|
// Only the newest registration counts.
|
|
registration(reverted.public),
|
|
registration(reverted.public, runtime: null, createdAt: 2),
|
|
];
|
|
final profiles = [
|
|
signedAgentProfile(
|
|
fakeAgentKeys,
|
|
fakeOwner,
|
|
content: '{"name":"Remote"}',
|
|
),
|
|
signedAgentProfile(desktop, fakeOwner, content: '{"name":"Desktop"}'),
|
|
signedAgentProfile(outsider, desktop, content: '{"name":"Not owned"}'),
|
|
for (final keys in [oldApp, reverted, imported])
|
|
signedAgentProfile(keys, fakeOwner, content: '{"name":"Owned"}'),
|
|
];
|
|
final found = await loadOwnedAgentDirectory(fakeOwner.public, (
|
|
filter,
|
|
) async {
|
|
if (filter.kinds.contains(30177)) {
|
|
expect(filter.authors, [fakeOwner.public]);
|
|
return registrations;
|
|
}
|
|
expect(filter.kinds, [0]);
|
|
return profiles
|
|
.where((profile) => filter.authors!.contains(profile.pubkey))
|
|
.toList();
|
|
});
|
|
expect(found.first.model, 'Claude Sonnet');
|
|
expect(found.first.runtime, 'block.builderlab/builderlab');
|
|
expect(found[1].runtime, 'block.claude-code/claude-code');
|
|
expect(found.map((entry) => entry.pubkey), [
|
|
fakeAgent,
|
|
desktop.public,
|
|
imported.public,
|
|
]);
|
|
});
|
|
|
|
test('a relay that never ends pagination fails within the budget', () async {
|
|
final template = registration(fakeAgent).toJson();
|
|
var pages = 0;
|
|
await expectLater(
|
|
loadOwnedAgentDirectory(fakeOwner.public, (filter) async {
|
|
pages++;
|
|
// Fresh ids on every page; the loop must stop on its own budget.
|
|
return [
|
|
for (var i = 0; i < 100; i++)
|
|
NostrEvent.fromJson({
|
|
...template,
|
|
'id': (pages * 1000 + i).toRadixString(16).padLeft(64, '0'),
|
|
}),
|
|
];
|
|
}),
|
|
throwsStateError,
|
|
);
|
|
expect(pages, ownedAgentDirectoryPageBudget);
|
|
});
|
|
|
|
test('forged runtime metadata cannot mark an agent as hosted', () async {
|
|
final forged = NostrEvent.fromJson({
|
|
...registration(fakeAgent).toJson(),
|
|
'sig': '0' * 128,
|
|
});
|
|
final found = await loadOwnedAgentDirectory(
|
|
fakeOwner.public,
|
|
(filter) async => filter.kinds.contains(30177)
|
|
? [forged]
|
|
: [signedAgentProfile(fakeAgentKeys, fakeOwner)],
|
|
);
|
|
expect(found.single.runtime, isNull);
|
|
});
|
|
|
|
test('a registration whose signature fails keeps the agent without its '
|
|
'model', () async {
|
|
final signed = registration(
|
|
fakeAgent,
|
|
content: '{"name":"Remote","model":"Claude Sonnet"}',
|
|
);
|
|
// Same id and content, but another key's signature over the id.
|
|
final forged = NostrEvent.fromJson({
|
|
...signed.toJson(),
|
|
'sig': nostr.Event.from(
|
|
kind: 1,
|
|
content: 'other',
|
|
secretKey: fakeAgentKeys.secret,
|
|
).sig,
|
|
});
|
|
final profiles = [
|
|
signedAgentProfile(
|
|
fakeAgentKeys,
|
|
fakeOwner,
|
|
content: '{"name":"Remote"}',
|
|
),
|
|
];
|
|
Future<List<OwnedAgentDirectoryEntry>> load(NostrEvent event) =>
|
|
loadOwnedAgentDirectory(
|
|
fakeOwner.public,
|
|
(filter) async => filter.kinds.contains(30177) ? [event] : profiles,
|
|
);
|
|
|
|
expect((await load(signed)).single.model, 'Claude Sonnet');
|
|
final found = (await load(forged)).single;
|
|
expect(found.pubkey, fakeAgent);
|
|
expect(found.model, isNull);
|
|
});
|
|
|
|
test('a registration is listed only with a type runtime and a name', () {
|
|
final agent = fakeAgent;
|
|
final cases = <(String, NostrEvent, bool)>[
|
|
('valid', registration(agent), true),
|
|
('no runtime', registration(agent, runtime: null), false),
|
|
('runtime without a type', registration(agent, runtime: 'goose'), false),
|
|
('uppercase runtime', registration(agent, runtime: 'Block/Goose'), false),
|
|
('empty name', registration(agent, content: '{"name":" "}'), false),
|
|
('no name', registration(agent, content: '{}'), false),
|
|
('not JSON', registration(agent, content: 'instance'), false),
|
|
('JSON list', registration(agent, content: '[]'), false),
|
|
];
|
|
for (final (label, event, listed) in cases) {
|
|
expect(isListedAgentRegistration(event), listed, reason: label);
|
|
}
|
|
});
|
|
}
|