@@ -10549,103 +10549,120 @@ void main() {
1054910549 },
1055010550 );
1055110551
10552- testWidgets(
10553- 'Codex DM hangup leaves cleanup to relay with a one-owner snapshot',
10554- (tester) async {
10555- final now = DateTime.now().millisecondsSinceEpoch ~/ 1000;
10556- final media = _HuddleTestMedia();
10557- final transport = _HuddleTestTransport(
10558- peers: const {2: HuddlePeer(pubkey: 'self', peerIndex: 2, epoch: 0)},
10559- );
10560- final relaySession = _ReconnectingRelaySession();
10561- String? leftChannelId;
10562- String? archivedChannelId;
10563-
10564- await tester.pumpWidget(
10565- _buildTestable(
10566- channel: Channel(
10567- id: _channelId,
10568- name: 'Codex',
10569- description: '',
10570- channelType: 'dm',
10571- visibility: 'private',
10572- createdBy: 'self',
10573- createdAt: DateTime(2025),
10574- memberCount: 2,
10575- participants: const ['Self', 'Agent'],
10576- participantPubkeys: const ['self', 'agent'],
10577- isMember: true,
10578- ),
10579- voiceAgents: const {'agent'},
10580- huddleHumanCountLoader: (_) async => 1,
10581- messages: [
10582- _huddleMsg(
10583- id: 'last-human-call-leave',
10584- kind: EventKind.huddleStarted,
10585- pubkey: 'desktop',
10586- createdAt: now,
10587- ),
10588- ],
10589- users: const {
10590- 'desktop': UserProfile(pubkey: 'desktop'),
10591- 'agent': UserProfile(pubkey: 'agent', displayName: 'Pollen'),
10592- 'self': UserProfile(pubkey: 'self'),
10552+ for (final scenario in [
10553+ (anotherDevice: false, otherHuman: false),
10554+ (anotherDevice: true, otherHuman: false),
10555+ (anotherDevice: false, otherHuman: true),
10556+ ]) {
10557+ final anotherDevice = scenario.anotherDevice;
10558+ final shouldEnd = !anotherDevice && !scenario.otherHuman;
10559+ testWidgets(
10560+ 'Codex DM hangup ends only after the last human device: $scenario',
10561+ (tester) async {
10562+ final now = DateTime.now().millisecondsSinceEpoch ~/ 1000;
10563+ final media = _HuddleTestMedia();
10564+ final transport = _HuddleTestTransport(
10565+ peers: {
10566+ 2: const HuddlePeer(pubkey: 'self', peerIndex: 2, epoch: 0),
10567+ if (anotherDevice)
10568+ 3: const HuddlePeer(pubkey: 'self', peerIndex: 3, epoch: 0),
1059310569 },
10594- relayConfigNotifier: _HuddleRelayConfigNotifier(),
10595- relaySessionNotifier: relaySession,
10596- huddleCurrentPubkey: 'self',
10597- huddleMembers: [
10598- ChannelMember(
10599- pubkey: 'self',
10600- role: 'member',
10601- joinedAt: DateTime(2025),
10570+ );
10571+ final relaySession = _ReconnectingRelaySession();
10572+ String? leftChannelId;
10573+ String? archivedChannelId;
10574+
10575+ await tester.pumpWidget(
10576+ _buildTestable(
10577+ channel: Channel(
10578+ id: _channelId,
10579+ name: 'Codex',
10580+ description: '',
10581+ channelType: 'dm',
10582+ visibility: 'private',
10583+ createdBy: 'self',
10584+ createdAt: DateTime(2025),
10585+ memberCount: 2,
10586+ participants: const ['Self', 'Agent'],
10587+ participantPubkeys: const ['self', 'agent'],
10588+ isMember: true,
1060210589 ),
10603- ChannelMember(
10604- pubkey: 'agent',
10605- role: 'bot',
10606- joinedAt: DateTime(2025),
10590+ voiceAgents: scenario.otherHuman ? const {} : const {'agent'},
10591+ huddleHumanCountLoader: (_) async => scenario.otherHuman ? 2 : 1,
10592+ messages: [
10593+ _huddleMsg(
10594+ id: 'last-human-call-leave',
10595+ kind: EventKind.huddleStarted,
10596+ pubkey: 'desktop',
10597+ createdAt: now,
10598+ ),
10599+ ],
10600+ users: const {
10601+ 'desktop': UserProfile(pubkey: 'desktop'),
10602+ 'agent': UserProfile(pubkey: 'agent', displayName: 'Pollen'),
10603+ 'self': UserProfile(pubkey: 'self'),
10604+ },
10605+ relayConfigNotifier: _HuddleRelayConfigNotifier(),
10606+ relaySessionNotifier: relaySession,
10607+ huddleCurrentPubkey: 'self',
10608+ huddleMembers: [
10609+ ChannelMember(
10610+ pubkey: 'self',
10611+ role: 'member',
10612+ joinedAt: DateTime(2025),
10613+ ),
10614+ ChannelMember(
10615+ pubkey: 'agent',
10616+ role: scenario.otherHuman ? 'member' : 'bot',
10617+ joinedAt: DateTime(2025),
10618+ ),
10619+ ],
10620+ huddleMediaFactory: () => media,
10621+ huddleTransportFactory: (_) => transport,
10622+ createChannelActions: (ref) => _FakeChannelActions(
10623+ ref,
10624+ onLeaveChannel: (channelId) async => leftChannelId = channelId,
10625+ onArchiveChannel: (channelId) async =>
10626+ archivedChannelId = channelId,
1060710627 ),
10608- ],
10609- huddleMediaFactory: () => media,
10610- huddleTransportFactory: (_) => transport,
10611- createChannelActions: (ref) => _FakeChannelActions(
10612- ref,
10613- onLeaveChannel: (channelId) async => leftChannelId = channelId,
10614- onArchiveChannel: (channelId) async =>
10615- archivedChannelId = channelId,
1061610628 ),
10617- ),
10618- );
10619- await tester.pumpAndSettle();
10629+ );
10630+ await tester.pumpAndSettle();
1062010631
10621- await tester.tap(find.widgetWithText(FilledButton, 'Join'));
10622- await tester.pumpAndSettle();
10623- relaySession.connect();
10624- await tester.pump();
10625- await tester.tap(find.byKey(const ValueKey('huddle-leave')));
10626- await tester.pump();
10627- for (
10628- var attempt = 0;
10629- attempt < 100 && archivedChannelId == null;
10630- attempt++
10631- ) {
10632+ await tester.tap(find.widgetWithText(FilledButton, 'Join'));
10633+ await tester.pumpAndSettle();
10634+ relaySession.connect();
1063210635 await tester.pump();
10633- }
10634- for (var attempt = 0; attempt < 20; attempt++) {
10636+ await tester.tap(find.byKey(const ValueKey('huddle-leave')));
10637+ await tester.pump();
10638+ for (
10639+ var attempt = 0;
10640+ attempt < 100 && archivedChannelId == null;
10641+ attempt++
10642+ ) {
10643+ await tester.pump();
10644+ }
10645+ for (var attempt = 0; attempt < 20; attempt++) {
10646+ await tester.pump();
10647+ }
10648+ await tester.pump(const Duration(milliseconds: 300));
10649+ await tester.pump(const Duration(milliseconds: 300));
1063510650 await tester.pump();
10636- }
10637- await tester.pump(const Duration(milliseconds: 300));
10638- await tester.pump(const Duration(milliseconds: 300));
10639- await tester.pump();
1064010651
10641- expect(leftChannelId, isNull);
10642- expect(archivedChannelId, isNull);
10643- expect(
10644- relaySession.publishedKinds,
10645- isNot(contains(EventKind.huddleEnded)),
10646- );
10647- },
10648- );
10652+ expect(leftChannelId, isNull);
10653+ expect(
10654+ archivedChannelId,
10655+ shouldEnd ? '8d764100-fd8f-44cf-9c98-6d8fbd739b8c' : isNull,
10656+ );
10657+ expect(
10658+ relaySession.publishedKinds,
10659+ shouldEnd
10660+ ? contains(EventKind.huddleEnded)
10661+ : isNot(contains(EventKind.huddleEnded)),
10662+ );
10663+ },
10664+ );
10665+ }
1064910666
1065010667 testWidgets('top-right call end auto-ends for the last human', (
1065110668 tester,
0 commit comments