@@ -269,6 +269,122 @@ suite.define(() => {
269269 await context . close ( ) ;
270270 } ) ;
271271
272+ it ( "keeps attributed user avatars beside their bubbles through send reconciliation" , async ( ) => {
273+ const context = await suite . browser . newContext ( {
274+ viewport : { height : 900 , width : 860 } ,
275+ } ) ;
276+ const page = await context . newPage ( ) ;
277+ const localSenderId = "c3e32452-0467-47e5-aafa-233cd5dae29f" ;
278+ const peerSenderId = "315ee057-302f-45b4-829d-2c5db1bfed75" ;
279+ const localAvatarUrl = `/api/users/${ localSenderId } /avatar?v=7` ;
280+ const priorPrompt = "A prior attributed prompt." ;
281+ const peerPrompt = "A peer attributed prompt." ;
282+ const prompt = "A newly sent attributed prompt." ;
283+ await page . route ( `**/api/users/${ localSenderId } /avatar*` , async ( route ) => {
284+ await route . fulfill ( {
285+ body : `<svg xmlns="http://www.w3.org/2000/svg" width="36" height="36"><rect width="36" height="36" fill="purple"/></svg>` ,
286+ contentType : "image/svg+xml" ,
287+ status : 200 ,
288+ } ) ;
289+ } ) ;
290+ const gateway = await installMockGateway ( page , {
291+ historyMessages : [
292+ {
293+ __openclaw : { senderId : localSenderId , senderName : "Collin Johnson" } ,
294+ content : [ { text : priorPrompt , type : "text" } ] ,
295+ role : "user" ,
296+ timestamp : Date . now ( ) - 3_000 ,
297+ } ,
298+ {
299+ __openclaw : { senderId : peerSenderId , senderName : "Riley Chen" } ,
300+ content : [ { text : peerPrompt , type : "text" } ] ,
301+ role : "user" ,
302+ timestamp : Date . now ( ) - 2_000 ,
303+ } ,
304+ {
305+ content : [ { text : "Ready for the next message." , type : "text" } ] ,
306+ role : "assistant" ,
307+ timestamp : Date . now ( ) - 1_000 ,
308+ } ,
309+ ] ,
310+ presenceUsers : [
311+ { self : true , id : localSenderId , name : "Collin Johnson" , avatarUrl : localAvatarUrl } ,
312+ { id : peerSenderId , name : "Riley Chen" } ,
313+ ] ,
314+ } ) ;
315+
316+ const readUserAvatarLayout = async ( message : string ) => {
317+ const bubble = page . locator ( ".chat-group.user .chat-bubble" , { hasText : message } ) ;
318+ await bubble . waitFor ( ) ;
319+ return await bubble . evaluate ( ( bubbleElement ) => {
320+ const group = bubbleElement . closest < HTMLElement > ( ".chat-group.user" ) ;
321+ const avatar = group
322+ ? [ ...group . querySelectorAll < HTMLElement > ( ".chat-avatar" ) ] . find (
323+ ( candidate ) => getComputedStyle ( candidate ) . display !== "none" ,
324+ )
325+ : null ;
326+ if ( ! group || ! avatar ) {
327+ throw new Error ( "Expected a visible attributed user avatar" ) ;
328+ }
329+ const bubbleRect = bubbleElement . getBoundingClientRect ( ) ;
330+ const avatarRect = avatar . getBoundingClientRect ( ) ;
331+ return {
332+ avatarLeft : avatarRect . left ,
333+ avatarRight : avatarRect . right ,
334+ bubbleLeft : bubbleRect . left ,
335+ bubbleRight : bubbleRect . right ,
336+ isPeer : group . classList . contains ( "chat-group--peer" ) ,
337+ } ;
338+ } ) ;
339+ } ;
340+
341+ try {
342+ await page . goto ( controlUiSessionUrl ( suite . server . baseUrl , "agent:main:main" ) ) ;
343+ const before = await readUserAvatarLayout ( priorPrompt ) ;
344+ const peerBefore = await readUserAvatarLayout ( peerPrompt ) ;
345+
346+ await page . locator ( ".agent-chat__composer-combobox textarea" ) . fill ( prompt ) ;
347+ await page . getByRole ( "button" , { name : "Send message" } ) . click ( ) ;
348+ const sendRequest = await gateway . waitForRequest ( "chat.send" ) ;
349+ const afterSend = await readUserAvatarLayout ( prompt ) ;
350+ const priorAfterSend = await readUserAvatarLayout ( priorPrompt ) ;
351+ const peerAfterSend = await readUserAvatarLayout ( peerPrompt ) ;
352+
353+ const params = sendRequest . params ;
354+ if ( ! params || typeof params !== "object" || ! ( "idempotencyKey" in params ) ) {
355+ throw new Error ( "Expected chat send idempotency key" ) ;
356+ }
357+ const runId = params . idempotencyKey ;
358+ if ( typeof runId !== "string" || ! runId . trim ( ) ) {
359+ throw new Error ( "Expected non-empty chat send idempotency key" ) ;
360+ }
361+ await gateway . emitChatFinal ( { runId, text : "The attributed send completed." } ) ;
362+ await page
363+ . locator ( ".chat-thread .chat-bubble" , { hasText : "The attributed send completed." } )
364+ . waitFor ( ) ;
365+ const afterFinal = await readUserAvatarLayout ( prompt ) ;
366+
367+ for ( const [ phase , layout ] of [
368+ [ "initial history" , before ] ,
369+ [ "optimistic send" , afterSend ] ,
370+ [ "prior message after send" , priorAfterSend ] ,
371+ [ "final response" , afterFinal ] ,
372+ ] as const ) {
373+ expect ( layout . isPeer , phase ) . toBe ( false ) ;
374+ expect ( layout . avatarLeft , phase ) . toBeGreaterThanOrEqual ( layout . bubbleRight + 9 ) ;
375+ }
376+ for ( const [ phase , layout ] of [
377+ [ "peer initial history" , peerBefore ] ,
378+ [ "peer message after send" , peerAfterSend ] ,
379+ ] as const ) {
380+ expect ( layout . isPeer , phase ) . toBe ( true ) ;
381+ expect ( layout . avatarRight , phase ) . toBeLessThanOrEqual ( layout . bubbleLeft - 9 ) ;
382+ }
383+ } finally {
384+ await context . close ( ) ;
385+ }
386+ } ) ;
387+
272388 it ( "keeps missing local-viewer avatar initials through a live rerender" , async ( ) => {
273389 const artifactDir = resolveArtifactDir ( ) ;
274390 if ( artifactDir ) {
0 commit comments