@@ -149,8 +149,19 @@ func TestBuildSecureEnvironment(t *testing.T) {
149149
150150 // Set up test environment
151151 os .Clearenv ()
152- os .Setenv ("PATH" , "/usr/bin:/bin" )
153- os .Setenv ("HOME" , "/home/user" )
152+
153+ // Set platform-specific test paths
154+ var testPath , testHome string
155+ if runtime .GOOS == "windows" {
156+ testPath = "C:\\ Windows\\ System32;C:\\ Windows"
157+ testHome = "C:\\ Users\\ testuser"
158+ } else {
159+ testPath = "/usr/bin:/bin"
160+ testHome = "/home/user"
161+ }
162+
163+ os .Setenv ("PATH" , testPath )
164+ os .Setenv ("HOME" , testHome )
154165 os .Setenv ("SECRET_KEY" , "secret123" ) // Should be filtered out
155166 os .Setenv ("API_TOKEN" , "token123" ) // Should be filtered out
156167 os .Setenv ("LC_ALL" , "en_US.UTF-8" ) // Should be included
@@ -175,10 +186,18 @@ func TestBuildSecureEnvironment(t *testing.T) {
175186
176187 // Should include allowed system variables with enhanced PATH discovery
177188 pathValue := envMap ["PATH" ]
178- assert .Contains (t , pathValue , "/usr/bin" , "PATH should contain /usr/bin" )
179- assert .Contains (t , pathValue , "/bin" , "PATH should contain /bin" )
189+ if runtime .GOOS == "windows" {
190+ // On Windows, PATH should contain Windows system paths
191+ assert .Contains (t , pathValue , "C:\\ Windows\\ System32" , "PATH should contain C:\\ Windows\\ System32" )
192+ assert .Contains (t , pathValue , "C:\\ Windows" , "PATH should contain C:\\ Windows" )
193+ } else {
194+ // On Unix/macOS, PATH should contain Unix system paths
195+ assert .Contains (t , pathValue , "/usr/bin" , "PATH should contain /usr/bin" )
196+ assert .Contains (t , pathValue , "/bin" , "PATH should contain /bin" )
197+ }
198+
180199 // Enhanced PATH discovery may include additional paths like /opt/homebrew/bin
181- assert .Equal (t , "/home/user" , envMap ["HOME" ])
200+ assert .Equal (t , testHome , envMap ["HOME" ])
182201 assert .Equal (t , "en_US.UTF-8" , envMap ["LC_ALL" ])
183202
184203 // Should include custom variables
@@ -227,7 +246,12 @@ func TestGetSystemEnvVar(t *testing.T) {
227246 }()
228247
229248 // Set test environment
230- testPath := "/test/bin:/test/usr/bin"
249+ var testPath string
250+ if runtime .GOOS == "windows" {
251+ testPath = "C:\\ test\\ bin;C:\\ test\\ usr\\ bin"
252+ } else {
253+ testPath = "/test/bin:/test/usr/bin"
254+ }
231255 os .Setenv ("PATH" , testPath )
232256
233257 manager := NewManager (& EnvConfig {
@@ -273,8 +297,19 @@ func TestGetFilteredEnvCount(t *testing.T) {
273297
274298 // Set up test environment
275299 os .Clearenv ()
276- os .Setenv ("PATH" , "/usr/bin:/bin" )
277- os .Setenv ("HOME" , "/home/user" )
300+
301+ // Set platform-specific test paths
302+ var testPath , testHome string
303+ if runtime .GOOS == "windows" {
304+ testPath = "C:\\ Windows\\ System32;C:\\ Windows"
305+ testHome = "C:\\ Users\\ testuser"
306+ } else {
307+ testPath = "/usr/bin:/bin"
308+ testHome = "/home/user"
309+ }
310+
311+ os .Setenv ("PATH" , testPath )
312+ os .Setenv ("HOME" , testHome )
278313 os .Setenv ("SECRET_KEY" , "secret123" )
279314 os .Setenv ("API_TOKEN" , "token123" )
280315
@@ -400,7 +435,16 @@ func TestRealWorldNpxScenario(t *testing.T) {
400435 }()
401436
402437 // Set up realistic environment
403- testPath := "/usr/local/bin:/usr/bin:/bin"
438+ var testPath string
439+ var expectedPaths []string
440+ if runtime .GOOS == "windows" {
441+ testPath = "C:\\ Program Files\\ nodejs;C:\\ Windows\\ System32;C:\\ Windows"
442+ expectedPaths = []string {"C:\\ Program Files\\ nodejs" , "C:\\ Windows\\ System32" , "C:\\ Windows" }
443+ } else {
444+ testPath = "/usr/local/bin:/usr/bin:/bin"
445+ expectedPaths = []string {"/usr/local/bin" , "/usr/bin" , "/bin" }
446+ }
447+
404448 os .Setenv ("PATH" , testPath )
405449
406450 // Create environment config for npx usage
@@ -415,9 +459,14 @@ func TestRealWorldNpxScenario(t *testing.T) {
415459 if strings .HasPrefix (envVar , "PATH=" ) {
416460 actualPath = envVar [5 :] // Remove "PATH=" prefix
417461 // Enhanced path discovery should include the original test paths
418- if strings .Contains (actualPath , "/usr/local/bin" ) &&
419- strings .Contains (actualPath , "/usr/bin" ) &&
420- strings .Contains (actualPath , "/bin" ) {
462+ foundAllPaths := true
463+ for _ , expectedPath := range expectedPaths {
464+ if ! strings .Contains (actualPath , expectedPath ) {
465+ foundAllPaths = false
466+ break
467+ }
468+ }
469+ if foundAllPaths {
421470 foundPath = true
422471 break
423472 }
0 commit comments