@@ -4,6 +4,7 @@ import path from "node:path";
44import { expect , it } from "vitest" ;
55import {
66 controlUiBundledSettingsStorageKey ,
7+ controlUiE2eWaitTimeoutMs ,
78 installMockGateway ,
89} from "../test-helpers/control-ui-e2e.ts" ;
910import { chatThreadDistanceFromBottom , waitForChatScrollIdle } from "./chat-flow.test-support.ts" ;
@@ -113,16 +114,25 @@ async function showSplitDashboard(page: import("playwright").Page, sessionKey: s
113114
114115suite . define ( ( ) => {
115116 it . each ( [
116- { reducedMotion : "no-preference" , interruption : "wheel" } ,
117- { reducedMotion : "reduce" , interruption : "wheel" } ,
118- { reducedMotion : "no-preference" , interruption : "pointer" } ,
117+ { reducedMotion : "no-preference" , interruption : "wheel" , recoveryPosition : "within-viewport" } ,
118+ { reducedMotion : "reduce" , interruption : "wheel" , recoveryPosition : "within-viewport" } ,
119+ {
120+ reducedMotion : "no-preference" ,
121+ interruption : "synthetic-pointer" ,
122+ recoveryPosition : "within-viewport" ,
123+ } ,
124+ {
125+ reducedMotion : "no-preference" ,
126+ interruption : "native-pointer" ,
127+ recoveryPosition : "above-viewport" ,
128+ } ,
119129 ] as const ) (
120- "remeasures recovered assistant text after interrupted scrolling ($reducedMotion, $interruption)" ,
121- async ( { reducedMotion, interruption } ) => {
130+ "remeasures recovered assistant text after interrupted scrolling ($reducedMotion, $interruption, $recoveryPosition )" ,
131+ async ( { reducedMotion, interruption, recoveryPosition } ) => {
122132 const artifactDir = path . resolve (
123133 process . env . OPENCLAW_CONTROL_UI_E2E_ARTIFACT_DIR ??
124134 ".artifacts/control-ui-e2e/virtual-sizing/after" ,
125- interruption === "wheel" ? reducedMotion : `${ reducedMotion } -${ interruption } ` ,
135+ `${ reducedMotion } -${ interruption } - ${ recoveryPosition } ` ,
126136 ) ;
127137 await fs . mkdir ( artifactDir , { recursive : true } ) ;
128138 await suite . withPage (
@@ -144,7 +154,7 @@ suite.define(() => {
144154 __openclaw : {
145155 id : `sizing-message-${ index } ` ,
146156 seq : index + 1 ,
147- ...( index === 1 || ( interruption === "pointer" && index % 2 === 1 )
157+ ...( index === 1 || ( interruption === "native- pointer" && index % 2 === 1 )
148158 ? { truncated : true , reason : "display-cap" }
149159 : { } ) ,
150160 } ,
@@ -163,43 +173,100 @@ suite.define(() => {
163173 . locator ( '.chat-bubble[data-entry-id="sizing-message-1"]' )
164174 . waitFor ( { state : "visible" } ) ;
165175 await page . screenshot ( { path : path . join ( artifactDir , "01-before-scroll.png" ) } ) ;
166- await page . locator ( ".chat-scroll-to-bottom" ) . click ( ) ;
167- await page . waitForFunction ( ( pointerInterruption ) => {
168- const scroller = document . querySelector < HTMLElement > (
169- ".chat-pane-cache__pane--active .chat-thread" ,
170- ) ;
171- return (
172- scroller &&
173- scroller . scrollTop > 0 &&
174- ( ! pointerInterruption ||
175- Array . from (
176- scroller . querySelectorAll < HTMLElement > (
177- '.chat-bubble[data-entry-id^="sizing-message-"]' ,
178- ) ,
179- ) . some (
180- ( bubble ) =>
181- Number ( bubble . dataset . entryId ! . slice ( "sizing-message-" . length ) ) % 2 === 1 &&
182- bubble . closest ( ".chat-virtual-row" ) ! . getBoundingClientRect ( ) . bottom <=
183- scroller . getBoundingClientRect ( ) . top ,
184- ) )
185- ) ;
186- } , interruption === "pointer" ) ;
187- const during = await thread . evaluate ( ( element ) => ( {
188- top : element . scrollTop ,
189- max : element . scrollHeight - element . clientHeight ,
190- } ) ) ;
176+ let during : { top : number ; max : number } ;
177+ if ( interruption === "synthetic-pointer" ) {
178+ // Check native gutter hit testing separately from animation timing.
179+ const pointer = await thread . evaluateHandle ( ( element ) => {
180+ const observed = { trusted : false , scroller : false } ;
181+ document . addEventListener (
182+ "pointerdown" ,
183+ ( event ) => {
184+ observed . trusted = event . isTrusted ;
185+ observed . scroller = event . target === element ;
186+ } ,
187+ { capture : true , once : true } ,
188+ ) ;
189+ return observed ;
190+ } ) ;
191+ const track = await thread . boundingBox ( ) ;
192+ expect ( track ) . not . toBeNull ( ) ;
193+ await page . mouse . click ( track ! . x + track ! . width - 3 , track ! . y + 20 ) ;
194+ expect ( await pointer . jsonValue ( ) ) . toEqual ( { trusted : true , scroller : true } ) ;
195+ await pointer . dispose ( ) ;
196+ // Synthetic intent runs in the first positive native scroll callback;
197+ // a Node round trip can outlive the fixed row's visible range.
198+ // Smooth animation and production cancellation remain real.
199+ during = await page
200+ . locator ( ".chat-scroll-to-bottom" )
201+ . evaluate ( ( button , waitTimeout ) => {
202+ const scroller = document . querySelector < HTMLElement > (
203+ ".chat-pane-cache__pane--active .chat-thread" ,
204+ ) ! ;
205+ return new Promise < { top : number ; max : number } > ( ( resolve , reject ) => {
206+ const interrupt = ( event : Event ) => {
207+ if ( ! event . isTrusted || scroller . scrollTop <= 0 ) {
208+ return ;
209+ }
210+ clearTimeout ( timer ) ;
211+ scroller . removeEventListener ( "scroll" , interrupt ) ;
212+ const position = {
213+ top : scroller . scrollTop ,
214+ max : scroller . scrollHeight - scroller . clientHeight ,
215+ } ;
216+ scroller . dispatchEvent (
217+ new PointerEvent ( "pointerdown" , { bubbles : true , pointerType : "mouse" } ) ,
218+ ) ;
219+ resolve ( position ) ;
220+ } ;
221+ const timer = setTimeout ( ( ) => {
222+ scroller . removeEventListener ( "scroll" , interrupt ) ;
223+ reject ( new Error ( "Native scrolling did not reach the interruption geometry" ) ) ;
224+ } , waitTimeout ) ;
225+ scroller . addEventListener ( "scroll" , interrupt ) ;
226+ ( button as HTMLElement ) . click ( ) ;
227+ } ) ;
228+ } , controlUiE2eWaitTimeoutMs ) ;
229+ } else {
230+ await page . locator ( ".chat-scroll-to-bottom" ) . click ( ) ;
231+ await page . waitForFunction ( ( pointerInterruption ) => {
232+ const scroller = document . querySelector < HTMLElement > (
233+ ".chat-pane-cache__pane--active .chat-thread" ,
234+ ) ;
235+ return (
236+ scroller &&
237+ scroller . scrollTop > 0 &&
238+ ( ! pointerInterruption ||
239+ Array . from (
240+ scroller . querySelectorAll < HTMLElement > (
241+ '.chat-bubble[data-entry-id^="sizing-message-"]' ,
242+ ) ,
243+ ) . some (
244+ ( bubble ) =>
245+ Number ( bubble . dataset . entryId ! . slice ( "sizing-message-" . length ) ) % 2 === 1 &&
246+ bubble . closest ( ".chat-virtual-row" ) ! . getBoundingClientRect ( ) . bottom <=
247+ scroller . getBoundingClientRect ( ) . top ,
248+ ) )
249+ ) ;
250+ } , interruption === "native-pointer" ) ;
251+ during = await thread . evaluate ( ( element ) => ( {
252+ top : element . scrollTop ,
253+ max : element . scrollHeight - element . clientHeight ,
254+ } ) ) ;
255+ }
191256 if ( reducedMotion === "no-preference" ) {
192257 expect ( during . top ) . toBeLessThan ( during . max ) ;
193258 }
194259 if ( interruption === "wheel" ) {
195260 await thread . hover ( ) ;
196261 await page . mouse . wheel ( 0 , - 100_000 ) ;
197262 } else {
198- const track = await thread . boundingBox ( ) ;
199- expect ( track ) . not . toBeNull ( ) ;
200- // A real pointer press in the scroll gutter can take over without
201- // a wheel event or a changed offset.
202- await page . mouse . click ( track ! . x + track ! . width - 3 , track ! . y + 20 ) ;
263+ if ( interruption === "native-pointer" ) {
264+ const track = await thread . boundingBox ( ) ;
265+ expect ( track ) . not . toBeNull ( ) ;
266+ // A real pointer press in the scroll gutter can take over without
267+ // a wheel event or a changed offset.
268+ await page . mouse . click ( track ! . x + track ! . width - 3 , track ! . y + 20 ) ;
269+ }
203270 await page . locator ( ".chat-scroll-to-bottom" ) . waitFor ( { state : "visible" } ) ;
204271 // Chromium can commit its last canceled animation offset after the
205272 // pointer action returns. Capture the reader before releasing text.
@@ -216,7 +283,7 @@ suite.define(() => {
216283 // Native smooth scrolling can pass the first message before the pointer
217284 // arrives. Recover a still-mounted pending row above the settled reader.
218285 const messageId =
219- interruption === "pointer"
286+ interruption === "native- pointer"
220287 ? await thread . evaluate ( ( element ) => {
221288 const top = element . getBoundingClientRect ( ) . top ;
222289 const bubbles = Array . from (
@@ -246,8 +313,19 @@ suite.define(() => {
246313 expect ( pendingRequest ) . toBeDefined ( ) ;
247314 const initial = await bubble . evaluate ( ( element ) => {
248315 const row = element . closest < HTMLElement > ( ".chat-virtual-row" ) ! ;
249- return { key : row . dataset . virtualRowKey , height : row . offsetHeight } ;
316+ return {
317+ key : row . dataset . virtualRowKey ,
318+ height : row . offsetHeight ,
319+ bottom : row . getBoundingClientRect ( ) . bottom ,
320+ viewportTop : row . closest ( ".chat-thread" ) ! . getBoundingClientRect ( ) . top ,
321+ } ;
250322 } ) ;
323+ if ( interruption !== "wheel" ) {
324+ expect (
325+ initial . bottom <= initial . viewportTop ,
326+ `recovered row must remain mounted ${ recoveryPosition } ` ,
327+ ) . toBe ( recoveryPosition === "above-viewport" ) ;
328+ }
251329 const fullText = Array . from (
252330 { length : 5 } ,
253331 ( _ , index ) =>
@@ -293,13 +371,20 @@ suite.define(() => {
293371 2 ,
294372 ) ,
295373 ) ;
296- if ( interruption === "pointer ") {
374+ if ( interruption !== "wheel ") {
297375 // Growth above the reader legitimately adjusts scrollTop; the visible
298376 // row must stay anchored regardless of where the pointer stopped scrolling.
299377 expect ( finalAnchor . key ) . toBe ( interruptedAnchor . key ) ;
300378 expect (
301379 Math . abs ( finalAnchor . viewportTop - interruptedAnchor . viewportTop ) ,
302380 ) . toBeLessThanOrEqual ( 1 ) ;
381+ if ( interruption === "synthetic-pointer" ) {
382+ expect (
383+ Math . abs (
384+ ( await thread . evaluate ( ( element ) => element . scrollTop ) ) - interruptedOffset ,
385+ ) ,
386+ ) . toBeLessThanOrEqual ( 1 ) ;
387+ }
303388 }
304389 expect ( final . key ) . toBe ( initial . key ) ;
305390 expect ( final . height ) . toBeGreaterThan ( initial . height ) ;
0 commit comments