1+ // @effect -diagnostics nodeBuiltinImport:off -- The process fixture runs real shell commands with isolated config files.
12import * as NodeServices from "@effect/platform-node/NodeServices" ;
23import * as Clock from "effect/Clock" ;
34import { assert , describe , it } from "@effect/vitest" ;
@@ -12,8 +13,11 @@ import * as Sink from "effect/Sink";
1213import * as Stream from "effect/Stream" ;
1314import * as ChildProcess from "effect/process/ChildProcess" ;
1415import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner" ;
16+ import * as NodeChildProcess from "node:child_process" ;
17+ import * as NodeFS from "node:fs" ;
1518import * as TestClock from "effect/testing/TestClock" ;
1619import * as NodeOS from "node:os" ;
20+ import * as NodePath from "node:path" ;
1721import { vi } from "vite-plus/test" ;
1822
1923import * as DesktopEnvironment from "../app/DesktopEnvironment.ts" ;
@@ -130,6 +134,77 @@ function runShellEnvironment(input: {
130134}
131135
132136describe ( "DesktopShellEnvironment" , ( ) => {
137+ // Explicit opt-in keeps real shell coverage independent of globally installed tools.
138+ it . effect . runIf ( process . env . T3_TEST_NU_PATH !== undefined ) (
139+ "hydrates the desktop through a renamed Nushell symlink with native export conversions" ,
140+ ( ) =>
141+ Effect . gen ( function * ( ) {
142+ const home = NodeFS . mkdtempSync ( NodePath . join ( NodeOS . tmpdir ( ) , "t3-desktop-nu-" ) ) ;
143+ try {
144+ const toolPath = NodePath . join ( home , "nu tools" , "bin" ) ;
145+ const extraToolPath = NodePath . join ( home , "extra-tools" , "bin" ) ;
146+ const convertedToolPath = NodePath . join ( home , "converted-tools" , "bin" ) ;
147+ NodeFS . mkdirSync ( toolPath , { recursive : true } ) ;
148+ NodeFS . mkdirSync ( extraToolPath , { recursive : true } ) ;
149+ NodeFS . mkdirSync ( convertedToolPath , { recursive : true } ) ;
150+ const shell = NodePath . join ( toolPath , "nushell" ) ;
151+ NodeFS . symlinkSync ( process . env . T3_TEST_NU_PATH ! , shell ) ;
152+ const config = NodePath . join ( home , "config.nu" ) ;
153+ const envConfig = NodePath . join ( home , "env.nu" ) ;
154+ NodeFS . writeFileSync ( envConfig , "" ) ;
155+ NodeFS . writeFileSync (
156+ config ,
157+ [
158+ `$env.PATH = [${ JSON . stringify ( toolPath ) } , ${ JSON . stringify ( extraToolPath ) } ]` ,
159+ '$env.SSH_AUTH_SOCK = "/tmp/nu-agent.sock"' ,
160+ '$env.__MISE_DIFF = " first\\nsecond "' ,
161+ '$env.HOMEBREW_PREFIX = ""' ,
162+ "$env.ENV_CONVERSIONS = {" ,
163+ " PATH: {" ,
164+ " from_string: {|value| $value | split row (char esep) }," ,
165+ ' to_string: {|value| $value | str join (char esep) | str replace "nu tools" "converted-tools" }' ,
166+ " }," ,
167+ " __MISE_DIFF: { from_string: {|value| $value }, to_string: { str upcase } }" ,
168+ "}" ,
169+ 'print "startup noise"' ,
170+ ] . join ( "\n" ) ,
171+ ) ;
172+ const env : NodeJS . ProcessEnv = { SHELL : shell , PATH : `/inherited/bin:${ extraToolPath } ` } ;
173+ yield * runShellEnvironment ( {
174+ env,
175+ platform : "linux" ,
176+ handler : ( command ) => {
177+ if ( command . _tag !== "StandardCommand" || command . command !== shell ) return "" ;
178+ const result = NodeChildProcess . spawnSync (
179+ command . command ,
180+ [ "--no-history" , "--config" , config , "--env-config" , envConfig , ...command . args ] ,
181+ {
182+ encoding : "utf8" ,
183+ timeout : 5000 ,
184+ env : { HOME : home , XDG_CONFIG_HOME : home , PATH : toolPath } ,
185+ } ,
186+ ) ;
187+ if ( result . error ) throw result . error ;
188+ return { output : result . stdout , exitCode : result . status ?? 1 } ;
189+ } ,
190+ } ) ;
191+
192+ assert . deepEqual (
193+ { PATH : env . PATH , __MISE_DIFF : env . __MISE_DIFF } ,
194+ {
195+ PATH : `${ convertedToolPath } :${ extraToolPath } :/inherited/bin` ,
196+ __MISE_DIFF : " FIRST\nSECOND " ,
197+ } ,
198+ ) ;
199+ assert . equal ( env . SSH_AUTH_SOCK , "/tmp/nu-agent.sock" ) ;
200+ assert . isUndefined ( env . DISPLAY ) ;
201+ assert . isUndefined ( env . HOMEBREW_PREFIX ) ;
202+ } finally {
203+ NodeFS . rmSync ( home , { recursive : true , force : true } ) ;
204+ }
205+ } ) ,
206+ ) ;
207+
133208 it . effect ( "rejects PATH output from a failed shell and tries the next candidate" , ( ) =>
134209 Effect . gen ( function * ( ) {
135210 const env : NodeJS . ProcessEnv = { SHELL : "/bin/failing" , PATH : "/usr/bin" } ;
0 commit comments