fix: show resolved gateway port in setup wizard

This commit is contained in:
Shakker
2026-03-27 09:22:45 +00:00
committed by Shakker
parent 4b9542716c
commit e765daaed3
2 changed files with 52 additions and 8 deletions

View File

@@ -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);
});
});

View File

@@ -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",