From f781fd038b1c2ab4b7c82a543ff87c0966cc8e64 Mon Sep 17 00:00:00 2001 From: Nguyen Thanh Dat Date: Thu, 17 Sep 2026 07:02:51 +0700 Subject: [PATCH] fix(cli): let restart honor PORT like serve and dashboard (#13327) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Same fix pattern #7049 already applied to `dashboard`: dropping the Commander default `20128` on `restart --port` lets `opts.port` stay undefined so `runServe()`s `opts.port ?? process.env.PORT ?? "20128"` fallback can actually reach `PORT`. 3 files, +36/-1. Thanks, @datrixlab — matching the existing precedent instead of inventing a new mechanism made this trivial to review. **Batch validation** — boarded with the other 10 PRs of your batch into one worktree cut from `release/v3.8.51`; every PR verified as an ancestor of the combined HEAD before validating. - Focused tests across all 11 PRs: **104/104 pass** on the combined tree. - Gates on the combined tree: `check-changelog-integrity` PASS, `check-complexity` PASS, `check-cognitive-complexity` PASS, `typecheck:core` PASS, `check:open-sse-typecheck` PASS. - `check-file-size` is red, but reproduces with byte-identical line counts on the pure `release/v3.8.51` tip (`open-sse/handlers/imageGeneration.ts` 3304, `open-sse/services/combo/roundRobinCombo.ts` 1221, `open-sse/utils/stream.ts` 3115). Inherited base-red, nothing added by this batch — it is also why this PR's "Fast Quality Gates" check was red. --- bin/cli/commands/restart.mjs | 3 +- .../fixes/13327-cli-restart-honors-port.md | 1 + tests/unit/cli-restart-port.test.ts | 33 +++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 changelog.d/fixes/13327-cli-restart-honors-port.md create mode 100644 tests/unit/cli-restart-port.test.ts 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"); +});