mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-31 20:32:20 +03:00
* fix(cli): use rundll32 instead of cmd.exe for Windows browser fallback in dashboard command Extract resolveOpenCommand(platform, url) as an exported pure function so tests import the actual production code instead of duplicating logic. The openFallback function in bin/cli/commands/dashboard.mjs used cmd /c start to open the dashboard URL on Windows, spawning an unnecessary cmd.exe process. Replaces with rundll32 url.dll,FileProtocolHandler which opens the URL directly through the Windows shell handler API without any shell wrapper. Tests: 5 tests importing the actual resolveOpenCommand function, covering all platform branches (darwin, win32, linux) and URL pass-through. Changelog fragment included. * chore: rename changelog fragment 7842->7844 to match actual PR number --------- Co-authored-by: tientien17 <tientien17@users.noreply.github.com>
36 lines
1.4 KiB
TypeScript
36 lines
1.4 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { resolveOpenCommand } from "../../bin/cli/commands/dashboard.mjs";
|
|
|
|
test("openFallback: darwin uses 'open' command", () => {
|
|
const { cmd, args } = resolveOpenCommand("darwin", "http://localhost:20128");
|
|
assert.equal(cmd, "open");
|
|
assert.deepEqual(args, ["http://localhost:20128"]);
|
|
});
|
|
|
|
test("openFallback: win32 uses 'rundll32 url.dll,FileProtocolHandler' instead of cmd.exe", () => {
|
|
const { cmd, args } = resolveOpenCommand("win32", "http://localhost:20128");
|
|
assert.equal(cmd, "rundll32");
|
|
assert.deepEqual(args, ["url.dll,FileProtocolHandler", "http://localhost:20128"]);
|
|
assert.notEqual(cmd, "cmd");
|
|
});
|
|
|
|
test("openFallback: linux/other uses 'xdg-open' command", () => {
|
|
const { cmd, args } = resolveOpenCommand("linux", "http://localhost:20128");
|
|
assert.equal(cmd, "xdg-open");
|
|
assert.deepEqual(args, ["http://localhost:20128"]);
|
|
});
|
|
|
|
test("openFallback: unknown platform falls back to xdg-open", () => {
|
|
const { cmd, args } = resolveOpenCommand("aix", "http://localhost:20128");
|
|
assert.equal(cmd, "xdg-open");
|
|
assert.deepEqual(args, ["http://localhost:20128"]);
|
|
});
|
|
|
|
test("openFallback: URL with special characters is passed through verbatim", () => {
|
|
const url = "http://localhost:20128/dashboard?q=test&filter=a+b";
|
|
const { cmd, args } = resolveOpenCommand("win32", url);
|
|
assert.equal(cmd, "rundll32");
|
|
assert.equal(args[1], url);
|
|
});
|