@@ -1193,6 +1193,65 @@ describe("CloudManagedEndpointRuntime", () => {
11931193 } ) ,
11941194 ) ;
11951195
1196+ it . effect ( "requests recovery when the older connector exited during a failed swap" , ( ) =>
1197+ Effect . gen ( function * ( ) {
1198+ const olderClient = {
1199+ status : "available" ,
1200+ executablePath : "/managed/2025.9.0/cloudflared" ,
1201+ source : "managed" ,
1202+ version : "2025.9.0" ,
1203+ } as const ;
1204+ const pinnedClient = {
1205+ status : "available" ,
1206+ executablePath : "/managed/pinned/cloudflared" ,
1207+ source : "managed" ,
1208+ version : RelayClient . CLOUDFLARED_VERSION ,
1209+ } as const ;
1210+ let installed = false ;
1211+ const releaseInstall = yield * Deferred . make < void > ( ) ;
1212+ const spawner = ChildProcessSpawner . make ( ( command ) =>
1213+ Effect . gen ( function * ( ) {
1214+ const executable = ChildProcess . isStandardCommand ( command ) ? command . command : "" ;
1215+ if ( executable === pinnedClient . executablePath ) {
1216+ return yield * PlatformError . systemError ( {
1217+ _tag : "PermissionDenied" ,
1218+ module : "ChildProcess" ,
1219+ method : "spawn" ,
1220+ } ) ;
1221+ }
1222+ // The older connector has exited by the time the swap fails.
1223+ const handle = makeHandle ( { pid : 12 , onKill : ( ) => { } , isRunning : ( ) => ! installed } ) ;
1224+ yield * Effect . addFinalizer ( ( ) => handle . kill ( ) . pipe ( Effect . ignore ) ) ;
1225+ return handle ;
1226+ } ) ,
1227+ ) ;
1228+ const runtime = yield * buildCloudManagedEndpointRuntime (
1229+ spawner ,
1230+ Layer . succeed (
1231+ RelayClient . RelayClient ,
1232+ RelayClient . RelayClient . of ( {
1233+ resolve : Effect . sync ( ( ) => ( installed ? pinnedClient : olderClient ) ) ,
1234+ install : Deferred . await ( releaseInstall ) . pipe (
1235+ Effect . andThen (
1236+ Effect . sync ( ( ) => {
1237+ installed = true ;
1238+ return pinnedClient ;
1239+ } ) ,
1240+ ) ,
1241+ ) ,
1242+ installWithProgress : ( ) => Effect . die ( "unused" ) ,
1243+ pruneManagedVersions : Effect . void ,
1244+ } ) ,
1245+ ) ,
1246+ ) ;
1247+ const config = { providerKind : "cloudflare_tunnel" , connectorToken : "token" } as const ;
1248+ expect ( yield * runtime . applyConfig ( config ) ) . toMatchObject ( { status : "running" , pid : 12 } ) ;
1249+
1250+ yield * Deferred . succeed ( releaseInstall , undefined ) ;
1251+ expect ( Option . getOrThrow ( yield * Stream . runHead ( runtime . recoveryRequests ) ) ) . toEqual ( config ) ;
1252+ } ) ,
1253+ ) ;
1254+
11961255 it . effect ( "restarts a self-updated pinned-folder connector once the pin is reinstalled" , ( ) =>
11971256 Effect . gen ( function * ( ) {
11981257 const executablePath = "/managed/pinned/cloudflared" ;
0 commit comments