From cadd271a078993cc5adcfcd11ef8564ef7449a76 Mon Sep 17 00:00:00 2001 From: Serendeep Date: Sat, 22 Aug 2026 13:04:23 +0200 Subject: [PATCH 01/12] fix(shared): hydrate PATH with Nushell login shells --- packages/shared/src/shell.test.ts | 20 ++++++++++++++++++++ packages/shared/src/shell.ts | 17 ++++++++++++++--- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/packages/shared/src/shell.test.ts b/packages/shared/src/shell.test.ts index 89ec055f599e..34a797ca0002 100644 --- a/packages/shared/src/shell.test.ts +++ b/packages/shared/src/shell.test.ts @@ -122,6 +122,26 @@ describe("readPathFromLaunchctl", () => { }); describe("readEnvironmentFromLoginShell", () => { + it("uses Nushell-compatible syntax for a nu login shell", () => { + const execFile = vi.fn< + ( + file: string, + args: ReadonlyArray, + options: { encoding: "utf8"; timeout: number }, + ) => string + >(() => "__T3CODE_ENV_PATH_START__\n/a:/b\n__T3CODE_ENV_PATH_END__\n"); + + expect(readEnvironmentFromLoginShell("/opt/homebrew/bin/nu", ["PATH"], execFile)).toEqual({ + PATH: "/a:/b", + }); + + const command = execFile.mock.calls[0]?.[1][1]; + expect(command).toContain("do --ignore-errors { printenv PATH }"); + expect(command).not.toContain("|| true"); + expect(command).toContain("__T3CODE_ENV_PATH_START__"); + expect(command).toContain("__T3CODE_ENV_PATH_END__"); + }); + it("extracts multiple environment variables from a login shell command", () => { const execFile = vi.fn< ( diff --git a/packages/shared/src/shell.ts b/packages/shared/src/shell.ts index da6db2166765..5792a03cbff2 100644 --- a/packages/shared/src/shell.ts +++ b/packages/shared/src/shell.ts @@ -245,16 +245,27 @@ function envCaptureEnd(name: string): string { return `__T3CODE_ENV_${name}_END__`; } -function buildEnvironmentCaptureCommand(names: ReadonlyArray): string { +function isNushellExecutable(shell: string): boolean { + const executableName = NodePath.basename(shell).toLowerCase(); + return executableName === "nu" || executableName === "nu.exe"; +} + +function buildEnvironmentCaptureCommand(shell: string, names: ReadonlyArray): string { + const isNushell = isNushellExecutable(shell); + return names .map((name) => { if (!SHELL_ENV_NAME_PATTERN.test(name)) { throw new Error(`Unsupported environment variable name: ${name}`); } + const readVariable = isNushell + ? `do --ignore-errors { printenv ${name} }` + : `printenv ${name} || true`; + return [ `printf '%s\\n' '${envCaptureStart(name)}'`, - `printenv ${name} || true`, + readVariable, `printf '%s\\n' '${envCaptureEnd(name)}'`, ].join("; "); }) @@ -312,7 +323,7 @@ export const readEnvironmentFromLoginShell: ShellEnvironmentReader = ( return {}; } - const output = execFile(shell, ["-ilc", buildEnvironmentCaptureCommand(names)], { + const output = execFile(shell, ["-ilc", buildEnvironmentCaptureCommand(shell, names)], { encoding: "utf8", timeout: 5000, }); From ea33634ae4138bb3a33d4672f84ea83ca5521793 Mon Sep 17 00:00:00 2001 From: Serendeep Date: Sat, 22 Aug 2026 13:41:22 +0200 Subject: [PATCH 02/12] fix(shared): preserve Nushell probe output --- packages/shared/src/shell.test.ts | 6 +++--- packages/shared/src/shell.ts | 12 ++++++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/shared/src/shell.test.ts b/packages/shared/src/shell.test.ts index 34a797ca0002..c6411fa4988f 100644 --- a/packages/shared/src/shell.test.ts +++ b/packages/shared/src/shell.test.ts @@ -136,10 +136,10 @@ describe("readEnvironmentFromLoginShell", () => { }); const command = execFile.mock.calls[0]?.[1][1]; - expect(command).toContain("do --ignore-errors { printenv PATH }"); + expect(command).toBe( + "print '__T3CODE_ENV_PATH_START__'; try { printenv PATH } catch { print '' }; print '__T3CODE_ENV_PATH_END__'", + ); expect(command).not.toContain("|| true"); - expect(command).toContain("__T3CODE_ENV_PATH_START__"); - expect(command).toContain("__T3CODE_ENV_PATH_END__"); }); it("extracts multiple environment variables from a login shell command", () => { diff --git a/packages/shared/src/shell.ts b/packages/shared/src/shell.ts index 5792a03cbff2..e5ca01f0fa58 100644 --- a/packages/shared/src/shell.ts +++ b/packages/shared/src/shell.ts @@ -259,13 +259,17 @@ function buildEnvironmentCaptureCommand(shell: string, names: ReadonlyArray Date: Mon, 19 Oct 2026 16:53:55 +0000 Subject: [PATCH 03/12] test(shell): verify Nushell environment hydration with real commands --- .../src/shell/DesktopShellEnvironment.test.ts | 56 ++++++++++++++ packages/shared/src/shell.test.ts | 74 +++++++++++++------ 2 files changed, 107 insertions(+), 23 deletions(-) diff --git a/apps/desktop/src/shell/DesktopShellEnvironment.test.ts b/apps/desktop/src/shell/DesktopShellEnvironment.test.ts index aee5a0bc81b5..41939c318cd4 100644 --- a/apps/desktop/src/shell/DesktopShellEnvironment.test.ts +++ b/apps/desktop/src/shell/DesktopShellEnvironment.test.ts @@ -1,3 +1,4 @@ +// @effect-diagnostics nodeBuiltinImport:off -- The process fixture runs real shell commands with isolated config files. import * as NodeServices from "@effect/platform-node/NodeServices"; import { assert, describe, it } from "@effect/vitest"; import * as Effect from "effect/Effect"; @@ -9,7 +10,10 @@ import * as Sink from "effect/Sink"; import * as Stream from "effect/Stream"; import * as ChildProcess from "effect/process/ChildProcess"; import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner"; +import * as NodeChildProcess from "node:child_process"; +import * as NodeFS from "node:fs"; import * as NodeOS from "node:os"; +import * as NodePath from "node:path"; import { vi } from "vite-plus/test"; import * as DesktopEnvironment from "../app/DesktopEnvironment.ts"; @@ -122,6 +126,58 @@ function runShellEnvironment(input: { } describe("DesktopShellEnvironment", () => { + // Explicit opt-in keeps real shell coverage independent of globally installed tools. + it.effect.runIf(process.env.T3_TEST_NU_PATH !== undefined)( + "hydrates the desktop from Nushell despite missing variables and startup output", + () => + Effect.gen(function* () { + const shell = process.env.T3_TEST_NU_PATH!; + const home = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-desktop-nu-")); + try { + const config = NodePath.join(home, "config.nu"); + const envConfig = NodePath.join(home, "env.nu"); + NodeFS.writeFileSync(envConfig, ""); + NodeFS.writeFileSync( + config, + [ + '$env.PATH = ["/nu tools/bin", "/usr/bin", "/bin"]', + '$env.SSH_AUTH_SOCK = "/tmp/nu-agent.sock"', + '$env.__MISE_DIFF = " first\\nsecond "', + '$env.HOMEBREW_PREFIX = ""', + 'print "startup noise"', + ].join("\n"), + ); + const env: NodeJS.ProcessEnv = { SHELL: shell, PATH: "/inherited/bin:/usr/bin" }; + yield* runShellEnvironment({ + env, + platform: "linux", + handler: (command) => { + if (command._tag !== "StandardCommand" || command.command !== shell) return ""; + const result = NodeChildProcess.spawnSync( + command.command, + ["--no-history", "--config", config, "--env-config", envConfig, ...command.args], + { + encoding: "utf8", + timeout: 5000, + env: { HOME: home, XDG_CONFIG_HOME: home, PATH: "/usr/bin:/bin" }, + }, + ); + if (result.error) throw result.error; + return { output: result.stdout, exitCode: result.status ?? 1 }; + }, + }); + + assert.equal(env.PATH, "/nu tools/bin:/usr/bin:/bin:/inherited/bin"); + assert.equal(env.SSH_AUTH_SOCK, "/tmp/nu-agent.sock"); + assert.equal(env.__MISE_DIFF, " first\nsecond "); + assert.isUndefined(env.DISPLAY); + assert.isUndefined(env.HOMEBREW_PREFIX); + } finally { + NodeFS.rmSync(home, { recursive: true, force: true }); + } + }), + ); + it.effect("rejects PATH output from a failed shell and tries the next candidate", () => Effect.gen(function* () { const env: NodeJS.ProcessEnv = { SHELL: "/bin/failing", PATH: "/usr/bin" }; diff --git a/packages/shared/src/shell.test.ts b/packages/shared/src/shell.test.ts index 59a0e138457e..9e5212920eda 100644 --- a/packages/shared/src/shell.test.ts +++ b/packages/shared/src/shell.test.ts @@ -1,3 +1,4 @@ +// @effect-diagnostics nodeBuiltinImport:off -- The synchronous shell probe runs real commands with isolated config files. import * as NodeServices from "@effect/platform-node/NodeServices"; import { it as effectIt } from "@effect/vitest"; import * as HostProcess from "@t3tools/shared/HostProcess"; @@ -8,6 +9,10 @@ import * as Path from "effect/Path"; import * as Result from "effect/Result"; import * as TestClock from "effect/testing/TestClock"; import * as Tracer from "effect/Tracer"; +import * as NodeChildProcess from "node:child_process"; +import * as NodeFS from "node:fs"; +import * as NodeOS from "node:os"; +import * as NodePath from "node:path"; import { describe, expect, it, vi } from "vite-plus/test"; import { @@ -124,25 +129,46 @@ describe("readPathFromLaunchctl", () => { }); describe("readEnvironmentFromLoginShell", () => { - it("uses Nushell-compatible syntax for a nu login shell", () => { - const execFile = vi.fn< - ( - file: string, - args: ReadonlyArray, - options: { encoding: "utf8"; timeout: number }, - ) => string - >(() => "__T3CODE_ENV_PATH_START__\n/a:/b\n__T3CODE_ENV_PATH_END__\n"); - - expect(readEnvironmentFromLoginShell("/opt/homebrew/bin/nu", ["PATH"], execFile)).toEqual({ - PATH: "/a:/b", - }); + // Opt in with an explicit binary, like the provider live probes; CI need not install Nu. + it.runIf(process.env.T3_TEST_NU_PATH !== undefined)( + "captures configured Nushell PATH and multiline values past missing variables", + () => { + const shell = process.env.T3_TEST_NU_PATH!; + const home = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-nu-env-")); + try { + const config = NodePath.join(home, "config.nu"); + const envConfig = NodePath.join(home, "env.nu"); + NodeFS.writeFileSync(envConfig, ""); + NodeFS.writeFileSync( + config, + [ + '$env.PATH = ["/nu tools/bin", "/usr/bin", "/bin"]', + '$env.CUSTOM_VAR = " first\\nsecond "', + '$env.EMPTY_VAR = ""', + 'print "startup noise"', + ].join("\n"), + ); - const command = execFile.mock.calls[0]?.[1][1]; - expect(command).toBe( - "print '__T3CODE_ENV_PATH_START__'; try { printenv PATH } catch { print '' }; print '__T3CODE_ENV_PATH_END__'", - ); - expect(command).not.toContain("|| true"); - }); + expect( + readEnvironmentFromLoginShell( + shell, + ["MISSING_VAR", "PATH", "EMPTY_VAR", "CUSTOM_VAR"], + (file, args, options) => + NodeChildProcess.execFileSync( + file, + ["--no-history", "--config", config, "--env-config", envConfig, ...args], + { + ...options, + env: { HOME: home, XDG_CONFIG_HOME: home, PATH: "/usr/bin:/bin" }, + }, + ), + ), + ).toEqual({ PATH: "/nu tools/bin:/usr/bin:/bin", CUSTOM_VAR: " first\nsecond " }); + } finally { + NodeFS.rmSync(home, { recursive: true, force: true }); + } + }, + ); it("extracts multiple environment variables from a login shell command", () => { const execFile = vi.fn< @@ -191,7 +217,7 @@ describe("readEnvironmentFromLoginShell", () => { }); }); - it("preserves surrounding whitespace in captured values", () => { + it("preserves multiline values and surrounding whitespace", () => { const execFile = vi.fn< ( file: string, @@ -199,13 +225,15 @@ describe("readEnvironmentFromLoginShell", () => { options: { encoding: "utf8"; timeout: number }, ) => string >(() => - ["__T3CODE_ENV_CUSTOM_VAR_START__", " padded value ", "__T3CODE_ENV_CUSTOM_VAR_END__"].join( - "\n", - ), + [ + "__T3CODE_ENV_CUSTOM_VAR_START__", + " first\nsecond ", + "__T3CODE_ENV_CUSTOM_VAR_END__", + ].join("\n"), ); expect(readEnvironmentFromLoginShell("/bin/zsh", ["CUSTOM_VAR"], execFile)).toEqual({ - CUSTOM_VAR: " padded value ", + CUSTOM_VAR: " first\nsecond ", }); }); }); From 1bc31f36e13c2497ceb9dc9926d5fe0d8f6c654d Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 19 Oct 2026 16:56:48 +0000 Subject: [PATCH 04/12] fix(desktop): hydrate Nushell login shell environment --- .../src/shell/DesktopShellEnvironment.ts | 19 ++++++------------- packages/shared/src/shell.ts | 11 +++++------ 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/apps/desktop/src/shell/DesktopShellEnvironment.ts b/apps/desktop/src/shell/DesktopShellEnvironment.ts index 8fa8a60b2e62..3fdec7932366 100644 --- a/apps/desktop/src/shell/DesktopShellEnvironment.ts +++ b/apps/desktop/src/shell/DesktopShellEnvironment.ts @@ -1,4 +1,8 @@ -import { listLoginShellCandidates, setWindowsPath } from "@t3tools/shared/shell"; +import { + buildEnvironmentCaptureCommand, + listLoginShellCandidates, + setWindowsPath, +} from "@t3tools/shared/shell"; import * as Context from "effect/Context"; import * as Duration from "effect/Duration"; import * as Effect from "effect/Effect"; @@ -199,17 +203,6 @@ const logShellEnvironmentCommandError = ( }), ); -const capturePosixEnvironmentCommand = (names: ReadonlyArray) => - names - .map((name) => { - return [ - `printf '%s\\n' '${startMarker(name)}'`, - `printenv ${name} || true`, - `printf '%s\\n' '${endMarker(name)}'`, - ].join("; "); - }) - .join("; "); - const captureWindowsEnvironmentCommand = (names: ReadonlyArray) => [ "$ErrorActionPreference = 'Stop'", @@ -320,7 +313,7 @@ const readLoginShellEnvironment = ( : runCommandOutput({ probe: "login-shell", command: shell, - args: ["-ilc", capturePosixEnvironmentCommand(names)], + args: ["-ilc", buildEnvironmentCaptureCommand(shell, names)], timeout: LOGIN_SHELL_TIMEOUT, }).pipe(Effect.map((output) => extractEnvironment(output, names))); diff --git a/packages/shared/src/shell.ts b/packages/shared/src/shell.ts index 779d0d46a50e..b3880292cf6c 100644 --- a/packages/shared/src/shell.ts +++ b/packages/shared/src/shell.ts @@ -201,13 +201,12 @@ function envCaptureEnd(name: string): string { return `__T3CODE_ENV_${name}_END__`; } -function isNushellExecutable(shell: string): boolean { +export function buildEnvironmentCaptureCommand( + shell: string, + names: ReadonlyArray, +): string { const executableName = NodePath.basename(shell).toLowerCase(); - return executableName === "nu" || executableName === "nu.exe"; -} - -function buildEnvironmentCaptureCommand(shell: string, names: ReadonlyArray): string { - const isNushell = isNushellExecutable(shell); + const isNushell = executableName === "nu" || executableName === "nu.exe"; return names .map((name) => { From 9680ad363d659f53254cd82630ba8d9802c124e1 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 19 Oct 2026 20:03:18 +0000 Subject: [PATCH 05/12] test(shell): cover Nushell capture without system tools --- .../src/shell/DesktopShellEnvironment.test.ts | 17 +++++++++++------ packages/shared/src/shell.test.ts | 12 ++++++++---- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/apps/desktop/src/shell/DesktopShellEnvironment.test.ts b/apps/desktop/src/shell/DesktopShellEnvironment.test.ts index 41939c318cd4..5c98127a3899 100644 --- a/apps/desktop/src/shell/DesktopShellEnvironment.test.ts +++ b/apps/desktop/src/shell/DesktopShellEnvironment.test.ts @@ -128,26 +128,31 @@ function runShellEnvironment(input: { describe("DesktopShellEnvironment", () => { // Explicit opt-in keeps real shell coverage independent of globally installed tools. it.effect.runIf(process.env.T3_TEST_NU_PATH !== undefined)( - "hydrates the desktop from Nushell despite missing variables and startup output", + "hydrates the desktop through a renamed Nushell symlink without external tools", () => Effect.gen(function* () { - const shell = process.env.T3_TEST_NU_PATH!; const home = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-desktop-nu-")); try { + const toolPath = NodePath.join(home, "nu tools", "bin"); + const extraToolPath = NodePath.join(home, "extra-tools", "bin"); + NodeFS.mkdirSync(toolPath, { recursive: true }); + NodeFS.mkdirSync(extraToolPath, { recursive: true }); + const shell = NodePath.join(toolPath, "nushell"); + NodeFS.symlinkSync(process.env.T3_TEST_NU_PATH!, shell); const config = NodePath.join(home, "config.nu"); const envConfig = NodePath.join(home, "env.nu"); NodeFS.writeFileSync(envConfig, ""); NodeFS.writeFileSync( config, [ - '$env.PATH = ["/nu tools/bin", "/usr/bin", "/bin"]', + `$env.PATH = [${JSON.stringify(toolPath)}, ${JSON.stringify(extraToolPath)}]`, '$env.SSH_AUTH_SOCK = "/tmp/nu-agent.sock"', '$env.__MISE_DIFF = " first\\nsecond "', '$env.HOMEBREW_PREFIX = ""', 'print "startup noise"', ].join("\n"), ); - const env: NodeJS.ProcessEnv = { SHELL: shell, PATH: "/inherited/bin:/usr/bin" }; + const env: NodeJS.ProcessEnv = { SHELL: shell, PATH: `/inherited/bin:${extraToolPath}` }; yield* runShellEnvironment({ env, platform: "linux", @@ -159,7 +164,7 @@ describe("DesktopShellEnvironment", () => { { encoding: "utf8", timeout: 5000, - env: { HOME: home, XDG_CONFIG_HOME: home, PATH: "/usr/bin:/bin" }, + env: { HOME: home, XDG_CONFIG_HOME: home, PATH: toolPath }, }, ); if (result.error) throw result.error; @@ -167,7 +172,7 @@ describe("DesktopShellEnvironment", () => { }, }); - assert.equal(env.PATH, "/nu tools/bin:/usr/bin:/bin:/inherited/bin"); + assert.equal(env.PATH, `${toolPath}:${extraToolPath}:/inherited/bin`); assert.equal(env.SSH_AUTH_SOCK, "/tmp/nu-agent.sock"); assert.equal(env.__MISE_DIFF, " first\nsecond "); assert.isUndefined(env.DISPLAY); diff --git a/packages/shared/src/shell.test.ts b/packages/shared/src/shell.test.ts index 689bb76e0149..f9b8802d6826 100644 --- a/packages/shared/src/shell.test.ts +++ b/packages/shared/src/shell.test.ts @@ -136,18 +136,22 @@ describe("readPathFromLaunchctl", () => { describe("readEnvironmentFromLoginShell", () => { // Opt in with an explicit binary, like the provider live probes; CI need not install Nu. it.runIf(process.env.T3_TEST_NU_PATH !== undefined)( - "captures configured Nushell PATH and multiline values past missing variables", + "captures Nushell PATH and multiline values without external tools", () => { const shell = process.env.T3_TEST_NU_PATH!; const home = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-nu-env-")); try { + const toolPath = NodePath.join(home, "nu tools", "bin"); + const extraToolPath = NodePath.join(home, "extra-tools", "bin"); + NodeFS.mkdirSync(toolPath, { recursive: true }); + NodeFS.mkdirSync(extraToolPath, { recursive: true }); const config = NodePath.join(home, "config.nu"); const envConfig = NodePath.join(home, "env.nu"); NodeFS.writeFileSync(envConfig, ""); NodeFS.writeFileSync( config, [ - '$env.PATH = ["/nu tools/bin", "/usr/bin", "/bin"]', + `$env.PATH = [${JSON.stringify(toolPath)}, ${JSON.stringify(extraToolPath)}]`, '$env.CUSTOM_VAR = " first\\nsecond "', '$env.EMPTY_VAR = ""', 'print "startup noise"', @@ -164,11 +168,11 @@ describe("readEnvironmentFromLoginShell", () => { ["--no-history", "--config", config, "--env-config", envConfig, ...args], { ...options, - env: { HOME: home, XDG_CONFIG_HOME: home, PATH: "/usr/bin:/bin" }, + env: { HOME: home, XDG_CONFIG_HOME: home, PATH: toolPath }, }, ), ), - ).toEqual({ PATH: "/nu tools/bin:/usr/bin:/bin", CUSTOM_VAR: " first\nsecond " }); + ).toEqual({ PATH: `${toolPath}:${extraToolPath}`, CUSTOM_VAR: " first\nsecond " }); } finally { NodeFS.rmSync(home, { recursive: true, force: true }); } From c4a2dbce27a1c21ffe96b70efd3c0c8eb07d55f6 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 19 Oct 2026 20:06:05 +0000 Subject: [PATCH 06/12] fix(shared): capture Nushell environment without external tools --- packages/shared/src/shell.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/shared/src/shell.ts b/packages/shared/src/shell.ts index caf660617dd6..9e5d0723a8e5 100644 --- a/packages/shared/src/shell.ts +++ b/packages/shared/src/shell.ts @@ -211,7 +211,7 @@ export function buildEnvironmentCaptureCommand( names: ReadonlyArray, ): string { const executableName = NodePath.basename(shell).toLowerCase(); - const isNushell = executableName === "nu" || executableName === "nu.exe"; + const isNushell = executableName.startsWith("nu"); return names .map((name) => { @@ -220,9 +220,13 @@ export function buildEnvironmentCaptureCommand( } if (isNushell) { + const value = + name === "PATH" + ? "$env.PATH? | default [] | str join (char esep)" + : `$env.${name}? | default ''`; return [ `print '${envCaptureStart(name)}'`, - `try { printenv ${name} } catch { print '' }`, + `print (${value})`, `print '${envCaptureEnd(name)}'`, ].join("; "); } From b0a5bac76af98a662eba67b9b6fb75071d5bec0b Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 19 Oct 2026 20:13:12 +0000 Subject: [PATCH 07/12] test(shared): require expanded Nushell home PATH entries --- packages/shared/src/shell.test.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/shared/src/shell.test.ts b/packages/shared/src/shell.test.ts index f9b8802d6826..29f4c2794d9e 100644 --- a/packages/shared/src/shell.test.ts +++ b/packages/shared/src/shell.test.ts @@ -151,7 +151,7 @@ describe("readEnvironmentFromLoginShell", () => { NodeFS.writeFileSync( config, [ - `$env.PATH = [${JSON.stringify(toolPath)}, ${JSON.stringify(extraToolPath)}]`, + `$env.PATH = [${JSON.stringify(toolPath)}, "~/extra-tools/bin", "rel/dir", ""]`, '$env.CUSTOM_VAR = " first\\nsecond "', '$env.EMPTY_VAR = ""', 'print "startup noise"', @@ -172,7 +172,10 @@ describe("readEnvironmentFromLoginShell", () => { }, ), ), - ).toEqual({ PATH: `${toolPath}:${extraToolPath}`, CUSTOM_VAR: " first\nsecond " }); + ).toEqual({ + PATH: `${toolPath}:${extraToolPath}:rel/dir:`, + CUSTOM_VAR: " first\nsecond ", + }); } finally { NodeFS.rmSync(home, { recursive: true, force: true }); } From 82d5b79f5ab3244c41753e15ac6a71a80462e76f Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 19 Oct 2026 20:15:57 +0000 Subject: [PATCH 08/12] fix(shared): expand Nushell list PATH home entries --- packages/shared/src/shell.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/shared/src/shell.ts b/packages/shared/src/shell.ts index 9e5d0723a8e5..466f7d8481bd 100644 --- a/packages/shared/src/shell.ts +++ b/packages/shared/src/shell.ts @@ -220,9 +220,13 @@ export function buildEnvironmentCaptureCommand( } if (isNushell) { + // Nu expands home paths only when exporting a list-valued PATH. const value = name === "PATH" - ? "$env.PATH? | default [] | str join (char esep)" + ? "if ($env.PATH? | describe | str starts-with 'list') { " + + "$env.PATH | each {|p| if ($p | str starts-with '~') { " + + "$p | path expand --no-symlink } else { $p } } | str join (char esep) " + + "} else { $env.PATH? | default '' }" : `$env.${name}? | default ''`; return [ `print '${envCaptureStart(name)}'`, From be7bba36502766a63cece5687e73374356413f29 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 19 Oct 2026 20:25:01 +0000 Subject: [PATCH 09/12] test(desktop): require Nushell export conversions --- .../src/shell/DesktopShellEnvironment.test.ts | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/apps/desktop/src/shell/DesktopShellEnvironment.test.ts b/apps/desktop/src/shell/DesktopShellEnvironment.test.ts index 5c98127a3899..d28f439bb8d1 100644 --- a/apps/desktop/src/shell/DesktopShellEnvironment.test.ts +++ b/apps/desktop/src/shell/DesktopShellEnvironment.test.ts @@ -128,15 +128,17 @@ function runShellEnvironment(input: { describe("DesktopShellEnvironment", () => { // Explicit opt-in keeps real shell coverage independent of globally installed tools. it.effect.runIf(process.env.T3_TEST_NU_PATH !== undefined)( - "hydrates the desktop through a renamed Nushell symlink without external tools", + "hydrates the desktop through a renamed Nushell symlink with native export conversions", () => Effect.gen(function* () { const home = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-desktop-nu-")); try { const toolPath = NodePath.join(home, "nu tools", "bin"); const extraToolPath = NodePath.join(home, "extra-tools", "bin"); + const convertedToolPath = NodePath.join(home, "converted-tools", "bin"); NodeFS.mkdirSync(toolPath, { recursive: true }); NodeFS.mkdirSync(extraToolPath, { recursive: true }); + NodeFS.mkdirSync(convertedToolPath, { recursive: true }); const shell = NodePath.join(toolPath, "nushell"); NodeFS.symlinkSync(process.env.T3_TEST_NU_PATH!, shell); const config = NodePath.join(home, "config.nu"); @@ -149,6 +151,13 @@ describe("DesktopShellEnvironment", () => { '$env.SSH_AUTH_SOCK = "/tmp/nu-agent.sock"', '$env.__MISE_DIFF = " first\\nsecond "', '$env.HOMEBREW_PREFIX = ""', + "$env.ENV_CONVERSIONS = {", + " PATH: {", + " from_string: {|value| $value | split row (char esep) },", + ' to_string: {|value| $value | str join (char esep) | str replace "nu tools" "converted-tools" }', + " },", + " __MISE_DIFF: { from_string: {|value| $value }, to_string: {|value| $value | str upcase } }", + "}", 'print "startup noise"', ].join("\n"), ); @@ -172,9 +181,14 @@ describe("DesktopShellEnvironment", () => { }, }); - assert.equal(env.PATH, `${toolPath}:${extraToolPath}:/inherited/bin`); + assert.deepEqual( + { PATH: env.PATH, __MISE_DIFF: env.__MISE_DIFF }, + { + PATH: `${convertedToolPath}:${extraToolPath}:/inherited/bin`, + __MISE_DIFF: " FIRST\nSECOND ", + }, + ); assert.equal(env.SSH_AUTH_SOCK, "/tmp/nu-agent.sock"); - assert.equal(env.__MISE_DIFF, " first\nsecond "); assert.isUndefined(env.DISPLAY); assert.isUndefined(env.HOMEBREW_PREFIX); } finally { From 819547c7998835c1ac39ec96861bb3f3a8bfff92 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 19 Oct 2026 20:28:19 +0000 Subject: [PATCH 10/12] fix(shared): honor Nushell environment export conversions --- packages/shared/src/shell.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/shared/src/shell.ts b/packages/shared/src/shell.ts index 466f7d8481bd..9c7773f26cdc 100644 --- a/packages/shared/src/shell.ts +++ b/packages/shared/src/shell.ts @@ -220,14 +220,19 @@ export function buildEnvironmentCaptureCommand( } if (isNushell) { - // Nu expands home paths only when exporting a list-valued PATH. - const value = + // Without a configured conversion, Nu expands home paths only in a list PATH. + const defaultValue = name === "PATH" ? "if ($env.PATH? | describe | str starts-with 'list') { " + "$env.PATH | each {|p| if ($p | str starts-with '~') { " + "$p | path expand --no-symlink } else { $p } } | str join (char esep) " + "} else { $env.PATH? | default '' }" : `$env.${name}? | default ''`; + const value = + `if $env.${name}? == null { '' } else if ` + + `$env.ENV_CONVERSIONS?.${name}?.to_string? != null { ` + + `do $env.ENV_CONVERSIONS.${name}.to_string $env.${name} ` + + `} else { ${defaultValue} }`; return [ `print '${envCaptureStart(name)}'`, `print (${value})`, From 22d3d29b3a433e64dae1b004573720bdbb183cb0 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 19 Oct 2026 20:36:36 +0000 Subject: [PATCH 11/12] test(desktop): cover Nushell pipeline export conversion --- apps/desktop/src/shell/DesktopShellEnvironment.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/desktop/src/shell/DesktopShellEnvironment.test.ts b/apps/desktop/src/shell/DesktopShellEnvironment.test.ts index d28f439bb8d1..3adf74bf76f8 100644 --- a/apps/desktop/src/shell/DesktopShellEnvironment.test.ts +++ b/apps/desktop/src/shell/DesktopShellEnvironment.test.ts @@ -156,7 +156,7 @@ describe("DesktopShellEnvironment", () => { " from_string: {|value| $value | split row (char esep) },", ' to_string: {|value| $value | str join (char esep) | str replace "nu tools" "converted-tools" }', " },", - " __MISE_DIFF: { from_string: {|value| $value }, to_string: {|value| $value | str upcase } }", + " __MISE_DIFF: { from_string: {|value| $value }, to_string: { str upcase } }", "}", 'print "startup noise"', ].join("\n"), From 065492fb5e3e25dd9000ae411298cb6d0e4513d4 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 19 Oct 2026 20:39:34 +0000 Subject: [PATCH 12/12] fix(shared): pass pipeline input to Nushell export conversions --- packages/shared/src/shell.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/shared/src/shell.ts b/packages/shared/src/shell.ts index 9c7773f26cdc..25e9f08ce37b 100644 --- a/packages/shared/src/shell.ts +++ b/packages/shared/src/shell.ts @@ -231,7 +231,7 @@ export function buildEnvironmentCaptureCommand( const value = `if $env.${name}? == null { '' } else if ` + `$env.ENV_CONVERSIONS?.${name}?.to_string? != null { ` + - `do $env.ENV_CONVERSIONS.${name}.to_string $env.${name} ` + + `$env.${name} | do $env.ENV_CONVERSIONS.${name}.to_string $env.${name} ` + `} else { ${defaultValue} }`; return [ `print '${envCaptureStart(name)}'`,