@@ -18,6 +18,7 @@ const gatewayMocks = vi.hoisted(() => ({
1818 | undefined ,
1919 onMessageError : undefined as ( ( error : Error ) => void ) | undefined ,
2020 onFatalError : undefined as ( ( error : Error ) => void ) | undefined ,
21+ currentBus : undefined as BuzzBus | undefined ,
2122 resolveAgentIdentity : vi . fn ( ) ,
2223 resolveAgentRoute : vi . fn ( ) ,
2324 startBuzzBus : vi . fn ( ) ,
@@ -63,6 +64,7 @@ describe("Buzz gateway lifecycle", () => {
6364 gatewayMocks . onMessage = undefined ;
6465 gatewayMocks . onMessageError = undefined ;
6566 gatewayMocks . onFatalError = undefined ;
67+ gatewayMocks . currentBus = undefined ;
6668 gatewayMocks . busSendText . mockResolvedValue ( "event-id" ) ;
6769 gatewayMocks . busSendTyping . mockResolvedValue ( undefined ) ;
6870 gatewayMocks . sendBuzzTextOneShot . mockResolvedValue ( "standalone-event-id" ) ;
@@ -95,7 +97,9 @@ describe("Buzz gateway lifecycle", () => {
9597 gatewayMocks . onMessage = options . onMessage ;
9698 gatewayMocks . onMessageError = options . onMessageError ;
9799 gatewayMocks . onFatalError = options . onFatalError ;
98- return createMockBus ( ) ;
100+ const bus = createMockBus ( ) ;
101+ gatewayMocks . currentBus = bus ;
102+ return bus ;
99103 } ,
100104 ) ;
101105 } ) ;
@@ -250,6 +254,84 @@ describe("Buzz gateway lifecycle", () => {
250254 await expect ( lifecycle ) . resolves . toBeUndefined ( ) ;
251255 } ) ;
252256
257+ it ( "resolves native mentions from the active bus directory without a relay lookup" , async ( ) => {
258+ const abortController = new AbortController ( ) ;
259+ const memberPublicKey = "b" . repeat ( 64 ) ;
260+ const cfg = {
261+ channels : {
262+ buzz : {
263+ relayUrl : "wss://buzz.example.com" ,
264+ privateKey : PRIVATE_KEY ,
265+ groups : { [ CHANNEL_ID ] : { } } ,
266+ } ,
267+ } ,
268+ } as OpenClawConfig ;
269+ const account = resolveBuzzAccount ( { cfg } ) ;
270+ const ctx = {
271+ cfg,
272+ accountId : account . accountId ,
273+ account,
274+ runtime : { } ,
275+ abortSignal : abortController . signal ,
276+ log : { info : vi . fn ( ) , error : vi . fn ( ) } ,
277+ getStatus : vi . fn ( ) ,
278+ setStatus : vi . fn ( ) ,
279+ } as unknown as ChannelGatewayContext < ResolvedBuzzAccount > ;
280+ const lifecycle = startBuzzGatewayAccount ( ctx ) ;
281+ await vi . waitFor ( ( ) => expect ( gatewayMocks . currentBus ) . toBeDefined ( ) ) ;
282+ const bus = gatewayMocks . currentBus ;
283+ if ( ! bus ) {
284+ throw new Error ( "expected active Buzz bus" ) ;
285+ }
286+ bus . directory . replaceMemberships (
287+ new Map ( [
288+ [
289+ CHANNEL_ID ,
290+ {
291+ roomId : CHANNEL_ID ,
292+ createdAt : 1_700_000_000 ,
293+ eventId : "1" . repeat ( 64 ) ,
294+ publisherPublicKey : "f" . repeat ( 64 ) ,
295+ members : new Set ( [ BOT_PUBLIC_KEY , memberPublicKey ] ) ,
296+ roles : new Map ( [
297+ [ BOT_PUBLIC_KEY , "bot" ] ,
298+ [ memberPublicKey , "member" ] ,
299+ ] ) ,
300+ } ,
301+ ] ,
302+ ] ) ,
303+ ) ;
304+ bus . directory . applyProfileEvent ( {
305+ id : "2" . repeat ( 64 ) ,
306+ kind : 0 ,
307+ pubkey : memberPublicKey ,
308+ created_at : 1_700_000_000 ,
309+ content : JSON . stringify ( { display_name : "Alice" } ) ,
310+ sig : "e" . repeat ( 128 ) ,
311+ tags : [ ] ,
312+ } ) ;
313+
314+ await buzzOutboundAdapter . sendText ( {
315+ cfg,
316+ to : `buzz:${ CHANNEL_ID } ` ,
317+ text : "Hello @Alice" ,
318+ accountId : "default" ,
319+ threadId : "root-id" ,
320+ } ) ;
321+
322+ expect ( gatewayMocks . busSendText ) . toHaveBeenCalledWith ( {
323+ channelId : CHANNEL_ID ,
324+ text : "Hello @Alice" ,
325+ threadId : "root-id" ,
326+ replyToId : undefined ,
327+ mentionedPubkeys : [ memberPublicKey ] ,
328+ } ) ;
329+ expect ( gatewayMocks . sendBuzzTextOneShot ) . not . toHaveBeenCalled ( ) ;
330+
331+ abortController . abort ( ) ;
332+ await expect ( lifecycle ) . resolves . toBeUndefined ( ) ;
333+ } ) ;
334+
253335 it ( "uses the active bus for heartbeat typing without destabilizing the account" , async ( ) => {
254336 const abortController = new AbortController ( ) ;
255337 const cfg = {
0 commit comments