@@ -59,6 +59,62 @@ async function closeContext(context: BrowserContext): Promise<void> {
5959}
6060
6161suite . define ( ( ) => {
62+ it ( "cache-busts stale-build recovery on a first dashboard navigation" , async ( ) => {
63+ const context = await suite . browser . newContext ( {
64+ serviceWorkers : "block" ,
65+ viewport : { height : 900 , width : 1280 } ,
66+ } ) ;
67+ const page = await context . newPage ( ) ;
68+ const documentRequests : Array < { fresh : boolean ; pathname : string } > = [ ] ;
69+ const appOrigin = new URL ( suite . server . baseUrl ) . origin ;
70+ await page . route ( `${ appOrigin } /**` , async ( route ) => {
71+ const request = route . request ( ) ;
72+ if ( request . resourceType ( ) === "document" ) {
73+ const url = new URL ( request . url ( ) ) ;
74+ documentRequests . push ( {
75+ fresh : url . searchParams . has ( "openclaw_mount_recovery" ) ,
76+ pathname : url . pathname ,
77+ } ) ;
78+ }
79+ await route . continue ( ) ;
80+ } ) ;
81+ const gateway = await installMockGateway ( page , {
82+ deferredMethods : [ "connect" ] ,
83+ sessionKey : "agent:example-agent:example-session" ,
84+ } ) ;
85+ const mismatch = {
86+ code : "UNAVAILABLE" ,
87+ message : "Control UI updated; reload this page to continue" ,
88+ details : {
89+ code : ConnectErrorDetailCodes . CONTROL_UI_BUILD_MISMATCH ,
90+ gatewayBuildId : "replacement-build" ,
91+ reloadRequired : true ,
92+ } ,
93+ retryable : false ,
94+ } ;
95+ const target = new URL ( "dashboard/example-agent/example-session" , suite . server . baseUrl ) ;
96+
97+ try {
98+ await page . goto ( target . href ) ;
99+ await gateway . waitForRequest ( "connect" ) ;
100+ await gateway . rejectDeferred ( "connect" , mismatch ) ;
101+
102+ await expect . poll ( ( ) => documentRequests . length ) . toBe ( 2 ) ;
103+ await gateway . waitForRequest ( "connect" ) ;
104+ expect ( documentRequests ) . toEqual ( [
105+ { fresh : false , pathname : target . pathname } ,
106+ { fresh : true , pathname : target . pathname } ,
107+ ] ) ;
108+ await gateway . resolveDeferred ( "connect" ) ;
109+
110+ await page . locator ( "openclaw-app-shell" ) . waitFor ( ) ;
111+ expect ( await page . locator ( "openclaw-login-gate" ) . count ( ) ) . toBe ( 0 ) ;
112+ await expect . poll ( ( ) => page . url ( ) ) . toBe ( target . href ) ;
113+ } finally {
114+ await closeContext ( context ) ;
115+ }
116+ } ) ;
117+
62118 it ( "reloads once for a build rejection, then keeps visible recovery guidance" , async ( ) => {
63119 const context = await suite . browser . newContext ( { viewport : { height : 900 , width : 1280 } } ) ;
64120 const page = await context . newPage ( ) ;
0 commit comments