Files
openclaw/src/commands/health-format.test.ts
max ec910a235e refactor: consolidate duplicate utility functions (#12439)
* refactor: consolidate duplicate utility functions

- Add escapeRegExp to src/utils.ts and remove 10 local duplicates
- Rename bash-tools clampNumber to clampWithDefault (different signature)
- Centralize formatError calls to use formatErrorMessage from infra/errors.ts
- Re-export formatErrorMessage from cli/cli-utils.ts to preserve API

* refactor: consolidate remaining escapeRegExp duplicates

* refactor: consolidate sleep, stripAnsi, and clamp duplicates
2026-02-08 23:59:43 -08:00

35 lines
1.2 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { stripAnsi } from "../terminal/ansi.js";
import { formatHealthCheckFailure } from "./health-format.js";
describe("formatHealthCheckFailure", () => {
it("keeps non-rich output stable", () => {
const err = new Error("gateway closed (1006 abnormal closure): no close reason");
expect(formatHealthCheckFailure(err, { rich: false })).toBe(
`Health check failed: ${String(err)}`,
);
});
it("formats gateway connection details as indented key/value lines", () => {
const err = new Error(
[
"gateway closed (1006 abnormal closure (no close frame)): no close reason",
"Gateway target: ws://127.0.0.1:19001",
"Source: local loopback",
"Config: /Users/steipete/.openclaw-dev/openclaw.json",
"Bind: loopback",
].join("\n"),
);
expect(stripAnsi(formatHealthCheckFailure(err, { rich: true }))).toBe(
[
"Health check failed: gateway closed (1006 abnormal closure (no close frame)): no close reason",
" Gateway target: ws://127.0.0.1:19001",
" Source: local loopback",
" Config: /Users/steipete/.openclaw-dev/openclaw.json",
" Bind: loopback",
].join("\n"),
);
});
});