@@ -346,22 +346,21 @@ const getOfflineSnapshot = Effect.fn("getOfflineSnapshot")(function* () {
346346} ) ;
347347
348348const tryResolveLiveProjectExecutionMode = Effect . fn ( "tryResolveLiveProjectExecutionMode" ) (
349- function * (
350- environmentAuth : EnvironmentAuth . EnvironmentAuth [ "Service" ] ,
351- config : ServerConfig . ServerConfig [ "Service" ] ,
352- ) {
349+ function * ( config : ServerConfig . ServerConfig [ "Service" ] ) {
353350 const runtimeState = yield * readPersistedServerRuntimeState ( config . serverRuntimeStatePath ) ;
354- if ( Option . isNone ( runtimeState ) ) {
351+ const fs = yield * FileSystem . FileSystem ;
352+ if ( Option . isNone ( runtimeState ) || ! ( yield * fs . exists ( config . dbPath ) ) ) {
355353 return Option . none < { readonly origin : string } > ( ) ;
356354 }
357355
358- const attempt = withProjectCliSessionToken ( environmentAuth , ( token ) =>
359- fetchLiveOrchestrationSnapshot ( runtimeState . value . origin , token ) . pipe (
360- Effect . as ( {
361- origin : runtimeState . value . origin ,
362- } ) ,
363- ) ,
364- ) ;
356+ const attempt = Effect . gen ( function * ( ) {
357+ const environmentAuth = yield * EnvironmentAuth . EnvironmentAuth ;
358+ return yield * withProjectCliSessionToken ( environmentAuth , ( token ) =>
359+ fetchLiveOrchestrationSnapshot ( runtimeState . value . origin , token ) . pipe (
360+ Effect . as ( { origin : runtimeState . value . origin } ) ,
361+ ) ,
362+ ) ;
363+ } ) . pipe ( Effect . provide ( EnvironmentAuth . layerRuntimeExistingDatabase ) ) ;
365364
366365 const attempted = yield * Effect . result ( attempt ) ;
367366 if ( attempted . _tag === "Success" ) {
@@ -399,22 +398,24 @@ const runProjectMutation = Effect.fn("runProjectMutation")(function* (
399398 const minimumLogLevel = config . logLevel ;
400399
401400 return yield * Effect . gen ( function * ( ) {
402- const environmentAuth = yield * EnvironmentAuth . EnvironmentAuth ;
403- const liveMode = yield * tryResolveLiveProjectExecutionMode ( environmentAuth , config ) ;
401+ const liveMode = yield * tryResolveLiveProjectExecutionMode ( config ) ;
404402
405403 if ( Option . isSome ( liveMode ) ) {
406- return yield * withProjectCliSessionToken ( environmentAuth , ( token ) =>
407- Effect . gen ( function * ( ) {
408- const snapshot = yield * fetchLiveOrchestrationSnapshot ( liveMode . value . origin , token ) ;
409- const output = yield * run ( {
410- snapshot,
411- dispatch : ( command ) =>
412- dispatchLiveOrchestrationCommand ( liveMode . value . origin , token , command ) ,
413- mode : "live" ,
414- } ) ;
415- yield * Console . log ( output ) ;
416- } ) ,
417- ) ;
404+ return yield * Effect . gen ( function * ( ) {
405+ const environmentAuth = yield * EnvironmentAuth . EnvironmentAuth ;
406+ return yield * withProjectCliSessionToken ( environmentAuth , ( token ) =>
407+ Effect . gen ( function * ( ) {
408+ const snapshot = yield * fetchLiveOrchestrationSnapshot ( liveMode . value . origin , token ) ;
409+ const output = yield * run ( {
410+ snapshot,
411+ dispatch : ( command ) =>
412+ dispatchLiveOrchestrationCommand ( liveMode . value . origin , token , command ) ,
413+ mode : "live" ,
414+ } ) ;
415+ yield * Console . log ( output ) ;
416+ } ) ,
417+ ) ;
418+ } ) . pipe ( Effect . provide ( EnvironmentAuth . layerRuntimeExistingDatabase ) ) ;
418419 }
419420
420421 const layerOfflineRuntime = layerProjectCliRuntime . pipe (
@@ -440,9 +441,9 @@ const runProjectMutation = Effect.fn("runProjectMutation")(function* (
440441 ) . pipe ( Effect . provide ( ProcessRunner . layer ) ) ;
441442 } ) . pipe (
442443 Effect . provide (
443- Layer . mergeAll ( EnvironmentAuth . layerRuntime , WorkspacePaths . layer ) . pipe (
444+ WorkspacePaths . layer . pipe (
444445 Layer . provideMerge ( FetchHttpClient . layer ) ,
445- Layer . provide ( ServerConfig . layer ( config ) ) ,
446+ Layer . provideMerge ( ServerConfig . layer ( config ) ) ,
446447 Layer . provide ( Layer . succeed ( References . MinimumLogLevel , minimumLogLevel ) ) ,
447448 ) ,
448449 ) ,
0 commit comments