From e765daaed3048df3fa341c1abb0c1c2e22e75b1e Mon Sep 17 00:00:00 2001 From: Shakker Date: Fri, 27 Mar 2026 09:22:45 +0000 Subject: [PATCH] fix: show resolved gateway port in setup wizard --- src/wizard/setup.test.ts | 51 +++++++++++++++++++++++++++++++++++++++- src/wizard/setup.ts | 9 ++----- 2 files changed, 52 insertions(+), 8 deletions(-) diff --git a/src/wizard/setup.test.ts b/src/wizard/setup.test.ts index 73dda5a03e1..8c007821f0b 100644 --- a/src/wizard/setup.test.ts +++ b/src/wizard/setup.test.ts @@ -80,6 +80,13 @@ const setupSkills = vi.hoisted(() => vi.fn(async (cfg) => cfg)); const healthCommand = vi.hoisted(() => vi.fn(async () => {})); const ensureWorkspaceAndSessions = vi.hoisted(() => vi.fn(async () => {})); const writeConfigFile = vi.hoisted(() => vi.fn(async () => {})); +const resolveGatewayPort = vi.hoisted(() => + vi.fn((_cfg?: unknown, env?: NodeJS.ProcessEnv) => { + const raw = env?.OPENCLAW_GATEWAY_PORT ?? process.env.OPENCLAW_GATEWAY_PORT; + const port = raw ? Number.parseInt(String(raw), 10) : Number.NaN; + return Number.isFinite(port) && port > 0 ? port : 18789; + }), +); const readConfigFileSnapshot = vi.hoisted(() => vi.fn(async () => ({ path: "/tmp/.openclaw/openclaw.json", @@ -157,7 +164,7 @@ vi.mock("../commands/onboard-hooks.js", () => ({ vi.mock("../config/config.js", () => ({ DEFAULT_GATEWAY_PORT: 18789, - resolveGatewayPort: () => 18789, + resolveGatewayPort, readConfigFileSnapshot, writeConfigFile, })); @@ -643,4 +650,46 @@ describe("runSetupWizard", () => { }), ); }); + + it("shows the resolved gateway port in quickstart for fresh envs", async () => { + const previousPort = process.env.OPENCLAW_GATEWAY_PORT; + process.env.OPENCLAW_GATEWAY_PORT = "18791"; + const note: WizardPrompter["note"] = vi.fn(async () => {}); + const prompter = buildWizardPrompter({ note }); + const runtime = createRuntime(); + + try { + await runSetupWizard( + { + acceptRisk: true, + flow: "quickstart", + authChoice: "skip", + installDaemon: false, + skipProviders: true, + skipSkills: true, + skipSearch: true, + skipHealth: true, + skipUi: true, + }, + runtime, + prompter, + ); + } finally { + if (previousPort === undefined) { + delete process.env.OPENCLAW_GATEWAY_PORT; + } else { + process.env.OPENCLAW_GATEWAY_PORT = previousPort; + } + } + + const calls = (note as unknown as { mock: { calls: unknown[][] } }).mock.calls; + expect( + calls.some( + (call) => + call?.[1] === "QuickStart" && + typeof call?.[0] === "string" && + call[0].includes("Gateway port: 18791"), + ), + ).toBe(true); + }); }); diff --git a/src/wizard/setup.ts b/src/wizard/setup.ts index 577b664fdb3..a5336d26c10 100644 --- a/src/wizard/setup.ts +++ b/src/wizard/setup.ts @@ -6,12 +6,7 @@ import type { ResetScope, } from "../commands/onboard-types.js"; import type { OpenClawConfig } from "../config/config.js"; -import { - DEFAULT_GATEWAY_PORT, - readConfigFileSnapshot, - resolveGatewayPort, - writeConfigFile, -} from "../config/config.js"; +import { readConfigFileSnapshot, resolveGatewayPort, writeConfigFile } from "../config/config.js"; import { normalizeSecretInputString } from "../config/types.secrets.js"; import { buildPluginCompatibilityNotices, @@ -346,7 +341,7 @@ export async function runSetupWizard( "Direct to chat channels.", ] : [ - `Gateway port: ${DEFAULT_GATEWAY_PORT}`, + `Gateway port: ${quickstartGateway.port}`, "Gateway bind: Loopback (127.0.0.1)", "Gateway auth: Token (default)", "Tailscale exposure: Off",