Make command resolution tests independent of host musrfit

Simulate configured and standard tool locations through the bridge filesystem mock. Verify directory precedence and PATH fallback without relying on /usr/local/bin/musrfit, which caused the first PSI runner validation to fail.
This commit is contained in:
salman committed 2026-10-29 14:51:54 +01:00
1 parent a14f7aee42
commit c97faa7259
1 file changed
+26 -13
+26 -13
View File
@@ -347,14 +347,21 @@ function testBinFolderBrowsePayloadTolerance() {
// PSI/local dirs so tools musrfit launches itself also follow the preference.
function testConfiguredBinDirDrivesCommandResolution() {
const bridge = makeBridge();
const { lib, localStorage } = load(bridge);
const tools = path.join(workDir, "musrfit-tools");
fs.mkdirSync(tools, { recursive: true });
fs.writeFileSync(path.join(tools, "musrfit"), "#!/bin/sh\n");
fs.writeFileSync(path.join(tools, "msr2data"), "#!/bin/sh\n");
fs.writeFileSync(path.join(tools, "dump_header"), "#!/bin/sh\n");
// Configuring this folder must make its binaries win even when the same
// tool exists in a built-in location such as /usr/local/bin.
// Define every visible tool explicitly. Auto-detection must not depend on
// musrfit or a separate runtime being installed on the developer/CI host.
const availableFiles = new Set([
path.join(tools, "musrfit"),
path.join(tools, "msr2data"),
path.join(tools, "dump_header"),
"/usr/local/bin/musrfit",
"/usr/bin/musrfit",
"/usr/bin/musrview"
]);
bridge.fs.existsSync = function(filename) {
return availableFiles.has(filename);
};
const { lib, localStorage } = load(bridge);
localStorage.setItem("musrflow.binDir", tools);
assert.strictEqual(
@@ -366,16 +373,22 @@ function testConfiguredBinDirDrivesCommandResolution() {
assert.strictEqual(
lib.resolveLocalCommand("dump_header"),
path.join(tools, "dump_header"));
// musrview is absent from the configured folder, so it falls back to the
// built-in locations rather than resolving to the configured dir.
assert.notStrictEqual(lib.resolveLocalCommand("musrview"), path.join(tools, "musrview"));
// A tool absent from the configured folder still uses host auto-detection.
assert.strictEqual(lib.resolveLocalCommand("musrview"), "/usr/bin/musrview");
assert.strictEqual(
lib.localCommandPathBias().indexOf(tools + ":/usr/local/bin") === 0, true);
// Clearing the preference restores auto-detection.
// Clearing the preference restores the ordered host search, followed by
// a bare command for PATH lookup when no candidate file is found.
localStorage.removeItem("musrflow.binDir");
assert.strictEqual(lib.resolveLocalCommand("musrfit"),
path.join("/usr/local/bin", "musrfit"));
assert.strictEqual(lib.resolveLocalCommand("musrfit"), "/usr/local/bin/musrfit");
availableFiles.delete("/usr/local/bin/musrfit");
assert.strictEqual(lib.resolveLocalCommand("musrfit"), "/usr/bin/musrfit");
availableFiles.delete("/usr/bin/musrfit");
assert.strictEqual(lib.resolveLocalCommand("musrfit"), "musrfit");
localStorage.setItem("musrflow.binDir", tools);
assert.strictEqual(lib.resolveLocalCommand("musrfit"), path.join(tools, "musrfit"));
}
// The binDir preference round-trips through set/get/initialize and the