mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 06:11:24 +00:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -68,17 +68,22 @@ export async function configureGatewayForOnboarding(
|
||||
placeholder: "192.168.1.100",
|
||||
initialValue: customBindHost ?? "",
|
||||
validate: (value) => {
|
||||
if (!value) return "IP address is required for custom bind mode";
|
||||
if (!value) {
|
||||
return "IP address is required for custom bind mode";
|
||||
}
|
||||
const trimmed = value.trim();
|
||||
const parts = trimmed.split(".");
|
||||
if (parts.length !== 4) return "Invalid IPv4 address (e.g., 192.168.1.100)";
|
||||
if (parts.length !== 4) {
|
||||
return "Invalid IPv4 address (e.g., 192.168.1.100)";
|
||||
}
|
||||
if (
|
||||
parts.every((part) => {
|
||||
const n = parseInt(part, 10);
|
||||
return !Number.isNaN(n) && n >= 0 && n <= 255 && part === String(n);
|
||||
})
|
||||
)
|
||||
) {
|
||||
return undefined;
|
||||
}
|
||||
return "Invalid IPv4 address (each octet must be 0-255)";
|
||||
},
|
||||
});
|
||||
|
||||
@@ -178,7 +178,9 @@ describe("runOnboardingWizard", () => {
|
||||
await fs.writeFile(path.join(workspaceDir, DEFAULT_BOOTSTRAP_FILENAME), "{}");
|
||||
|
||||
const select: WizardPrompter["select"] = vi.fn(async (opts) => {
|
||||
if (opts.message === "How do you want to hatch your bot?") return "tui";
|
||||
if (opts.message === "How do you want to hatch your bot?") {
|
||||
return "tui";
|
||||
}
|
||||
return "quickstart";
|
||||
});
|
||||
|
||||
@@ -233,7 +235,9 @@ describe("runOnboardingWizard", () => {
|
||||
const workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-onboard-"));
|
||||
|
||||
const select: WizardPrompter["select"] = vi.fn(async (opts) => {
|
||||
if (opts.message === "How do you want to hatch your bot?") return "tui";
|
||||
if (opts.message === "How do you want to hatch your bot?") {
|
||||
return "tui";
|
||||
}
|
||||
return "quickstart";
|
||||
});
|
||||
|
||||
|
||||
@@ -48,7 +48,9 @@ async function requireRiskAcknowledgement(params: {
|
||||
opts: OnboardOptions;
|
||||
prompter: WizardPrompter;
|
||||
}) {
|
||||
if (params.opts.acceptRisk === true) return;
|
||||
if (params.opts.acceptRisk === true) {
|
||||
return;
|
||||
}
|
||||
|
||||
await params.prompter.note(
|
||||
[
|
||||
@@ -238,19 +240,33 @@ export async function runOnboardingWizard(
|
||||
|
||||
if (flow === "quickstart") {
|
||||
const formatBind = (value: "loopback" | "lan" | "auto" | "custom" | "tailnet") => {
|
||||
if (value === "loopback") return "Loopback (127.0.0.1)";
|
||||
if (value === "lan") return "LAN";
|
||||
if (value === "custom") return "Custom IP";
|
||||
if (value === "tailnet") return "Tailnet (Tailscale IP)";
|
||||
if (value === "loopback") {
|
||||
return "Loopback (127.0.0.1)";
|
||||
}
|
||||
if (value === "lan") {
|
||||
return "LAN";
|
||||
}
|
||||
if (value === "custom") {
|
||||
return "Custom IP";
|
||||
}
|
||||
if (value === "tailnet") {
|
||||
return "Tailnet (Tailscale IP)";
|
||||
}
|
||||
return "Auto";
|
||||
};
|
||||
const formatAuth = (value: GatewayAuthChoice) => {
|
||||
if (value === "token") return "Token (default)";
|
||||
if (value === "token") {
|
||||
return "Token (default)";
|
||||
}
|
||||
return "Password";
|
||||
};
|
||||
const formatTailscale = (value: "off" | "serve" | "funnel") => {
|
||||
if (value === "off") return "Off";
|
||||
if (value === "serve") return "Serve";
|
||||
if (value === "off") {
|
||||
return "Off";
|
||||
}
|
||||
if (value === "serve") {
|
||||
return "Serve";
|
||||
}
|
||||
return "Funnel";
|
||||
};
|
||||
const quickstartLines = quickstartGateway.hasExisting
|
||||
|
||||
@@ -21,20 +21,26 @@ describe("WizardSession", () => {
|
||||
const secondPeek = await session.next();
|
||||
expect(secondPeek.step?.id).toBe(first.step?.id);
|
||||
|
||||
if (!first.step) throw new Error("expected first step");
|
||||
if (!first.step) {
|
||||
throw new Error("expected first step");
|
||||
}
|
||||
await session.answer(first.step.id, null);
|
||||
|
||||
const second = await session.next();
|
||||
expect(second.done).toBe(false);
|
||||
expect(second.step?.type).toBe("text");
|
||||
|
||||
if (!second.step) throw new Error("expected second step");
|
||||
if (!second.step) {
|
||||
throw new Error("expected second step");
|
||||
}
|
||||
await session.answer(second.step.id, "Peter");
|
||||
|
||||
const third = await session.next();
|
||||
expect(third.step?.type).toBe("note");
|
||||
|
||||
if (!third.step) throw new Error("expected third step");
|
||||
if (!third.step) {
|
||||
throw new Error("expected third step");
|
||||
}
|
||||
await session.answer(third.step.id, null);
|
||||
|
||||
const done = await session.next();
|
||||
@@ -46,7 +52,9 @@ describe("WizardSession", () => {
|
||||
const session = noteRunner();
|
||||
const first = await session.next();
|
||||
await expect(session.answer("bad-id", null)).rejects.toThrow(/wizard: no pending step/i);
|
||||
if (!first.step) throw new Error("expected first step");
|
||||
if (!first.step) {
|
||||
throw new Error("expected first step");
|
||||
}
|
||||
await session.answer(first.step.id, null);
|
||||
});
|
||||
|
||||
|
||||
@@ -201,7 +201,9 @@ export class WizardSession {
|
||||
}
|
||||
|
||||
cancel() {
|
||||
if (this.status !== "running") return;
|
||||
if (this.status !== "running") {
|
||||
return;
|
||||
}
|
||||
this.status = "cancelled";
|
||||
this.error = "cancelled";
|
||||
this.currentStep = null;
|
||||
@@ -245,7 +247,9 @@ export class WizardSession {
|
||||
}
|
||||
|
||||
private resolveStep(step: WizardStep | null) {
|
||||
if (!this.stepDeferred) return;
|
||||
if (!this.stepDeferred) {
|
||||
return;
|
||||
}
|
||||
const deferred = this.stepDeferred;
|
||||
this.stepDeferred = null;
|
||||
deferred.resolve(step);
|
||||
|
||||
Reference in New Issue
Block a user