Files
openclaw/src/cli/failure-output.test.ts
2026-06-04 19:37:38 -04:00

39 lines
1.2 KiB
TypeScript

// Failure output tests cover CLI error formatting and failure summaries.
import { describe, expect, it } from "vitest";
import { formatCliFailureLines } from "./failure-output.js";
describe("formatCliFailureLines", () => {
it("shows a concise reason and recovery commands by default", () => {
const lines = formatCliFailureLines({
title: "Could not start the CLI.",
error: new Error("config file is invalid"),
argv: ["node", "openclaw", "status"],
env: {},
});
expect(lines).toEqual([
"[openclaw] Could not start the CLI.",
"[openclaw] Reason: config file is invalid",
"[openclaw] Debug: set OPENCLAW_DEBUG=1 to include the stack trace.",
"[openclaw] Try: openclaw doctor",
"[openclaw] Help: openclaw --help",
]);
});
it("prints stack details when debug output is requested", () => {
const lines = formatCliFailureLines({
title: "The CLI command failed.",
error: new Error("boom"),
env: { OPENCLAW_DEBUG: "1" },
});
expect(lines.slice(0, 4)).toEqual([
"[openclaw] The CLI command failed.",
"[openclaw] Reason: boom",
"[openclaw] Stack:",
"[openclaw] Error: boom",
]);
expect(lines.join("\n")).toContain("Error: boom");
});
});