From 17c75df67082d340fb7a555d43ee3720589db94a Mon Sep 17 00:00:00 2001 From: Shakker Date: Mon, 11 May 2026 15:16:48 +0100 Subject: [PATCH] test: check config guard error output --- src/cli/program/config-guard.test.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/cli/program/config-guard.test.ts b/src/cli/program/config-guard.test.ts index 99f31de3d81..9c01089947f 100644 --- a/src/cli/program/config-guard.test.ts +++ b/src/cli/program/config-guard.test.ts @@ -1,4 +1,5 @@ import { beforeEach, describe, expect, it, vi } from "vitest"; +import { formatCliCommand } from "../command-format.js"; import { ensureConfigReady, __test__ } from "./config-guard.js"; const loadAndMaybeMigrateDoctorConfigMock = vi.hoisted(() => vi.fn()); @@ -31,6 +32,10 @@ function makeRuntime() { }; } +function plainErrorCalls(runtime: ReturnType): string[] { + return runtime.error.mock.calls.map((call) => String(call[0]).replace(/\u001b\[[0-9;]*m/g, "")); +} + async function withCapturedStdout(run: () => Promise): Promise { const writes: string[] = []; const writeSpy = vi.spyOn(process.stdout, "write").mockImplementation(((chunk: unknown) => { @@ -128,9 +133,16 @@ describe("ensureConfigReady", () => { setInvalidSnapshot(); const runtime = await runEnsureConfigReady(["message"]); - expect(runtime.error).toHaveBeenCalledWith(expect.stringContaining("config is invalid")); - expect(runtime.error).toHaveBeenCalledWith(expect.stringContaining("doctor --fix")); - expect(runtime.error).toHaveBeenCalledWith(expect.stringContaining("config validate")); + expect(plainErrorCalls(runtime)).toEqual([ + "OpenClaw config is invalid", + "File: /tmp/openclaw.json", + "Problem:", + " - channels.quietchat: invalid", + "", + `Fix: ${formatCliCommand("openclaw doctor --fix")}`, + `Inspect: ${formatCliCommand("openclaw config validate")}`, + "Status, health, logs, and doctor commands still run with invalid config.", + ]); expect(runtime.exit).toHaveBeenCalledWith(1); });