|
1 | 1 | import { beforeEach, describe, expect, it, vi } from "vitest"; |
| 2 | +import { formatCliCommand } from "../command-format.js"; |
2 | 3 | import { ensureConfigReady, __test__ } from "./config-guard.js"; |
3 | 4 | |
4 | 5 | const loadAndMaybeMigrateDoctorConfigMock = vi.hoisted(() => vi.fn()); |
@@ -31,6 +32,10 @@ function makeRuntime() {
|
31 | 32 | }; |
32 | 33 | } |
33 | 34 | |
| 35 | +function plainErrorCalls(runtime: ReturnType<typeof makeRuntime>): string[] { |
| 36 | +return runtime.error.mock.calls.map((call) => String(call[0]).replace(/\u001b\[[0-9;]*m/g, "")); |
| 37 | +} |
| 38 | + |
34 | 39 | async function withCapturedStdout(run: () => Promise<void>): Promise<string> { |
35 | 40 | const writes: string[] = []; |
36 | 41 | const writeSpy = vi.spyOn(process.stdout, "write").mockImplementation(((chunk: unknown) => { |
@@ -128,9 +133,16 @@ describe("ensureConfigReady", () => {
|
128 | 133 | setInvalidSnapshot(); |
129 | 134 | const runtime = await runEnsureConfigReady(["message"]); |
130 | 135 | |
131 | | -expect(runtime.error).toHaveBeenCalledWith(expect.stringContaining("config is invalid")); |
132 | | -expect(runtime.error).toHaveBeenCalledWith(expect.stringContaining("doctor --fix")); |
133 | | -expect(runtime.error).toHaveBeenCalledWith(expect.stringContaining("config validate")); |
| 136 | +expect(plainErrorCalls(runtime)).toEqual([ |
| 137 | +"OpenClaw config is invalid", |
| 138 | +"File: /tmp/openclaw.json", |
| 139 | +"Problem:", |
| 140 | +" - channels.quietchat: invalid", |
| 141 | +"", |
| 142 | +`Fix: ${formatCliCommand("openclaw doctor --fix")}`, |
| 143 | +`Inspect: ${formatCliCommand("openclaw config validate")}`, |
| 144 | +"Status, health, logs, and doctor commands still run with invalid config.", |
| 145 | +]); |
134 | 146 | expect(runtime.exit).toHaveBeenCalledWith(1); |
135 | 147 | }); |
136 | 148 | |
|