diff --git a/bin/cli/commands/restart.mjs b/bin/cli/commands/restart.mjs index 96a182c845..7dd6375ab4 100644 --- a/bin/cli/commands/restart.mjs +++ b/bin/cli/commands/restart.mjs @@ -6,7 +6,8 @@ export function registerRestart(program) { program .command("restart") .description(t("restart.description")) - .option("--port ", t("serve.port"), "20128") + // No Commander default: runServe() falls back to PORT, then 20128 (#7049). + .option("--port ", t("serve.port")) .action(async (opts) => { const exitCode = await runRestartCommand(opts); if (exitCode !== 0) process.exit(exitCode); diff --git a/changelog.d/fixes/13327-cli-restart-honors-port.md b/changelog.d/fixes/13327-cli-restart-honors-port.md new file mode 100644 index 0000000000..3c3ed0fefc --- /dev/null +++ b/changelog.d/fixes/13327-cli-restart-honors-port.md @@ -0,0 +1 @@ +- **fix(cli):** `omniroute restart` now comes back on the port set by `PORT` (shell or `/.env`) instead of always 20128, like `serve` and `dashboard` ([#13327](https://github.com/diegosouzapw/OmniRoute/pull/13327)) diff --git a/tests/unit/cli-restart-port.test.ts b/tests/unit/cli-restart-port.test.ts new file mode 100644 index 0000000000..9d6ba24b3c --- /dev/null +++ b/tests/unit/cli-restart-port.test.ts @@ -0,0 +1,33 @@ +/** + * `omniroute restart` declared `--port` with a Commander default of "20128", so the + * `opts.port ?? process.env.PORT` fallback in runServe() never reached PORT: a server + * started on PORT=3000 (from the shell or /.env) came back on 20128 after a + * restart. #7049 fixed the same default on `dashboard`. + */ +import test from "node:test"; +import assert from "node:assert/strict"; +import { Command } from "commander"; + +async function parseRestart(args: string[]) { + const { registerRestart } = await import("../../bin/cli/commands/restart.mjs"); + const program = new Command().exitOverride(); + registerRestart(program); + let parsed: Record | undefined; + program.commands + .find((cmd) => cmd.name() === "restart")! + .action((opts: Record) => { + parsed = opts; + }); + await program.parseAsync(["restart", ...args], { from: "user" }); + return parsed; +} + +test("restart without --port leaves the port to runServe's PORT fallback", async () => { + const opts = await parseRestart([]); + assert.equal(opts?.port, undefined); +}); + +test("restart --port still passes the explicit port", async () => { + const opts = await parseRestart(["--port", "3000"]); + assert.equal(opts?.port, "3000"); +});