11import { assert , describe , it } from "@effect/vitest" ;
2+ import * as NodeServices from "@effect/platform-node/NodeServices" ;
3+ import * as FileSystem from "effect/FileSystem" ;
4+ import * as Path from "effect/Path" ;
25import * as Effect from "effect/Effect" ;
36import * as Layer from "effect/Layer" ;
47
@@ -10,7 +13,11 @@ import * as ElectronApp from "../../electron/ElectronApp.ts";
1013import * as ElectronTheme from "../../electron/ElectronTheme.ts" ;
1114import * as DesktopAppSettings from "../../settings/DesktopAppSettings.ts" ;
1215import * as DesktopWindow from "../../window/DesktopWindow.ts" ;
13- import { getLocalEnvironmentEnabled , setLocalEnvironmentEnabled } from "./localEnvironment.ts" ;
16+ import {
17+ getHostEnvironmentId ,
18+ getLocalEnvironmentEnabled ,
19+ setLocalEnvironmentEnabled ,
20+ } from "./localEnvironment.ts" ;
1421
1522const layerUnusedLifecycleRuntime = Layer . mergeAll (
1623 DesktopShutdown . layer ,
@@ -27,6 +34,26 @@ const layerUnusedLifecycleRuntime = Layer.mergeAll(
2734) ;
2835
2936describe ( "local environment IPC" , ( ) => {
37+ it . effect ( "reads the shared home identity without creating one" , ( ) =>
38+ Effect . gen ( function * ( ) {
39+ const fs = yield * FileSystem . FileSystem ;
40+ const path = yield * Path . Path ;
41+ const stateDir = yield * fs . makeTempDirectoryScoped ( ) ;
42+ const environment = DesktopEnvironment . DesktopEnvironment . of ( {
43+ path,
44+ stateDir,
45+ } as DesktopEnvironment . DesktopEnvironment [ "Service" ] ) ;
46+ const read = getHostEnvironmentId
47+ . handler ( undefined )
48+ . pipe ( Effect . provideService ( DesktopEnvironment . DesktopEnvironment , environment ) ) ;
49+ assert . strictEqual ( yield * read , null ) ;
50+ assert . isFalse ( yield * fs . exists ( path . join ( stateDir , "environment-id" ) ) ) ;
51+ yield * fs . writeFileString ( path . join ( stateDir , "environment-id" ) , " service-id\n" ) ;
52+ assert . strictEqual ( yield * read , "service-id" ) ;
53+ yield * fs . writeFileString ( path . join ( stateDir , "environment-id" ) , "\n" ) ;
54+ assert . strictEqual ( yield * read , null ) ;
55+ } ) . pipe ( Effect . scoped , Effect . provide ( NodeServices . layer ) ) ,
56+ ) ;
3057 it . effect ( "relaunches only when the setting changes and keeps other settings" , ( ) => {
3158 const relaunchReasons : Array < string > = [ ] ;
3259 const layer = Layer . mergeAll (
0 commit comments