@@ -661,6 +661,156 @@ suite.define(() => {
661661 await page . close ( ) ;
662662 } ) ;
663663
664+ it ( "auto-pages an underfilled native transcript until it becomes scrollable" , async ( ) => {
665+ const artifactDir = process . env . OPENCLAW_UI_E2E_ARTIFACT_DIR ?. trim ( ) ;
666+ if ( artifactDir ) {
667+ await fs . mkdir ( artifactDir , { recursive : true } ) ;
668+ }
669+ const viewport = { width : 1280 , height : 900 } ;
670+ const context = await suite . newBrowserContext ( {
671+ locale : "en-US" ,
672+ serviceWorkers : "block" ,
673+ viewport,
674+ ...( artifactDir ? { recordVideo : { dir : artifactDir , size : viewport } } : { } ) ,
675+ } ) ;
676+ const page = await context . newPage ( ) ;
677+ const proofVideo = page . video ( ) ;
678+ const historyMessage = ( seq : number , role : "assistant" | "user" , text : string ) => ( {
679+ __openclaw : { seq } ,
680+ content : [ { type : role === "assistant" ? "output_text" : "input_text" , text } ] ,
681+ role,
682+ timestamp : 1_800_000_000_000 + seq ,
683+ } ) ;
684+ const recent = [
685+ historyMessage ( 21 , "user" , "Recent question" ) ,
686+ historyMessage ( 22 , "assistant" , "Recent answer" ) ,
687+ ] ;
688+ // Consecutive assistant records collapse into one rendered group, so this
689+ // page advances the raw offset without filling the real transcript viewport.
690+ const firstOlderPage = Array . from ( { length : 4 } , ( _ , index ) =>
691+ historyMessage ( index + 17 , "assistant" , `Short older answer ${ index + 17 } ` ) ,
692+ ) ;
693+ const secondOlderPage = Array . from ( { length : 16 } , ( _ , index ) => {
694+ const seq = index + 1 ;
695+ const role = seq % 2 === 0 ? "assistant" : "user" ;
696+ return historyMessage (
697+ seq ,
698+ role ,
699+ `Scrollable older ${ role } message ${ seq } \n${ "Transcript detail line\n" . repeat ( 3 ) } ` ,
700+ ) ;
701+ } ) ;
702+ const gateway = await installMockGateway ( page , {
703+ deferredMethods : [ "chat.history" ] ,
704+ featureMethods : [ "chat.metadata" , "chat.startup" ] ,
705+ methodResponses : {
706+ "chat.startup" : {
707+ messages : recent ,
708+ hasMore : true ,
709+ nextOffset : 2 ,
710+ totalMessages : 30 ,
711+ sessionId : "native-underfill-pagination" ,
712+ thinkingLevel : null ,
713+ } ,
714+ "chat.history" : {
715+ cases : [
716+ {
717+ match : { offset : 2 } ,
718+ response : {
719+ messages : firstOlderPage ,
720+ hasMore : true ,
721+ nextOffset : 6 ,
722+ totalMessages : 30 ,
723+ sessionId : "native-underfill-pagination" ,
724+ thinkingLevel : null ,
725+ } ,
726+ } ,
727+ {
728+ match : { offset : 6 } ,
729+ response : {
730+ messages : secondOlderPage ,
731+ hasMore : true ,
732+ nextOffset : 22 ,
733+ totalMessages : 30 ,
734+ sessionId : "native-underfill-pagination" ,
735+ thinkingLevel : null ,
736+ } ,
737+ } ,
738+ ] ,
739+ } ,
740+ } ,
741+ } ) ;
742+
743+ try {
744+ await page . goto ( `${ suite . server . baseUrl } chat` ) ;
745+ const pane = page . locator ( 'openclaw-chat-pane[aria-hidden="false"]' ) ;
746+ const thread = pane . locator ( ".chat-thread" ) ;
747+ await page . getByText ( "Recent answer" , { exact : true } ) . waitFor ( ) ;
748+ await expect
749+ . poll ( async ( ) =>
750+ ( await gateway . getRequests ( "chat.history" ) ) . map (
751+ ( request ) => ( request . params as { offset ?: number } | undefined ) ?. offset ,
752+ ) ,
753+ )
754+ . toEqual ( [ 2 ] ) ;
755+ await pane . locator ( ".chat-history-loading" ) . waitFor ( ) ;
756+ expect ( await thread . evaluate ( ( element ) => element . scrollHeight <= element . clientHeight ) ) . toBe (
757+ true ,
758+ ) ;
759+ if ( artifactDir ) {
760+ await page . screenshot ( {
761+ path : path . join ( artifactDir , "00-native-history-initial-underfill-loading.png" ) ,
762+ fullPage : true ,
763+ } ) ;
764+ }
765+
766+ await gateway . deferNext ( "chat.history" , { offset : 6 } ) ;
767+ await gateway . resolveDeferred ( "chat.history" ) ;
768+ await expect
769+ . poll ( async ( ) =>
770+ ( await gateway . getRequests ( "chat.history" ) ) . map (
771+ ( request ) => ( request . params as { offset ?: number } | undefined ) ?. offset ,
772+ ) ,
773+ )
774+ . toEqual ( [ 2 , 6 ] ) ;
775+ await pane . locator ( ".chat-history-loading" ) . waitFor ( ) ;
776+ expect ( await thread . evaluate ( ( element ) => element . scrollHeight <= element . clientHeight ) ) . toBe (
777+ true ,
778+ ) ;
779+ if ( artifactDir ) {
780+ await page . screenshot ( {
781+ path : path . join ( artifactDir , "01-native-history-continued-auto-load.png" ) ,
782+ fullPage : true ,
783+ } ) ;
784+ }
785+
786+ await gateway . resolveDeferred ( "chat.history" ) ;
787+ await expect
788+ . poll ( ( ) => thread . evaluate ( ( element ) => element . scrollHeight > element . clientHeight ) )
789+ . toBe ( true ) ;
790+ await expect . poll ( ( ) => pane . locator ( ".chat-history-loading" ) . count ( ) ) . toBe ( 0 ) ;
791+ expect ( await pane . locator ( ".chat-history-sentinel" ) . count ( ) ) . toBe ( 1 ) ;
792+ if ( artifactDir ) {
793+ await page . screenshot ( {
794+ path : path . join ( artifactDir , "02-native-history-final-scrollable.png" ) ,
795+ fullPage : true ,
796+ } ) ;
797+ }
798+ await new Promise < void > ( ( resolve ) => {
799+ setTimeout ( resolve , 300 ) ;
800+ } ) ;
801+ expect (
802+ ( await gateway . getRequests ( "chat.history" ) ) . map (
803+ ( request ) => ( request . params as { offset ?: number } | undefined ) ?. offset ,
804+ ) ,
805+ ) . toEqual ( [ 2 , 6 ] ) ;
806+ } finally {
807+ await suite . closeBrowserContext ( context ) ;
808+ if ( artifactDir && proofVideo ) {
809+ await proofVideo . saveAs ( path . join ( artifactDir , "native-history-auto-pagination.webm" ) ) ;
810+ }
811+ }
812+ } ) ;
813+
664814 it ( "shows loaded native history before fetching and revealing an earlier page" , async ( ) => {
665815 const page = await suite . browser . newPage ( { viewport : { width : 1280 , height : 800 } } ) ;
666816 const artifactDir = process . env . OPENCLAW_UI_E2E_ARTIFACT_DIR ?. trim ( ) ;
0 commit comments