|
2 | 2 | import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures"; |
3 | 3 | import { beforeEach, describe, expect, it, vi } from "vitest"; |
4 | 4 | import type { OpenClawConfig } from "../config/config.js"; |
5 | | -import type { RuntimeEnv } from "../runtime.js"; |
| 5 | +import { ExitError, type RuntimeEnv } from "../runtime.js"; |
6 | 6 | import { withEnvAsync } from "../test-utils/env.js"; |
7 | 7 | import { |
8 | 8 | createWizardTestRuntime, |
@@ -166,7 +166,7 @@ vi.mock("./onboard-helpers.js", () => ({ |
166 | 166 | })); |
167 | 167 |
|
168 | 168 | vi.mock("./health.js", () => ({ |
169 | | - healthCommand: mocks.healthCommand, |
| 169 | + healthCommandNonExiting: mocks.healthCommand, |
170 | 170 | })); |
171 | 171 |
|
172 | 172 | vi.mock("./health-format.js", () => ({ |
@@ -225,6 +225,7 @@ vi.mock("../config/mutate.js", async () => { |
225 | 225 | import { WizardCancelledError } from "../wizard/prompts.js"; |
226 | 226 | import { maybeInstallDaemon } from "./configure.daemon.js"; |
227 | 227 | import { runConfigureWizard } from "./configure.wizard.js"; |
| 228 | +import { formatHealthCheckFailure } from "./health-format.js"; |
228 | 229 |
|
229 | 230 | const createRuntime = createWizardTestRuntime; |
230 | 231 |
|
@@ -411,15 +412,23 @@ describe("runConfigureWizard", () => { |
411 | 412 | ); |
412 | 413 | }); |
413 | 414 |
|
414 | | - it.each([false, true])("reports failed remote health checks (reachable: %s)", async (probeOk) => { |
| 415 | + it.each([ |
| 416 | + ["unreachable gateway", false, new Error("health request failed")], |
| 417 | + ["health request failure", true, new Error("health request failed")], |
| 418 | + ["trapped health CLI exit", true, new ExitError(1)], |
| 419 | + ])("reports failed remote health checks (%s)", async (_reason, probeOk, error) => { |
415 | 420 | setupBaseWizardState(); |
416 | 421 | queueWizardPrompts({ select: ["remote"], confirm: [] }); |
417 | 422 | mocks.waitForGatewayReachable.mockResolvedValueOnce({ ok: probeOk }); |
418 | | - mocks.healthCommand.mockRejectedValueOnce(new Error("health request failed")); |
| 423 | + mocks.healthCommand.mockRejectedValueOnce(error); |
419 | 424 |
|
420 | 425 | await runConfigureWizard({ command: "configure", sections: ["health"] }, createRuntime()); |
421 | 426 |
|
422 | 427 | expect(mocks.clackOutro).toHaveBeenCalledWith(expect.stringContaining("health check failed")); |
| 428 | + if (error instanceof ExitError) { |
| 429 | + // healthCommand already printed its diagnostic before the trapped exit. |
| 430 | + expect(formatHealthCheckFailure).not.toHaveBeenCalled(); |
| 431 | + } |
423 | 432 | }); |
424 | 433 |
|
425 | 434 | it("skips remote health when a configured SecretRef is unresolved", async () => { |
|
0 commit comments