@@ -3,6 +3,7 @@ import { assert, describe, it } from "@effect/vitest";
33import * as Effect from "effect/Effect" ;
44import * as FileSystem from "effect/FileSystem" ;
55import * as Layer from "effect/Layer" ;
6+ import * as Option from "effect/Option" ;
67import * as Schema from "effect/Schema" ;
78
89import * as DesktopEnvironment from "../app/DesktopEnvironment.ts" ;
@@ -43,12 +44,13 @@ function makeEnvironmentLayer(
4344 options ?: {
4445 readonly isPackaged ?: boolean ;
4546 readonly devServerUrl ?: string ;
47+ readonly platform ?: NodeJS . Platform ;
4648 } ,
4749) {
4850 return DesktopEnvironment . layer ( {
4951 dirname : "/repo/apps/desktop/src" ,
5052 homeDirectory : baseDir ,
51- platform : "darwin" ,
53+ platform : options ?. platform ?? "darwin" ,
5254 processArch : "x64" ,
5355 appVersion : "1.2.3" ,
5456 appPath : "/repo" ,
@@ -71,6 +73,14 @@ function makeEnvironmentLayer(
7173 ) ;
7274}
7375
76+ const restoreEnv = ( name : string , value : string | undefined ) => {
77+ if ( value === undefined ) {
78+ delete process . env [ name ] ;
79+ } else {
80+ process . env [ name ] = value ;
81+ }
82+ } ;
83+
7484const withHarness = < A , E , R > (
7585 effect : Effect . Effect <
7686 A ,
@@ -198,4 +208,58 @@ describe("DesktopBackendConfiguration", () => {
198208 ) ;
199209 } ) . pipe ( Effect . scoped , Effect . provide ( NodeServices . layer ) ) ,
200210 ) ;
211+
212+ it . effect ( "preserves existing WSLENV entries when forwarding WSL backend secrets" , ( ) =>
213+ Effect . gen ( function * ( ) {
214+ const fileSystem = yield * FileSystem . FileSystem ;
215+ const baseDir = yield * fileSystem . makeTempDirectoryScoped ( {
216+ prefix : "t3-desktop-backend-config-test-" ,
217+ } ) ;
218+
219+ const previousWslEnv = process . env . WSLENV ;
220+ const previousOpenAiKey = process . env . OPENAI_API_KEY ;
221+ const previousAnthropicKey = process . env . ANTHROPIC_API_KEY ;
222+ try {
223+ process . env . WSLENV = "GOPATH/p:OPENAI_API_KEY/u:EMPTY::AZURE_DEVOPS_EXT_PAT/u" ;
224+ process . env . OPENAI_API_KEY = "openai-key" ;
225+ process . env . ANTHROPIC_API_KEY = "anthropic-key" ;
226+
227+ yield * Effect . gen ( function * ( ) {
228+ const configuration = yield * DesktopBackendConfiguration . DesktopBackendConfiguration ;
229+ const config = yield * configuration . resolve ;
230+
231+ assert . equal ( config . executablePath , "wsl.exe" ) ;
232+ assert . equal ( config . env . OPENAI_API_KEY , "openai-key" ) ;
233+ assert . equal ( config . env . ANTHROPIC_API_KEY , "anthropic-key" ) ;
234+ assert . equal (
235+ config . env . WSLENV ,
236+ "GOPATH/p:OPENAI_API_KEY/u:EMPTY:AZURE_DEVOPS_EXT_PAT/u:ANTHROPIC_API_KEY" ,
237+ ) ;
238+ } ) . pipe (
239+ Effect . provide (
240+ DesktopBackendConfiguration . layer . pipe (
241+ Layer . provideMerge ( serverExposureLayer ) ,
242+ Layer . provideMerge (
243+ DesktopAppSettings . layerTest ( {
244+ ...DesktopAppSettings . DEFAULT_DESKTOP_SETTINGS ,
245+ wslMode : "wsl" ,
246+ } ) ,
247+ ) ,
248+ Layer . provideMerge (
249+ DesktopWslEnvironment . layerTest ( {
250+ isAvailable : true ,
251+ windowsToWslPath : ( ) => Option . some ( "/mnt/c/repo/apps/server/src/index.ts" ) ,
252+ } ) ,
253+ ) ,
254+ Layer . provideMerge ( makeEnvironmentLayer ( baseDir , { platform : "win32" } ) ) ,
255+ ) ,
256+ ) ,
257+ ) ;
258+ } finally {
259+ restoreEnv ( "WSLENV" , previousWslEnv ) ;
260+ restoreEnv ( "OPENAI_API_KEY" , previousOpenAiKey ) ;
261+ restoreEnv ( "ANTHROPIC_API_KEY" , previousAnthropicKey ) ;
262+ }
263+ } ) . pipe ( Effect . scoped , Effect . provide ( NodeServices . layer ) ) ,
264+ ) ;
201265} ) ;
0 commit comments