11import * as NodeServices from "@effect/platform-node/NodeServices" ;
2- import { afterEach , beforeEach , expect , it } from "@effect/vitest" ;
2+ import { expect , it } from "@effect/vitest" ;
33import * as HostProcess from "@t3tools/shared/HostProcess" ;
44import * as Effect from "effect/Effect" ;
55import * as FileSystem from "effect/FileSystem" ;
@@ -29,7 +29,13 @@ const environmentFor = (
2929 } as unknown as DesktopEnvironment . DesktopEnvironment [ "Service" ] ) ;
3030
3131const commandIn = (
32- input : { home : string ; baseDir ?: string ; platform ?: NodeJS . Platform ; isPackaged ?: boolean } ,
32+ input : {
33+ home : string ;
34+ baseDir ?: string ;
35+ platform ?: NodeJS . Platform ;
36+ isPackaged ?: boolean ;
37+ env ?: NodeJS . ProcessEnv ;
38+ } ,
3339 spawner ?: ChildProcessSpawner . ChildProcessSpawner [ "Service" ] ,
3440) =>
3541 Effect . gen ( function * ( ) {
@@ -42,6 +48,7 @@ const commandIn = (
4248 DesktopEnvironment . DesktopEnvironment ,
4349 environmentFor ( path , { ...input , baseDir } ) ,
4450 ) ,
51+ Effect . provideService ( HostProcess . Environment , input . env ?? { PATH : "" } ) ,
4552 ) ;
4653 return yield * spawner
4754 ? make . pipe ( Effect . provideService ( ChildProcessSpawner . ChildProcessSpawner , spawner ) )
@@ -84,14 +91,6 @@ const fakePowerShell = (initial: string) => {
8491 return { registry, spawner } ;
8592} ;
8693
87- const machinePath = process . env . PATH ;
88- beforeEach ( ( ) => {
89- process . env . PATH = "" ;
90- } ) ;
91- afterEach ( ( ) => {
92- process . env . PATH = machinePath ;
93- } ) ;
94-
9594it . layer ( NodeServices . layer ) ( "DesktopCliCommand" , ( it ) => {
9695 it . effect ( "links the launcher onto PATH and removes only that link" , ( ) =>
9796 Effect . gen ( function * ( ) {
@@ -124,7 +123,8 @@ it.layer(NodeServices.layer)("DesktopCliCommand", (it) => {
124123 const fs = yield * FileSystem . FileSystem ;
125124 const path = yield * Path . Path ;
126125 const home = yield * fs . makeTempDirectoryScoped ( ) ;
127- const command = yield * commandIn ( { home } ) ;
126+ const env : NodeJS . ProcessEnv = { PATH : "" } ;
127+ const command = yield * commandIn ( { home, env } ) ;
128128 const theirs = path . join ( home , ".local" , "bin" , "t3" ) ;
129129 yield * fs . makeDirectory ( path . dirname ( theirs ) , { recursive : true } ) ;
130130 yield * fs . writeFileString ( theirs , "npm's t3\n" ) ;
@@ -139,7 +139,7 @@ it.layer(NodeServices.layer)("DesktopCliCommand", (it) => {
139139
140140 const launcher = path . join ( home , ".t3" , "bin" , "t3" ) ;
141141 yield * fs . writeFileString ( launcher , "npm's t3\n" ) ;
142- process . env . PATH = path . dirname ( launcher ) ;
142+ env . PATH = path . dirname ( launcher ) ;
143143 expect ( yield * command . state ) . toMatchObject ( { onPath : false , shadowedBy : launcher } ) ;
144144 expect ( ( yield * Effect . flip ( command . install ) ) . message ) . toContain ( "Could not set up" ) ;
145145 yield * command . uninstall ;
@@ -173,9 +173,9 @@ it.layer(NodeServices.layer)("DesktopCliCommand", (it) => {
173173 const shadow = path . join ( home , "shadow" ) ;
174174 yield * fs . makeDirectory ( shadow ) ;
175175 yield * fs . writeFileString ( path . join ( shadow , "t3" ) , "#!/bin/sh\n" , { mode : 0o755 } ) ;
176- process . env . PATH = [ shadow , path . join ( home , ".local" , "bin" ) ] . join ( ":" ) ;
176+ const env = { PATH : [ shadow , path . join ( home , ".local" , "bin" ) ] . join ( ":" ) } ;
177177
178- const command = yield * commandIn ( { home } ) ;
178+ const command = yield * commandIn ( { home, env } ) ;
179179 const theirs = path . join ( shadow , "t3" ) ;
180180 expect ( ( yield * command . state ) . shadowedBy ) . toBe ( theirs ) ;
181181 const error = yield * Effect . flip ( command . install ) ;
@@ -209,9 +209,9 @@ it.layer(NodeServices.layer)("DesktopCliCommand", (it) => {
209209 yield * fs . chmod ( path . join ( plain , "t3" ) , process . getuid ?.( ) === 0 ? 0o600 : 0o601 ) ;
210210 yield * fs . makeDirectory ( shadow ) ;
211211 yield * fs . writeFileString ( path . join ( shadow , "t3" ) , "#!/bin/sh\n" , { mode : 0o755 } ) ;
212- process . env . PATH = [ folder , plain , shadow , path . join ( home , ".local" , "bin" ) ] . join ( ":" ) ;
212+ const env = { PATH : [ folder , plain , shadow , path . join ( home , ".local" , "bin" ) ] . join ( ":" ) } ;
213213
214- const command = yield * commandIn ( { home } ) ;
214+ const command = yield * commandIn ( { home, env } ) ;
215215 expect ( ( yield * command . state ) . shadowedBy ) . toBe ( path . join ( shadow , "t3" ) ) ;
216216
217217 const error = yield * Effect . flip ( command . install ) ;
@@ -231,9 +231,9 @@ it.layer(NodeServices.layer)("DesktopCliCommand", (it) => {
231231 const path = yield * Path . Path ;
232232 const home = yield * fs . makeTempDirectoryScoped ( ) ;
233233 const launcher = path . join ( home , ".t3" , "bin" , "t3" ) ;
234- process . env . PATH = [ path . dirname ( launcher ) , path . join ( home , ".local" , "bin" ) ] . join ( ":" ) ;
234+ const env = { PATH : [ path . dirname ( launcher ) , path . join ( home , ".local" , "bin" ) ] . join ( ":" ) } ;
235235
236- const command = yield * commandIn ( { home } ) ;
236+ const command = yield * commandIn ( { home, env } ) ;
237237 const installed = yield * command . install ;
238238
239239 expect ( yield * fs . exists ( launcher ) ) . toBe ( true ) ;
0 commit comments