@@ -143,6 +143,122 @@ suite.define(() => {
143143 await context . close ( ) ;
144144 } ) ;
145145
146+ it ( "keeps attributed user avatars beside their bubbles through send reconciliation" , async ( ) => {
147+ const context = await suite . browser . newContext ( {
148+ viewport : { height : 900 , width : 860 } ,
149+ } ) ;
150+ const page = await context . newPage ( ) ;
151+ const localSenderId = "c3e32452-0467-47e5-aafa-233cd5dae29f" ;
152+ const peerSenderId = "315ee057-302f-45b4-829d-2c5db1bfed75" ;
153+ const localAvatarUrl = `/api/users/${ localSenderId } /avatar?v=7` ;
154+ const priorPrompt = "A prior attributed prompt." ;
155+ const peerPrompt = "A peer attributed prompt." ;
156+ const prompt = "A newly sent attributed prompt." ;
157+ await page . route ( `**/api/users/${ localSenderId } /avatar*` , async ( route ) => {
158+ await route . fulfill ( {
159+ body : `<svg xmlns="http://www.w3.org/2000/svg" width="36" height="36"><rect width="36" height="36" fill="purple"/></svg>` ,
160+ contentType : "image/svg+xml" ,
161+ status : 200 ,
162+ } ) ;
163+ } ) ;
164+ const gateway = await installMockGateway ( page , {
165+ historyMessages : [
166+ {
167+ __openclaw : { senderId : localSenderId , senderName : "Collin Johnson" } ,
168+ content : [ { text : priorPrompt , type : "text" } ] ,
169+ role : "user" ,
170+ timestamp : Date . now ( ) - 3_000 ,
171+ } ,
172+ {
173+ __openclaw : { senderId : peerSenderId , senderName : "Riley Chen" } ,
174+ content : [ { text : peerPrompt , type : "text" } ] ,
175+ role : "user" ,
176+ timestamp : Date . now ( ) - 2_000 ,
177+ } ,
178+ {
179+ content : [ { text : "Ready for the next message." , type : "text" } ] ,
180+ role : "assistant" ,
181+ timestamp : Date . now ( ) - 1_000 ,
182+ } ,
183+ ] ,
184+ presenceUsers : [
185+ { self : true , id : localSenderId , name : "Collin Johnson" , avatarUrl : localAvatarUrl } ,
186+ { id : peerSenderId , name : "Riley Chen" } ,
187+ ] ,
188+ } ) ;
189+
190+ const readUserAvatarLayout = async ( message : string ) => {
191+ const bubble = page . locator ( ".chat-group.user .chat-bubble" , { hasText : message } ) ;
192+ await bubble . waitFor ( ) ;
193+ return await bubble . evaluate ( ( bubbleElement ) => {
194+ const group = bubbleElement . closest < HTMLElement > ( ".chat-group.user" ) ;
195+ const avatar = group
196+ ? [ ...group . querySelectorAll < HTMLElement > ( ".chat-avatar" ) ] . find (
197+ ( candidate ) => getComputedStyle ( candidate ) . display !== "none" ,
198+ )
199+ : null ;
200+ if ( ! group || ! avatar ) {
201+ throw new Error ( "Expected a visible attributed user avatar" ) ;
202+ }
203+ const bubbleRect = bubbleElement . getBoundingClientRect ( ) ;
204+ const avatarRect = avatar . getBoundingClientRect ( ) ;
205+ return {
206+ avatarLeft : avatarRect . left ,
207+ avatarRight : avatarRect . right ,
208+ bubbleLeft : bubbleRect . left ,
209+ bubbleRight : bubbleRect . right ,
210+ isPeer : group . classList . contains ( "chat-group--peer" ) ,
211+ } ;
212+ } ) ;
213+ } ;
214+
215+ try {
216+ await page . goto ( controlUiSessionUrl ( suite . server . baseUrl , "agent:main:main" ) ) ;
217+ const before = await readUserAvatarLayout ( priorPrompt ) ;
218+ const peerBefore = await readUserAvatarLayout ( peerPrompt ) ;
219+
220+ await page . locator ( ".agent-chat__composer-combobox textarea" ) . fill ( prompt ) ;
221+ await page . getByRole ( "button" , { name : "Send message" } ) . click ( ) ;
222+ const sendRequest = await gateway . waitForRequest ( "chat.send" ) ;
223+ const afterSend = await readUserAvatarLayout ( prompt ) ;
224+ const priorAfterSend = await readUserAvatarLayout ( priorPrompt ) ;
225+ const peerAfterSend = await readUserAvatarLayout ( peerPrompt ) ;
226+
227+ const params = sendRequest . params ;
228+ if ( ! params || typeof params !== "object" || ! ( "idempotencyKey" in params ) ) {
229+ throw new Error ( "Expected chat send idempotency key" ) ;
230+ }
231+ const runId = params . idempotencyKey ;
232+ if ( typeof runId !== "string" || ! runId . trim ( ) ) {
233+ throw new Error ( "Expected non-empty chat send idempotency key" ) ;
234+ }
235+ await gateway . emitChatFinal ( { runId, text : "The attributed send completed." } ) ;
236+ await page
237+ . locator ( ".chat-thread .chat-bubble" , { hasText : "The attributed send completed." } )
238+ . waitFor ( ) ;
239+ const afterFinal = await readUserAvatarLayout ( prompt ) ;
240+
241+ for ( const [ phase , layout ] of [
242+ [ "initial history" , before ] ,
243+ [ "optimistic send" , afterSend ] ,
244+ [ "prior message after send" , priorAfterSend ] ,
245+ [ "final response" , afterFinal ] ,
246+ ] as const ) {
247+ expect ( layout . isPeer , phase ) . toBe ( false ) ;
248+ expect ( layout . avatarLeft , phase ) . toBeGreaterThanOrEqual ( layout . bubbleRight + 9 ) ;
249+ }
250+ for ( const [ phase , layout ] of [
251+ [ "peer initial history" , peerBefore ] ,
252+ [ "peer message after send" , peerAfterSend ] ,
253+ ] as const ) {
254+ expect ( layout . isPeer , phase ) . toBe ( true ) ;
255+ expect ( layout . avatarRight , phase ) . toBeLessThanOrEqual ( layout . bubbleLeft - 9 ) ;
256+ }
257+ } finally {
258+ await context . close ( ) ;
259+ }
260+ } ) ;
261+
146262 it ( "keeps missing local-viewer avatar initials through a live rerender" , async ( ) => {
147263 const artifactDir = resolveArtifactDir ( ) ;
148264 if ( artifactDir ) {
0 commit comments