From 716b0efbc099237fa669e9b09553bd2764310571 Mon Sep 17 00:00:00 2001 From: salman Date: Thu, 19 Nov 2026 13:37:05 +0100 Subject: [PATCH] Resolve portable run paths for Electron metadata --- muSRFitelec.js | 23 +++++++++++++++++++++++ tests/electron-portable-naming.test.js | 4 ++++ 2 files changed, 27 insertions(+) diff --git a/muSRFitelec.js b/muSRFitelec.js index 3e8b154..20a4673 100644 --- a/muSRFitelec.js +++ b/muSRFitelec.js @@ -397,6 +397,29 @@ window.MusRFlowPlatform.resolveDataFile = function(runName) { let resolved = resolveLocalRunData(file.run, file.year, file.instrument); if (resolved && resolved.runName === runName) return resolved.filePath; } + + // Portable RUN directives omit the data-file extension and rely on + // musrfit_startup.xml search paths. dump_header does not perform that same + // lookup, so resolve the token to an existing file before launching it. + // portableRunResolver enforces a relative, traversal-free path beneath the + // configured root; only known muSR data extensions are considered. + let startup = typeof portableRunNamingStartup !== "undefined" + ? portableRunNamingStartup : null; + let roots = startup && Array.isArray(startup.dataPaths) + ? startup.dataPaths : []; + let candidates = [String(runName || "")]; + if (!/\.(?:root|bin|mdu|msr|nxs)$/i.test(candidates[0])) { + candidates = candidates.concat([".root", ".bin", ".mdu", ".msr", ".nxs"].map( + function(extension) { return candidates[0] + extension; } + )); + } + for (let root of roots) { + for (let candidate of candidates) { + if (portableRunResolver(candidate, root)) { + return nodePath.join(root, candidate); + } + } + } return ''; }; diff --git a/tests/electron-portable-naming.test.js b/tests/electron-portable-naming.test.js index 12f9c63..b3a8c1c 100644 --- a/tests/electron-portable-naming.test.js +++ b/tests/electron-portable-naming.test.js @@ -86,6 +86,10 @@ function testPortableEnabledViaConfiguredXml() { lib.runFileNameAuto(514, "2026", "LEM", "/psi.ch/data/"), "RUN d2026/tdc/lem26_his_0514 MUE4 PSI MUSR-ROOT" ); + assert.strictEqual( + lib.window.MusRFlowPlatform.resolveDataFile("d2026/tdc/lem26_his_0514"), + portableFile + ); // The indicator is null-safe in a document without the status element. assert.strictEqual(lib.updateStartupNamingSourceIndicator(), undefined); }