@@ -278,6 +278,114 @@ suite.define(() => {
278278 }
279279 } ) ;
280280
281+ it ( "releases a retired profile save after reconnect while preserving the draft" , async ( ) => {
282+ const context = await suite . browser . newContext ( {
283+ locale : "en-US" ,
284+ serviceWorkers : "block" ,
285+ viewport : { height : 1_000 , width : 1_440 } ,
286+ } ) ;
287+ const page = await context . newPage ( ) ;
288+ const gateway = await installMockGateway ( page , {
289+ featureMethods : [ "config.patch" , "environments.list" ] ,
290+ methodResponses : {
291+ "config.get" : configResponse ( { } , "cloud-workers-reconnect-1" ) ,
292+ "environments.list" : { environments : [ ] , profiles : [ ] } ,
293+ } ,
294+ } ) ;
295+
296+ try {
297+ await page . goto ( `${ suite . server . baseUrl } settings/cloud-workers` ) ;
298+ await page . getByRole ( "button" , { name : "Add profile" } ) . click ( ) ;
299+ const editor = page . locator ( ".settings-section" , {
300+ has : page . getByRole ( "heading" , { name : "Add profile" , exact : true } ) ,
301+ } ) ;
302+ const profileId = page . getByLabel ( "Profile ID" ) ;
303+ const backend = page . getByLabel ( "Crabbox backend" ) ;
304+ await profileId . fill ( "reconnect-proof" ) ;
305+ await backend . fill ( "hetzner" ) ;
306+ await waitForSettledFormControls ( page , [
307+ { locator : profileId , value : "reconnect-proof" } ,
308+ { locator : backend , value : "hetzner" } ,
309+ ] ) ;
310+
311+ await gateway . deferNext ( "config.patch" ) ;
312+ await editor . getByRole ( "button" , { name : "Save" } ) . click ( ) ;
313+ await gateway . waitForRequest ( "config.patch" ) ;
314+ await expect . poll ( ( ) => profileId . isDisabled ( ) ) . toBe ( true ) ;
315+
316+ const socketCount = await gateway . getSocketCount ( ) ;
317+ const configGetCount = ( await gateway . getRequests ( "config.get" ) ) . length ;
318+ await gateway . setMethodResponse (
319+ "config.get" ,
320+ configResponse ( { } , "cloud-workers-reconnect-2" ) ,
321+ ) ;
322+ await gateway . closeLatest ( 1012 , "cloud worker save reconnect proof" ) ;
323+ await expect . poll ( ( ) => gateway . getSocketCount ( ) ) . toBeGreaterThan ( socketCount ) ;
324+ await expect
325+ . poll ( async ( ) => ( await gateway . getRequests ( "config.get" ) ) . length )
326+ . toBeGreaterThan ( configGetCount ) ;
327+
328+ await expect . poll ( ( ) => profileId . isEnabled ( ) ) . toBe ( true ) ;
329+ await expect . poll ( ( ) => backend . isEnabled ( ) ) . toBe ( true ) ;
330+ await expect . poll ( ( ) => profileId . inputValue ( ) ) . toBe ( "reconnect-proof" ) ;
331+ await expect . poll ( ( ) => backend . inputValue ( ) ) . toBe ( "hetzner" ) ;
332+ await expect . poll ( ( ) => editor . getByRole ( "button" , { name : "Save" } ) . isEnabled ( ) ) . toBe ( true ) ;
333+ await expect
334+ . poll ( ( ) => editor . getByRole ( "button" , { name : "Cancel" } ) . isEnabled ( ) )
335+ . toBe ( true ) ;
336+
337+ await gateway . resolveDeferred ( "config.patch" , {
338+ ok : true ,
339+ hash : "retired-cloud-workers-save" ,
340+ config : { } ,
341+ } ) ;
342+ await expect . poll ( ( ) => profileId . inputValue ( ) ) . toBe ( "reconnect-proof" ) ;
343+ await expect . poll ( ( ) => page . getByText ( "Gateway restart required." ) . count ( ) ) . toBe ( 0 ) ;
344+ await expect . poll ( ( ) => page . getByRole ( "alert" ) . count ( ) ) . toBe ( 0 ) ;
345+
346+ await gateway . deferNext ( "config.patch" ) ;
347+ const retryRequestCount = ( await gateway . getRequests ( "config.patch" ) ) . length ;
348+ await editor . getByRole ( "button" , { name : "Save" } ) . click ( ) ;
349+ const retryPatch = await waitForConfigPatch ( gateway , retryRequestCount ) ;
350+ expect ( retryPatch ) . toMatchObject ( {
351+ cloudWorkers : {
352+ profiles : {
353+ "reconnect-proof" : {
354+ provider : "crabbox" ,
355+ settings : { provider : "hetzner" } ,
356+ } ,
357+ } ,
358+ } ,
359+ } ) ;
360+ const savedProfile = {
361+ provider : "crabbox" ,
362+ install : "bundle" ,
363+ settings : {
364+ provider : "hetzner" ,
365+ class : "standard" ,
366+ ttl : "8h" ,
367+ idleTimeout : "45m" ,
368+ } ,
369+ } ;
370+ await gateway . setMethodResponse (
371+ "config.get" ,
372+ configResponse (
373+ { cloudWorkers : { profiles : { "reconnect-proof" : savedProfile } } } ,
374+ "cloud-workers-reconnect-3" ,
375+ ) ,
376+ ) ;
377+ await gateway . resolveDeferred ( "config.patch" , {
378+ ok : true ,
379+ hash : "cloud-workers-reconnect-3" ,
380+ config : { cloudWorkers : { profiles : { "reconnect-proof" : savedProfile } } } ,
381+ } ) ;
382+ await page . getByText ( "Gateway restart required." , { exact : true } ) . waitFor ( ) ;
383+ await expect . poll ( ( ) => page . getByLabel ( "Profile ID" ) . count ( ) ) . toBe ( 0 ) ;
384+ } finally {
385+ await context . close ( ) ;
386+ }
387+ } ) ;
388+
281389 it ( "deletes a profile only after confirmation" , async ( ) => {
282390 const context = await suite . browser . newContext ( { locale : "en-US" , serviceWorkers : "block" } ) ;
283391 const page = await context . newPage ( ) ;
0 commit comments