11// Control UI E2E tests cover session ownership dormancy and owner filtering.
22import { mkdir } from "node:fs/promises" ;
33import path from "node:path" ;
4- import type { Page } from "playwright" ;
4+ import type { BrowserContext , Page } from "playwright" ;
55import { expect as expectBrowser } from "playwright/test" ;
66import { afterEach , expect , it } from "vitest" ;
77import { installMockGateway } from "../test-helpers/control-ui-e2e.ts" ;
@@ -13,6 +13,12 @@ const suite = createControlUiE2eSuite({
1313
1414const captureUiProofEnabled = process . env . OPENCLAW_CAPTURE_UI_PROOF === "1" ;
1515const uiProofArtifactDir = path . join ( process . cwd ( ) , ".artifacts" , "control-ui-e2e" , "drafts-ux" ) ;
16+ const sessionOwnerProofArtifactDir = path . join (
17+ process . cwd ( ) ,
18+ ".artifacts" ,
19+ "control-ui-e2e" ,
20+ "session-owner-stack" ,
21+ ) ;
1622
1723let page : Page | undefined ;
1824function sessionsList ( owners : [ string , string ] ) {
@@ -67,6 +73,72 @@ function draftSessionsList() {
6773 return result ;
6874}
6975
76+ function collaborativeSessionsList ( ) {
77+ const ada = {
78+ type : "human" as const ,
79+ id : "profile-ada" ,
80+ label : "Ada" ,
81+ avatarUrl : "/api/users/profile-ada/avatar?v=1" ,
82+ } ;
83+ const bob = {
84+ type : "human" as const ,
85+ id : "profile-bob" ,
86+ label : "Bob" ,
87+ avatarUrl : "/api/users/profile-bob/avatar?v=1" ,
88+ } ;
89+ const carol = { type : "human" as const , id : "profile-carol" , label : "Carol" } ;
90+ return {
91+ count : 3 ,
92+ owners : [ ada , bob , carol ] ,
93+ defaults : { contextTokens : null , model : null , modelProvider : null } ,
94+ path : "" ,
95+ sessions : [
96+ {
97+ key : "agent:main:collaboration" ,
98+ kind : "direct" ,
99+ label : "Fix issue #127689" ,
100+ createdActor : ada ,
101+ owner : { actor : ada } ,
102+ participants : [ bob ] ,
103+ participantCount : 1 ,
104+ updatedAt : 3 ,
105+ } ,
106+ {
107+ key : "agent:main:release-planning" ,
108+ kind : "direct" ,
109+ label : "Release planning" ,
110+ createdActor : bob ,
111+ owner : { actor : bob } ,
112+ participants : [ ada , { type : "agent" as const , id : "research" , label : "Research" } ] ,
113+ participantCount : 2 ,
114+ updatedAt : 2 ,
115+ } ,
116+ {
117+ key : "agent:main:single-owner" ,
118+ kind : "direct" ,
119+ label : "Single-owner baseline" ,
120+ createdActor : carol ,
121+ owner : { actor : carol } ,
122+ updatedAt : 1 ,
123+ } ,
124+ ] ,
125+ ts : 1 ,
126+ } ;
127+ }
128+
129+ async function createAvatarPng ( context : BrowserContext , background : string , label : string ) {
130+ const avatarPage = await context . newPage ( ) ;
131+ try {
132+ await avatarPage . setViewportSize ( { width : 64 , height : 64 } ) ;
133+ await avatarPage . setContent (
134+ `<body style="margin:0;width:64px;height:64px;display:grid;place-items:center;background:${ background } ;color:white;font:700 26px system-ui">${ label } </body>` ,
135+ ) ;
136+ return await avatarPage . screenshot ( { animations : "disabled" , type : "png" } ) ;
137+ } finally {
138+ await avatarPage . close ( ) . catch ( ( ) => { } ) ;
139+ }
140+ }
141+
70142async function captureUiProof ( targetPage : Page , fileName : string ) {
71143 if ( ! captureUiProofEnabled ) {
72144 return ;
@@ -79,6 +151,17 @@ async function captureUiProof(targetPage: Page, fileName: string) {
79151 } ) ;
80152}
81153
154+ async function captureSessionOwnerProof ( targetPage : Page , fileName : string ) {
155+ if ( ! captureUiProofEnabled ) {
156+ return ;
157+ }
158+ await mkdir ( sessionOwnerProofArtifactDir , { recursive : true } ) ;
159+ await targetPage . locator ( ".sidebar-sessions" ) . screenshot ( {
160+ animations : "disabled" ,
161+ path : path . join ( sessionOwnerProofArtifactDir , fileName ) ,
162+ } ) ;
163+ }
164+
82165async function openSidebarSortMenu ( targetPage : Page ) {
83166 const filterAndSort = targetPage . getByRole ( "button" , { name : "Filter & sort" } ) ;
84167 await expect . poll ( ( ) => filterAndSort . count ( ) , { timeout : 2_000 } ) . toBe ( 1 ) ;
@@ -109,6 +192,123 @@ suite.define(() => {
109192 page = undefined ;
110193 } ) ;
111194
195+ it ( "keeps collaborative owner stacks legible without shifting session rows" , async ( ) => {
196+ const context = await suite . browser . newContext ( { viewport : { height : 800 , width : 1200 } } ) ;
197+ const currentPage = await context . newPage ( ) ;
198+ page = currentPage ;
199+ const [ adaAvatar , bobAvatar ] = await Promise . all ( [
200+ createAvatarPng ( context , "#3f6f76" , "A" ) ,
201+ createAvatarPng ( context , "#985b42" , "B" ) ,
202+ ] ) ;
203+ await currentPage . route ( "**/api/users/profile-ada/avatar*" , ( route ) =>
204+ route . fulfill ( { body : adaAvatar , contentType : "image/png" , status : 200 } ) ,
205+ ) ;
206+ await currentPage . route ( "**/api/users/profile-bob/avatar*" , ( route ) =>
207+ route . fulfill ( { body : bobAvatar , contentType : "image/png" , status : 200 } ) ,
208+ ) ;
209+ await installMockGateway ( currentPage , {
210+ hasMultipleSessionSharingIdentities : true ,
211+ sessionKey : "agent:main:collaboration" ,
212+ historyMessages : [ { role : "assistant" , content : [ { type : "text" , text : "Ready." } ] } ] ,
213+ methodResponses : { "sessions.list" : collaborativeSessionsList ( ) } ,
214+ } ) ;
215+
216+ await currentPage . goto ( `${ suite . server ?. baseUrl ?? "" } chat` ) ;
217+ const collaborativeRow = currentPage . locator ( '[data-session-key="agent:main:collaboration"]' ) ;
218+ const overflowRow = currentPage . locator ( '[data-session-key="agent:main:release-planning"]' ) ;
219+ const singleOwnerRow = currentPage . locator ( '[data-session-key="agent:main:single-owner"]' ) ;
220+ await collaborativeRow . waitFor ( ) ;
221+ await overflowRow . waitFor ( ) ;
222+ await singleOwnerRow . waitFor ( ) ;
223+ await expect . poll ( ( ) => collaborativeRow . locator ( ".session-owner-stack img" ) . count ( ) ) . toBe ( 2 ) ;
224+ await expect
225+ . poll ( ( ) =>
226+ collaborativeRow
227+ . locator ( ".session-owner-stack img" )
228+ . evaluateAll ( ( images ) =>
229+ images . every (
230+ ( image ) =>
231+ image instanceof HTMLImageElement && image . complete && image . naturalWidth > 0 ,
232+ ) ,
233+ ) ,
234+ )
235+ . toBe ( true ) ;
236+
237+ const geometry = await collaborativeRow . evaluate ( ( row ) => {
238+ const stack = row . querySelector < HTMLElement > ( ".session-owner-stack" ) ;
239+ const back = row . querySelector < HTMLElement > ( ".session-owner-stack__back .viewer-avatar" ) ;
240+ const front = row . querySelector < HTMLElement > ( ".session-owner-stack__front" ) ;
241+ const slot = row . querySelector < HTMLElement > ( ".sidebar-session-indicator" ) ;
242+ const text = row . querySelector < HTMLElement > ( ".sidebar-recent-session__text" ) ;
243+ if ( ! stack || ! back || ! front || ! slot || ! text ) {
244+ throw new Error ( "expected complete collaborative session row" ) ;
245+ }
246+ const stackBounds = stack . getBoundingClientRect ( ) ;
247+ const backBounds = back . getBoundingClientRect ( ) ;
248+ const frontBounds = front . getBoundingClientRect ( ) ;
249+ const slotBounds = slot . getBoundingClientRect ( ) ;
250+ const textBounds = text . getBoundingClientRect ( ) ;
251+ return {
252+ backSize : [ backBounds . width , backBounds . height ] ,
253+ centerDelta :
254+ stackBounds . left + stackBounds . width / 2 - ( slotBounds . left + slotBounds . width / 2 ) ,
255+ frontSize : [ frontBounds . width , frontBounds . height ] ,
256+ overlap : backBounds . right - frontBounds . left ,
257+ reveal : frontBounds . left - backBounds . left ,
258+ slotWidth : slotBounds . width ,
259+ stackSize : [ stackBounds . width , stackBounds . height ] ,
260+ textGap : textBounds . left - stackBounds . right ,
261+ } ;
262+ } ) ;
263+ expect ( geometry ) . toEqual ( {
264+ backSize : [ 18 , 18 ] ,
265+ centerDelta : 0 ,
266+ frontSize : [ 18 , 18 ] ,
267+ overlap : 8 ,
268+ reveal : 10 ,
269+ slotWidth : 20 ,
270+ stackSize : [ 28 , 20 ] ,
271+ textGap : 4 ,
272+ } ) ;
273+ await expectBrowser ( overflowRow . locator ( ".session-owner-stack__overflow" ) ) . toHaveText ( "+2" ) ;
274+ const rowHeights = await Promise . all ( [
275+ collaborativeRow . evaluate ( ( row ) => row . getBoundingClientRect ( ) . height ) ,
276+ singleOwnerRow . evaluate ( ( row ) => row . getBoundingClientRect ( ) . height ) ,
277+ ] ) ;
278+ expect ( rowHeights [ 0 ] ) . toBeCloseTo ( rowHeights [ 1 ] ?? 0 , 5 ) ;
279+ const titleLefts = await Promise . all (
280+ [ collaborativeRow , singleOwnerRow ] . map ( ( row ) =>
281+ row
282+ . locator ( ".sidebar-recent-session__text" )
283+ . evaluate ( ( text ) => text . getBoundingClientRect ( ) . left ) ,
284+ ) ,
285+ ) ;
286+ expect ( titleLefts [ 0 ] ) . toBeCloseTo ( titleLefts [ 1 ] ?? 0 , 5 ) ;
287+
288+ if ( captureUiProofEnabled ) {
289+ const legacyStyles = await currentPage . addStyleTag ( {
290+ content : `
291+ .session-owner-stack { width: 24px; }
292+ .session-owner-stack__back { width: 14px; height: 14px; }
293+ .session-owner-stack__back .viewer-avatar,
294+ .session-owner-stack__overflow { width: 14px; height: 14px; font-size: 7px; }
295+ .session-owner-stack__front { width: 20px; height: 20px; }
296+ ` ,
297+ } ) ;
298+ await captureSessionOwnerProof ( currentPage , "00-before-light.png" ) ;
299+ await currentPage . evaluate ( ( ) =>
300+ document . documentElement . setAttribute ( "data-theme-mode" , "dark" ) ,
301+ ) ;
302+ await captureSessionOwnerProof ( currentPage , "01-before-dark.png" ) ;
303+ await legacyStyles . evaluate ( ( style ) => style . parentNode ?. removeChild ( style ) ) ;
304+ await captureSessionOwnerProof ( currentPage , "02-after-dark.png" ) ;
305+ await currentPage . evaluate ( ( ) =>
306+ document . documentElement . setAttribute ( "data-theme-mode" , "light" ) ,
307+ ) ;
308+ await captureSessionOwnerProof ( currentPage , "03-after-light.png" ) ;
309+ }
310+ } ) ;
311+
112312 it ( "shows permanent owner chips and filters existing custom groups" , async ( ) => {
113313 const context = await suite . browser . newContext ( { viewport : { height : 800 , width : 1200 } } ) ;
114314 const currentPage = await context . newPage ( ) ;
0 commit comments