mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-24 04:49:48 +00:00
test: check config guard error output
This commit is contained in:
@@ -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<typeof makeRuntime>): string[] {
|
||||
return runtime.error.mock.calls.map((call) => String(call[0]).replace(/\u001b\[[0-9;]*m/g, ""));
|
||||
}
|
||||
|
||||
async function withCapturedStdout(run: () => Promise<void>): Promise<string> {
|
||||
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);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user