fix: clarify windows onboarding gateway health

This commit is contained in:
Peter Steinberger
2026-03-13 02:40:25 +00:00
parent 23c7fc745f
commit b858d6c3a9
5 changed files with 100 additions and 2 deletions

View File

@@ -1,6 +1,6 @@
import fs from "node:fs/promises";
import path from "node:path";
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
import { afterAll, afterEach, beforeAll, describe, expect, it, vi } from "vitest";
import { makeTempWorkspace } from "../test-helpers/workspace.js";
import { captureEnv } from "../test-utils/env.js";
import { createThrowingRuntime, readJsonFile } from "./onboard-non-interactive.test-helpers.js";
@@ -13,6 +13,12 @@ const gatewayClientCalls: Array<{
onClose?: (code: number, reason: string) => void;
}> = [];
const ensureWorkspaceAndSessionsMock = vi.fn(async (..._args: unknown[]) => {});
let waitForGatewayReachableMock:
| ((params: { url: string; token?: string; password?: string }) => Promise<{
ok: boolean;
detail?: string;
}>)
| undefined;
vi.mock("../gateway/client.js", () => ({
GatewayClient: class {
@@ -46,6 +52,10 @@ vi.mock("./onboard-helpers.js", async (importOriginal) => {
return {
...actual,
ensureWorkspaceAndSessions: ensureWorkspaceAndSessionsMock,
waitForGatewayReachable: (...args: Parameters<typeof actual.waitForGatewayReachable>) =>
waitForGatewayReachableMock
? waitForGatewayReachableMock(args[0])
: actual.waitForGatewayReachable(...args),
};
});
@@ -116,6 +126,10 @@ describe("onboard (non-interactive): gateway and remote auth", () => {
envSnapshot.restore();
});
afterEach(() => {
waitForGatewayReachableMock = undefined;
});
it("writes gateway token auth into config", async () => {
await withStateDir("state-noninteractive-", async (stateDir) => {
const token = "tok_test_123";
@@ -302,6 +316,33 @@ describe("onboard (non-interactive): gateway and remote auth", () => {
});
}, 60_000);
it("explains local health failure when no daemon was requested", async () => {
await withStateDir("state-local-health-hint-", async (stateDir) => {
waitForGatewayReachableMock = vi.fn(async () => ({
ok: false,
detail: "socket closed: 1006 abnormal closure",
}));
await expect(
runNonInteractiveOnboarding(
{
nonInteractive: true,
mode: "local",
workspace: path.join(stateDir, "openclaw"),
authChoice: "skip",
skipSkills: true,
skipHealth: false,
installDaemon: false,
gatewayBind: "loopback",
},
runtime,
),
).rejects.toThrow(
/only waits for an already-running gateway unless you pass --install-daemon[\s\S]*--skip-health/,
);
});
}, 60_000);
it("auto-generates token auth when binding LAN and persists the token", async () => {
if (process.platform === "win32") {
// Windows runner occasionally drops the temp config write in this flow; skip to keep CI green.

View File

@@ -104,11 +104,33 @@ export async function runNonInteractiveOnboardingLocal(params: {
customBindHost: nextConfig.gateway?.customBindHost,
basePath: undefined,
});
await waitForGatewayReachable({
const probe = await waitForGatewayReachable({
url: links.wsUrl,
token: gatewayResult.gatewayToken,
deadlineMs: 15_000,
});
if (!probe.ok) {
const message = [
`Gateway did not become reachable at ${links.wsUrl}.`,
probe.detail ? `Last probe: ${probe.detail}` : undefined,
!opts.installDaemon
? [
"Non-interactive local onboarding only waits for an already-running gateway unless you pass --install-daemon.",
`Fix: start \`${formatCliCommand("openclaw gateway run")}\`, re-run with \`--install-daemon\`, or use \`--skip-health\`.`,
process.platform === "win32"
? "Native Windows managed gateway install currently uses Scheduled Tasks and may require running PowerShell as Administrator."
: undefined,
]
.filter(Boolean)
.join("\n")
: undefined,
]
.filter(Boolean)
.join("\n");
runtime.error(message);
runtime.exit(1);
return;
}
await healthCommand({ json: false, timeoutMs: 10_000 }, runtime);
}