diff --git a/bin/cli/tray/autostart.mjs b/bin/cli/tray/autostart.mjs index f554f4554c..d078d0076b 100644 --- a/bin/cli/tray/autostart.mjs +++ b/bin/cli/tray/autostart.mjs @@ -13,11 +13,13 @@ const LINUX_DESKTOP_NAME = "omniroute.desktop"; function resolveCliPath() { const candidates = []; if (process.argv[1]) candidates.push(process.argv[1]); - try { - const which = execSync("command -v omniroute 2>/dev/null", { encoding: "utf8" }).trim(); - if (which) candidates.push(which); - } catch { - // command -v unavailable + if (process.platform !== "win32") { + try { + const which = execSync("command -v omniroute 2>/dev/null", { encoding: "utf8" }).trim(); + if (which) candidates.push(which); + } catch { + // command -v unavailable + } } candidates.push(join(dirname(fileURLToPath(import.meta.url)), "..", "..", "omniroute.mjs")); diff --git a/changelog.d/fixes/12993-windows-autostart-posix-lookup.md b/changelog.d/fixes/12993-windows-autostart-posix-lookup.md new file mode 100644 index 0000000000..c5c3887160 --- /dev/null +++ b/changelog.d/fixes/12993-windows-autostart-posix-lookup.md @@ -0,0 +1 @@ +- **fix(cli):** skip the POSIX CLI path lookup during Windows autostart setup, preventing a bogus path error before successful enablement ([#12993](https://github.com/diegosouzapw/OmniRoute/pull/12993)) diff --git a/tests/unit/cli/autostart-windows.test.ts b/tests/unit/cli/autostart-windows.test.ts index 439d00ebcb..2cb3ef1962 100644 --- a/tests/unit/cli/autostart-windows.test.ts +++ b/tests/unit/cli/autostart-windows.test.ts @@ -69,6 +69,23 @@ test("Windows enable/disable writes and removes VBS in Startup folder", async () // autostart-macos-launchctl.test.ts. // --------------------------------------------------------------------------- +test("Windows path resolution skips the POSIX command lookup", () => { + const source = readFileSync(join(process.cwd(), "bin/cli/tray/autostart.mjs"), "utf8"); + const resolveCliPath = source.match(/function resolveCliPath\(\) \{([\s\S]*?)\n\}/); + + assert.ok(resolveCliPath, "resolveCliPath should exist"); + const nonWindowsGuard = resolveCliPath[1].match( + /if \(process\.platform !== "win32"\) \{([\s\S]*?)\n \}/ + ); + assert.ok(nonWindowsGuard, "resolveCliPath should have a non-Windows guard"); + assert.match(nonWindowsGuard[1], /command -v omniroute/); + assert.doesNotMatch( + resolveCliPath[1].replace(nonWindowsGuard[0], ""), + /command -v omniroute/, + "the POSIX PATH probe must only appear inside the non-Windows guard" + ); +}); + test("Windows enableWin writes VBS to Startup folder, not reg add", () => { const source = readFileSync(join(process.cwd(), "bin/cli/tray/autostart.mjs"), "utf8");