// @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"; import { DesktopHostTelemetryMessage } from "@t3tools/contracts"; import * as Schema from "effect/Schema"; import * as Effect from "effect/Effect"; import * as Fiber from "effect/Fiber"; import * as FileSystem from "effect/FileSystem"; import * as Path from "effect/Path"; import * as Option from "effect/Option"; import * as TestClock from "effect/testing/TestClock"; 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 { applyShellEnvironment, pathSetup, pathSetupCommand, CommandAvailability, CommandResolutionCache, makePathDirectoryListings, PathDirectoryListings, type CommandAvailabilityChecker, gitForWindowsBash, isCommandAvailable, listLoginShellCandidates, mergePathEntries, mergePathValues, npmShimExecutable, preferGitForWindowsBinary, readEnvironmentFromLoginShell, readEnvironmentFromWindowsShell, resolveCommandPath, resolveSpawnCommand, resolveWindowsEnvironment, runsGitWithoutConsole, windowsEnvironmentValueCommand, SpawnExecutableResolution, WindowsShellEnvironment, type WindowsShellEnvironmentReader, XcodeGitLocation, } from "./shell.ts"; const decodeDesktopHostMessage = Schema.decodeUnknownSync(DesktopHostTelemetryMessage); const nativeProbe = vi.hoisted(() => ({ execFile: vi.fn(), original: undefined as unknown as typeof import("node:child_process").execFile, })); vi.mock("node:child_process", async (importOriginal) => { const original = await importOriginal(); nativeProbe.original = original.execFile; return { ...original, execFile: nativeProbe.execFile.mockImplementation(original.execFile) }; }); const withWindowsEnvironmentMocks = ( effect: Effect.Effect, readEnvironment: ( ...args: Parameters ) => Partial>, commandAvailable: CommandAvailabilityChecker, ) => effect.pipe( Effect.provideService(WindowsShellEnvironment, (...args) => Effect.sync(() => readEnvironment(...args)), ), Effect.provideService(CommandAvailability, commandAvailable), ); 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 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 = [${JSON.stringify(toolPath)}, "~/extra-tools/bin", "rel/dir", ""]`, '$env.CUSTOM_VAR = " first\\nsecond "', '$env.EMPTY_VAR = ""', 'print "startup noise"', ].join("\n"), ); 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: toolPath }, }, ), ), ).toEqual({ PATH: `${toolPath}:${extraToolPath}:rel/dir:`, CUSTOM_VAR: " first\nsecond ", }); } finally { NodeFS.rmSync(home, { recursive: true, force: true }); } }, ); it.runIf(NodeFS.existsSync("/bin/bash"))( "captures values when the profile replaces PATH and a DEBUG trap echoes commands", () => { const home = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-bash-env-")); try { const tools = NodePath.join(home, "tools 'quoted $dir"); NodeFS.mkdirSync(tools); const printenv = NodeChildProcess.execFileSync("/bin/bash", ["-c", "type -P printenv"], { encoding: "utf8", env: { PATH: process.env.PATH }, }).trim(); NodeFS.copyFileSync(printenv, NodePath.join(tools, "printenv")); vi.stubEnv("PATH", tools); const shellPath = NodePath.join(home, "bin"); const bashEnv = NodePath.join(home, "env.bash"); NodeFS.writeFileSync( bashEnv, [ `export PATH='${shellPath.replaceAll("'", "'\\''")}'`, // Simulate a non-FHS host while retaining the real executable in its private prefix. "function /usr/bin/printenv { return 127; }", `trap 'echo -ne "\\033]0;\${BASH_COMMAND}\\007"' DEBUG`, ].join("\n"), ); expect( readEnvironmentFromLoginShell( "/bin/bash", ["XDG_DATA_HOME", "PATH"], // Non-interactive bash reads only BASH_ENV, not the host's /etc startup files that -il runs. (file, [, command = ""], options) => NodeChildProcess.execFileSync(file, ["-c", command], { ...options, env: { HOME: home, PATH: tools, TERM: "dumb", BASH_ENV: bashEnv }, }), ), ).toEqual({ PATH: shellPath }); } finally { vi.unstubAllEnvs(); NodeFS.rmSync(home, { recursive: true, force: true }); } }, ); it("extracts multiple environment variables from a login shell command", () => { const execFile = vi.fn< ( file: string, args: ReadonlyArray, options: { encoding: "utf8"; timeout: number }, ) => string >(() => [ "__T3CODE_ENV_PATH_START__", "/a:/b", "__T3CODE_ENV_PATH_END__", "__T3CODE_ENV_SSH_AUTH_SOCK_START__", "/tmp/secretive.sock", "__T3CODE_ENV_SSH_AUTH_SOCK_END__", ].join("\n"), ); expect(readEnvironmentFromLoginShell("/bin/zsh", ["PATH", "SSH_AUTH_SOCK"], execFile)).toEqual({ PATH: "/a:/b", SSH_AUTH_SOCK: "/tmp/secretive.sock", }); expect(execFile).toHaveBeenCalledTimes(1); expect(execFile).toHaveBeenCalledWith("/bin/zsh", expect.any(Array), { encoding: "utf8", timeout: 5000, killSignal: "SIGKILL", detached: true, stdio: ["ignore", "pipe", "ignore"], }); }); it("omits environment variables that are missing or empty", () => { const execFile = vi.fn< ( file: string, args: ReadonlyArray, options: { encoding: "utf8"; timeout: number }, ) => string >(() => [ "__T3CODE_ENV_PATH_START__", "/a:/b", "__T3CODE_ENV_PATH_END__", "__T3CODE_ENV_SSH_AUTH_SOCK_START__", "__T3CODE_ENV_SSH_AUTH_SOCK_END__", ].join("\n"), ); expect(readEnvironmentFromLoginShell("/bin/zsh", ["PATH", "SSH_AUTH_SOCK"], execFile)).toEqual({ PATH: "/a:/b", }); }); it("preserves multiline values and surrounding whitespace", () => { const execFile = vi.fn< ( file: string, args: ReadonlyArray, options: { encoding: "utf8"; timeout: number }, ) => string >(() => [ "__T3CODE_ENV_CUSTOM_VAR_START__", " first\nsecond ", "__T3CODE_ENV_CUSTOM_VAR_END__", ].join("\n"), ); expect(readEnvironmentFromLoginShell("/bin/zsh", ["CUSTOM_VAR"], execFile)).toEqual({ CUSTOM_VAR: " first\nsecond ", }); }); }); describe("listLoginShellCandidates", () => { it("returns env shell, user shell, then the platform fallback without duplicates", () => { expect(listLoginShellCandidates("darwin", " /opt/homebrew/bin/nu ", "/bin/zsh")).toEqual([ "/opt/homebrew/bin/nu", "/bin/zsh", ]); }); }); describe("mergePathEntries", () => { it("prefers login-shell PATH entries and keeps inherited extras", () => { expect( mergePathEntries("/opt/homebrew/bin:/usr/bin", "/Users/test/.local/bin:/usr/bin", "darwin"), ).toBe("/opt/homebrew/bin:/usr/bin:/Users/test/.local/bin"); expect(mergePathEntries("/opt/bin :/opt/bin", "/opt/bin :/usr/bin", "linux")).toBe( "/opt/bin :/opt/bin:/usr/bin", ); }); }); describe("windowsEnvironmentValueCommand", () => { it("joins PATH as Process, then Machine, then User so prepends win and User installs still appear", () => { const command = windowsEnvironmentValueCommand("PATH"); const processAt = command.indexOf("[Environment]::GetEnvironmentVariable('PATH','Process')"); const machineAt = command.indexOf("[Environment]::GetEnvironmentVariable('PATH','Machine')"); const userAt = command.indexOf("[Environment]::GetEnvironmentVariable('PATH','User')"); expect(processAt).toBeGreaterThan(-1); expect(processAt).toBeLessThan(machineAt); expect(machineAt).toBeLessThan(userAt); }); }); describe("readEnvironmentFromWindowsShell", () => { effectIt.effect("yields while the native shell probe is pending", () => Effect.gen(function* () { let completed = false; const [environment, completedBeforeProbeReturned] = yield* Effect.all( [ readEnvironmentFromWindowsShell(["PATH"]).pipe( Effect.tap(() => Effect.sync(() => { completed = true; }), ), ), Effect.sync(() => completed), ], { concurrency: 2 }, ); expect(completedBeforeProbeReturned).toBe(false); expect(environment).toBeTypeOf("object"); }), ); effectIt.layer(NodeServices.layer)("synchronous spawn failures", (it) => { it.effect("tries both shells and preserves baseline PATH repair", () => Effect.gen(function* () { const execFile = nativeProbe.execFile; execFile.mockImplementationOnce(() => { throw new Error("spawn EPERM"); }); execFile.mockImplementationOnce(() => { throw new Error("spawn EINVAL"); }); try { const patch = yield* resolveWindowsEnvironment({ PATH: "C:\\Windows", APPDATA: "C:\\Roaming", }).pipe(Effect.provideService(CommandAvailability, () => Effect.succeed(true))); expect(patch).toEqual({ PATH: "C:\\Windows;C:\\Roaming\\npm" }); expect(execFile.mock.calls.slice(-2).map(([file]) => file)).toEqual([ "pwsh.exe", "powershell.exe", ]); } finally { execFile.mockClear(); } }), ); }); effectIt.effect("returns an empty environment after both shell candidates fail", () => Effect.gen(function* () { const execFile = vi.fn(() => Effect.succeed(Option.none())); expect(yield* readEnvironmentFromWindowsShell(["PATH"], {}, execFile)).toEqual({}); expect(execFile).toHaveBeenCalledTimes(2); }), ); effectIt.effect("does not launch a shell when no variables are requested", () => Effect.gen(function* () { const execFile = vi.fn(() => Effect.succeed(Option.none())); expect(yield* readEnvironmentFromWindowsShell([], {}, execFile)).toEqual({}); expect(execFile).not.toHaveBeenCalled(); }), ); effectIt.effect( "kills the native probe child on interruption without trying the next shell", () => Effect.gen(function* () { const started = Promise.withResolvers(); const kill = vi.fn(() => true); const child = { kill, unref: vi.fn() } as unknown as ReturnType< typeof import("node:child_process").execFile >; const execFile = nativeProbe.execFile; execFile.mockClear(); execFile.mockImplementationOnce(() => { started.resolve(); return child; }); try { const fiber = yield* readEnvironmentFromWindowsShell(["PATH"]).pipe(Effect.forkChild); yield* Effect.promise(() => started.promise); yield* Fiber.interrupt(fiber); expect(kill).toHaveBeenCalledTimes(1); expect(execFile).toHaveBeenCalledTimes(1); expect(execFile.mock.calls[0]?.[0]).toBe("pwsh.exe"); } finally { execFile.mockClear(); } }), ); effectIt.effect("gives up on a shell that survives the kill and holds stdout open", () => Effect.gen(function* () { const stdout = { destroy: vi.fn() }; const unref = vi.fn(); const child = { kill: vi.fn(() => true), stdout, unref } as unknown as ReturnType< typeof import("node:child_process").execFile >; const execFile = nativeProbe.execFile; execFile.mockClear(); execFile.mockImplementation(() => child); try { const fiber = yield* readEnvironmentFromWindowsShell(["PATH"]).pipe(Effect.forkChild); yield* Effect.yieldNow; yield* TestClock.adjust("6 seconds"); expect(execFile.mock.calls.map(([file]) => file)).toEqual(["pwsh.exe", "powershell.exe"]); yield* TestClock.adjust("6 seconds"); expect(yield* Fiber.join(fiber)).toEqual({}); expect(stdout.destroy).toHaveBeenCalledTimes(2); expect(unref).toHaveBeenCalledTimes(2); } finally { execFile.mockReset(); execFile.mockImplementation(nativeProbe.original); } }), ); effectIt.effect("extracts environment variables from a PowerShell command", () => Effect.gen(function* () { const execFile = vi.fn< ( file: string, args: ReadonlyArray, options: { encoding: "utf8"; timeout: number }, ) => string >( () => "__T3CODE_ENV_PATH_START__\nC:\\Users\\testuser\\AppData\\Roaming\\npm\n__T3CODE_ENV_PATH_END__\n", ); expect( yield* readEnvironmentFromWindowsShell(["PATH"], {}, (...args) => Effect.sync(() => Option.liftThrowable(execFile)(...args)), ), ).toEqual({ PATH: "C:\\Users\\testuser\\AppData\\Roaming\\npm", }); expect(execFile).toHaveBeenCalledWith( "pwsh.exe", expect.arrayContaining(["-NoLogo", "-NoProfile", "-NonInteractive", "-Command"]), { encoding: "utf8", timeout: 5000 }, ); expect(execFile.mock.calls[0]?.[1].at(-1)).toContain( "[Console]::OutputEncoding = [System.Text.UTF8Encoding]::new($false)", ); }), ); effectIt.effect("strips CRLF delimiters from captured PowerShell values", () => Effect.gen(function* () { const execFile = vi.fn< ( file: string, args: ReadonlyArray, options: { encoding: "utf8"; timeout: number }, ) => string >( () => "__T3CODE_ENV_FNM_DIR_START__\r\nC:\\Users\\testuser\\AppData\\Roaming\\fnm\r\n__T3CODE_ENV_FNM_DIR_END__\r\n", ); expect( yield* readEnvironmentFromWindowsShell(["FNM_DIR"], {}, (...args) => Effect.sync(() => Option.liftThrowable(execFile)(...args)), ), ).toEqual({ FNM_DIR: "C:\\Users\\testuser\\AppData\\Roaming\\fnm", }); }), ); effectIt.effect.runIf(HostProcess.Platform.defaultValue() === "win32")( "reads a non-ASCII value from the real shell", () => Effect.gen(function* () { const name = "T3CODE_TEST_NON_ASCII_PATH"; const value = "C:\\Users\\Jürgen\\Grüße"; vi.stubEnv(name, value); try { expect(yield* readEnvironmentFromWindowsShell([name])).toEqual({ [name]: value }); } finally { vi.unstubAllEnvs(); } }), ); effectIt.effect("omits -NoProfile when loadProfile is enabled", () => Effect.gen(function* () { const execFile = vi.fn< ( file: string, args: ReadonlyArray, options: { encoding: "utf8"; timeout: number }, ) => string >(() => "__T3CODE_ENV_PATH_START__\nC:\\Tools\n__T3CODE_ENV_PATH_END__\n"); expect( yield* readEnvironmentFromWindowsShell(["PATH"], { loadProfile: true }, (...args) => Effect.sync(() => Option.liftThrowable(execFile)(...args)), ), ).toEqual({ PATH: "C:\\Tools", }); expect(execFile).toHaveBeenCalledWith( "pwsh.exe", expect.arrayContaining(["-NoLogo", "-NonInteractive", "-Command"]), { encoding: "utf8", timeout: 5000 }, ); expect(execFile.mock.calls[0]?.[1]).not.toContain("-NoProfile"); }), ); effectIt.effect("falls back to Windows PowerShell when pwsh.exe is unavailable", () => Effect.gen(function* () { const execFile = vi.fn< ( file: string, args: ReadonlyArray, options: { encoding: "utf8"; timeout: number }, ) => string >((file) => { if (file === "pwsh.exe") { throw new Error("spawn pwsh.exe ENOENT"); } return "__T3CODE_ENV_PATH_START__\nC:\\Tools\n__T3CODE_ENV_PATH_END__\n"; }); expect( yield* readEnvironmentFromWindowsShell(["PATH"], {}, (...args) => Effect.sync(() => Option.liftThrowable(execFile)(...args)), ), ).toEqual({ PATH: "C:\\Tools", }); expect(execFile).toHaveBeenNthCalledWith(1, "pwsh.exe", expect.any(Array), { encoding: "utf8", timeout: 5000, }); expect(execFile).toHaveBeenNthCalledWith(2, "powershell.exe", expect.any(Array), { encoding: "utf8", timeout: 5000, }); }), ); }); describe("mergePathValues", () => { it("sanitizes and dedupes Windows entries while preserving preferred order", () => { expect( mergePathValues( 'C:\\Users\\testuser\\AppData\\Roaming\\npm;"C:\\Program Files\\nodejs"', "c:\\users\\testuser\\appdata\\roaming\\npm;C:\\Windows\\System32", "win32", ), ).toBe( "C:\\Users\\testuser\\AppData\\Roaming\\npm;C:\\Program Files\\nodejs;C:\\Windows\\System32", ); }); it("removes stray quotes from Windows entries", () => { expect( mergePathValues( 'C:\\Windows\\System32;C:\\cloudflared.exe;C:";C:\\Program Files\\nodejs', undefined, "win32", ), ).toBe("C:\\Windows\\System32;C:\\cloudflared.exe;C:;C:\\Program Files\\nodejs"); }); it("dedupes case-sensitively on POSIX", () => { expect(mergePathValues("/usr/local/bin:/usr/bin", "/usr/bin:/USR/BIN", "linux")).toBe( "/usr/local/bin:/usr/bin:/USR/BIN", ); expect(mergePathValues("/opt/bin :/opt/bin", "/opt/bin :/usr/bin", "linux")).toBe( "/opt/bin :/opt/bin:/usr/bin", ); expect(mergePathValues('/opt/bin"', "/opt/bin", "linux")).toBe('/opt/bin":/opt/bin'); }); }); effectIt.layer(NodeServices.layer)("resolveCommandPath", (it) => { // Windows rejects `"` in file names. it.effect.skipIf(HostProcess.Platform.defaultValue() === "win32")( "finds executables in a POSIX PATH directory ending in whitespace and quotes", () => Effect.gen(function* () { const fs = yield* FileSystem.FileSystem; const path = yield* Path.Path; const cwd = yield* fs.makeTempDirectoryScoped({ directory: ".", prefix: "t3-path-" }); const directory = `${cwd}/bin \u00a0"`; yield* fs.makeDirectory(directory); const executable = `${directory}/audit-command`; yield* fs.writeFileString(executable, "#!/bin/sh\n"); yield* fs.chmod(executable, 0o755); const env = { PATH: directory }; expect( yield* resolveCommandPath("audit-command", { env }).pipe( Effect.provideService(HostProcess.Platform, "linux"), Effect.provideService(CommandResolutionCache, new Map()), ), ).toBe(path.join(directory, "audit-command")); const resolveExecutable = yield* SpawnExecutableResolution; expect(resolveExecutable("audit-command", "linux", env)).toBe(executable); }), ); const recordProbes = (env: NodeJS.ProcessEnv) => Effect.gen(function* () { const probed: Array = []; const result = yield* resolveCommandPath("definitely-not-installed", { env }).pipe( Effect.provideService(HostProcess.Platform, "win32"), Effect.provideService(CommandResolutionCache, new Map()), Effect.provide( FileSystem.layerNoop({ stat: (filePath) => Effect.sync(() => { probed.push(filePath); // No mtime, so no listing: every candidate is probed directly. return { type: "Directory", mtime: Option.none() } as FileSystem.File.Info; }), }), ), ); expect(result).toBeNull(); return probed; }); it.effect("still visits a PATH entry that differs only in case", () => Effect.gen(function* () { const probed = yield* recordProbes({ PATH: "C:\\bin;C:\\BIN", PATHEXT: ".COM;.EXE", }); // Windows PATH directories can be case-sensitive; preserve both spellings. expect(probed).toEqual(expect.arrayContaining(["C:\\bin", "C:\\BIN"])); expect(probed).toHaveLength(2 + 8); }), ); it.effect.each(["audit-command", "audit-command.CMD"])( "resolves lowercase executable files for %s in a case-sensitive Windows PATH directory", (command) => Effect.gen(function* () { const fs = yield* FileSystem.FileSystem; const path = yield* Path.Path; const cwd = yield* fs.makeTempDirectoryScoped({ prefix: "t3-case-sensitive-path-" }); const executable = path.join(cwd, "audit-command.cmd"); yield* fs.writeFileString(executable, "@echo off\n"); const decoy = path.join(cwd, "audit-command.exe"); yield* fs.writeFileString(decoy, ""); for (const key of ["PATHEXT", "PathExt", "pathext"]) { const resolved = yield* resolveCommandPath(command, { env: { PATH: cwd, [key]: ".CMD" }, }).pipe( Effect.provideService(HostProcess.Platform, "win32"), Effect.provideService(CommandResolutionCache, new Map()), Effect.provideService(FileSystem.FileSystem, { ...fs, stat: (filePath) => fs.stat( filePath === cwd || filePath === executable || filePath === decoy ? filePath : path.join(cwd, "missing"), ), }), ); expect(resolved).toBe(executable); } }), ); it.effect("probes the requested spelling outside Windows, for case-insensitive volumes", () => Effect.gen(function* () { const fs = yield* FileSystem.FileSystem; const path = yield* Path.Path; const directory = yield* fs.makeTempDirectoryScoped(); yield* fs.writeFileString(path.join(directory, "code"), ""); yield* TestClock.setTime(4_200_000_000_000); const probed: Array = []; yield* resolveCommandPath("Code", { env: { PATH: directory } }).pipe( Effect.provideService(HostProcess.Platform, "darwin"), Effect.provideService(CommandResolutionCache, new Map()), Effect.provideServiceEffect(PathDirectoryListings, makePathDirectoryListings), Effect.provideService(FileSystem.FileSystem, { ...fs, stat: (file) => { if (file !== directory) probed.push(file); return fs.stat(file); }, }), ); expect(probed).toEqual([path.join(directory, "Code")]); }), ); it.effect("lists each PATH directory once, probes only listed names, and relists on change", () => Effect.gen(function* () { const fs = yield* FileSystem.FileSystem; const path = yield* Path.Path; const first = yield* fs.makeTempDirectoryScoped(); const second = yield* fs.makeTempDirectoryScoped(); yield* fs.writeFileString(path.join(first, "cursor.CMD"), ""); yield* fs.writeFileString(path.join(second, "cursor.EXE"), ""); const env = { PATH: `${first};${second}`, PATHEXT: ".EXE;.CMD" }; // Past the settle window of both directories, including the far-future mtime set below. yield* TestClock.setTime(4_200_000_000_000); const probed: Array = []; const listed: Array = []; yield* Effect.gen(function* () { expect(yield* resolveCommandPath("cursor", { env })).toBe(path.join(first, "cursor.CMD")); expect(yield* isCommandAvailable("absent", { env })).toBe(false); expect(yield* isCommandAvailable("also-absent", { env })).toBe(false); expect(listed).toEqual([first, second]); yield* fs.writeFileString(path.join(second, "late.EXE"), ""); yield* fs.utimes(second, 4_102_444_800, 4_102_444_800); expect(yield* resolveCommandPath("late", { env })).toBe(path.join(second, "late.EXE")); expect(listed).toEqual([first, second, second]); }).pipe( Effect.provideService(FileSystem.FileSystem, { ...fs, stat: (file) => { if (file !== first && file !== second) probed.push(file); return fs.stat(file); }, readDirectory: (directory, options) => { listed.push(directory); return fs.readDirectory(directory, options); }, }), ); expect(probed).toEqual([path.join(first, "cursor.CMD"), path.join(second, "late.EXE")]); }).pipe( Effect.provideService(HostProcess.Platform, "win32"), Effect.provideService(CommandResolutionCache, new Map()), Effect.provideServiceEffect(PathDirectoryListings, makePathDirectoryListings), ), ); }); describe("runsGitWithoutConsole", () => { const git = "C:\\Program Files\\Git\\ucrt64\\bin\\git.exe"; it.each([ [["rev-parse", "--git-path", "index"], true], [["rev-parse", "--git-common-dir", "--show-toplevel"], true], [ [ "rev-parse", "--path-format=absolute", "--git-path", "index", "--git-common-dir", "--show-toplevel", ], true, ], [["--git-dir", "C:\\repo\\.git", "symbolic-ref", "refs/remotes/origin/HEAD"], true], [["remote", "get-url", "--", "origin"], true], [["config", "--get", "branch.main.pushRemote"], true], [["symbolic-ref", "--quiet", "HEAD"], true], [["rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{upstream}"], true], [["rev-parse", "HEAD"], false], [["symbolic-ref", "HEAD", "refs/heads/x"], false], [["symbolic-ref", "-qd", "refs/remotes/origin/HEAD"], false], [["config", "--get", "--edit"], false], [["-c", "core.pager=x", "config", "--get", "user.name"], false], ])("Git for Windows %j without a console: %s", (args, expected) => { expect(runsGitWithoutConsole("win32", git, args)).toBe(expected); }); it.each([ ["win32", "C:\\Program Files\\Git\\cmd\\git.exe"], ["win32", "C:\\Users\\x\\scoop\\shims\\git.exe"], ["linux", git], ] as const)("keeps the console on %s for %s", (platform, executable) => { expect(runsGitWithoutConsole(platform, executable, ["rev-parse", "--show-toplevel"])).toBe( false, ); }); }); describe("preferGitForWindowsBinary", () => { const files = (...paths: Array) => (filePath: string) => paths.includes(filePath); it("runs the git.exe Git for Windows' launcher would start", () => { expect( preferGitForWindowsBinary( "C:\\Program Files\\Git\\cmd\\git.EXE", {}, files( "C:\\Program Files\\Git\\ucrt64\\bin\\git.exe", "C:\\Program Files\\Git\\mingw64\\bin\\git.exe", ), ), ).toBe("C:\\Program Files\\Git\\ucrt64\\bin\\git.exe"); expect( preferGitForWindowsBinary( "D:\\PortableGit\\bin\\git.exe", {}, files("D:\\PortableGit\\mingw64\\bin\\git.exe"), ), ).toBe("D:\\PortableGit\\mingw64\\bin\\git.exe"); expect( preferGitForWindowsBinary( "C:\\Program Files\\Git\\cmd\\git.exe", {}, files("C:\\Program Files\\Git\\clangarm64\\bin\\git.exe"), ), ).toBe("C:\\Program Files\\Git\\clangarm64\\bin\\git.exe"); }); it("keeps the launcher when MSYSTEM is set", () => { // git.exe adds hook dependencies to PATH only when MSYSTEM is unset. expect( preferGitForWindowsBinary( "C:\\Program Files\\Git\\cmd\\git.exe", { MSYSTEM: "MINGW64" }, files("C:\\Program Files\\Git\\mingw64\\bin\\git.exe"), ), ).toBe("C:\\Program Files\\Git\\cmd\\git.exe"); }); it("leaves other gits and other launchers alone", () => { const everything = () => true; expect(preferGitForWindowsBinary("C:\\Users\\me\\scoop\\shims\\git.exe", {}, everything)).toBe( "C:\\Users\\me\\scoop\\shims\\git.exe", ); expect(preferGitForWindowsBinary("C:\\Program Files\\Git\\cmd\\gitk.exe", {}, everything)).toBe( "C:\\Program Files\\Git\\cmd\\gitk.exe", ); }); }); describe("gitForWindowsBash", () => { const bash = "C:\\Program Files\\Git\\bin\\bash.exe"; const isBash = (filePath: string) => filePath === bash; it.each([ "C:\\Program Files\\Git\\cmd\\git.exe", "C:\\Program Files\\Git\\bin\\git.exe", "C:\\Program Files\\Git\\mingw64\\bin\\git.exe", ])("finds Git Bash from %s", (git) => { expect(gitForWindowsBash(git, isBash)).toBe(bash); }); it("finds nothing without a Git for Windows bash", () => { expect(gitForWindowsBash("C:\\Users\\me\\scoop\\shims\\git.exe", isBash)).toBeUndefined(); expect(gitForWindowsBash("C:\\Program Files\\Git\\cmd\\gitk.exe", () => true)).toBeUndefined(); }); }); // Byte for byte what `npm install -g opencode-ai` writes as `opencode.cmd`. const NPM_OPENCODE_SHIM = [ "@ECHO off", "GOTO start", ":find_dp0", "SET dp0=%~dp0", "EXIT /b", ":start", "SETLOCAL", "CALL :find_dp0", '"%dp0%\\node_modules\\opencode-ai\\bin\\opencode.exe" %*', "", ].join("\r\n"); describe("npmShimExecutable", () => { const shimPath = "C:\\Users\\me\\AppData\\Roaming\\npm\\opencode.cmd"; const executable = "C:\\Users\\me\\AppData\\Roaming\\npm\\node_modules\\opencode-ai\\bin\\opencode.exe"; const exists = (filePath: string) => filePath === executable; it("finds the executable npm's shim runs", () => { expect(npmShimExecutable(shimPath, () => NPM_OPENCODE_SHIM, exists)).toBe(executable); expect( npmShimExecutable(shimPath.replace(".cmd", ".CMD"), () => NPM_OPENCODE_SHIM, exists), ).toBe(executable); }); it("keeps a shim that does more than run the executable", () => { const withSetting = NPM_OPENCODE_SHIM.replace( "SETLOCAL", "SETLOCAL\r\nSET OPENCODE_CONFIG=C:\\x", ); expect(npmShimExecutable(shimPath, () => withSetting, exists)).toBeUndefined(); const nodeScript = NPM_OPENCODE_SHIM.replace( '"%dp0%\\node_modules\\opencode-ai\\bin\\opencode.exe" %*', '"%_prog%" "%dp0%\\node_modules\\opencode-ai\\bin\\opencode.js" %*', ); expect( npmShimExecutable( shimPath, () => nodeScript, () => true, ), ).toBeUndefined(); }); it("keeps a shim CMD would read differently", () => { // CMD preserves trailing SET whitespace, changing the executable path. for (const suffix of ["\u00a0", "\t", " "]) { const altered = NPM_OPENCODE_SHIM.replace("SET dp0=%~dp0", `SET dp0=%~dp0${suffix}`); expect( npmShimExecutable( shimPath, () => altered, () => true, ), ).toBeUndefined(); } const nonBreakingSeparator = NPM_OPENCODE_SHIM.replace( 'opencode.exe" %*', 'opencode.exe"\u00a0%*', ); expect( npmShimExecutable( shimPath, () => nonBreakingSeparator, () => true, ), ).toBeUndefined(); const indented = NPM_OPENCODE_SHIM.replace("SETLOCAL", " SETLOCAL"); expect( npmShimExecutable( shimPath, () => indented, () => true, ), ).toBeUndefined(); }); it("keeps the shim when its executable is missing or it is not a .cmd", () => { expect( npmShimExecutable( shimPath, () => NPM_OPENCODE_SHIM, () => false, ), ).toBeUndefined(); expect( npmShimExecutable( shimPath, () => undefined, () => true, ), ).toBeUndefined(); expect( npmShimExecutable( shimPath.replace(".cmd", ".bat"), () => NPM_OPENCODE_SHIM, () => true, ), ).toBeUndefined(); }); }); effectIt.layer(NodeServices.layer)("resolveSpawnCommand", (it) => { it.effect("runs Windows executables directly without a shell", () => Effect.gen(function* () { const command = yield* resolveSpawnCommand("node.exe", ["script.js", "hello & goodbye"], { env: { PATH: "", PATHEXT: ".COM;.EXE;.BAT;.CMD" }, }).pipe( Effect.provideService(HostProcess.Platform, "win32"), Effect.provideService(CommandResolutionCache, new Map()), ); expect(command).toEqual({ command: "node.exe", args: ["script.js", "hello & goodbye"], shell: false, }); }), ); it.effect.runIf(HostProcess.Platform.defaultValue() === "win32")( "runs the executable behind an npm shim directly when asked", () => Effect.gen(function* () { const fs = yield* FileSystem.FileSystem; const path = yield* Path.Path; const prefix = yield* fs.makeTempDirectoryScoped({ prefix: "t3-npm-shim-" }); const shim = path.join(prefix, "opencode.cmd"); const executable = path.join(prefix, "node_modules", "opencode-ai", "bin", "opencode.exe"); yield* fs.makeDirectory(path.dirname(executable), { recursive: true }); yield* fs.writeFileString(executable, ""); yield* fs.writeFileString(shim, NPM_OPENCODE_SHIM); const resolve = (bypassNpmShim: boolean) => resolveSpawnCommand("opencode", ["serve", "--port=4096"], { env: { PATH: "", PATHEXT: ".COM;.EXE;.BAT;.CMD" }, bypassNpmShim, }).pipe( Effect.provideService(HostProcess.Platform, "win32"), Effect.provideService(CommandResolutionCache, new Map()), Effect.provideService(SpawnExecutableResolution, () => shim), ); expect(yield* resolve(true)).toEqual({ command: executable, args: ["serve", "--port=4096"], shell: false, }); expect((yield* resolve(false)).shell).toBe(true); }), ); it.effect("builds one escaped cmd.exe line for Windows command shims", () => Effect.gen(function* () { const command = yield* resolveSpawnCommand( "vp", [ "run", "value & calc", "%PATH%", 'quote"value', "C:\\dir with space\\", 'slash\\"quote', "x|y^", ], { env: { PATH: "", PATHEXT: ".COM;.EXE;.BAT;.CMD" } }, ).pipe( Effect.provideService(HostProcess.Platform, "win32"), Effect.provideService(CommandResolutionCache, new Map()), Effect.provideService( SpawnExecutableResolution, () => "C:\\Program Files\\npm & tools\\vp.cmd", ), ); // No args alongside `shell: true`: Node prints DEP0190 for that pairing. expect(command).toEqual({ command: [ String.raw`^"C:\Program^ Files\npm^ ^&^ tools\vp.cmd^"`, String.raw`^"run^"`, String.raw`^"value^ ^&^ calc^"`, String.raw`^"^%PATH^%^"`, String.raw`^"quote\^"value^"`, String.raw`^"C:\dir^ with^ space\\^"`, String.raw`^"slash\\\^"quote^"`, String.raw`^"x^|y^^^^"`, ].join(" "), args: [], shell: true, }); }), ); it.effect("resolves against the effective environment when extending host env", () => Effect.gen(function* () { let resolvedEnvironment: NodeJS.ProcessEnv | undefined; yield* resolveSpawnCommand("codex", ["app-server"], { env: { CODEX_HOME: "C:\\Users\\tester\\.codex" }, extendEnv: true, }).pipe( Effect.provideService(HostProcess.Platform, "win32"), Effect.provideService(CommandResolutionCache, new Map()), Effect.provideService(HostProcess.Environment, { PATH: "C:\\Users\\tester\\AppData\\Roaming\\npm", PATHEXT: ".COM;.EXE;.BAT;.CMD", }), Effect.provideService(SpawnExecutableResolution, (_command, _platform, env) => { resolvedEnvironment = env; return "C:\\Users\\tester\\AppData\\Roaming\\npm\\codex.cmd"; }), ); expect(resolvedEnvironment).toEqual({ PATH: "C:\\Users\\tester\\AppData\\Roaming\\npm", PATHEXT: ".COM;.EXE;.BAT;.CMD", CODEX_HOME: "C:\\Users\\tester\\.codex", }); }), ); describe("macOS git", () => { // Files that exist, the git first on PATH, and what `xcrun --find git` prints. const setup = (options: { readonly platform?: NodeJS.Platform; readonly gitOnPath: string; readonly xcrunGit: string | undefined; }) => { const files = new Set([options.gitOnPath, ...(options.xcrunGit ? [options.xcrunGit] : [])]); const host = { xcrunGit: options.xcrunGit, xcrunCalls: 0 }; const resolve = resolveSpawnCommand("git", ["status"], { env: { PATH: "/fake/bin" } }).pipe( Effect.map((resolved) => resolved.command), Effect.provideService(HostProcess.Platform, options.platform ?? "darwin"), Effect.provideService(SpawnExecutableResolution, (command) => command === "git" ? options.gitOnPath : files.has(command) ? command : undefined, ), Effect.provideService(XcodeGitLocation, () => { host.xcrunCalls += 1; return host.xcrunGit; }), ); return { files, host, resolve }; }; const XCODE_GIT = "/Applications/Xcode.app/Contents/Developer/usr/bin/git"; it.effect("runs the git behind the xcrun shim and looks it up once", () => Effect.gen(function* () { const { host, resolve } = setup({ gitOnPath: "/usr/bin/git", xcrunGit: XCODE_GIT }); expect(yield* resolve).toBe(XCODE_GIT); expect(yield* resolve).toBe(XCODE_GIT); expect(host.xcrunCalls).toBe(1); }).pipe(Effect.provideService(CommandResolutionCache, new Map())), ); it.effect("keeps git when PATH has another git or the host is not macOS", () => Effect.gen(function* () { const homebrew = setup({ gitOnPath: "/opt/homebrew/bin/git", xcrunGit: XCODE_GIT }); expect(yield* homebrew.resolve).toBe("git"); expect(homebrew.host.xcrunCalls).toBe(0); const linux = setup({ platform: "linux", gitOnPath: "/usr/bin/git", xcrunGit: XCODE_GIT }); expect(yield* linux.resolve).toBe("git"); }).pipe(Effect.provideService(CommandResolutionCache, new Map())), ); it.effect("keeps git when xcrun fails or names a missing file", () => Effect.gen(function* () { const failed = setup({ gitOnPath: "/usr/bin/git", xcrunGit: undefined }); expect(yield* failed.resolve).toBe("git"); const missing = setup({ gitOnPath: "/usr/bin/git", xcrunGit: XCODE_GIT }); missing.files.delete(XCODE_GIT); expect(yield* missing.resolve).toBe("git"); }).pipe(Effect.provideService(CommandResolutionCache, new Map())), ); it.effect("looks again when the resolved git disappears", () => Effect.gen(function* () { const betaGit = "/Applications/Xcode-beta.app/Contents/Developer/usr/bin/git"; const { files, host, resolve } = setup({ gitOnPath: "/usr/bin/git", xcrunGit: XCODE_GIT }); expect(yield* resolve).toBe(XCODE_GIT); files.delete(XCODE_GIT); files.add(betaGit); host.xcrunGit = betaGit; expect(yield* resolve).toBe(betaGit); expect(host.xcrunCalls).toBe(2); }).pipe(Effect.provideService(CommandResolutionCache, new Map())), ); }); it.effect("does not fall back to a shell for unresolved Windows commands", () => Effect.gen(function* () { const command = yield* resolveSpawnCommand("missing & calc", ["unsafe & value"], { env: { PATH: "", PATHEXT: ".COM;.EXE;.BAT;.CMD" }, }).pipe( Effect.provideService(HostProcess.Platform, "win32"), Effect.provideService(CommandResolutionCache, new Map()), ); expect(command).toEqual({ command: "missing & calc", args: ["unsafe & value"], shell: false, }); }), ); }); effectIt.layer(NodeServices.layer)("resolveWindowsEnvironment", (it) => { it.effect("uses known CLI directories as a fallback without changing shell PATH priority", () => Effect.gen(function* () { const readEnvironment = vi.fn( (_names: ReadonlyArray, options?: { loadProfile?: boolean }) => options?.loadProfile ? { PATH: "C:\\Profile\\Bin" } : { PATH: "C:\\Shell\\Bin;C:\\Windows\\System32" }, ); const commandAvailable = vi.fn(() => Effect.succeed(true)); expect( yield* withWindowsEnvironmentMocks( resolveWindowsEnvironment({ PATH: "C:\\Windows\\System32", APPDATA: "C:\\Users\\testuser\\AppData\\Roaming", LOCALAPPDATA: "C:\\Users\\testuser\\AppData\\Local", USERPROFILE: "C:\\Users\\testuser", }), readEnvironment, commandAvailable, ), ).toEqual({ PATH: [ "C:\\Shell\\Bin", "C:\\Windows\\System32", "C:\\Users\\testuser\\AppData\\Roaming\\npm", "C:\\Users\\testuser\\AppData\\Local\\Programs\\nodejs", "C:\\Users\\testuser\\AppData\\Local\\Volta\\bin", "C:\\Users\\testuser\\AppData\\Local\\pnpm", "C:\\Users\\testuser\\.local\\bin", "C:\\Users\\testuser\\.bun\\bin", "C:\\Users\\testuser\\scoop\\shims", ].join(";"), }); expect(readEnvironment).toHaveBeenCalledTimes(1); expect(readEnvironment).toHaveBeenCalledWith(["PATH"], { loadProfile: false }); expect(commandAvailable).toHaveBeenCalledWith( "node", expect.objectContaining({ env: expect.any(Object) }), ); }), ); it.effect( "probes node with one PATH key when inherited environment records have mixed casing", () => Effect.gen(function* () { const probedEnvironments: Array = []; yield* withWindowsEnvironmentMocks( resolveWindowsEnvironment({ Path: "C:\\Stale", PATH: "C:\\Windows\\System32" }), () => ({ PATH: "C:\\Shell\\Bin" }), (_command, options) => Effect.sync(() => { probedEnvironments.push(options?.env); return true; }), ); const pathEntries = Object.entries(probedEnvironments[0] ?? {}).filter( ([key]) => key.toUpperCase() === "PATH", ); expect(pathEntries).toEqual([["PATH", "C:\\Shell\\Bin;C:\\Windows\\System32"]]); }), ); it.effect("loads the PowerShell profile when baseline env cannot resolve node", () => Effect.gen(function* () { const readEnvironment = vi.fn( (_names: ReadonlyArray, options?: { loadProfile?: boolean }) => options?.loadProfile ? { PATH: "C:\\Profile\\Node;C:\\Windows\\System32", FNM_DIR: "C:\\Users\\testuser\\AppData\\Roaming\\fnm", FNM_MULTISHELL_PATH: "C:\\Users\\testuser\\AppData\\Local\\fnm_multishells\\123", } : { PATH: "C:\\Shell\\Bin;C:\\Windows\\System32" }, ); const commandAvailable = vi.fn(() => Effect.succeed(false)); expect( yield* withWindowsEnvironmentMocks( resolveWindowsEnvironment({ PATH: "C:\\Windows\\System32", APPDATA: "C:\\Users\\testuser\\AppData\\Roaming", LOCALAPPDATA: "C:\\Users\\testuser\\AppData\\Local", USERPROFILE: "C:\\Users\\testuser", }), readEnvironment, commandAvailable, ), ).toEqual({ PATH: [ "C:\\Profile\\Node", "C:\\Windows\\System32", "C:\\Shell\\Bin", "C:\\Users\\testuser\\AppData\\Roaming\\npm", "C:\\Users\\testuser\\AppData\\Local\\Programs\\nodejs", "C:\\Users\\testuser\\AppData\\Local\\Volta\\bin", "C:\\Users\\testuser\\AppData\\Local\\pnpm", "C:\\Users\\testuser\\.local\\bin", "C:\\Users\\testuser\\.bun\\bin", "C:\\Users\\testuser\\scoop\\shims", ].join(";"), FNM_DIR: "C:\\Users\\testuser\\AppData\\Roaming\\fnm", FNM_MULTISHELL_PATH: "C:\\Users\\testuser\\AppData\\Local\\fnm_multishells\\123", }); expect(readEnvironment).toHaveBeenNthCalledWith(1, ["PATH"], { loadProfile: false }); expect(readEnvironment).toHaveBeenNthCalledWith( 2, ["PATH", "FNM_DIR", "FNM_MULTISHELL_PATH"], { loadProfile: true, }, ); expect(commandAvailable).toHaveBeenCalledTimes(1); }), ); it.effect("keeps the baseline env when profiled probe still does not resolve node", () => Effect.gen(function* () { const readEnvironment = vi.fn( (_names: ReadonlyArray, options?: { loadProfile?: boolean }) => options?.loadProfile ? { FNM_DIR: "C:\\Users\\testuser\\AppData\\Roaming\\fnm" } : {}, ); const commandAvailable = vi.fn(() => Effect.succeed(false)); expect( yield* withWindowsEnvironmentMocks( resolveWindowsEnvironment({ PATH: "C:\\Windows\\System32", APPDATA: "C:\\Users\\testuser\\AppData\\Roaming", USERPROFILE: "C:\\Users\\testuser", }), readEnvironment, commandAvailable, ), ).toEqual({ PATH: [ "C:\\Windows\\System32", "C:\\Users\\testuser\\AppData\\Roaming\\npm", "C:\\Users\\testuser\\.local\\bin", "C:\\Users\\testuser\\.bun\\bin", "C:\\Users\\testuser\\scoop\\shims", ].join(";"), FNM_DIR: "C:\\Users\\testuser\\AppData\\Roaming\\fnm", }); expect(commandAvailable).toHaveBeenCalledTimes(1); }), ); }); describe("desktop shell environment updates", () => { it.each(["win32", "linux", "darwin"] as const)( "applies shell updates with %s PATH semantics", (platform) => { const message = decodeDesktopHostMessage({ version: 1, type: "shellEnvironment", discovered: true, platform, environment: { PATH: "C:\\fresh", FNM_DIR: null, __MISE_DIFF: null, SSH_AUTH_SOCK: "/current.sock", NODE_OPTIONS: "--bad", }, }); expect(message.type).toBe("shellEnvironment"); if (message.type !== "shellEnvironment") throw new Error("Expected shell environment update"); const env: NodeJS.ProcessEnv = { Path: "C:\\stale", FNM_DIR: "stale", __MISE_DIFF: "stale", UNRELATED: "keep", }; applyShellEnvironment(env, message.environment, platform); expect(env).toEqual({ PATH: "C:\\fresh", ...(platform === "win32" ? {} : { Path: "C:\\stale" }), SSH_AUTH_SOCK: "/current.sock", UNRELATED: "keep", }); env.Path = "C:\\stale"; env.path = "C:\\other"; applyShellEnvironment(env, { PATH: null, SSH_AUTH_SOCK: null }, platform); expect(env).toEqual({ ...(platform === "win32" ? {} : { Path: "C:\\stale", path: "C:\\other" }), UNRELATED: "keep", }); }, ); }); describe("pathSetupCommand", () => { // Undefined where a pasted line could break things: Windows (it would flatten %VAR% entries in // the registry PATH), macOS bash (several startup files), other shells, and unsafe paths. it.each([ [ "/home/theo/.local/bin", "/bin/bash", "linux", `printf '\\n%s\\n' 'export PATH="$PATH:/home/theo/.local/bin"' >> ~/.bashrc`, ], [ "/Users/theo/.local/bin", "/usr/bin/fish", "linux", `mkdir -p ~/.config/fish && printf '\\n%s\\n' 'fish_add_path --append --path $HOME/.local/bin' >> ~/.config/fish/config.fish`, ], [ "/opt/t3/bin", "/bin/zsh", "linux", `printf '\\n%s\\n' 'export PATH="$PATH:/opt/t3/bin"' >> ~/.zshrc`, ], ["/Users/theo/.local/bin", "/bin/tcsh", "darwin", undefined], ["/Users/theo/.local/bin", "/bin/bash", "darwin", undefined], ["C:\\Users\\theo\\.local\\bin", "pwsh", "win32", undefined], ["/Users/theo/it's here", "/bin/zsh", "darwin", undefined], ["/opt/a$PWD/bin", "/bin/zsh", "linux", undefined], // Relative: PATH would follow the working directory into any checkout's `bin`. ["bin", "/bin/zsh", "linux", undefined], ] as const)("%s with %s on %s", (directory, shell, platform, expected) => { expect(pathSetupCommand({ directory, home: "/Users/theo", shell, platform })).toBe(expected); }); it("writes the startup file fish and zsh read, under XDG_CONFIG_HOME or ZDOTDIR", () => { const setup = { directory: "/opt/t3/bin", home: "/home/theo", shell: "/usr/bin/fish" } as const; expect(pathSetup({ ...setup, platform: "linux", configHome: "/home/theo/cfg" })?.file).toBe( "/home/theo/cfg/fish/config.fish", ); expect(pathSetup({ ...setup, platform: "linux" })?.file).toBe("~/.config/fish/config.fish"); // zsh reads .zshrc from ZDOTDIR when it is set. expect( pathSetup({ ...setup, shell: "/bin/zsh", platform: "darwin", zdotdir: "/Users/theo/.zsh" }) ?.file, ).toBe("/Users/theo/.zsh/.zshrc"); // A set folder that cannot be written safely means no setup, never the unread default. expect( pathSetup({ ...setup, shell: "/bin/zsh", platform: "darwin", zdotdir: "/Users/theo/my zsh" }), ).toBeUndefined(); expect( pathSetup({ ...setup, platform: "linux", configHome: "/home/theo/my cfg" }), ).toBeUndefined(); }); });