diff --git a/CHANGELOG.md b/CHANGELOG.md index 45bb95e..4ee3d14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -86,6 +86,10 @@ release path documented in [`TODO.md`](TODO.md). selection and actual RUN/ADDRUN entries in the MSR. ### Bundled ROOT + musrfit runtime +- Windows Fit/Plot preserves the host executable search path, including the + usual mixed-case `Path` key and semicolon separators. This fixes + `spawn wsl.exe ENOENT` after successful runtime setup. Linux runtime paths + are no longer prepended to the Windows host search path. - Linux Preferences now offers **Check tools** and confirmed offline runtime installation from `runtime-download.json`. Installs verify the archive and extracted tools in a private user directory, support cancellation, and retain diff --git a/muSRFitelec.js b/muSRFitelec.js index 0f00191..0103b76 100644 --- a/muSRFitelec.js +++ b/muSRFitelec.js @@ -1368,6 +1368,13 @@ function buildToolEnvironment() { ? libDir + ":" + env.LD_LIBRARY_PATH : libDir; } + if (nodeProcess.platform === "win32") { + // Plain bridge snapshots can contain Path and PATH. Node forwards only + // one case-insensitive match, so emit a single, canonical search path. + for (let key of Object.keys(env)) { + if (key.toUpperCase() === "PATH") delete env[key]; + } + } env.PATH = localCommandPathBias(); let dataSearchPath = localRunDataSearchPath(false); if (dataSearchPath) env.MUSRFULLDATAPATH = dataSearchPath; @@ -1582,6 +1589,21 @@ function resolveLocalCommand(commandName) { // usual PSI/local locations so children of musrfit that resolve their own // helpers follow the preference. function localCommandPathBias() { + let configuredBinDir = typeof getConfiguredBinDir === "function" + ? getConfiguredBinDir() : ""; + if (nodeProcess.platform === "win32") { + // Windows normally calls this variable Path. Preserve its directories + // and use semicolons; Linux prefixes can hide System32 and wsl.exe. + // Bundled Linux tools run inside WSL, not on the Windows host PATH. + let env = nodeProcess.env || {}; + let pathKey = Object.keys(env).sort().find(function(key) { + return key.toUpperCase() === "PATH"; + }); + let dirs = configuredBinDir ? [configuredBinDir] : []; + if (pathKey && env[pathKey]) dirs.push(env[pathKey]); + return dirs.join(";"); + } + let dirs = ["/usr/local/bin", "/usr/bin", "/bin"]; let systemBinDir = systemRuntimeBinDir(); if (systemBinDir !== "") { @@ -1591,8 +1613,6 @@ function localCommandPathBias() { if (bundledBinDir !== "") { dirs.unshift(bundledBinDir); } - let configuredBinDir = typeof getConfiguredBinDir === "function" - ? getConfiguredBinDir() : ""; if (configuredBinDir !== "") { dirs.unshift(configuredBinDir); } diff --git a/tests/electron-bundled-runtime.test.js b/tests/electron-bundled-runtime.test.js index 5b3fa16..5f0d098 100644 --- a/tests/electron-bundled-runtime.test.js +++ b/tests/electron-bundled-runtime.test.js @@ -224,6 +224,40 @@ fs.writeFileSync(path.join(separateRuntimeRoot, "musrfit_startup.xml"), " key.toUpperCase() === 'PATH'), ['PATH']); + assert.deepStrictEqual(sandbox.process.env, originalEnvironment); + assert(!env.PATH.includes('/usr/bin'), 'Linux search paths do not belong in the Windows host PATH'); + assert(!env.PATH.includes(runtimeRoot), 'The Linux runtime markers must not shadow Windows programs'); + + const nativeTools = String.raw`D:\Scientific tools\musrfit\bin`; + sandbox.getConfiguredBinDir = function() { + return nativeTools; + }; + assert.strictEqual(sandbox.buildToolEnvironment().PATH, nativeTools + ';' + windowsPath); + } + + // A plain object can contain both spellings, even though Windows itself + // treats them as one variable. Match Node's precedence and emit one key. + const sandbox = buildSandbox(resourcesPath, { Path: 'ignored', PATH: windowsPath }, 'win32'); + loadLibraries(sandbox); + const env = sandbox.buildToolEnvironment(); + assert.strictEqual(env.PATH, windowsPath); + assert.deepStrictEqual(Object.keys(env).filter(key => key.toUpperCase() === 'PATH'), ['PATH']); +})(); + // On a Linux host the WSL translation is inert even when the bundle is present. (function testWslTranslationInertOnLinux() { const sandbox = buildSandbox(resourcesPath, {}, "linux");