mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-03 03:03:24 -04:00
fix: local updates for PR #4873
Co-authored-by: Hisleren <Hisleren@users.noreply.github.com>
This commit is contained in:
committed by
Gustavo Madeira Santana
parent
201d7fa956
commit
e5a95b5b66
69
src/wizard/onboarding.gateway-config.test.ts
Normal file
69
src/wizard/onboarding.gateway-config.test.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import type { RuntimeEnv } from "../runtime.js";
|
||||
import type { WizardPrompter } from "./prompts.js";
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
randomToken: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("../commands/onboard-helpers.js", async (importActual) => {
|
||||
const actual = await importActual<typeof import("../commands/onboard-helpers.js")>();
|
||||
return {
|
||||
...actual,
|
||||
randomToken: mocks.randomToken,
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("../infra/tailscale.js", () => ({
|
||||
findTailscaleBinary: vi.fn(async () => undefined),
|
||||
}));
|
||||
|
||||
import { configureGatewayForOnboarding } from "./onboarding.gateway-config.js";
|
||||
|
||||
describe("configureGatewayForOnboarding", () => {
|
||||
it("generates a token when the prompt returns undefined", async () => {
|
||||
mocks.randomToken.mockReturnValue("generated-token");
|
||||
|
||||
const selectQueue = ["loopback", "token", "off"];
|
||||
const textQueue = ["18789", undefined];
|
||||
const prompter: WizardPrompter = {
|
||||
intro: vi.fn(async () => {}),
|
||||
outro: vi.fn(async () => {}),
|
||||
note: vi.fn(async () => {}),
|
||||
select: vi.fn(async () => selectQueue.shift() as string),
|
||||
multiselect: vi.fn(async () => []),
|
||||
text: vi.fn(async () => textQueue.shift() as string),
|
||||
confirm: vi.fn(async () => false),
|
||||
progress: vi.fn(() => ({ update: vi.fn(), stop: vi.fn() })),
|
||||
};
|
||||
|
||||
const runtime: RuntimeEnv = {
|
||||
log: vi.fn(),
|
||||
error: vi.fn(),
|
||||
exit: vi.fn(),
|
||||
};
|
||||
|
||||
const result = await configureGatewayForOnboarding({
|
||||
flow: "advanced",
|
||||
baseConfig: {},
|
||||
nextConfig: {},
|
||||
localPort: 18789,
|
||||
quickstartGateway: {
|
||||
hasExisting: false,
|
||||
port: 18789,
|
||||
bind: "loopback",
|
||||
authMode: "token",
|
||||
tailscaleMode: "off",
|
||||
token: undefined,
|
||||
password: undefined,
|
||||
customBindHost: undefined,
|
||||
tailscaleResetOnExit: false,
|
||||
},
|
||||
prompter,
|
||||
runtime,
|
||||
});
|
||||
|
||||
expect(result.settings.gatewayToken).toBe("generated-token");
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
import { randomToken } from "../commands/onboard-helpers.js";
|
||||
import { normalizeGatewayTokenInput, randomToken } from "../commands/onboard-helpers.js";
|
||||
import type { GatewayAuthChoice } from "../commands/onboard-types.js";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { findTailscaleBinary } from "../infra/tailscale.js";
|
||||
@@ -182,9 +182,7 @@ export async function configureGatewayForOnboarding(
|
||||
placeholder: "Needed for multi-machine or non-loopback access",
|
||||
initialValue: quickstartGateway.token ?? "",
|
||||
});
|
||||
// FIX: Ensure undefined becomes an empty string, not "undefined" string
|
||||
const rawInput = tokenInput ? String(tokenInput).trim() : "";
|
||||
gatewayToken = rawInput || randomToken();
|
||||
gatewayToken = normalizeGatewayTokenInput(tokenInput) || randomToken();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user